1 // Search script generated by doxygen
2 // Copyright (C) 2009 by Dimitri van Heesch.
4 // The code in this file is loosly based on main.js, part of Natural Docs,
5 // which is Copyright (C) 2003-2008 Greg Valure
6 // Natural Docs is licensed under the GPL.
8 var indexSectionsWithContent =
10 0: "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
11 1: "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
12 2: "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
13 3: "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
14 4: "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
15 5: "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
16 6: "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
19 var indexSectionNames =
30 function convertToId(search)
33 for (i=0;i<search.length;i++)
35 var c = search.charAt(i);
36 var cn = c.charCodeAt(0);
37 if (c.match(/[a-z0-9]/))
43 result+="_0"+cn.toString(16);
47 result+="_"+cn.toString(16);
53 function getXPos(item)
58 while (item && item!=document.body)
61 item = item.offsetParent;
67 function getYPos(item)
72 while (item && item!=document.body)
75 item = item.offsetParent;
81 /* A class handling everything associated with the search panel.
84 name - The name of the global variable that will be
85 storing this instance. Is needed to be able to set timeouts.
86 resultPath - path to use for external files
88 function SearchBox(name, resultsPath, inFrame, label)
90 if (!name || !resultsPath) { alert("Missing parameters to SearchBox."); }
92 // ---------- Instance variables
94 this.resultsPath = resultsPath;
96 this.keyTimeoutLength = 500;
97 this.closeSelectionTimeout = 300;
98 this.lastSearchValue = "";
99 this.lastResultsPage = "";
100 this.hideTimeout = 0;
101 this.searchIndex = 0;
102 this.searchActive = false;
103 this.insideFrame = inFrame;
104 this.searchLabel = label;
106 // ----------- DOM Elements
108 this.DOMSearchField = function()
109 { return document.getElementById("MSearchField"); }
111 this.DOMSearchSelect = function()
112 { return document.getElementById("MSearchSelect"); }
114 this.DOMSearchSelectWindow = function()
115 { return document.getElementById("MSearchSelectWindow"); }
117 this.DOMPopupSearchResults = function()
118 { return document.getElementById("MSearchResults"); }
120 this.DOMPopupSearchResultsWindow = function()
121 { return document.getElementById("MSearchResultsWindow"); }
123 this.DOMSearchClose = function()
124 { return document.getElementById("MSearchClose"); }
126 this.DOMSearchBox = function()
127 { return document.getElementById("MSearchBox"); }
129 // ------------ Event Handlers
131 // Called when focus is added or removed from the search field.
132 this.OnSearchFieldFocus = function(isActive)
134 this.Activate(isActive);
137 this.OnSearchSelectShow = function()
139 var searchSelectWindow = this.DOMSearchSelectWindow();
140 var searchField = this.DOMSearchSelect();
142 if (this.insideFrame)
144 var left = getXPos(searchField);
145 var top = getYPos(searchField);
146 left += searchField.offsetWidth + 6;
147 top += searchField.offsetHeight;
149 // show search selection popup
150 searchSelectWindow.style.display='block';
151 left -= searchSelectWindow.offsetWidth;
152 searchSelectWindow.style.left = left + 'px';
153 searchSelectWindow.style.top = top + 'px';
157 var left = getXPos(searchField);
158 var top = getYPos(searchField);
159 top += searchField.offsetHeight;
161 // show search selection popup
162 searchSelectWindow.style.display='block';
163 searchSelectWindow.style.left = left + 'px';
164 searchSelectWindow.style.top = top + 'px';
167 // stop selection hide timer
168 if (this.hideTimeout)
170 clearTimeout(this.hideTimeout);
173 return false; // to avoid "image drag" default event
176 this.OnSearchSelectHide = function()
178 this.hideTimeout = setTimeout(this.name +".CloseSelectionWindow()",
179 this.closeSelectionTimeout);
182 // Called when the content of the search field is changed.
183 this.OnSearchFieldChange = function(evt)
185 if (this.keyTimeout) // kill running timer
187 clearTimeout(this.keyTimeout);
191 var e = (evt) ? evt : window.event; // for IE
192 if (e.keyCode==40 || e.keyCode==13)
196 this.OnSearchSelectShow();
197 var win=this.DOMSearchSelectWindow();
198 for (i=0;i<win.childNodes.length;i++)
200 var child = win.childNodes[i]; // get span within a
201 if (child.className=='SelectItem')
209 else if (window.frames.MSearchResults.searchResults)
211 var elem = window.frames.MSearchResults.searchResults.NavNext(0);
212 if (elem) elem.focus();
215 else if (e.keyCode==27) // Escape out of the search field
217 this.DOMSearchField().blur();
218 this.DOMPopupSearchResultsWindow().style.display = 'none';
219 this.DOMSearchClose().style.display = 'none';
220 this.lastSearchValue = '';
221 this.Activate(false);
226 var searchValue = this.DOMSearchField().value.replace(/ +/g, "");
228 if (searchValue != this.lastSearchValue) // search value has changed
230 if (searchValue != "") // non-empty search
232 // set timer for search update
233 this.keyTimeout = setTimeout(this.name + '.Search()',
234 this.keyTimeoutLength);
236 else // empty search field
238 this.DOMPopupSearchResultsWindow().style.display = 'none';
239 this.DOMSearchClose().style.display = 'none';
240 this.lastSearchValue = '';
245 this.SelectItemCount = function(id)
248 var win=this.DOMSearchSelectWindow();
249 for (i=0;i<win.childNodes.length;i++)
251 var child = win.childNodes[i]; // get span within a
252 if (child.className=='SelectItem')
260 this.SelectItemSet = function(id)
263 var win=this.DOMSearchSelectWindow();
264 for (i=0;i<win.childNodes.length;i++)
266 var child = win.childNodes[i]; // get span within a
267 if (child.className=='SelectItem')
269 var node = child.firstChild;
272 node.innerHTML='•';
276 node.innerHTML=' ';
283 // Called when an search filter selection is made.
284 // set item with index id as the active item
285 this.OnSelectItem = function(id)
287 this.searchIndex = id;
288 this.SelectItemSet(id);
289 var searchValue = this.DOMSearchField().value.replace(/ +/g, "");
290 if (searchValue!="" && this.searchActive) // something was found -> do a search
296 this.OnSearchSelectKey = function(evt)
298 var e = (evt) ? evt : window.event; // for IE
299 if (e.keyCode==40 && this.searchIndex<this.SelectItemCount()) // Down
302 this.OnSelectItem(this.searchIndex);
304 else if (e.keyCode==38 && this.searchIndex>0) // Up
307 this.OnSelectItem(this.searchIndex);
309 else if (e.keyCode==13 || e.keyCode==27)
311 this.OnSelectItem(this.searchIndex);
312 this.CloseSelectionWindow();
313 this.DOMSearchField().focus();
320 // Closes the results window.
321 this.CloseResultsWindow = function()
323 this.DOMPopupSearchResultsWindow().style.display = 'none';
324 this.DOMSearchClose().style.display = 'none';
325 this.Activate(false);
328 this.CloseSelectionWindow = function()
330 this.DOMSearchSelectWindow().style.display = 'none';
333 // Performs a search.
334 this.Search = function()
338 // strip leading whitespace
339 var searchValue = this.DOMSearchField().value.replace(/^ +/, "");
341 var code = searchValue.toLowerCase().charCodeAt(0);
345 hexCode="0"+code.toString(16);
349 hexCode=code.toString(16);
353 var resultsPageWithSearch;
356 if (indexSectionsWithContent[this.searchIndex].charAt(code) == '1')
358 resultsPage = this.resultsPath + '/' + indexSectionNames[this.searchIndex] + '_' + hexCode + '.html';
359 resultsPageWithSearch = resultsPage+'?'+escape(searchValue);
360 hasResultsPage = true;
362 else // nothing available for this search term
364 resultsPage = this.resultsPath + '/nomatches.html';
365 resultsPageWithSearch = resultsPage;
366 hasResultsPage = false;
369 window.frames.MSearchResults.location = resultsPageWithSearch;
370 var domPopupSearchResultsWindow = this.DOMPopupSearchResultsWindow();
372 if (domPopupSearchResultsWindow.style.display!='block')
374 var domSearchBox = this.DOMSearchBox();
375 this.DOMSearchClose().style.display = 'inline';
376 if (this.insideFrame)
378 var domPopupSearchResults = this.DOMPopupSearchResults();
379 domPopupSearchResultsWindow.style.position = 'relative';
380 domPopupSearchResultsWindow.style.display = 'block';
381 var width = document.body.clientWidth - 8; // the -8 is for IE :-(
382 domPopupSearchResultsWindow.style.width = width + 'px';
383 domPopupSearchResults.style.width = width + 'px';
387 var domPopupSearchResults = this.DOMPopupSearchResults();
388 var left = getXPos(domSearchBox) + 150; // domSearchBox.offsetWidth;
389 var top = getYPos(domSearchBox) + 20; // domSearchBox.offsetHeight + 1;
390 domPopupSearchResultsWindow.style.display = 'block';
391 left -= domPopupSearchResults.offsetWidth;
392 domPopupSearchResultsWindow.style.top = top + 'px';
393 domPopupSearchResultsWindow.style.left = left + 'px';
397 this.lastSearchValue = searchValue;
398 this.lastResultsPage = resultsPage;
401 // -------- Activation Functions
403 // Activates or deactivates the search panel, resetting things to
404 // their default values if necessary.
405 this.Activate = function(isActive)
407 if (isActive || // open it
408 this.DOMPopupSearchResultsWindow().style.display == 'block'
411 this.DOMSearchBox().className = 'MSearchBoxActive';
413 var searchField = this.DOMSearchField();
415 if (searchField.value == this.searchLabel) // clear "Search" term upon entry
417 searchField.value = '';
418 this.searchActive = true;
421 else if (!isActive) // directly remove the panel
423 this.DOMSearchBox().className = 'MSearchBoxInactive';
424 this.DOMSearchField().value = this.searchLabel;
425 this.searchActive = false;
426 this.lastSearchValue = ''
427 this.lastResultsPage = '';
432 // -----------------------------------------------------------------------
434 // The class that handles everything on the search results page.
435 function SearchResults(name)
437 // The number of matches from the last run of <Search()>.
438 this.lastMatchCount = 0;
440 this.repeatOn = false;
442 // Toggles the visibility of the passed element ID.
443 this.FindChildElement = function(id)
445 var parentElement = document.getElementById(id);
446 var element = parentElement.firstChild;
448 while (element && element!=parentElement)
450 if (element.nodeName == 'DIV' && element.className == 'SRChildren')
455 if (element.nodeName == 'DIV' && element.hasChildNodes())
457 element = element.firstChild;
459 else if (element.nextSibling)
461 element = element.nextSibling;
467 element = element.parentNode;
469 while (element && element!=parentElement && !element.nextSibling);
471 if (element && element!=parentElement)
473 element = element.nextSibling;
479 this.Toggle = function(id)
481 var element = this.FindChildElement(id);
484 if (element.style.display == 'block')
486 element.style.display = 'none';
490 element.style.display = 'block';
495 // Searches for the passed string. If there is no parameter,
496 // it takes it from the URL query.
498 // Always returns true, since other documents may try to call it
499 // and that may or may not be possible.
500 this.Search = function(search)
502 if (!search) // get search word from URL
504 search = window.location.search;
505 search = search.substring(1); // Remove the leading '?'
506 search = unescape(search);
509 search = search.replace(/^ +/, ""); // strip leading spaces
510 search = search.replace(/ +$/, ""); // strip trailing spaces
511 search = search.toLowerCase();
512 search = convertToId(search);
514 var resultRows = document.getElementsByTagName("div");
518 while (i < resultRows.length)
520 var row = resultRows.item(i);
521 if (row.className == "SRResult")
523 var rowMatchName = row.id.toLowerCase();
524 rowMatchName = rowMatchName.replace(/^sr\d*_/, ''); // strip 'sr123_'
526 if (search.length<=rowMatchName.length &&
527 rowMatchName.substr(0, search.length)==search)
529 row.style.display = 'block';
534 row.style.display = 'none';
539 document.getElementById("Searching").style.display='none';
540 if (matches == 0) // no results
542 document.getElementById("NoMatches").style.display='block';
544 else // at least one result
546 document.getElementById("NoMatches").style.display='none';
548 this.lastMatchCount = matches;
552 // return the first item with index index or higher that is visible
553 this.NavNext = function(index)
558 var focusName = 'Item'+index;
559 focusItem = document.getElementById(focusName);
560 if (focusItem && focusItem.parentNode.parentNode.style.display=='block')
564 else if (!focusItem) // last element
574 this.NavPrev = function(index)
579 var focusName = 'Item'+index;
580 focusItem = document.getElementById(focusName);
581 if (focusItem && focusItem.parentNode.parentNode.style.display=='block')
585 else if (!focusItem) // last element
595 this.ProcessKeys = function(e)
597 if (e.type == "keydown")
599 this.repeatOn = false;
600 this.lastKey = e.keyCode;
602 else if (e.type == "keypress")
606 if (this.lastKey) this.repeatOn = true;
607 return false; // ignore first keypress after keydown
610 else if (e.type == "keyup")
613 this.repeatOn = false;
615 return this.lastKey!=0;
618 this.Nav = function(evt,itemIndex)
620 var e = (evt) ? evt : window.event; // for IE
621 if (e.keyCode==13) return true;
622 if (!this.ProcessKeys(e)) return false;
624 if (this.lastKey==38) // Up
626 var newIndex = itemIndex-1;
627 var focusItem = this.NavPrev(newIndex);
630 var child = this.FindChildElement(focusItem.parentNode.parentNode.id);
631 if (child && child.style.display == 'block') // children visible
635 while (1) // search for last child
637 tmpElem = document.getElementById('Item'+newIndex+'_c'+n);
654 else // return focus to search field
656 parent.document.getElementById("MSearchField").focus();
659 else if (this.lastKey==40) // Down
661 var newIndex = itemIndex+1;
663 var item = document.getElementById('Item'+itemIndex);
664 var elem = this.FindChildElement(item.parentNode.parentNode.id);
665 if (elem && elem.style.display == 'block') // children visible
667 focusItem = document.getElementById('Item'+itemIndex+'_c0');
669 if (!focusItem) focusItem = this.NavNext(newIndex);
670 if (focusItem) focusItem.focus();
672 else if (this.lastKey==39) // Right
674 var item = document.getElementById('Item'+itemIndex);
675 var elem = this.FindChildElement(item.parentNode.parentNode.id);
676 if (elem) elem.style.display = 'block';
678 else if (this.lastKey==37) // Left
680 var item = document.getElementById('Item'+itemIndex);
681 var elem = this.FindChildElement(item.parentNode.parentNode.id);
682 if (elem) elem.style.display = 'none';
684 else if (this.lastKey==27) // Escape
686 parent.searchBox.CloseResultsWindow();
687 parent.document.getElementById("MSearchField").focus();
689 else if (this.lastKey==13) // Enter
696 this.NavChild = function(evt,itemIndex,childIndex)
698 var e = (evt) ? evt : window.event; // for IE
699 if (e.keyCode==13) return true;
700 if (!this.ProcessKeys(e)) return false;
702 if (this.lastKey==38) // Up
706 var newIndex = childIndex-1;
707 document.getElementById('Item'+itemIndex+'_c'+newIndex).focus();
709 else // already at first child, jump to parent
711 document.getElementById('Item'+itemIndex).focus();
714 else if (this.lastKey==40) // Down
716 var newIndex = childIndex+1;
717 var elem = document.getElementById('Item'+itemIndex+'_c'+newIndex);
718 if (!elem) // last child, jump to parent next parent
720 elem = this.NavNext(itemIndex+1);
727 else if (this.lastKey==27) // Escape
729 parent.searchBox.CloseResultsWindow();
730 parent.document.getElementById("MSearchField").focus();
732 else if (this.lastKey==13) // Enter
740 function setKeyActions(elem,action)
742 elem.setAttribute('onkeydown',action);
743 elem.setAttribute('onkeypress',action);
744 elem.setAttribute('onkeyup',action);
747 function setClassAttr(elem,attr)
749 elem.setAttribute('class',attr);
750 elem.setAttribute('className',attr);
753 function createResults()
755 var results = document.getElementById("SRResults");
756 for (var e=0; e<searchData.length; e++)
758 var id = searchData[e][0];
759 var srResult = document.createElement('div');
760 srResult.setAttribute('id','SR_'+id);
761 setClassAttr(srResult,'SRResult');
762 var srEntry = document.createElement('div');
763 setClassAttr(srEntry,'SREntry');
764 var srLink = document.createElement('a');
765 srLink.setAttribute('id','Item'+e);
766 setKeyActions(srLink,'return searchResults.Nav(event,'+e+')');
767 setClassAttr(srLink,'SRSymbol');
768 srLink.innerHTML = searchData[e][1][0];
769 srEntry.appendChild(srLink);
770 if (searchData[e][1].length==2) // single result
772 srLink.setAttribute('href',searchData[e][1][1][0]);
773 if (searchData[e][1][1][1])
775 srLink.setAttribute('target','_parent');
777 var srScope = document.createElement('span');
778 setClassAttr(srScope,'SRScope');
779 srScope.innerHTML = searchData[e][1][1][2];
780 srEntry.appendChild(srScope);
782 else // multiple results
784 srLink.setAttribute('href','javascript:searchResults.Toggle("SR_'+id+'")');
785 var srChildren = document.createElement('div');
786 setClassAttr(srChildren,'SRChildren');
787 for (var c=0; c<searchData[e][1].length-1; c++)
789 var srChild = document.createElement('a');
790 srChild.setAttribute('id','Item'+e+'_c'+c);
791 setKeyActions(srChild,'return searchResults.NavChild(event,'+e+','+c+')');
792 setClassAttr(srChild,'SRScope');
793 srChild.setAttribute('href',searchData[e][1][c+1][0]);
794 if (searchData[e][1][c+1][1])
796 srChild.setAttribute('target','_parent');
798 srChild.innerHTML = searchData[e][1][c+1][2];
799 srChildren.appendChild(srChild);
801 srEntry.appendChild(srChildren);
803 srResult.appendChild(srEntry);
804 results.appendChild(srResult);