if (!Mark || !elasticlunr) {
return;
}
-
+
+ //IE 11 Compatibility from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith
+ if (!String.prototype.startsWith) {
+ String.prototype.startsWith = function(search, pos) {
+ return this.substr(!pos || pos < 0 ? 0 : +pos, search.length) === search;
+ };
+ }
+
var search_wrap = document.getElementById('search-wrapper'),
searchbar = document.getElementById('searchbar'),
searchbar_outer = document.getElementById('searchbar-outer'),
content = document.getElementById('content'),
searchindex = null,
- resultsoptions = {
+ doc_urls = [],
+ results_options = {
teaser_word_count: 30,
limit_results: 30,
},
- searchoptions = {
+ search_options = {
bool: "AND",
expand: true,
fields: {
teaser_count++;
// The ?URL_MARK_PARAM= parameter belongs inbetween the page and the #heading-anchor
- var url = result.ref.split("#");
+ var url = doc_urls[result.ref].split("#");
if (url.length == 1) { // no anchor found
url.push("");
}
- return '<a href="' + url[0] + '?' + URL_MARK_PARAM + '=' + searchterms + '#' + url[1]
+ return '<a href="' + path_to_root + url[0] + '?' + URL_MARK_PARAM + '=' + searchterms + '#' + url[1]
+ '" aria-details="teaser_' + teaser_count + '">' + result.doc.breadcrumbs + '</a>'
+ '<span class="teaser" id="teaser_' + teaser_count + '" aria-label="Search Result Teaser">'
+ teaser + '</span>';
}
var window_weight = [];
- var window_size = Math.min(weighted.length, resultsoptions.teaser_word_count);
+ var window_size = Math.min(weighted.length, results_options.teaser_word_count);
var cur_sum = 0;
for (var wordindex = 0; wordindex < window_size; wordindex++) {
return teaser_split.join('');
}
- function init() {
- resultsoptions = window.search.resultsoptions;
- searchoptions = window.search.searchoptions;
- searchbar_outer = window.search.searchbar_outer;
- searchindex = elasticlunr.Index.load(window.search.index);
+ function init(config) {
+ results_options = config.results_options;
+ search_options = config.search_options;
+ searchbar_outer = config.searchbar_outer;
+ doc_urls = config.doc_urls;
+ searchindex = elasticlunr.Index.load(config.index);
// Set up events
searchicon.addEventListener('click', function(e) { searchIconClickHandler(); }, false);
if (searchindex == null) { return; }
// Do the actual search
- var results = searchindex.search(searchterm, searchoptions);
- var resultcount = Math.min(results.length, resultsoptions.limit_results);
+ var results = searchindex.search(searchterm, search_options);
+ var resultcount = Math.min(results.length, results_options.limit_results);
// Display search metrics
searchresults_header.innerText = formatSearchMetric(resultcount, searchterm);
showResults(true);
}
- init();
+ fetch(path_to_root + 'searchindex.json')
+ .then(response => response.json())
+ .then(json => init(json))
+ .catch(error => { // Try to load searchindex.js if fetch failed
+ var script = document.createElement('script');
+ script.src = path_to_root + 'searchindex.js';
+ script.onload = () => init(window.search);
+ document.head.appendChild(script);
+ });
+
// Exported functions
search.hasFocus = hasFocus;
})(window.search);