From 826e222f80abf6c70282c6cd6a7d4621555d03ce Mon Sep 17 00:00:00 2001
From: Andreas Gohr <gohr@cosmocode.de>
Date: Wed, 28 Mar 2018 16:14:18 +0200
Subject: [PATCH] show adavanced tools with JavaScript only

---
 inc/Ui/Search.php     |  5 -----
 inc/lang/en/lang.php  |  2 +-
 lib/scripts/search.js | 16 ++++++++++------
 3 files changed, 11 insertions(+), 12 deletions(-)

diff --git a/inc/Ui/Search.php b/inc/Ui/Search.php
index 9535c3640..47171902f 100644
--- a/inc/Ui/Search.php
+++ b/inc/Ui/Search.php
@@ -187,11 +187,6 @@ class Search extends Ui
      */
     protected function addSearchAssistanceElements(Form $searchForm)
     {
-        global $lang;
-        $searchForm->addButton('toggleAssistant', $lang['search_toggle_tools'])
-            ->attr('type', 'button')
-            ->addClass('toggleAssistant');
-
         $searchForm->addTagOpen('div')
             ->addClass('advancedOptions')
             ->attr('style', 'display: none;')
diff --git a/inc/lang/en/lang.php b/inc/lang/en/lang.php
index b60cdd0a9..4d11bac08 100644
--- a/inc/lang/en/lang.php
+++ b/inc/lang/en/lang.php
@@ -72,7 +72,7 @@ $lang['nosecedit']             = 'The page was changed in the meantime, section
 $lang['searchcreatepage']      = 'If you didn\'t find what you were looking for, you can create or edit the page %s, named after your query.';
 
 $lang['search_fullresults']    = 'Fulltext results';
-$lang['search_toggle_tools']   = 'Toggle search tools';
+$lang['js']['search_toggle_tools']   = 'Toggle Search Tools';
 $lang['search_exact_match']    = 'Exact match';
 $lang['search_starts_with']    = 'Starts with';
 $lang['search_ends_with']      = 'Ends with';
diff --git a/lib/scripts/search.js b/lib/scripts/search.js
index c6171256f..363170825 100644
--- a/lib/scripts/search.js
+++ b/lib/scripts/search.js
@@ -6,10 +6,13 @@ jQuery(function () {
         return;
     }
 
-    const $toggleAssistanceButton = $searchForm.find('button.toggleAssistant');
-    if (!$toggleAssistanceButton.length) {
-        return;
-    }
+    const $toggleAssistanceButton = jQuery('<button>')
+        .addClass('toggleAssistant')
+        .attr('type', 'button')
+        .attr('aria-expanded', 'false')
+        .text(LANG.search_toggle_tools)
+        .prependTo($searchForm.find('fieldset'))
+    ;
 
     $toggleAssistanceButton.on('click', function () {
         jQuery('.advancedOptions').toggle(0, function () {
@@ -17,15 +20,16 @@ jQuery(function () {
             if ($me.attr('aria-hidden')) {
                 $me.removeAttr('aria-hidden');
                 $toggleAssistanceButton.attr('aria-expanded', 'true');
+                DokuCookie.setValue('sa', 'on');
             } else {
                 $me.attr('aria-hidden', 'true');
                 $toggleAssistanceButton.attr('aria-expanded', 'false');
+                DokuCookie.setValue('sa', 'off');
             }
         });
-        DokuCookie.setValue('sa', !DokuCookie.getValue('sa'));
     });
 
-    if (DokuCookie.getValue('sa')) {
+    if (DokuCookie.getValue('sa') === 'on') {
         $toggleAssistanceButton.click();
     }
 
-- 
GitLab