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: "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000101100101000100100010010000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
11 1: "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
12 2: "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000100000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
13 3: "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000101000101000100000010000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
14 4: "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000100010010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
17 var indexSectionNames =
26 function convertToId(search)
29 for (i=0;i<search.length;i++)
31 var c = search.charAt(i);
32 var cn = c.charCodeAt(0);
33 if (c.match(/[a-z0-9]/))
39 result+="_0"+cn.toString(16);
43 result+="_"+cn.toString(16);
49 function getXPos(item)
54 while (item && item!=document.body)
57 item = item.offsetParent;
63 function getYPos(item)
68 while (item && item!=document.body)
71 item = item.offsetParent;
77 /* A class handling everything associated with the search panel.
80 name - The name of the global variable that will be
81 storing this instance. Is needed to be able to set timeouts.
82 resultPath - path to use for external files
84 function SearchBox(name, resultsPath, inFrame, label)
86 if (!name || !resultsPath) { alert("Missing parameters to SearchBox."); }
88 // ---------- Instance variables
90 this.resultsPath = resultsPath;
92 this.keyTimeoutLength = 500;
93 this.closeSelectionTimeout = 300;
94 this.lastSearchValue = "";
95 this.lastResultsPage = "";
98 this.searchActive = false;
99 this.insideFrame = inFrame;
100 this.searchLabel = label;
102 // ----------- DOM Elements
104 this.DOMSearchField = function()
105 { return document.getElementById("MSearchField"); }
107 this.DOMSearchSelect = function()
108 { return document.getElementById("MSearchSelect"); }
110 this.DOMSearchSelectWindow = function()
111 { return document.getElementById("MSearchSelectWindow"); }
113 this.DOMPopupSearchResults = function()
114 { return document.getElementById("MSearchResults"); }
116 this.DOMPopupSearchResultsWindow = function()
117 { return document.getElementById("MSearchResultsWindow"); }
119 this.DOMSearchClose = function()
120 { return document.getElementById("MSearchClose"); }
122 this.DOMSearchBox = function()
123 { return document.getElementById("MSearchBox"); }
125 // ------------ Event Handlers
127 // Called when focus is added or removed from the search field.
128 this.OnSearchFieldFocus = function(isActive)
130 this.Activate(isActive);
133 this.OnSearchSelectShow = function()
135 var searchSelectWindow = this.DOMSearchSelectWindow();
136 var searchField = this.DOMSearchSelect();
138 if (this.insideFrame)
140 var left = getXPos(searchField);
141 var top = getYPos(searchField);
142 left += searchField.offsetWidth + 6;
143 top += searchField.offsetHeight;
145 // show search selection popup
146 searchSelectWindow.style.display='block';
147 left -= searchSelectWindow.offsetWidth;
148 searchSelectWindow.style.left = left + 'px';
149 searchSelectWindow.style.top = top + 'px';
153 var left = getXPos(searchField);
154 var top = getYPos(searchField);
155 top += searchField.offsetHeight;
157 // show search selection popup
158 searchSelectWindow.style.display='block';
159 searchSelectWindow.style.left = left + 'px';
160 searchSelectWindow.style.top = top + 'px';
163 // stop selection hide timer
164 if (this.hideTimeout)
166 clearTimeout(this.hideTimeout);
169 return false; // to avoid "image drag" default event
172 this.OnSearchSelectHide = function()
174 this.hideTimeout = setTimeout(this.name +".CloseSelectionWindow()",
175 this.closeSelectionTimeout);
178 // Called when the content of the search field is changed.
179 this.OnSearchFieldChange = function(evt)
181 if (this.keyTimeout) // kill running timer
183 clearTimeout(this.keyTimeout);
187 var e = (evt) ? evt : window.event; // for IE
188 if (e.keyCode==40 || e.keyCode==13)
192 this.OnSearchSelectShow();
193 var win=this.DOMSearchSelectWindow();
194 for (i=0;i<win.childNodes.length;i++)
196 var child = win.childNodes[i]; // get span within a
197 if (child.className=='SelectItem')
205 else if (window.frames.MSearchResults.searchResults)
207 var elem = window.frames.MSearchResults.searchResults.NavNext(0);
208 if (elem) elem.focus();
211 else if (e.keyCode==27) // Escape out of the search field
213 this.DOMSearchField().blur();
214 this.DOMPopupSearchResultsWindow().style.display = 'none';
215 this.DOMSearchClose().style.display = 'none';
216 this.lastSearchValue = '';
217 this.Activate(false);
222 var searchValue = this.DOMSearchField().value.replace(/ +/g, "");
224 if (searchValue != this.lastSearchValue) // search value has changed
226 if (searchValue != "") // non-empty search
228 // set timer for search update
229 this.keyTimeout = setTimeout(this.name + '.Search()',
230 this.keyTimeoutLength);
232 else // empty search field
234 this.DOMPopupSearchResultsWindow().style.display = 'none';
235 this.DOMSearchClose().style.display = 'none';
236 this.lastSearchValue = '';
241 this.SelectItemCount = function(id)
244 var win=this.DOMSearchSelectWindow();
245 for (i=0;i<win.childNodes.length;i++)
247 var child = win.childNodes[i]; // get span within a
248 if (child.className=='SelectItem')
256 this.SelectItemSet = function(id)
259 var win=this.DOMSearchSelectWindow();
260 for (i=0;i<win.childNodes.length;i++)
262 var child = win.childNodes[i]; // get span within a
263 if (child.className=='SelectItem')
265 var node = child.firstChild;
268 node.innerHTML='•';
272 node.innerHTML=' ';
279 // Called when an search filter selection is made.
280 // set item with index id as the active item
281 this.OnSelectItem = function(id)
283 this.searchIndex = id;
284 this.SelectItemSet(id);
285 var searchValue = this.DOMSearchField().value.replace(/ +/g, "");
286 if (searchValue!="" && this.searchActive) // something was found -> do a search
292 this.OnSearchSelectKey = function(evt)
294 var e = (evt) ? evt : window.event; // for IE
295 if (e.keyCode==40 && this.searchIndex<this.SelectItemCount()) // Down
298 this.OnSelectItem(this.searchIndex);
300 else if (e.keyCode==38 && this.searchIndex>0) // Up
303 this.OnSelectItem(this.searchIndex);
305 else if (e.keyCode==13 || e.keyCode==27)
307 this.OnSelectItem(this.searchIndex);
308 this.CloseSelectionWindow();
309 this.DOMSearchField().focus();
316 // Closes the results window.
317 this.CloseResultsWindow = function()
319 this.DOMPopupSearchResultsWindow().style.display = 'none';
320 this.DOMSearchClose().style.display = 'none';
321 this.Activate(false);
324 this.CloseSelectionWindow = function()
326 this.DOMSearchSelectWindow().style.display = 'none';
329 // Performs a search.
330 this.Search = function()
334 // strip leading whitespace
335 var searchValue = this.DOMSearchField().value.replace(/^ +/, "");
337 var code = searchValue.toLowerCase().charCodeAt(0);
341 hexCode="0"+code.toString(16);
345 hexCode=code.toString(16);
349 var resultsPageWithSearch;
352 if (indexSectionsWithContent[this.searchIndex].charAt(code) == '1')
354 resultsPage = this.resultsPath + '/' + indexSectionNames[this.searchIndex] + '_' + hexCode + '.html';
355 resultsPageWithSearch = resultsPage+'?'+escape(searchValue);
356 hasResultsPage = true;
358 else // nothing available for this search term
360 resultsPage = this.resultsPath + '/nomatches.html';
361 resultsPageWithSearch = resultsPage;
362 hasResultsPage = false;
365 window.frames.MSearchResults.location.href = resultsPageWithSearch;
366 var domPopupSearchResultsWindow = this.DOMPopupSearchResultsWindow();
368 if (domPopupSearchResultsWindow.style.display!='block')
370 var domSearchBox = this.DOMSearchBox();
371 this.DOMSearchClose().style.display = 'inline';
372 if (this.insideFrame)
374 var domPopupSearchResults = this.DOMPopupSearchResults();
375 domPopupSearchResultsWindow.style.position = 'relative';
376 domPopupSearchResultsWindow.style.display = 'block';
377 var width = document.body.clientWidth - 8; // the -8 is for IE :-(
378 domPopupSearchResultsWindow.style.width = width + 'px';
379 domPopupSearchResults.style.width = width + 'px';
383 var domPopupSearchResults = this.DOMPopupSearchResults();
384 var left = getXPos(domSearchBox) + domSearchBox.offsetWidth;
385 var top = getYPos(domSearchBox) + domSearchBox.offsetHeight + 1;
386 domPopupSearchResultsWindow.style.display = 'block';
387 left -= domPopupSearchResults.offsetWidth;
388 domPopupSearchResultsWindow.style.top = top + 'px';
389 domPopupSearchResultsWindow.style.left = left + 'px';
393 this.lastSearchValue = searchValue;
394 this.lastResultsPage = resultsPage;
397 // -------- Activation Functions
399 // Activates or deactivates the search panel, resetting things to
400 // their default values if necessary.
401 this.Activate = function(isActive)
403 if (isActive || // open it
404 this.DOMPopupSearchResultsWindow().style.display == 'block'
407 this.DOMSearchBox().className = 'MSearchBoxActive';
409 var searchField = this.DOMSearchField();
411 if (searchField.value == this.searchLabel) // clear "Search" term upon entry
413 searchField.value = '';
414 this.searchActive = true;
417 else if (!isActive) // directly remove the panel
419 this.DOMSearchBox().className = 'MSearchBoxInactive';
420 this.DOMSearchField().value = this.searchLabel;
421 this.searchActive = false;
422 this.lastSearchValue = ''
423 this.lastResultsPage = '';
428 // -----------------------------------------------------------------------
430 // The class that handles everything on the search results page.
431 function SearchResults(name)
433 // The number of matches from the last run of <Search()>.
434 this.lastMatchCount = 0;
436 this.repeatOn = false;
438 // Toggles the visibility of the passed element ID.
439 this.FindChildElement = function(id)
441 var parentElement = document.getElementById(id);
442 var element = parentElement.firstChild;
444 while (element && element!=parentElement)
446 if (element.nodeName == 'DIV' && element.className == 'SRChildren')
451 if (element.nodeName == 'DIV' && element.hasChildNodes())
453 element = element.firstChild;
455 else if (element.nextSibling)
457 element = element.nextSibling;
463 element = element.parentNode;
465 while (element && element!=parentElement && !element.nextSibling);
467 if (element && element!=parentElement)
469 element = element.nextSibling;
475 this.Toggle = function(id)
477 var element = this.FindChildElement(id);
480 if (element.style.display == 'block')
482 element.style.display = 'none';
486 element.style.display = 'block';
491 // Searches for the passed string. If there is no parameter,
492 // it takes it from the URL query.
494 // Always returns true, since other documents may try to call it
495 // and that may or may not be possible.
496 this.Search = function(search)
498 if (!search) // get search word from URL
500 search = window.location.search;
501 search = search.substring(1); // Remove the leading '?'
502 search = unescape(search);
505 search = search.replace(/^ +/, ""); // strip leading spaces
506 search = search.replace(/ +$/, ""); // strip trailing spaces
507 search = search.toLowerCase();
508 search = convertToId(search);
510 var resultRows = document.getElementsByTagName("div");
514 while (i < resultRows.length)
516 var row = resultRows.item(i);
517 if (row.className == "SRResult")
519 var rowMatchName = row.id.toLowerCase();
520 rowMatchName = rowMatchName.replace(/^sr\d*_/, ''); // strip 'sr123_'
522 if (search.length<=rowMatchName.length &&
523 rowMatchName.substr(0, search.length)==search)
525 row.style.display = 'block';
530 row.style.display = 'none';
535 document.getElementById("Searching").style.display='none';
536 if (matches == 0) // no results
538 document.getElementById("NoMatches").style.display='block';
540 else // at least one result
542 document.getElementById("NoMatches").style.display='none';
544 this.lastMatchCount = matches;
548 // return the first item with index index or higher that is visible
549 this.NavNext = function(index)
554 var focusName = 'Item'+index;
555 focusItem = document.getElementById(focusName);
556 if (focusItem && focusItem.parentNode.parentNode.style.display=='block')
560 else if (!focusItem) // last element
570 this.NavPrev = function(index)
575 var focusName = 'Item'+index;
576 focusItem = document.getElementById(focusName);
577 if (focusItem && focusItem.parentNode.parentNode.style.display=='block')
581 else if (!focusItem) // last element
591 this.ProcessKeys = function(e)
593 if (e.type == "keydown")
595 this.repeatOn = false;
596 this.lastKey = e.keyCode;
598 else if (e.type == "keypress")
602 if (this.lastKey) this.repeatOn = true;
603 return false; // ignore first keypress after keydown
606 else if (e.type == "keyup")
609 this.repeatOn = false;
611 return this.lastKey!=0;
614 this.Nav = function(evt,itemIndex)
616 var e = (evt) ? evt : window.event; // for IE
617 if (e.keyCode==13) return true;
618 if (!this.ProcessKeys(e)) return false;
620 if (this.lastKey==38) // Up
622 var newIndex = itemIndex-1;
623 var focusItem = this.NavPrev(newIndex);
626 var child = this.FindChildElement(focusItem.parentNode.parentNode.id);
627 if (child && child.style.display == 'block') // children visible
631 while (1) // search for last child
633 tmpElem = document.getElementById('Item'+newIndex+'_c'+n);
650 else // return focus to search field
652 parent.document.getElementById("MSearchField").focus();
655 else if (this.lastKey==40) // Down
657 var newIndex = itemIndex+1;
659 var item = document.getElementById('Item'+itemIndex);
660 var elem = this.FindChildElement(item.parentNode.parentNode.id);
661 if (elem && elem.style.display == 'block') // children visible
663 focusItem = document.getElementById('Item'+itemIndex+'_c0');
665 if (!focusItem) focusItem = this.NavNext(newIndex);
666 if (focusItem) focusItem.focus();
668 else if (this.lastKey==39) // Right
670 var item = document.getElementById('Item'+itemIndex);
671 var elem = this.FindChildElement(item.parentNode.parentNode.id);
672 if (elem) elem.style.display = 'block';
674 else if (this.lastKey==37) // Left
676 var item = document.getElementById('Item'+itemIndex);
677 var elem = this.FindChildElement(item.parentNode.parentNode.id);
678 if (elem) elem.style.display = 'none';
680 else if (this.lastKey==27) // Escape
682 parent.searchBox.CloseResultsWindow();
683 parent.document.getElementById("MSearchField").focus();
685 else if (this.lastKey==13) // Enter
692 this.NavChild = function(evt,itemIndex,childIndex)
694 var e = (evt) ? evt : window.event; // for IE
695 if (e.keyCode==13) return true;
696 if (!this.ProcessKeys(e)) return false;
698 if (this.lastKey==38) // Up
702 var newIndex = childIndex-1;
703 document.getElementById('Item'+itemIndex+'_c'+newIndex).focus();
705 else // already at first child, jump to parent
707 document.getElementById('Item'+itemIndex).focus();
710 else if (this.lastKey==40) // Down
712 var newIndex = childIndex+1;
713 var elem = document.getElementById('Item'+itemIndex+'_c'+newIndex);
714 if (!elem) // last child, jump to parent next parent
716 elem = this.NavNext(itemIndex+1);
723 else if (this.lastKey==27) // Escape
725 parent.searchBox.CloseResultsWindow();
726 parent.document.getElementById("MSearchField").focus();
728 else if (this.lastKey==13) // Enter