aboutsummaryrefslogtreecommitdiffhomepage
path: root/doc/html/mkdocs/js/search.js
diff options
context:
space:
mode:
authorVirtualTam <virtualtam+github@flibidi.net>2017-08-05 10:40:35 +0200
committerGitHub <noreply@github.com>2017-08-05 10:40:35 +0200
commitb4ff0afb24db6e4cb3543bbd71f01bbb0716b144 (patch)
treef86caabf507fcd44db38353092f7b4476516bcd5 /doc/html/mkdocs/js/search.js
parent1fdb40fc169b42af7622610c4f088688de231118 (diff)
parent29712e905b8a9bdf1eaa21cbda3ca7c9eb215937 (diff)
downloadShaarli-b4ff0afb24db6e4cb3543bbd71f01bbb0716b144.tar.gz
Shaarli-b4ff0afb24db6e4cb3543bbd71f01bbb0716b144.tar.zst
Shaarli-b4ff0afb24db6e4cb3543bbd71f01bbb0716b144.zip
Merge pull request #910 from virtualtam/documentation/improvements
Include generated doc in release archives, remove HTML from SCM
Diffstat (limited to 'doc/html/mkdocs/js/search.js')
-rw-r--r--doc/html/mkdocs/js/search.js88
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 @@
1require([
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});