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: "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000111111111101111101111001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
11 1: "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000100000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
12 2: "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
13 3: "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000111111111101111101111001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
14 4: "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
15 5: "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
16 6: "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
17 7: "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000111010101001110101010001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
18 8: "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000111000101001111101100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
21 var indexSectionNames =
34 function convertToId(search)
37 for (i=0;i<search.length;i++)
39 var c = search.charAt(i);
40 var cn = c.charCodeAt(0);
41 if (c.match(/[a-z0-9]/))
47 result+="_0"+cn.toString(16);
51 result+="_"+cn.toString(16);
57 function getXPos(item)
62 while (item && item!=document.body)
65 item = item.offsetParent;
71 function getYPos(item)
76 while (item && item!=document.body)
79 item = item.offsetParent;
85 /* A class handling everything associated with the search panel.
88 name - The name of the global variable that will be
89 storing this instance. Is needed to be able to set timeouts.
90 resultPath - path to use for external files
92 function SearchBox(name, resultsPath, inFrame, label)
94 if (!name || !resultsPath) { alert("Missing parameters to SearchBox."); }
96 // ---------- Instance variables
98 this.resultsPath = resultsPath;
100 this.keyTimeoutLength = 500;
101 this.closeSelectionTimeout = 300;
102 this.lastSearchValue = "";
103 this.lastResultsPage = "";
104 this.hideTimeout = 0;
105 this.searchIndex = 0;
106 this.searchActive = false;
107 this.insideFrame = inFrame;
108 this.searchLabel = label;
110 // ----------- DOM Elements
112 this.DOMSearchField = function()
113 { return document.getElementById("MSearchField"); }
115 this.DOMSearchSelect = function()
116 { return document.getElementById("MSearchSelect"); }
118 this.DOMSearchSelectWindow = function()
119 { return document.getElementById("MSearchSelectWindow"); }
121 this.DOMPopupSearchResults = function()
122 { return document.getElementById("MSearchResults"); }
124 this.DOMPopupSearchResultsWindow = function()
125 { return document.getElementById("MSearchResultsWindow"); }
127 this.DOMSearchClose = function()
128 { return document.getElementById("MSearchClose"); }
130 this.DOMSearchBox = function()
131 { return document.getElementById("MSearchBox"); }
133 // ------------ Event Handlers
135 // Called when focus is added or removed from the search field.
136 this.OnSearchFieldFocus = function(isActive)
138 this.Activate(isActive);
141 this.OnSearchSelectShow = function()
143 var searchSelectWindow = this.DOMSearchSelectWindow();
144 var searchField = this.DOMSearchSelect();
146 if (this.insideFrame)
148 var left = getXPos(searchField);
149 var top = getYPos(searchField);
150 left += searchField.offsetWidth + 6;
151 top += searchField.offsetHeight;
153 // show search selection popup
154 searchSelectWindow.style.display='block';
155 left -= searchSelectWindow.offsetWidth;
156 searchSelectWindow.style.left = left + 'px';
157 searchSelectWindow.style.top = top + 'px';
161 var left = getXPos(searchField);
162 var top = getYPos(searchField);
163 top += searchField.offsetHeight;
165 // show search selection popup
166 searchSelectWindow.style.display='block';
167 searchSelectWindow.style.left = left + 'px';
168 searchSelectWindow.style.top = top + 'px';
171 // stop selection hide timer
172 if (this.hideTimeout)
174 clearTimeout(this.hideTimeout);
177 return false; // to avoid "image drag" default event
180 this.OnSearchSelectHide = function()
182 this.hideTimeout = setTimeout(this.name +".CloseSelectionWindow()",
183 this.closeSelectionTimeout);
186 // Called when the content of the search field is changed.
187 this.OnSearchFieldChange = function(evt)
189 if (this.keyTimeout) // kill running timer
191 clearTimeout(this.keyTimeout);
195 var e = (evt) ? evt : window.event; // for IE
196 if (e.keyCode==40 || e.keyCode==13)
200 this.OnSearchSelectShow();
201 var win=this.DOMSearchSelectWindow();
202 for (i=0;i<win.childNodes.length;i++)
204 var child = win.childNodes[i]; // get span within a
205 if (child.className=='SelectItem')
213 else if (window.frames.MSearchResults.searchResults)
215 var elem = window.frames.MSearchResults.searchResults.NavNext(0);
216 if (elem) elem.focus();
219 else if (e.keyCode==27) // Escape out of the search field
221 this.DOMSearchField().blur();
222 this.DOMPopupSearchResultsWindow().style.display = 'none';
223 this.DOMSearchClose().style.display = 'none';
224 this.lastSearchValue = '';
225 this.Activate(false);
230 var searchValue = this.DOMSearchField().value.replace(/ +/g, "");
232 if (searchValue != this.lastSearchValue) // search value has changed
234 if (searchValue != "") // non-empty search
236 // set timer for search update
237 this.keyTimeout = setTimeout(this.name + '.Search()',
238 this.keyTimeoutLength);
240 else // empty search field
242 this.DOMPopupSearchResultsWindow().style.display = 'none';
243 this.DOMSearchClose().style.display = 'none';
244 this.lastSearchValue = '';
249 this.SelectItemCount = function(id)
252 var win=this.DOMSearchSelectWindow();
253 for (i=0;i<win.childNodes.length;i++)
255 var child = win.childNodes[i]; // get span within a
256 if (child.className=='SelectItem')
264 this.SelectItemSet = function(id)
267 var win=this.DOMSearchSelectWindow();
268 for (i=0;i<win.childNodes.length;i++)
270 var child = win.childNodes[i]; // get span within a
271 if (child.className=='SelectItem')
273 var node = child.firstChild;
276 node.innerHTML='•';
280 node.innerHTML=' ';
287 // Called when an search filter selection is made.
288 // set item with index id as the active item
289 this.OnSelectItem = function(id)
291 this.searchIndex = id;
292 this.SelectItemSet(id);
293 var searchValue = this.DOMSearchField().value.replace(/ +/g, "");
294 if (searchValue!="" && this.searchActive) // something was found -> do a search
300 this.OnSearchSelectKey = function(evt)
302 var e = (evt) ? evt : window.event; // for IE
303 if (e.keyCode==40 && this.searchIndex<this.SelectItemCount()) // Down
306 this.OnSelectItem(this.searchIndex);
308 else if (e.keyCode==38 && this.searchIndex>0) // Up
311 this.OnSelectItem(this.searchIndex);
313 else if (e.keyCode==13 || e.keyCode==27)
315 this.OnSelectItem(this.searchIndex);
316 this.CloseSelectionWindow();
317 this.DOMSearchField().focus();
324 // Closes the results window.
325 this.CloseResultsWindow = function()
327 this.DOMPopupSearchResultsWindow().style.display = 'none';
328 this.DOMSearchClose().style.display = 'none';
329 this.Activate(false);
332 this.CloseSelectionWindow = function()
334 this.DOMSearchSelectWindow().style.display = 'none';
337 // Performs a search.
338 this.Search = function()
342 // strip leading whitespace
343 var searchValue = this.DOMSearchField().value.replace(/^ +/, "");
345 var code = searchValue.toLowerCase().charCodeAt(0);
349 hexCode="0"+code.toString(16);
353 hexCode=code.toString(16);
357 var resultsPageWithSearch;
360 if (indexSectionsWithContent[this.searchIndex].charAt(code) == '1')
362 resultsPage = this.resultsPath + '/' + indexSectionNames[this.searchIndex] + '_' + hexCode + '.html';
363 resultsPageWithSearch = resultsPage+'?'+escape(searchValue);
364 hasResultsPage = true;
366 else // nothing available for this search term
368 resultsPage = this.resultsPath + '/nomatches.html';
369 resultsPageWithSearch = resultsPage;
370 hasResultsPage = false;
373 window.frames.MSearchResults.location = resultsPageWithSearch;
374 var domPopupSearchResultsWindow = this.DOMPopupSearchResultsWindow();
376 if (domPopupSearchResultsWindow.style.display!='block')
378 var domSearchBox = this.DOMSearchBox();
379 this.DOMSearchClose().style.display = 'inline';
380 if (this.insideFrame)
382 var domPopupSearchResults = this.DOMPopupSearchResults();
383 domPopupSearchResultsWindow.style.position = 'relative';
384 domPopupSearchResultsWindow.style.display = 'block';
385 var width = document.body.clientWidth - 8; // the -8 is for IE :-(
386 domPopupSearchResultsWindow.style.width = width + 'px';
387 domPopupSearchResults.style.width = width + 'px';
391 var domPopupSearchResults = this.DOMPopupSearchResults();
392 var left = getXPos(domSearchBox) + 150; // domSearchBox.offsetWidth;
393 var top = getYPos(domSearchBox) + 20; // domSearchBox.offsetHeight + 1;
394 domPopupSearchResultsWindow.style.display = 'block';
395 left -= domPopupSearchResults.offsetWidth;
396 domPopupSearchResultsWindow.style.top = top + 'px';
397 domPopupSearchResultsWindow.style.left = left + 'px';
401 this.lastSearchValue = searchValue;
402 this.lastResultsPage = resultsPage;
405 // -------- Activation Functions
407 // Activates or deactivates the search panel, resetting things to
408 // their default values if necessary.
409 this.Activate = function(isActive)
411 if (isActive || // open it
412 this.DOMPopupSearchResultsWindow().style.display == 'block'
415 this.DOMSearchBox().className = 'MSearchBoxActive';
417 var searchField = this.DOMSearchField();
419 if (searchField.value == this.searchLabel) // clear "Search" term upon entry
421 searchField.value = '';
422 this.searchActive = true;
425 else if (!isActive) // directly remove the panel
427 this.DOMSearchBox().className = 'MSearchBoxInactive';
428 this.DOMSearchField().value = this.searchLabel;
429 this.searchActive = false;
430 this.lastSearchValue = ''
431 this.lastResultsPage = '';
436 // -----------------------------------------------------------------------
438 // The class that handles everything on the search results page.
439 function SearchResults(name)
441 // The number of matches from the last run of <Search()>.
442 this.lastMatchCount = 0;
444 this.repeatOn = false;
446 // Toggles the visibility of the passed element ID.
447 this.FindChildElement = function(id)
449 var parentElement = document.getElementById(id);
450 var element = parentElement.firstChild;
452 while (element && element!=parentElement)
454 if (element.nodeName == 'DIV' && element.className == 'SRChildren')
459 if (element.nodeName == 'DIV' && element.hasChildNodes())
461 element = element.firstChild;
463 else if (element.nextSibling)
465 element = element.nextSibling;
471 element = element.parentNode;
473 while (element && element!=parentElement && !element.nextSibling);
475 if (element && element!=parentElement)
477 element = element.nextSibling;
483 this.Toggle = function(id)
485 var element = this.FindChildElement(id);
488 if (element.style.display == 'block')
490 element.style.display = 'none';
494 element.style.display = 'block';
499 // Searches for the passed string. If there is no parameter,
500 // it takes it from the URL query.
502 // Always returns true, since other documents may try to call it
503 // and that may or may not be possible.
504 this.Search = function(search)
506 if (!search) // get search word from URL
508 search = window.location.search;
509 search = search.substring(1); // Remove the leading '?'
510 search = unescape(search);
513 search = search.replace(/^ +/, ""); // strip leading spaces
514 search = search.replace(/ +$/, ""); // strip trailing spaces
515 search = search.toLowerCase();
516 search = convertToId(search);
518 var resultRows = document.getElementsByTagName("div");
522 while (i < resultRows.length)
524 var row = resultRows.item(i);
525 if (row.className == "SRResult")
527 var rowMatchName = row.id.toLowerCase();
528 rowMatchName = rowMatchName.replace(/^sr\d*_/, ''); // strip 'sr123_'
530 if (search.length<=rowMatchName.length &&
531 rowMatchName.substr(0, search.length)==search)
533 row.style.display = 'block';
538 row.style.display = 'none';
543 document.getElementById("Searching").style.display='none';
544 if (matches == 0) // no results
546 document.getElementById("NoMatches").style.display='block';
548 else // at least one result
550 document.getElementById("NoMatches").style.display='none';
552 this.lastMatchCount = matches;
556 // return the first item with index index or higher that is visible
557 this.NavNext = function(index)
562 var focusName = 'Item'+index;
563 focusItem = document.getElementById(focusName);
564 if (focusItem && focusItem.parentNode.parentNode.style.display=='block')
568 else if (!focusItem) // last element
578 this.NavPrev = function(index)
583 var focusName = 'Item'+index;
584 focusItem = document.getElementById(focusName);
585 if (focusItem && focusItem.parentNode.parentNode.style.display=='block')
589 else if (!focusItem) // last element
599 this.ProcessKeys = function(e)
601 if (e.type == "keydown")
603 this.repeatOn = false;
604 this.lastKey = e.keyCode;
606 else if (e.type == "keypress")
610 if (this.lastKey) this.repeatOn = true;
611 return false; // ignore first keypress after keydown
614 else if (e.type == "keyup")
617 this.repeatOn = false;
619 return this.lastKey!=0;
622 this.Nav = function(evt,itemIndex)
624 var e = (evt) ? evt : window.event; // for IE
625 if (e.keyCode==13) return true;
626 if (!this.ProcessKeys(e)) return false;
628 if (this.lastKey==38) // Up
630 var newIndex = itemIndex-1;
631 var focusItem = this.NavPrev(newIndex);
634 var child = this.FindChildElement(focusItem.parentNode.parentNode.id);
635 if (child && child.style.display == 'block') // children visible
639 while (1) // search for last child
641 tmpElem = document.getElementById('Item'+newIndex+'_c'+n);
658 else // return focus to search field
660 parent.document.getElementById("MSearchField").focus();
663 else if (this.lastKey==40) // Down
665 var newIndex = itemIndex+1;
667 var item = document.getElementById('Item'+itemIndex);
668 var elem = this.FindChildElement(item.parentNode.parentNode.id);
669 if (elem && elem.style.display == 'block') // children visible
671 focusItem = document.getElementById('Item'+itemIndex+'_c0');
673 if (!focusItem) focusItem = this.NavNext(newIndex);
674 if (focusItem) focusItem.focus();
676 else if (this.lastKey==39) // Right
678 var item = document.getElementById('Item'+itemIndex);
679 var elem = this.FindChildElement(item.parentNode.parentNode.id);
680 if (elem) elem.style.display = 'block';
682 else if (this.lastKey==37) // Left
684 var item = document.getElementById('Item'+itemIndex);
685 var elem = this.FindChildElement(item.parentNode.parentNode.id);
686 if (elem) elem.style.display = 'none';
688 else if (this.lastKey==27) // Escape
690 parent.searchBox.CloseResultsWindow();
691 parent.document.getElementById("MSearchField").focus();
693 else if (this.lastKey==13) // Enter
700 this.NavChild = function(evt,itemIndex,childIndex)
702 var e = (evt) ? evt : window.event; // for IE
703 if (e.keyCode==13) return true;
704 if (!this.ProcessKeys(e)) return false;
706 if (this.lastKey==38) // Up
710 var newIndex = childIndex-1;
711 document.getElementById('Item'+itemIndex+'_c'+newIndex).focus();
713 else // already at first child, jump to parent
715 document.getElementById('Item'+itemIndex).focus();
718 else if (this.lastKey==40) // Down
720 var newIndex = childIndex+1;
721 var elem = document.getElementById('Item'+itemIndex+'_c'+newIndex);
722 if (!elem) // last child, jump to parent next parent
724 elem = this.NavNext(itemIndex+1);
731 else if (this.lastKey==27) // Escape
733 parent.searchBox.CloseResultsWindow();
734 parent.document.getElementById("MSearchField").focus();
736 else if (this.lastKey==13) // Enter
744 function setKeyActions(elem,action)
746 elem.setAttribute('onkeydown',action);
747 elem.setAttribute('onkeypress',action);
748 elem.setAttribute('onkeyup',action);
751 function setClassAttr(elem,attr)
753 elem.setAttribute('class',attr);
754 elem.setAttribute('className',attr);
757 function createResults()
759 var results = document.getElementById("SRResults");
760 for (var e=0; e<searchData.length; e++)
762 var id = searchData[e][0];
763 var srResult = document.createElement('div');
764 srResult.setAttribute('id','SR_'+id);
765 setClassAttr(srResult,'SRResult');
766 var srEntry = document.createElement('div');
767 setClassAttr(srEntry,'SREntry');
768 var srLink = document.createElement('a');
769 srLink.setAttribute('id','Item'+e);
770 setKeyActions(srLink,'return searchResults.Nav(event,'+e+')');
771 setClassAttr(srLink,'SRSymbol');
772 srLink.innerHTML = searchData[e][1][0];
773 srEntry.appendChild(srLink);
774 if (searchData[e][1].length==2) // single result
776 srLink.setAttribute('href',searchData[e][1][1][0]);
777 if (searchData[e][1][1][1])
779 srLink.setAttribute('target','_parent');
781 var srScope = document.createElement('span');
782 setClassAttr(srScope,'SRScope');
783 srScope.innerHTML = searchData[e][1][1][2];
784 srEntry.appendChild(srScope);
786 else // multiple results
788 srLink.setAttribute('href','javascript:searchResults.Toggle("SR_'+id+'")');
789 var srChildren = document.createElement('div');
790 setClassAttr(srChildren,'SRChildren');
791 for (var c=0; c<searchData[e][1].length-1; c++)
793 var srChild = document.createElement('a');
794 srChild.setAttribute('id','Item'+e+'_c'+c);
795 setKeyActions(srChild,'return searchResults.NavChild(event,'+e+','+c+')');
796 setClassAttr(srChild,'SRScope');
797 srChild.setAttribute('href',searchData[e][1][c+1][0]);
798 if (searchData[e][1][c+1][1])
800 srChild.setAttribute('target','_parent');
802 srChild.innerHTML = searchData[e][1][c+1][2];
803 srChildren.appendChild(srChild);
805 srEntry.appendChild(srChildren);
807 srResult.appendChild(srEntry);
808 results.appendChild(srResult);