summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2020-10-23 11:29:17 +0200
committerYorhel <git@yorhel.nl>2020-10-23 11:29:19 +0200
commit9279d0396ffe48897874571a5331f26e1a7d1ee2 (patch)
tree214394c7595f2fbdf8afa084e6f86ef6aa617079
parenta41ba6e59347dea2cc8d33ab11783ecda59232eb (diff)
Fix searchtabs taking over the query when switching tabs
Fixes https://vndb.org/t2520.505
-rw-r--r--elm/searchtabs.js11
-rw-r--r--lib/VNWeb/HTML.pm4
2 files changed, 14 insertions, 1 deletions
diff --git a/elm/searchtabs.js b/elm/searchtabs.js
new file mode 100644
index 00000000..eed07ffc
--- /dev/null
+++ b/elm/searchtabs.js
@@ -0,0 +1,11 @@
+document.querySelectorAll('#searchtabs a').forEach(function(l) {
+ l.onclick = function() {
+ var str = document.getElementById('q').value;
+ if(str.length > 1) {
+ if(this.href.indexOf('/g') >= 0 || this.href.indexOf('/i') >= 0)
+ this.href += '/list';
+ this.href += '?q=' + encodeURIComponent(str);
+ }
+ return true;
+ };
+});
diff --git a/lib/VNWeb/HTML.pm b/lib/VNWeb/HTML.pm
index 3cc13494..5c0fa3e0 100644
--- a/lib/VNWeb/HTML.pm
+++ b/lib/VNWeb/HTML.pm
@@ -468,7 +468,7 @@ sub _scripts_ {
lit_(JSON::XS->new->canonical->encode(tuwf->req->{pagevars}) =~ s{</}{<\\/}rg =~ s/<!--/<\\u0021--/rg);
} if keys tuwf->req->{pagevars}->%*;
script_ type => 'application/javascript', src => config->{url_static}.'/f/elm.js?'.config->{version}, '' if tuwf->req->{pagevars}{elm};
- script_ type => 'application/javascript', src => config->{url_static}.'/f/plain.js?'.config->{version}, '' if $o->{js} || tuwf->req->{pagevars}{elm};
+ script_ type => 'application/javascript', src => config->{url_static}.'/f/plain.js?'.config->{version}, '' if tuwf->req->{js} || tuwf->req->{pagevars}{elm};
}
@@ -490,6 +490,7 @@ sub framework_ {
my $cont = pop;
my %o = @_;
tuwf->req->{pagevars} = { $o{pagevars}->%* } if $o{pagevars};
+ tuwf->req->{js} ||= $o{js};
html_ lang => 'en', sub {
head_ sub { _head_ \%o };
@@ -787,6 +788,7 @@ sub sortable_ {
sub searchbox_ {
my($sel, $value) = @_;
+ tuwf->req->{js} = 1;
fieldset_ class => 'search', sub {
p_ id => 'searchtabs', sub {
a_ href => '/v/all', $sel eq 'v' ? (class => 'sel') : (), 'Visual novels';