summaryrefslogtreecommitdiffstats
path: root/search/search.js
diff options
context:
space:
mode:
Diffstat (limited to 'search/search.js')
-rw-r--r--search/search.js116
1 files changed, 65 insertions, 51 deletions
diff --git a/search/search.js b/search/search.js
index 607f4e10..e103a262 100644
--- a/search/search.js
+++ b/search/search.js
@@ -73,6 +73,8 @@ function getYPos(item)
return y;
}
+var searchResults = new SearchResults("searchResults");
+
/* A class handling everything associated with the search panel.
Parameters:
@@ -80,7 +82,7 @@ function getYPos(item)
storing this instance. Is needed to be able to set timeouts.
resultPath - path to use for external files
*/
-function SearchBox(name, resultsPath, label, extension)
+function SearchBox(name, resultsPath, extension)
{
if (!name || !resultsPath) { alert("Missing parameters to SearchBox."); }
if (!extension || extension == "") { extension = ".html"; }
@@ -96,7 +98,6 @@ function SearchBox(name, resultsPath, label, extension)
this.hideTimeout = 0;
this.searchIndex = 0;
this.searchActive = false;
- this.searchLabel = label;
this.extension = extension;
// ----------- DOM Elements
@@ -188,7 +189,8 @@ function SearchBox(name, resultsPath, label, extension)
}
else
{
- window.frames.MSearchResults.postMessage("take_focus", "*");
+ var elem = searchResults.NavNext(0);
+ if (elem) elem.focus();
}
}
else if (e.keyCode==27) // Escape out of the search field
@@ -324,48 +326,66 @@ function SearchBox(name, resultsPath, label, extension)
idxChar = searchValue.substr(0, 2);
}
- var resultsPage;
- var resultsPageWithSearch;
- var hasResultsPage;
+ var jsFile;
var idx = indexSectionsWithContent[this.searchIndex].indexOf(idxChar);
if (idx!=-1)
{
var hexCode=idx.toString(16);
- resultsPage = this.resultsPath + '/' + indexSectionNames[this.searchIndex] + '_' + hexCode + this.extension;
- resultsPageWithSearch = resultsPage+'?'+escape(searchValue);
- hasResultsPage = true;
+ jsFile = this.resultsPath + indexSectionNames[this.searchIndex] + '_' + hexCode + '.js';
}
- else // nothing available for this search term
- {
- resultsPage = this.resultsPath + '/nomatches' + this.extension;
- resultsPageWithSearch = resultsPage;
- hasResultsPage = false;
+
+ var loadJS = function(url, impl, loc){
+ var scriptTag = document.createElement('script');
+ scriptTag.src = url;
+ scriptTag.onload = impl;
+ scriptTag.onreadystatechange = impl;
+ loc.appendChild(scriptTag);
}
- window.frames.MSearchResults.location = resultsPageWithSearch;
var domPopupSearchResultsWindow = this.DOMPopupSearchResultsWindow();
+ var domSearchBox = this.DOMSearchBox();
+ var domPopupSearchResults = this.DOMPopupSearchResults();
+ var domSearchClose = this.DOMSearchClose();
+ var resultsPath = this.resultsPath;
+
+ var handleResults = function() {
+ document.getElementById("Loading").style.display="none";
+ if (typeof searchData !== 'undefined') {
+ createResults(resultsPath);
+ document.getElementById("NoMatches").style.display="none";
+ }
+
+ searchResults.Search(searchValue);
- if (domPopupSearchResultsWindow.style.display!='block')
- {
- var domSearchBox = this.DOMSearchBox();
- this.DOMSearchClose().style.display = 'inline-block';
- var domPopupSearchResults = this.DOMPopupSearchResults();
- var left = getXPos(domSearchBox) + 150; // domSearchBox.offsetWidth;
- var top = getYPos(domSearchBox) + 20; // domSearchBox.offsetHeight + 1;
- domPopupSearchResultsWindow.style.display = 'block';
- left -= domPopupSearchResults.offsetWidth;
- var maxWidth = document.body.clientWidth;
- var width = 400;
- if (left<10) left=10;
- if (width+left+8>maxWidth) width=maxWidth-left-8;
- domPopupSearchResultsWindow.style.top = top + 'px';
- domPopupSearchResultsWindow.style.left = left + 'px';
- domPopupSearchResultsWindow.style.width = width + 'px';
+ if (domPopupSearchResultsWindow.style.display!='block')
+ {
+ domSearchClose.style.display = 'inline-block';
+ var left = getXPos(domSearchBox) + 150;
+ var top = getYPos(domSearchBox) + 20;
+ domPopupSearchResultsWindow.style.display = 'block';
+ left -= domPopupSearchResults.offsetWidth;
+ var maxWidth = document.body.clientWidth;
+ var maxHeight = document.body.clientHeight;
+ var width = 300;
+ if (left<10) left=10;
+ if (width+left+8>maxWidth) width=maxWidth-left-8;
+ var height = 400;
+ if (height+top+8>maxHeight) height=maxHeight-top-8;
+ domPopupSearchResultsWindow.style.top = top + 'px';
+ domPopupSearchResultsWindow.style.left = left + 'px';
+ domPopupSearchResultsWindow.style.width = width + 'px';
+ domPopupSearchResultsWindow.style.height = height + 'px';
+ }
+ }
+
+ if (jsFile) {
+ loadJS(jsFile, handleResults, this.DOMPopupSearchResultsWindow());
+ } else {
+ handleResults();
}
this.lastSearchValue = searchValue;
- this.lastResultsPage = resultsPage;
}
// -------- Activation Functions
@@ -379,22 +399,15 @@ function SearchBox(name, resultsPath, label, extension)
)
{
this.DOMSearchBox().className = 'MSearchBoxActive';
-
- var searchField = this.DOMSearchField();
-
- if (searchField.value == this.searchLabel) // clear "Search" term upon entry
- {
- searchField.value = '';
- this.searchActive = true;
- }
+ this.searchActive = true;
}
else if (!isActive) // directly remove the panel
{
this.DOMSearchBox().className = 'MSearchBoxInactive';
- this.DOMSearchField().value = this.searchLabel;
this.searchActive = false;
this.lastSearchValue = ''
this.lastResultsPage = '';
+ this.DOMSearchField().value = '';
}
}
}
@@ -623,7 +636,7 @@ function SearchResults(name)
}
else // return focus to search field
{
- parent.document.getElementById("MSearchField").focus();
+ document.getElementById("MSearchField").focus();
}
}
else if (this.lastKey==40) // Down
@@ -653,8 +666,8 @@ function SearchResults(name)
}
else if (this.lastKey==27) // Escape
{
- parent.searchBox.CloseResultsWindow();
- parent.document.getElementById("MSearchField").focus();
+ searchBox.CloseResultsWindow();
+ document.getElementById("MSearchField").focus();
}
else if (this.lastKey==13) // Enter
{
@@ -696,8 +709,8 @@ function SearchResults(name)
}
else if (this.lastKey==27) // Escape
{
- parent.searchBox.CloseResultsWindow();
- parent.document.getElementById("MSearchField").focus();
+ searchBox.CloseResultsWindow();
+ document.getElementById("MSearchField").focus();
}
else if (this.lastKey==13) // Enter
{
@@ -720,9 +733,10 @@ function setClassAttr(elem,attr)
elem.setAttribute('className',attr);
}
-function createResults()
+function createResults(resultsPath)
{
var results = document.getElementById("SRResults");
+ results.innerHTML = '';
for (var e=0; e<searchData.length; e++)
{
var id = searchData[e][0];
@@ -739,8 +753,8 @@ function createResults()
srEntry.appendChild(srLink);
if (searchData[e][1].length==2) // single result
{
- srLink.setAttribute('href',searchData[e][1][1][0]);
- srLink.setAttribute('onclick','parent.searchBox.CloseResultsWindow()');
+ srLink.setAttribute('href',resultsPath+searchData[e][1][1][0]);
+ srLink.setAttribute('onclick','searchBox.CloseResultsWindow()');
if (searchData[e][1][1][1])
{
srLink.setAttribute('target','_parent');
@@ -765,8 +779,8 @@ function createResults()
srChild.setAttribute('id','Item'+e+'_c'+c);
setKeyActions(srChild,'return searchResults.NavChild(event,'+e+','+c+')');
setClassAttr(srChild,'SRScope');
- srChild.setAttribute('href',searchData[e][1][c+1][0]);
- srChild.setAttribute('onclick','parent.searchBox.CloseResultsWindow()');
+ srChild.setAttribute('href',resultsPath+searchData[e][1][c+1][0]);
+ srChild.setAttribute('onclick','searchBox.CloseResultsWindow()');
if (searchData[e][1][c+1][1])
{
srChild.setAttribute('target','_parent');