diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/exe/js.php | 1 | ||||
-rw-r--r-- | lib/scripts/search.js | 67 | ||||
-rw-r--r-- | lib/tpl/dokuwiki/css/_search.css | 16 |
3 files changed, 84 insertions, 0 deletions
diff --git a/lib/exe/js.php b/lib/exe/js.php index ee017a41e..4c614f080 100644 --- a/lib/exe/js.php +++ b/lib/exe/js.php @@ -47,6 +47,7 @@ function js_out(){ DOKU_INC.'lib/scripts/cookie.js', DOKU_INC.'lib/scripts/script.js', DOKU_INC.'lib/scripts/qsearch.js', + DOKU_INC.'lib/scripts/search.js', DOKU_INC.'lib/scripts/tree.js', DOKU_INC.'lib/scripts/index.js', DOKU_INC.'lib/scripts/textselection.js', diff --git a/lib/scripts/search.js b/lib/scripts/search.js new file mode 100644 index 000000000..0c9dca76a --- /dev/null +++ b/lib/scripts/search.js @@ -0,0 +1,67 @@ +jQuery(function () { + 'use strict'; + + const $searchForm = jQuery('.search-results-form'); + if (!$searchForm.length) { + return; + } + if (!$searchForm.find('#search-results-form__show-assistance-button').length){ + return; + } + const $toggleAssistanceButton = $searchForm.find('#search-results-form__show-assistance-button'); + const $queryInput = $searchForm.find('[name="id"]'); + const $termInput = $searchForm.find('[name="searchTerm"]'); + + $toggleAssistanceButton.on('click', function () { + jQuery('.js-advancedSearchOptions').toggle(); + $queryInput.toggle(); + $termInput.toggle(); + }); + + + const $matchTypeSwitcher = $searchForm.find('[name="matchType"]'); + const $namespaceSwitcher = $searchForm.find('[name="namespace"]'); + const $refiningElements = $termInput.add($matchTypeSwitcher).add($namespaceSwitcher); + $refiningElements.on('input change', function () { + $queryInput.val( + rebuildQuery( + $termInput.val(), + $matchTypeSwitcher.filter(':checked').val(), + $namespaceSwitcher.filter(':checked').val() + ) + ); + }); + + /** + * Rebuild the search query from the parts + * + * @param {string} searchTerm the word which is to be searched + * @param {enum} matchType the type of matching that is to be done + * @param {string} namespace list of namespaces to which to limit the search + * + * @return {string} the query string for the actual search + */ + function rebuildQuery(searchTerm, matchType, namespace) { + let query = ''; + + switch (matchType) { + case 'contains': + query = '*' + searchTerm + '*'; + break; + case 'starts': + query = '*' + searchTerm; + break; + case 'ends': + query = searchTerm + '*'; + break; + default: + query = searchTerm; + } + + if (namespace && namespace.length) { + query += ' @' + namespace; + } + + return query; + } +}); diff --git a/lib/tpl/dokuwiki/css/_search.css b/lib/tpl/dokuwiki/css/_search.css index a8972ae72..8da2652a2 100644 --- a/lib/tpl/dokuwiki/css/_search.css +++ b/lib/tpl/dokuwiki/css/_search.css @@ -12,6 +12,22 @@ margin-bottom: 1.4em; } +.search-results-form .search-results-form__fieldset { + width: 80vw; +} + +.search-results-form__show-assistance-button { + float: right; +} + +.search-results-form__no-assistance-message { + color: grey; + float: right; + font-size: 80%; + margin-top: -0.3em; +} + + /*____________ matching pagenames ____________*/ .dokuwiki div.search_quickresult { |