Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/vantagedesign/ace-documentation.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/static
diff options
context:
space:
mode:
Diffstat (limited to 'static')
-rw-r--r--static/plugins/search.js21
1 files changed, 15 insertions, 6 deletions
diff --git a/static/plugins/search.js b/static/plugins/search.js
index 08afa15..80eed2a 100644
--- a/static/plugins/search.js
+++ b/static/plugins/search.js
@@ -5,7 +5,7 @@ function endsWith(str, suffix) {
}
// Initialize lunrjs using our generated index file
-function initLunr() {
+function initLunr(success_callback) {
if (!endsWith(baseurl,"/")){
baseurl = baseurl+'/'
};
@@ -13,10 +13,10 @@ function initLunr() {
// First retrieve the index file
$.getJSON(baseurl +"index.json")
.done(function(index) {
- pagesIndex = index;
+ pagesIndex = index;
// Set up lunrjs by declaring the fields we use
// Also provide their boost level for the ranking
- lunrIndex = new lunr.Index
+ lunrIndex = new lunr.Index;
lunrIndex.ref("uri");
lunrIndex.field('title', {
boost: 15
@@ -33,6 +33,7 @@ function initLunr() {
lunrIndex.add(page);
});
lunrIndex.pipeline.remove(lunrIndex.stemmer)
+ success_callback();
})
.fail(function(jqxhr, textStatus, error) {
var err = textStatus + ", " + error;
@@ -55,9 +56,7 @@ function search(query) {
});
}
-// Let's get started
-initLunr();
-$( document ).ready(function() {
+function configure_completion() {
var searchList = new autoComplete({
/* selector for the search box element */
selector: $("#search-by").get(0),
@@ -88,4 +87,14 @@ $( document ).ready(function() {
location.href = item.getAttribute('data-uri');
}
});
+};
+
+$( document ).ready(function() {
+ // configure lazy loading of the search database
+ $("#search-by").focusin(function() {
+ // download and initialize the index only once
+ if (typeof lunrIndex == 'undefined') {
+ initLunr(configure_completion);
+ }
+ });
});