jwebsite/_libs/lunr/lunrclient.min.js

2 lines
1.5 KiB
JavaScript
Raw Permalink Normal View History

2020-06-14 04:15:14 +00:00
"use strict";var LUNR_CONFIG={"resultsElementId":"searchResults","countElementId":"resultCount"};function getParameterByName(name){var url=window.location.href;name=name.replace(/[\[\]]/g,"\\$&");var regex=new RegExp("[?&]"+name+"(=([^&#]*)|&|#|$)"),results=regex.exec(url);if(!results){return null}if(!results[2]){return ""}return decodeURIComponent(results[2].replace(/\+/g," "))}function parseLunrResults(results){var html=[];for(var i=0;i<results.length;i+=1){var id=results[i]["ref"];var item=PREVIEW_LOOKUP[id];var title=item["t"];var preview=item["p"];var link=item["l"].replace("__site/","");var result=('<li><span class="result-title"><a href="'+link+'">'+title+'</a></span>');html.push(result)}if(html.length){html.join("");return '<ul>'+html+'</ul>'}else{return ""}}function escapeHtml(unsafe){return unsafe.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#039;")}function showResultCount(total){var element=document.getElementById(LUNR_CONFIG["countElementId"]);if(element!==null){element.innerHTML=total+"."}}function searchLunr(query){var idx=lunr.Index.load(LUNR_DATA);var results=idx.search(query);var resultHtml=parseLunrResults(results);var elementId=LUNR_CONFIG["resultsElementId"];document.getElementById(elementId).innerHTML=resultHtml;showResultCount(results.length)}window.onload=function(){var query=getParameterByName("q");if(query!=""&&query!=null){document.forms.lunrSearchForm.q.value=query;searchLunr(query)}else{showResultCount("0 (empty query)")}document.getElementById("focus").focus()};