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: "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100010000011001010011100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
11 1: "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
12 2: "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100010000011001000011100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
15 var indexSectionNames =
22 function convertToId(search)
25 for (i=0;i<search.length;i++)
27 var c = search.charAt(i);
28 var cn = c.charCodeAt(0);
29 if (c.match(/[a-z0-9]/))
35 result+="_0"+cn.toString(16);
39 result+="_"+cn.toString(16);
45 function getXPos(item)
50 while (item && item!=document.body)
53 item = item.offsetParent;
59 function getYPos(item)
64 while (item && item!=document.body)
67 item = item.offsetParent;
73 /* A class handling everything associated with the search panel.
76 name - The name of the global variable that will be
77 storing this instance. Is needed to be able to set timeouts.
78 resultPath - path to use for external files
80 function SearchBox(name, resultsPath, inFrame, label)
82 if (!name || !resultsPath) { alert("Missing parameters to SearchBox."); }
84 // ---------- Instance variables
86 this.resultsPath = resultsPath;
88 this.keyTimeoutLength = 500;
89 this.closeSelectionTimeout = 300;
90 this.lastSearchValue = "";
91 this.lastResultsPage = "";
94 this.searchActive = false;
95 this.insideFrame = inFrame;
96 this.searchLabel = label;
98 // ----------- DOM Elements
100 this.DOMSearchField = function()
101 { return document.getElementById("MSearchField"); }
103 this.DOMSearchSelect = function()
104 { return document.getElementById("MSearchSelect"); }
106 this.DOMSearchSelectWindow = function()
107 { return document.getElementById("MSearchSelectWindow"); }
109 this.DOMPopupSearchResults = function()
110 { return document.getElementById("MSearchResults"); }
112 this.DOMPopupSearchResultsWindow = function()
113 { return document.getElementById("MSearchResultsWindow"); }
115 this.DOMSearchClose = function()
116 { return document.getElementById("MSearchClose"); }
118 this.DOMSearchBox = function()
119 { return document.getElementById("MSearchBox"); }
121 // ------------ Event Handlers
123 // Called when focus is added or removed from the search field.
124 this.OnSearchFieldFocus = function(isActive)
126 this.Activate(isActive);
129 this.OnSearchSelectShow = function()
131 var searchSelectWindow = this.DOMSearchSelectWindow();
132 var searchField = this.DOMSearchSelect();
134 if (this.insideFrame)
136 var left = getXPos(searchField);
137 var top = getYPos(searchField);
138 left += searchField.offsetWidth + 6;
139 top += searchField.offsetHeight;
141 // show search selection popup
142 searchSelectWindow.style.display='block';
143 left -= searchSelectWindow.offsetWidth;
144 searchSelectWindow.style.left = left + 'px';
145 searchSelectWindow.style.top = top + 'px';
149 var left = getXPos(searchField);
150 var top = getYPos(searchField);
151 top += searchField.offsetHeight;
153 // show search selection popup
154 searchSelectWindow.style.display='block';
155 searchSelectWindow.style.left = left + 'px';
156 searchSelectWindow.style.top = top + 'px';
159 // stop selection hide timer
160 if (this.hideTimeout)
162 clearTimeout(this.hideTimeout);
165 return false; // to avoid "image drag" default event
168 this.OnSearchSelectHide = function()
170 this.hideTimeout = setTimeout(this.name +".CloseSelectionWindow()",
171 this.closeSelectionTimeout);
174 // Called when the content of the search field is changed.
175 this.OnSearchFieldChange = function(evt)
177 if (this.keyTimeout) // kill running timer
179 clearTimeout(this.keyTimeout);
183 var e = (evt) ? evt : window.event; // for IE
184 if (e.keyCode==40 || e.keyCode==13)
188 this.OnSearchSelectShow();
189 var win=this.DOMSearchSelectWindow();
190 for (i=0;i<win.childNodes.length;i++)
192 var child = win.childNodes[i]; // get span within a
193 if (child.className=='SelectItem')
201 else if (window.frames.MSearchResults.searchResults)
203 var elem = window.frames.MSearchResults.searchResults.NavNext(0);
204 if (elem) elem.focus();
207 else if (e.keyCode==27) // Escape out of the search field
209 this.DOMSearchField().blur();
210 this.DOMPopupSearchResultsWindow().style.display = 'none';
211 this.DOMSearchClose().style.display = 'none';
212 this.lastSearchValue = '';
213 this.Activate(false);
218 var searchValue = this.DOMSearchField().value.replace(/ +/g, "");
220 if (searchValue != this.lastSearchValue) // search value has changed
222 if (searchValue != "") // non-empty search
224 // set timer for search update
225 this.keyTimeout = setTimeout(this.name + '.Search()',
226 this.keyTimeoutLength);
228 else // empty search field
230 this.DOMPopupSearchResultsWindow().style.display = 'none';
231 this.DOMSearchClose().style.display = 'none';
232 this.lastSearchValue = '';
237 this.SelectItemCount = function(id)
240 var win=this.DOMSearchSelectWindow();
241 for (i=0;i<win.childNodes.length;i++)
243 var child = win.childNodes[i]; // get span within a
244 if (child.className=='SelectItem')
252 this.SelectItemSet = function(id)
255 var win=this.DOMSearchSelectWindow();
256 for (i=0;i<win.childNodes.length;i++)
258 var child = win.childNodes[i]; // get span within a
259 if (child.className=='SelectItem')
261 var node = child.firstChild;
264 node.innerHTML='•';
268 node.innerHTML=' ';
275 // Called when an search filter selection is made.
276 // set item with index id as the active item
277 this.OnSelectItem = function(id)
279 this.searchIndex = id;
280 this.SelectItemSet(id);
281 var searchValue = this.DOMSearchField().value.replace(/ +/g, "");
282 if (searchValue!="" && this.searchActive) // something was found -> do a search
288 this.OnSearchSelectKey = function(evt)
290 var e = (evt) ? evt : window.event; // for IE
291 if (e.keyCode==40 && this.searchIndex<this.SelectItemCount()) // Down
294 this.OnSelectItem(this.searchIndex);
296 else if (e.keyCode==38 && this.searchIndex>0) // Up
299 this.OnSelectItem(this.searchIndex);
301 else if (e.keyCode==13 || e.keyCode==27)
303 this.OnSelectItem(this.searchIndex);
304 this.CloseSelectionWindow();
305 this.DOMSearchField().focus();
312 // Closes the results window.
313 this.CloseResultsWindow = function()
315 this.DOMPopupSearchResultsWindow().style.display = 'none';
316 this.DOMSearchClose().style.display = 'none';
317 this.Activate(false);
320 this.CloseSelectionWindow = function()
322 this.DOMSearchSelectWindow().style.display = 'none';
325 // Performs a search.
326 this.Search = function()
330 // strip leading whitespace
331 var searchValue = this.DOMSearchField().value.replace(/^ +/, "");
333 var code = searchValue.toLowerCase().charCodeAt(0);
337 hexCode="0"+code.toString(16);
341 hexCode=code.toString(16);
345 var resultsPageWithSearch;
348 if (indexSectionsWithContent[this.searchIndex].charAt(code) == '1')
350 resultsPage = this.resultsPath + '/' + indexSectionNames[this.searchIndex] + '_' + hexCode + '.html';
351 resultsPageWithSearch = resultsPage+'?'+escape(searchValue);
352 hasResultsPage = true;
354 else // nothing available for this search term
356 resultsPage = this.resultsPath + '/nomatches.html';
357 resultsPageWithSearch = resultsPage;
358 hasResultsPage = false;
361 window.frames.MSearchResults.location.href = resultsPageWithSearch;
362 var domPopupSearchResultsWindow = this.DOMPopupSearchResultsWindow();
364 if (domPopupSearchResultsWindow.style.display!='block')
366 var domSearchBox = this.DOMSearchBox();
367 this.DOMSearchClose().style.display = 'inline';
368 if (this.insideFrame)
370 var domPopupSearchResults = this.DOMPopupSearchResults();
371 domPopupSearchResultsWindow.style.position = 'relative';
372 domPopupSearchResultsWindow.style.display = 'block';
373 var width = document.body.clientWidth - 8; // the -8 is for IE :-(
374 domPopupSearchResultsWindow.style.width = width + 'px';
375 domPopupSearchResults.style.width = width + 'px';
379 var domPopupSearchResults = this.DOMPopupSearchResults();
380 var left = getXPos(domSearchBox) + 150; // domSearchBox.offsetWidth;
381 var top = getYPos(domSearchBox) + 20; // domSearchBox.offsetHeight + 1;
382 domPopupSearchResultsWindow.style.display = 'block';
383 left -= domPopupSearchResults.offsetWidth;
384 domPopupSearchResultsWindow.style.top = top + 'px';
385 domPopupSearchResultsWindow.style.left = left + 'px';
389 this.lastSearchValue = searchValue;
390 this.lastResultsPage = resultsPage;
393 // -------- Activation Functions
395 // Activates or deactivates the search panel, resetting things to
396 // their default values if necessary.
397 this.Activate = function(isActive)
399 if (isActive || // open it
400 this.DOMPopupSearchResultsWindow().style.display == 'block'
403 this.DOMSearchBox().className = 'MSearchBoxActive';
405 var searchField = this.DOMSearchField();
407 if (searchField.value == this.searchLabel) // clear "Search" term upon entry
409 searchField.value = '';
410 this.searchActive = true;
413 else if (!isActive) // directly remove the panel
415 this.DOMSearchBox().className = 'MSearchBoxInactive';
416 this.DOMSearchField().value = this.searchLabel;
417 this.searchActive = false;
418 this.lastSearchValue = ''
419 this.lastResultsPage = '';
424 // -----------------------------------------------------------------------
426 // The class that handles everything on the search results page.
427 function SearchResults(name)
429 // The number of matches from the last run of <Search()>.
430 this.lastMatchCount = 0;
432 this.repeatOn = false;
434 // Toggles the visibility of the passed element ID.
435 this.FindChildElement = function(id)
437 var parentElement = document.getElementById(id);
438 var element = parentElement.firstChild;
440 while (element && element!=parentElement)
442 if (element.nodeName == 'DIV' && element.className == 'SRChildren')
447 if (element.nodeName == 'DIV' && element.hasChildNodes())
449 element = element.firstChild;
451 else if (element.nextSibling)
453 element = element.nextSibling;
459 element = element.parentNode;
461 while (element && element!=parentElement && !element.nextSibling);
463 if (element && element!=parentElement)
465 element = element.nextSibling;
471 this.Toggle = function(id)
473 var element = this.FindChildElement(id);
476 if (element.style.display == 'block')
478 element.style.display = 'none';
482 element.style.display = 'block';
487 // Searches for the passed string. If there is no parameter,
488 // it takes it from the URL query.
490 // Always returns true, since other documents may try to call it
491 // and that may or may not be possible.
492 this.Search = function(search)
494 if (!search) // get search word from URL
496 search = window.location.search;
497 search = search.substring(1); // Remove the leading '?'
498 search = unescape(search);
501 search = search.replace(/^ +/, ""); // strip leading spaces
502 search = search.replace(/ +$/, ""); // strip trailing spaces
503 search = search.toLowerCase();
504 search = convertToId(search);
506 var resultRows = document.getElementsByTagName("div");
510 while (i < resultRows.length)
512 var row = resultRows.item(i);
513 if (row.className == "SRResult")
515 var rowMatchName = row.id.toLowerCase();
516 rowMatchName = rowMatchName.replace(/^sr\d*_/, ''); // strip 'sr123_'
518 if (search.length<=rowMatchName.length &&
519 rowMatchName.substr(0, search.length)==search)
521 row.style.display = 'block';
526 row.style.display = 'none';
531 document.getElementById("Searching").style.display='none';
532 if (matches == 0) // no results
534 document.getElementById("NoMatches").style.display='block';
536 else // at least one result
538 document.getElementById("NoMatches").style.display='none';
540 this.lastMatchCount = matches;
544 // return the first item with index index or higher that is visible
545 this.NavNext = function(index)
550 var focusName = 'Item'+index;
551 focusItem = document.getElementById(focusName);
552 if (focusItem && focusItem.parentNode.parentNode.style.display=='block')
556 else if (!focusItem) // last element
566 this.NavPrev = function(index)
571 var focusName = 'Item'+index;
572 focusItem = document.getElementById(focusName);
573 if (focusItem && focusItem.parentNode.parentNode.style.display=='block')
577 else if (!focusItem) // last element
587 this.ProcessKeys = function(e)
589 if (e.type == "keydown")
591 this.repeatOn = false;
592 this.lastKey = e.keyCode;
594 else if (e.type == "keypress")
598 if (this.lastKey) this.repeatOn = true;
599 return false; // ignore first keypress after keydown
602 else if (e.type == "keyup")
605 this.repeatOn = false;
607 return this.lastKey!=0;
610 this.Nav = function(evt,itemIndex)
612 var e = (evt) ? evt : window.event; // for IE
613 if (e.keyCode==13) return true;
614 if (!this.ProcessKeys(e)) return false;
616 if (this.lastKey==38) // Up
618 var newIndex = itemIndex-1;
619 var focusItem = this.NavPrev(newIndex);
622 var child = this.FindChildElement(focusItem.parentNode.parentNode.id);
623 if (child && child.style.display == 'block') // children visible
627 while (1) // search for last child
629 tmpElem = document.getElementById('Item'+newIndex+'_c'+n);
646 else // return focus to search field
648 parent.document.getElementById("MSearchField").focus();
651 else if (this.lastKey==40) // Down
653 var newIndex = itemIndex+1;
655 var item = document.getElementById('Item'+itemIndex);
656 var elem = this.FindChildElement(item.parentNode.parentNode.id);
657 if (elem && elem.style.display == 'block') // children visible
659 focusItem = document.getElementById('Item'+itemIndex+'_c0');
661 if (!focusItem) focusItem = this.NavNext(newIndex);
662 if (focusItem) focusItem.focus();
664 else if (this.lastKey==39) // Right
666 var item = document.getElementById('Item'+itemIndex);
667 var elem = this.FindChildElement(item.parentNode.parentNode.id);
668 if (elem) elem.style.display = 'block';
670 else if (this.lastKey==37) // Left
672 var item = document.getElementById('Item'+itemIndex);
673 var elem = this.FindChildElement(item.parentNode.parentNode.id);
674 if (elem) elem.style.display = 'none';
676 else if (this.lastKey==27) // Escape
678 parent.searchBox.CloseResultsWindow();
679 parent.document.getElementById("MSearchField").focus();
681 else if (this.lastKey==13) // Enter
688 this.NavChild = function(evt,itemIndex,childIndex)
690 var e = (evt) ? evt : window.event; // for IE
691 if (e.keyCode==13) return true;
692 if (!this.ProcessKeys(e)) return false;
694 if (this.lastKey==38) // Up
698 var newIndex = childIndex-1;
699 document.getElementById('Item'+itemIndex+'_c'+newIndex).focus();
701 else // already at first child, jump to parent
703 document.getElementById('Item'+itemIndex).focus();
706 else if (this.lastKey==40) // Down
708 var newIndex = childIndex+1;
709 var elem = document.getElementById('Item'+itemIndex+'_c'+newIndex);
710 if (!elem) // last child, jump to parent next parent
712 elem = this.NavNext(itemIndex+1);
719 else if (this.lastKey==27) // Escape
721 parent.searchBox.CloseResultsWindow();
722 parent.document.getElementById("MSearchField").focus();
724 else if (this.lastKey==13) // Enter