summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzx14 <zx14@vndb.org>2018-10-28 11:33:29 +0700
committerYorhel <git@yorhel.nl>2018-10-28 18:51:01 +0100
commit0687115f993831353674397857f697e5be0c01f6 (patch)
tree5e6da589645737c3b3cb00c2b337cddb2a11d339
parentc26cf6eded734cc79c6dfdfd8ed2a81aabe9fe0b (diff)
Add JS-less NSFW screenshot toggle
(cherry picked from commit 6446d7d185543440b97be009fdf2a1f0c379b26f)
-rw-r--r--data/js/misc.js19
-rw-r--r--data/style.css3
-rw-r--r--lib/VNDB/Handler/VNPage.pm13
3 files changed, 12 insertions, 23 deletions
diff --git a/data/js/misc.js b/data/js/misc.js
index 57c40ba5..1d667313 100644
--- a/data/js/misc.js
+++ b/data/js/misc.js
@@ -79,25 +79,6 @@ if(byId('listsel'))
ulist_redirect('[rv]', '/list', this.name, 'e='+this.options[this.selectedIndex].value);
};
-// NSFW toggle for screenshots (/v+)
-if(byId('nsfwhide'))
- byId('nsfwhide').onclick = function() {
- var shown = 0;
- var l = byClass(byId('screenshots'), 'a', 'scrlnk');
- for(var i=0; i<l.length; i++) {
- if(hasClass(l[i], 'nsfw')) {
- var hidden = !hasClass(l[i], 'hidden');
- setClass(l[i], 'hidden', hidden);
- if(!hidden)
- shown++;
- } else
- shown++;
- }
- setText(byId('nsfwshown'), shown);
- return false;
- };
-
-
// Notification list onclick
(function(){
var d = byId('notifies');
diff --git a/data/style.css b/data/style.css
index 4b979bad..036220a7 100644
--- a/data/style.css
+++ b/data/style.css
@@ -353,6 +353,9 @@ h1.boxtitle, h1.boxtitle a {
#nsfw_chk:checked ~ * > #nsfw_show { display: none; }
#nsfw_chk:not(:checked) ~ * > #nsfw_hid { display: none; }
+#nsfwhide_chk:checked ~ * #nsfwshown { display: none; }
+#nsfwhide_chk:not(:checked) ~ * .nsfw { display: none; }
+
div.vndetails { margin: 0 auto; max-width: 820px; }
div.vnimg { float: left; width: 250px; margin: 0 10px; }
div.vnimg i { display: block; width: 100%; text-align: center; font-size: 11px; }
diff --git a/lib/VNDB/Handler/VNPage.pm b/lib/VNDB/Handler/VNPage.pm
index 3502cb13..be60558e 100644
--- a/lib/VNDB/Handler/VNPage.pm
+++ b/lib/VNDB/Handler/VNPage.pm
@@ -901,15 +901,20 @@ sub _release_icons {
sub _screenshots {
my($self, $v, $r) = @_;
- div class => 'mainbox', id => 'screenshots';
if(grep $_->{nsfw}, @{$v->{screenshots}}) {
+ input id => 'nsfwhide_chk', type => 'checkbox', class => 'visuallyhidden', $self->authPref('show_nsfw') ? (checked => 'checked') : ();
+ div class => 'mainbox', id => 'screenshots';
+
p class => 'nsfwtoggle';
txt 'Showing ';
- i id => 'nsfwshown', $self->authPref('show_nsfw') ? scalar @{$v->{screenshots}} : scalar grep(!$_->{nsfw}, @{$v->{screenshots}});
+ i id => 'nsfwshown', scalar grep(!$_->{nsfw}, @{$v->{screenshots}});
+ span class => 'nsfw', scalar @{$v->{screenshots}};
txt sprintf ' out of %d screenshot%s. ', scalar @{$v->{screenshots}}, @{$v->{screenshots}} == 1 ? '' : 's';
- a href => '#', id => "nsfwhide", 'show/hide NSFW';
+ label for => 'nsfwhide_chk', class => 'fake_link', 'show/hide NSFW';
end;
+ } else {
+ div class => 'mainbox', id => 'screenshots';
}
h1 'Screenshots';
@@ -926,7 +931,7 @@ sub _screenshots {
for (@scr) {
my($w, $h) = imgsize($_->{width}, $_->{height}, @{$self->{scr_size}});
a href => imgurl(sf => $_->{id}),
- class => sprintf('scrlnk%s%s', $_->{nsfw} ? ' nsfw':'', $_->{nsfw}&&!$self->authPref('show_nsfw')?' hidden':''),
+ class => sprintf('scrlnk%s', $_->{nsfw} ? ' nsfw':''),
'data-iv' => "$_->{width}x$_->{height}:scr";
img src => imgurl(st => $_->{id}),
width => $w, height => $h, alt => "Screenshot #$_->{id}";