diff options
author | VirtualTam <virtualtam@flibidi.net> | 2017-08-01 19:00:03 +0200 |
---|---|---|
committer | VirtualTam <virtualtam@flibidi.net> | 2017-08-02 14:48:41 +0200 |
commit | 9ff77362fe3c132ac390399e184424edcbfcf90a (patch) | |
tree | 8fa58c4a9cf32c80b766527b8792c6b277532a0b /doc/html/mkdocs/js/search.js | |
parent | c71c7e2bd49be4123a79d0bf9a882ea516f07674 (diff) | |
download | Shaarli-9ff77362fe3c132ac390399e184424edcbfcf90a.tar.gz Shaarli-9ff77362fe3c132ac390399e184424edcbfcf90a.tar.zst Shaarli-9ff77362fe3c132ac390399e184424edcbfcf90a.zip |
documentation: remove generated HTML from SCM
Relates to https://github.com/shaarli/Shaarli/issues/908
Signed-off-by: VirtualTam <virtualtam@flibidi.net>
Diffstat (limited to 'doc/html/mkdocs/js/search.js')
-rw-r--r-- | doc/html/mkdocs/js/search.js | 88 |
1 files changed, 0 insertions, 88 deletions
diff --git a/doc/html/mkdocs/js/search.js b/doc/html/mkdocs/js/search.js deleted file mode 100644 index d5c86616..00000000 --- a/doc/html/mkdocs/js/search.js +++ /dev/null | |||
@@ -1,88 +0,0 @@ | |||
1 | require([ | ||
2 | base_url + '/mkdocs/js/mustache.min.js', | ||
3 | base_url + '/mkdocs/js/lunr.min.js', | ||
4 | 'text!search-results-template.mustache', | ||
5 | 'text!../search_index.json', | ||
6 | ], function (Mustache, lunr, results_template, data) { | ||
7 | "use strict"; | ||
8 | |||
9 | function getSearchTerm() | ||
10 | { | ||
11 | var sPageURL = window.location.search.substring(1); | ||
12 | var sURLVariables = sPageURL.split('&'); | ||
13 | for (var i = 0; i < sURLVariables.length; i++) | ||
14 | { | ||
15 | var sParameterName = sURLVariables[i].split('='); | ||
16 | if (sParameterName[0] == 'q') | ||
17 | { | ||
18 | return decodeURIComponent(sParameterName[1].replace(/\+/g, '%20')); | ||
19 | } | ||
20 | } | ||
21 | } | ||
22 | |||
23 | var index = lunr(function () { | ||
24 | this.field('title', {boost: 10}); | ||
25 | this.field('text'); | ||
26 | this.ref('location'); | ||
27 | }); | ||
28 | |||
29 | data = JSON.parse(data); | ||
30 | var documents = {}; | ||
31 | |||
32 | for (var i=0; i < data.docs.length; i++){ | ||
33 | var doc = data.docs[i]; | ||
34 | doc.location = base_url + doc.location; | ||
35 | index.add(doc); | ||
36 | documents[doc.location] = doc; | ||
37 | } | ||
38 | |||
39 | var search = function(){ | ||
40 | |||
41 | var query = document.getElementById('mkdocs-search-query').value; | ||
42 | var search_results = document.getElementById("mkdocs-search-results"); | ||
43 | while (search_results.firstChild) { | ||
44 | search_results.removeChild(search_results.firstChild); | ||
45 | } | ||
46 | |||
47 | if(query === ''){ | ||
48 | return; | ||
49 | } | ||
50 | |||
51 | var results = index.search(query); | ||
52 | |||
53 | if (results.length > 0){ | ||
54 | for (var i=0; i < results.length; i++){ | ||
55 | var result = results[i]; | ||
56 | doc = documents[result.ref]; | ||
57 | doc.base_url = base_url; | ||
58 | doc.summary = doc.text.substring(0, 200); | ||
59 | var html = Mustache.to_html(results_template, doc); | ||
60 | search_results.insertAdjacentHTML('beforeend', html); | ||
61 | } | ||
62 | } else { | ||
63 | search_results.insertAdjacentHTML('beforeend', "<p>No results found</p>"); | ||
64 | } | ||
65 | |||
66 | if(jQuery){ | ||
67 | /* | ||
68 | * We currently only automatically hide bootstrap models. This | ||
69 | * requires jQuery to work. | ||
70 | */ | ||
71 | jQuery('#mkdocs_search_modal a').click(function(){ | ||
72 | jQuery('#mkdocs_search_modal').modal('hide'); | ||
73 | }); | ||
74 | } | ||
75 | |||
76 | }; | ||
77 | |||
78 | var search_input = document.getElementById('mkdocs-search-query'); | ||
79 | |||
80 | var term = getSearchTerm(); | ||
81 | if (term){ | ||
82 | search_input.value = term; | ||
83 | search(); | ||
84 | } | ||
85 | |||
86 | search_input.addEventListener("keyup", search); | ||
87 | |||
88 | }); | ||