function initHotKeys() {
var bodyEl = document.body;
var searchInput = document.getElementById('search');
document.addEventListener('keydown', function (event) {
if (event.defaultPrevented) {
return;
}
var key = event.key || event.keyCode;
// ESC to close search window
if (key === 'Escape' || key === 'Esc' || key === 27) {
document.body.classList.remove('has-active-search-window');
}
// / to close toggle window
if (key === '/' || key === 'Period' || key === 58) {
event.preventDefault();
document.body.classList.toggle('has-active-search-window');
if (bodyEl.classList.contains('has-active-search-window')) {
searchInput.focus();
}
}
//when search is active TAB puts search input into focus
if (bodyEl.classList.contains('has-active-search-window')) {
if (key === 'Tab' || key === 'Tab' || key === 9) {
searchInput.focus();
}
}
});
};
// search functionality
function debounce(func, wait) {
var timeout;
return function () {
var context = this;
var args = arguments;
clearTimeout(timeout);
timeout = setTimeout(function () {
timeout = null;
func.apply(context, args);
}, wait);
};
}
// The strategy is as follows:
// First, assign a value to each word in the document:
// Words that correspond to search terms (stemmer aware): 40
// Normal words: 2
// First word in a sentence: 8
// Then use a sliding window with a constant number of words and count the
// sum of the values of the words within the window. Then use the window that got the
// maximum sum. If there are multiple maximas, then get the last one.
// Enclose the terms in .
function makeTeaser(body, terms) {
var TERM_WEIGHT = 40;
var NORMAL_WORD_WEIGHT = 2;
var FIRST_WORD_WEIGHT = 8;
//var TEASER_MAX_WORDS = 17;
var TEASER_MAX_CHARS = 63;
var stemmedTerms = terms.map(function (w) {
return elasticlunr.stemmer(w.toLowerCase());
});
var termFound = false;
var index = 0;
var weighted = []; // contains elements of ["word", weight, index_in_document]
// split in sentences, then words
var sentences = body.toLowerCase().split(". ");
for (var i in sentences) {
var words = sentences[i].split(" ");
var value = FIRST_WORD_WEIGHT;
for (var j in words) {
var word = words[j];
if (word.length > 0) {
for (var k in stemmedTerms) {
if (elasticlunr.stemmer(word).startsWith(stemmedTerms[k])) {
value = TERM_WEIGHT;
termFound = true;
}
}
weighted.push([word, value, index]);
value = NORMAL_WORD_WEIGHT;
}
index += word.length;
index += 1; // ' ' or '.' if last word in sentence
}
index += 1; // because we split at a two-char boundary '. '
}
if (weighted.length === 0) {
return body;
}
var windowWeights = [];
var windowSize = 0;
// loop over words (weighted) till max chars is reached adding a counter to windowSize every time a new word has passed
var sumChars = 0;
for (var i = 0; i < weighted.length; i++) {
sumChars += weighted[i][0].length;
if (sumChars <= TEASER_MAX_CHARS) {
windowSize++;
}
}
// We add a window with all the weights first
var curSum = 0;
for (var i = 0; i < windowSize; i++) {
curSum += weighted[i][1];
}
windowWeights.push(curSum);
for (var i = 0; i < weighted.length - windowSize; i++) {
curSum -= weighted[i][1];
curSum += weighted[i + windowSize][1];
windowWeights.push(curSum);
}
// If we didn't find the term, just pick the first window
var maxSumIndex = 0;
if (termFound) {
var maxFound = 0;
// backwards
for (var i = windowWeights.length - 1; i >= 0; i--) {
if (windowWeights[i] > maxFound) {
maxFound = windowWeights[i];
maxSumIndex = i;
}
}
}
var teaser = [];
var startIndex = weighted[maxSumIndex][2];
for (var i = maxSumIndex; i < maxSumIndex + windowSize; i++) {
var word = weighted[i];
if (startIndex < word[2]) {
// missing text from index to start of `word`
teaser.push(body.substring(startIndex, word[2]));
startIndex = word[2];
}
startIndex = word[2] + word[0].length;
teaser.push(body.substring(word[2], startIndex));
}
teaser.push("…");
return teaser.join("");
}
function formatSearchResultTitle(item) {
var pathArray = item.ref.split( '/' );
var firstPartTitle = pathArray[3];
let firstTitleCapitals = firstPartTitle.charAt(0).toUpperCase() + firstPartTitle.slice(1);
var lastPartTitle = item.doc.title;
var fullTitle = firstTitleCapitals + '' + ' / ' + lastPartTitle + '';
return fullTitle;
}
function formatSearchResultItem(item, terms) {
var li = document.createElement("li");
var createA = document.createElement("a");
li.appendChild(createA);
var teaserTitle = formatSearchResultTitle(item);
li.classList.add("search-results__item");
var hrefA = item.ref;
createA.setAttribute('href', hrefA);
createA.setAttribute('class','no-underline db pl1 pv2');
createA.innerHTML = `${teaserTitle}`;
createA.innerHTML += `↩`;
createA.innerHTML += `${rune.symbol} ${rune.name}
${rune.desc}
Read more in Documentation -> ` } } var results = index.search(term, options).filter(function (r) { return r.doc.body !== ""; }); if (results.length === 0) { searchResultsHeader.innerText = `No search results for '${term}'.`; return; } currentTerm = term; searchResultsHeader.innerText = `${results.length} search results for '${term}':`; for (var i = 0; i < Math.min(results.length, MAX_ITEMS); i++) { if (!results[i].doc.body) { continue; } searchResultsItems.appendChild(formatSearchResultItem(results[i], term.split(" "))); } }, 150)); // reset input button inputReset.onclick=function(){ document.getElementById('search-form').reset(); } searchForm.addEventListener("reset", function(event){ var e = document.createEvent('KeyboardEvent'); e.initEvent("keyup", false, true); searchInput.dispatchEvent(e); }); } if (document.readyState === "complete" || (document.readyState !== "loading" && !document.documentElement.doScroll) ) { initToggleSearchWindow(); } else { document.addEventListener("DOMContentLoaded", function () { initSearch(); initHotKeys(); }); } if (window.location.href.includes("docs")) { tippy('.tooltip', { content(reference) { const title = reference.getAttribute('title') reference.removeAttribute('title') return title }, animateFill: false, animation: 'fade' }) let docsSelect = document.getElementById('docsSelect'); let goTo = function() { let url = docsSelect.options[docsSelect.selectedIndex].value; if (url.startsWith("http")) { document.location.assign(url); } } docsSelect.addEventListener('change', goTo); } // same-page navigation on-scroll behaviour if (document.body.classList.contains("page-indiced")) { let h2 = document.getElementsByTagName("h2"); let h3 = document.getElementsByTagName("h3"); let all = document.querySelectorAll("nav li a"); let headers = document.querySelectorAll("details summary"); // smooth scrolling on click all.forEach(link => { link.addEventListener("click", event => { event.preventDefault(); let target = document.querySelector(event.target.hash); target.scrollIntoView({ behavior: "smooth", block: "start" }); }); }); let lastId; let cur = []; window.addEventListener("scroll", event => { let fromTop = window.scrollY; all.forEach(link => { let section = document.querySelector(link.hash); let sectionChildren = document.querySelector(link.hash).nextElementSibling; if ( ((section.offsetTop <= fromTop) || (sectionChildren.offsetTop <= fromTop)) && (section.offsetTop + section.offsetHeight + sectionChildren.offsetHeight > fromTop) ) { link.classList.add("current"); } else { link.classList.remove("current"); } }); })}; // homepage video load behaviour on mobile if (document.body.classList.contains("index")) { if( navigator.userAgent.match(/Android/i) || navigator.userAgent.match(/webOS/i) || navigator.userAgent.match(/iPhone/i) || navigator.userAgent.match(/iPad/i) || navigator.userAgent.match(/iPod/i) || navigator.userAgent.match(/BlackBerry/i) || navigator.userAgent.match(/Windows Phone/i) ){ } else { document.getElementById("landscapevid").innerHTML = `