/* This file is part of Natural Docs, which is Copyright © 2003-2022 Code Clear LLC. Natural Docs is licensed under version 3 of the GNU Affero General Public License (AGPL). Refer to License.txt or www.naturaldocs.org for the complete details. This file may be distributed with documentation files generated by Natural Docs. Such documentation is not covered by Natural Docs' copyright and licensing, and may have its own copyright and distribution terms as decided by its author. */ "use strict";var NDSearch=new function(){this.Start=function(){this.domSearchField=document.getElementById("NDSearchField");this.domResults=document.createElement("div");this.domResults.id="NDSearchResults";this.domResults.style.display="none";this.domResults.style.position="fixed";this.domResultsContent=document.createElement("div");this.domResultsContent.id="SeContent";this.domResults.appendChild(this.domResultsContent);document.body.appendChild(this.domResults);this.initialTimeoutStatus=1;this.topLevelEntryCount=0;this.visibleEntryCount=0;this.openParents=[];this.keyboardSelectionIndex=-1;this.moreResultsThreshold=25;this.allPrefixesStatus=1;this.prefixObjects={};this.domSearchField.onfocus=function(){NDSearch.OnSearchFieldFocus();};this.domSearchField.onkeydown=function(event){NDSearch.OnSearchFieldKey(event);};this.domSearchField.oninput=function(event){NDSearch.OnSearchFieldChange(event);};this.domResults.onfocus=function(){NDSearch.OnResultsFocus();};this.DeactivateSearchField();};this.Update=function(){if(!this.SearchFieldIsActive()){return;}var searchInterpretations=this.GetSearchInterpretations();if(searchInterpretations.length==0){this.ClearResults();return;}if(this.allPrefixesStatus!=3){this.ClearResults(true);this.domResultsContent.innerHTML=this.BuildSearchingStatus();this.ShowResults();return;}var searchInterpretationPrefixes=this.GetMatchingPrefixes(searchInterpretations);this.RemoveUnusedPrefixObjects(searchInterpretationPrefixes);if(searchInterpretationPrefixes.length==0){this.ClearResults(true);this.domResultsContent.innerHTML=this.BuildNoMatchesStatus();this.ShowResults();return;}var location=new NDLocation(window.location.hash);var favorClasses=(location.type!="File");var forceExpansion=(this.TotalMatchesGreaterThan(searchInterpretations,searchInterpretationPrefixes,10)===false);var buildResults=this.BuildResults(searchInterpretations,searchInterpretationPrefixes,favorClasses,forceExpansion);var oldScrollTop=this.domResults.scrollTop;this.domResultsContent.innerHTML=buildResults.html;this.ShowResults();this.domResults.scrollTop=oldScrollTop;if(this.keyboardSelectionIndex!=-1){var domSelectedEntry=document.getElementById("SeSelectedEntry");if(domSelectedEntry!=undefined){this.ScrollEntryIntoView(domSelectedEntry,false);}}if(buildResults.prefixDataToLoad!=undefined){this.LoadPrefixData(buildResults.prefixDataToLoad);}};this.ClearResults=function(internalOnly){if(this.updateTimeout!=undefined){clearTimeout(this.updateTimeout);this.updateTimeout=undefined;}if(this.initialTimeout!=undefined){clearTimeout(this.initialTimeout);this.initialTimeout=undefined;}this.initialTimeoutStatus=1;if(!internalOnly){this.HideResults();}this.visibleEntryCount=0;this.topLevelEntryCount=0;this.openParents=[];this.keyboardSelectionIndex=-1;this.moreResultsThreshold=25;this.prefixObjects={};};this.ToggleParent=function(topLevelIndex,fromKeyboard){var openParentsIndex=this.openParents.indexOf(topLevelIndex);var opening=(openParentsIndex==-1);if(opening){this.openParents.push(topLevelIndex);}else{this.openParents.splice(openParentsIndex,1);}if(!fromKeyboard){this.keyboardSelectionIndex=-1;this.domSearchField.focus();}this.Update();if(opening){var children=this.domResultsContent.children;var topLevelCount=0;var domToggledElement=undefined;for(var i=0;i0){this.domResults.scrollTop--;}};this.LoadMoreResults=function(){this.moreResultsThreshold=this.visibleEntryCount+25;this.domSearchField.focus();this.Update();};this.ActivateLinkFromKeyboard=function(domLink){var address=domLink.getAttribute("href");if(address.substr(0,11)=="javascript:"){address=address.substr(11);address=address.replace(/^(NDSearch.ToggleParent\([0-9]+,)false(.*)$/,"$1true$2");eval(address);}else{location.href=address;}};this.OnSearchFieldFocus=function(){if(!this.SearchFieldIsActive()){this.ActivateSearchField();if(this.allPrefixesStatus==1){this.allPrefixesStatus=2;NDCore.LoadJavaScript("search/index.js");}}};this.OnSearchFieldKey=function(event){if(event===undefined){event=window.event;}if(event.keyCode==27){this.ClearResults();this.DeactivateSearchField();this.domSearchField.blur();document.getElementById("CFrame").contentWindow.focus();}else if(event.keyCode==38){if(this.keyboardSelectionIndex<=0){this.keyboardSelectionIndex=this.visibleEntryCount-1;}else{this.keyboardSelectionIndex--;}this.UpdateSelection();}else if(event.keyCode==40){if(this.visibleEntryCount==0){this.keyboardSelectionIndex=-1;}else if(this.keyboardSelectionIndex>=this.visibleEntryCount-1){this.keyboardSelectionIndex=0;}else{this.keyboardSelectionIndex++;}this.UpdateSelection();}else if(event.keyCode==37){if(this.keyboardSelectionIndex!=-1){var domSelectedEntry=document.getElementById("SeSelectedEntry");if(NDCore.HasClass(domSelectedEntry,"SeParent")&&NDCore.HasClass(domSelectedEntry,"open")){this.ActivateLinkFromKeyboard(domSelectedEntry);}}}else if(event.keyCode==39){if(this.keyboardSelectionIndex!=-1){var domSelectedEntry=document.getElementById("SeSelectedEntry");if(NDCore.HasClass(domSelectedEntry,"SeParent")&&NDCore.HasClass(domSelectedEntry,"closed")){this.ActivateLinkFromKeyboard(domSelectedEntry);}}}else if(event.keyCode==13){var domSelectedEntry=undefined;if(this.keyboardSelectionIndex!=-1){domSelectedEntry=document.getElementById("SeSelectedEntry");}else if(this.visibleEntryCount==1){domSelectedEntry=this.domResultsContent.firstChild;}else if(this.visibleEntryCount==2&&NDCore.HasClass(this.domResultsContent.firstChild,"SeParent")){domSelectedEntry=this.domResultsContent.childNodes[1].firstChild;}if(domSelectedEntry!=undefined){this.ActivateLinkFromKeyboard(domSelectedEntry);}else if(this.keyboardSelectionIndex==-1&&this.visibleEntryCount>0){this.keyboardSelectionIndex=0;this.UpdateSelection();}}};this.OnSearchFieldChange=function(event){if(event===undefined){event=window.event;}this.keyboardSelectionIndex=-1;if(this.initialTimeoutStatus==3){if(this.updateTimeout==undefined){this.updateTimeout=setTimeout(function(){clearTimeout(NDSearch.updateTimeout);NDSearch.updateTimeout=undefined;NDSearch.Update();},350);}}else{var searchInterpretations=this.GetSearchInterpretations();if(searchInterpretations.length!=0&&this.allPrefixesStatus==3&&this.GetMatchingPrefixes(searchInterpretations).length<=1){if(this.initialTimeoutStatus==2){clearTimeout(this.initialTimeout);this.initialTimeout=undefined;}this.initialTimeoutStatus=3;this.Update();}else if(this.initialTimeoutStatus==1){this.initialTimeoutStatus=2;this.initialTimeout=setTimeout(function(){if(NDSearch.initialTimeoutStatus==2){clearTimeout(NDSearch.initialTimeout);NDSearch.initialTimeout=undefined;NDSearch.initialTimeoutStatus=3;NDSearch.Update();}},1250);}}};this.OnResultsFocus=function(){this.domSearchField.focus();};this.OnUpdateLayout=function(){if(this.domResults!=undefined){this.PositionResults();if(this.keyboardSelectionIndex!=-1){var domSelectedEntry=document.getElementById("SeSelectedEntry");if(domSelectedEntry!=undefined){this.ScrollEntryIntoView(domSelectedEntry,false);}}}};this.GetSearchInterpretations=function(){var interpretations=[];var normalizedSearchText=this.domSearchField.value.toLowerCase();normalizedSearchText=normalizedSearchText.replace(/\s+/g," ");normalizedSearchText=normalizedSearchText.replace(/^ /,"");normalizedSearchText=normalizedSearchText.replace(/ $/,"");normalizedSearchText=normalizedSearchText.replace(/([^a-z0-9_]) /g,"$1");normalizedSearchText=normalizedSearchText.replace(/ (?=[^a-z0-9_])/g,"");normalizedSearchText=normalizedSearchText.replace(/::|->/g,".");normalizedSearchText=normalizedSearchText.replace(/\\/g,"/");normalizedSearchText=normalizedSearchText.replace(/^[./]+/,"");if(normalizedSearchText==""){return interpretations;}interpretations.push(normalizedSearchText);var lastChar=normalizedSearchText.charAt(normalizedSearchText.length-1);if(lastChar==":"||lastChar=="-"){interpretations.push(normalizedSearchText.substr(0,normalizedSearchText.length-1)+".");}return interpretations;};this.GetMatchingPrefixes=function(searchTextArray){var matchingPrefixes=[];if(this.allPrefixesStatus!=3){return matchingPrefixes;}for(var i=0;i=searchPrefix.length&&this.allPrefixes[prefixIndex].substr(0,searchPrefix.length)==searchPrefix){matchingPrefixes.push(this.allPrefixes[prefixIndex]);prefixIndex++;}else{break;}}}}if(searchTextArray.length<=1){return matchingPrefixes;}matchingPrefixes.sort();for(var i=1;i>1;if(prefix==this.allPrefixes[testIndex]){return testIndex;}else if(prefixmaximum){return true;}}}}}}return false;};this.BuildResults=function(searchInterpretations,searchInterpretationPrefixes,favorClasses,forceExpansion){var results={html:""};this.topLevelEntryCount=0;this.visibleEntryCount=0;var addSearchingStatus=false;for(var p=0;p"+"
"+lastMatchingMemberObject[1];if(lastMatchingMemberObject[0]!=undefined||lastMatchingMemberObject[2]!=undefined){html+="";if(lastMatchingMemberObject[0]!=undefined){html+=", "+lastMatchingMemberObject[0];}if(lastMatchingMemberObject[2]!=undefined){html+=", "+lastMatchingMemberObject[2];}html+="";}html+="";this.topLevelEntryCount++;this.visibleEntryCount++;return html;}else{var selected=(this.keyboardSelectionIndex==this.visibleEntryCount);var openClosed;if(forceExpansion||this.openParents.indexOf(this.topLevelEntryCount)!=-1){openClosed="open";}else{openClosed="closed";}var html=""+"
"+keywordObject[0]+" ("+memberMatches+")"+"
";this.topLevelEntryCount++;this.visibleEntryCount++;if(openClosed=="open"){html+="
";for(var i=0;i"+"
"+memberObject[1];if(memberObject[0]!=undefined||memberObject[2]!=undefined){html+="";if(memberObject[0]!=undefined){html+=", "+memberObject[0];}if(memberObject[2]!=undefined){html+=", "+memberObject[2];}html+="";}html+="";this.visibleEntryCount++;}}html+="
";}return html;}};this.BuildSearchingStatus=function(){return"
"+"Searching..."+"
";};this.BuildNoMatchesStatus=function(){return"
"+"No Matches"+"
";};this.BuildMoreResultsEntry=function(){var selected=(this.keyboardSelectionIndex==this.visibleEntryCount);var html=""+"
"+"More Results..."+"
";this.visibleEntryCount++;this.topLevelEntryCount++;return html;};this.MakePrefix=function(searchText){var prefix="";for(var i=0;i<3;i++){if(i>=searchText.length){break;}var char=searchText.charAt(i);if(char==" "||char=="."||char=="/"){break;}prefix+=char;}if(prefix.length>0){return prefix;}else{return undefined;}};this.PrefixToHex=function(prefix){var hex="";for(var i=0;imaxHeight){this.domResults.style.height=maxHeight+"px";}if(this.domResults.offsetWidth>maxWidth){this.domResults.style.width=maxWidth+"px";}else if(this.domResults.offsetWidthitemTop){offset=itemTop-windowTop;}if(offset!=0){this.domResults.scrollTop+=offset;}};this.OnPrefixIndexLoaded=function(prefixes){this.allPrefixes=prefixes;this.allPrefixesStatus=3;if(this.initialTimeoutStatus==3){this.Update();}};this.LoadPrefixData=function(prefix){if(this.prefixObjects[prefix]==undefined){var prefixObject=[];prefixObject[0]=prefix;prefixObject[2]=false;prefixObject[3]="NDPrefixLoader_"+this.PrefixToHex(prefix);this.prefixObjects[prefix]=prefixObject;NDCore.LoadJavaScript(this.PrefixToDataFile(prefix),prefixObject[3]);}};this.OnPrefixDataLoaded=function(prefix,commentTypes,keywordObjects){var prefixObject=this.prefixObjects[prefix];if(prefixObject==undefined){return;}for(var k=0;k