2015-06-04 17:37:22 +03:00
|
|
|
require([
|
2018-04-19 19:08:26 +03:00
|
|
|
base_url + '/mkdocs/js/mustache.min.js',
|
|
|
|
base_url + '/mkdocs/js/lunr.min.js',
|
2015-06-04 17:37:22 +03:00
|
|
|
'text!search-results-template.mustache',
|
2018-04-19 19:08:26 +03:00
|
|
|
'text!../search_index.json',
|
2015-06-04 17:37:22 +03:00
|
|
|
], function (Mustache, lunr, results_template, data) {
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
function getSearchTerm()
|
|
|
|
{
|
|
|
|
var sPageURL = window.location.search.substring(1);
|
|
|
|
var sURLVariables = sPageURL.split('&');
|
|
|
|
for (var i = 0; i < sURLVariables.length; i++)
|
|
|
|
{
|
|
|
|
var sParameterName = sURLVariables[i].split('=');
|
|
|
|
if (sParameterName[0] == 'q')
|
|
|
|
{
|
2016-06-24 13:07:42 +03:00
|
|
|
return decodeURIComponent(sParameterName[1].replace(/\+/g, '%20'));
|
2015-06-04 17:37:22 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var index = lunr(function () {
|
|
|
|
this.field('title', {boost: 10});
|
|
|
|
this.field('text');
|
|
|
|
this.ref('location');
|
|
|
|
});
|
|
|
|
|
|
|
|
data = JSON.parse(data);
|
|
|
|
var documents = {};
|
|
|
|
|
|
|
|
for (var i=0; i < data.docs.length; i++){
|
|
|
|
var doc = data.docs[i];
|
|
|
|
doc.location = base_url + doc.location;
|
|
|
|
index.add(doc);
|
|
|
|
documents[doc.location] = doc;
|
|
|
|
}
|
|
|
|
|
|
|
|
var search = function(){
|
|
|
|
|
|
|
|
var query = document.getElementById('mkdocs-search-query').value;
|
|
|
|
var search_results = document.getElementById("mkdocs-search-results");
|
|
|
|
while (search_results.firstChild) {
|
|
|
|
search_results.removeChild(search_results.firstChild);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(query === ''){
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var results = index.search(query);
|
|
|
|
|
|
|
|
if (results.length > 0){
|
|
|
|
for (var i=0; i < results.length; i++){
|
|
|
|
var result = results[i];
|
|
|
|
doc = documents[result.ref];
|
|
|
|
doc.base_url = base_url;
|
|
|
|
doc.summary = doc.text.substring(0, 200);
|
|
|
|
var html = Mustache.to_html(results_template, doc);
|
|
|
|
search_results.insertAdjacentHTML('beforeend', html);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
search_results.insertAdjacentHTML('beforeend', "<p>No results found</p>");
|
|
|
|
}
|
|
|
|
|
|
|
|
if(jQuery){
|
|
|
|
/*
|
|
|
|
* We currently only automatically hide bootstrap models. This
|
|
|
|
* requires jQuery to work.
|
|
|
|
*/
|
|
|
|
jQuery('#mkdocs_search_modal a').click(function(){
|
|
|
|
jQuery('#mkdocs_search_modal').modal('hide');
|
2017-03-27 13:20:12 +03:00
|
|
|
});
|
2015-06-04 17:37:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
var search_input = document.getElementById('mkdocs-search-query');
|
|
|
|
|
|
|
|
var term = getSearchTerm();
|
|
|
|
if (term){
|
|
|
|
search_input.value = term;
|
|
|
|
search();
|
|
|
|
}
|
|
|
|
|
2018-04-19 19:08:26 +03:00
|
|
|
search_input.addEventListener("keyup", search);
|
2015-06-04 17:37:22 +03:00
|
|
|
|
|
|
|
});
|