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: "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000111110111011110011111111000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
11 1: "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000011100110000100000110011000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
12 2: "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100110000100000110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
13 3: "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000111110111011110011111110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
16 var indexSectionNames =
24 function convertToId(search)
27 for (i=0;i<search.length;i++)
29 var c = search.charAt(i);
30 var cn = c.charCodeAt(0);
31 if (c.match(/[a-z0-9]/))
37 result+="_0"+cn.toString(16);
41 result+="_"+cn.toString(16);
47 function getXPos(item)
52 while (item && item!=document.body)
55 item = item.offsetParent;
61 function getYPos(item)
66 while (item && item!=document.body)
69 item = item.offsetParent;
75 /* A class handling everything associated with the search panel.
78 name - The name of the global variable that will be
79 storing this instance. Is needed to be able to set timeouts.
80 resultPath - path to use for external files
82 function SearchBox(name, resultsPath, inFrame, label)
84 if (!name || !resultsPath) { alert("Missing parameters to SearchBox."); }
86 // ---------- Instance variables
88 this.resultsPath = resultsPath;
90 this.keyTimeoutLength = 500;
91 this.closeSelectionTimeout = 300;
92 this.lastSearchValue = "";
93 this.lastResultsPage = "";
96 this.searchActive = false;
97 this.insideFrame = inFrame;
98 this.searchLabel = label;
100 // ----------- DOM Elements
102 this.DOMSearchField = function()
103 { return document.getElementById("MSearchField"); }
105 this.DOMSearchSelect = function()
106 { return document.getElementById("MSearchSelect"); }
108 this.DOMSearchSelectWindow = function()
109 { return document.getElementById("MSearchSelectWindow"); }
111 this.DOMPopupSearchResults = function()
112 { return document.getElementById("MSearchResults"); }
114 this.DOMPopupSearchResultsWindow = function()
115 { return document.getElementById("MSearchResultsWindow"); }
117 this.DOMSearchClose = function()
118 { return document.getElementById("MSearchClose"); }
120 this.DOMSearchBox = function()
121 { return document.getElementById("MSearchBox"); }
123 // ------------ Event Handlers
125 // Called when focus is added or removed from the search field.
126 this.OnSearchFieldFocus = function(isActive)
128 this.Activate(isActive);
131 this.OnSearchSelectShow = function()
133 var searchSelectWindow = this.DOMSearchSelectWindow();
134 var searchField = this.DOMSearchSelect();
136 if (this.insideFrame)
138 var left = getXPos(searchField);
139 var top = getYPos(searchField);
140 left += searchField.offsetWidth + 6;
141 top += searchField.offsetHeight;
143 // show search selection popup
144 searchSelectWindow.style.display='block';
145 left -= searchSelectWindow.offsetWidth;
146 searchSelectWindow.style.left = left + 'px';
147 searchSelectWindow.style.top = top + 'px';
151 var left = getXPos(searchField);
152 var top = getYPos(searchField);
153 top += searchField.offsetHeight;
155 // show search selection popup
156 searchSelectWindow.style.display='block';
157 searchSelectWindow.style.left = left + 'px';
158 searchSelectWindow.style.top = top + 'px';
161 // stop selection hide timer
162 if (this.hideTimeout)
164 clearTimeout(this.hideTimeout);
167 return false; // to avoid "image drag" default event
170 this.OnSearchSelectHide = function()
172 this.hideTimeout = setTimeout(this.name +".CloseSelectionWindow()",
173 this.closeSelectionTimeout);
176 // Called when the content of the search field is changed.
177 this.OnSearchFieldChange = function(evt)
179 if (this.keyTimeout) // kill running timer
181 clearTimeout(this.keyTimeout);
185 var e = (evt) ? evt : window.event; // for IE
186 if (e.keyCode==40 || e.keyCode==13)
190 this.OnSearchSelectShow();
191 var win=this.DOMSearchSelectWindow();
192 for (i=0;i<win.childNodes.length;i++)
194 var child = win.childNodes[i]; // get span within a
195 if (child.className=='SelectItem')
203 else if (window.frames.MSearchResults.searchResults)
205 var elem = window.frames.MSearchResults.searchResults.NavNext(0);
206 if (elem) elem.focus();
209 else if (e.keyCode==27) // Escape out of the search field
211 this.DOMSearchField().blur();
212 this.DOMPopupSearchResultsWindow().style.display = 'none';
213 this.DOMSearchClose().style.display = 'none';
214 this.lastSearchValue = '';
215 this.Activate(false);
220 var searchValue = this.DOMSearchField().value.replace(/ +/g, "");
222 if (searchValue != this.lastSearchValue) // search value has changed
224 if (searchValue != "") // non-empty search
226 // set timer for search update
227 this.keyTimeout = setTimeout(this.name + '.Search()',
228 this.keyTimeoutLength);
230 else // empty search field
232 this.DOMPopupSearchResultsWindow().style.display = 'none';
233 this.DOMSearchClose().style.display = 'none';
234 this.lastSearchValue = '';
239 this.SelectItemCount = function(id)
242 var win=this.DOMSearchSelectWindow();
243 for (i=0;i<win.childNodes.length;i++)
245 var child = win.childNodes[i]; // get span within a
246 if (child.className=='SelectItem')
254 this.SelectItemSet = function(id)
257 var win=this.DOMSearchSelectWindow();
258 for (i=0;i<win.childNodes.length;i++)
260 var child = win.childNodes[i]; // get span within a
261 if (child.className=='SelectItem')
263 var node = child.firstChild;
266 node.innerHTML='•';
270 node.innerHTML=' ';
277 // Called when an search filter selection is made.
278 // set item with index id as the active item
279 this.OnSelectItem = function(id)
281 this.searchIndex = id;
282 this.SelectItemSet(id);
283 var searchValue = this.DOMSearchField().value.replace(/ +/g, "");
284 if (searchValue!="" && this.searchActive) // something was found -> do a search
290 this.OnSearchSelectKey = function(evt)
292 var e = (evt) ? evt : window.event; // for IE
293 if (e.keyCode==40 && this.searchIndex<this.SelectItemCount()) // Down
296 this.OnSelectItem(this.searchIndex);
298 else if (e.keyCode==38 && this.searchIndex>0) // Up
301 this.OnSelectItem(this.searchIndex);
303 else if (e.keyCode==13 || e.keyCode==27)
305 this.OnSelectItem(this.searchIndex);
306 this.CloseSelectionWindow();
307 this.DOMSearchField().focus();
314 // Closes the results window.
315 this.CloseResultsWindow = function()
317 this.DOMPopupSearchResultsWindow().style.display = 'none';
318 this.DOMSearchClose().style.display = 'none';
319 this.Activate(false);
322 this.CloseSelectionWindow = function()
324 this.DOMSearchSelectWindow().style.display = 'none';
327 // Performs a search.
328 this.Search = function()
332 // strip leading whitespace
333 var searchValue = this.DOMSearchField().value.replace(/^ +/, "");
335 var code = searchValue.toLowerCase().charCodeAt(0);
339 hexCode="0"+code.toString(16);
343 hexCode=code.toString(16);
347 var resultsPageWithSearch;
350 if (indexSectionsWithContent[this.searchIndex].charAt(code) == '1')
352 resultsPage = this.resultsPath + '/' + indexSectionNames[this.searchIndex] + '_' + hexCode + '.html';
353 resultsPageWithSearch = resultsPage+'?'+escape(searchValue);
354 hasResultsPage = true;
356 else // nothing available for this search term
358 resultsPage = this.resultsPath + '/nomatches.html';
359 resultsPageWithSearch = resultsPage;
360 hasResultsPage = false;
363 window.frames.MSearchResults.location.href = resultsPageWithSearch;
364 var domPopupSearchResultsWindow = this.DOMPopupSearchResultsWindow();
366 if (domPopupSearchResultsWindow.style.display!='block')
368 var domSearchBox = this.DOMSearchBox();
369 this.DOMSearchClose().style.display = 'inline';
370 if (this.insideFrame)
372 var domPopupSearchResults = this.DOMPopupSearchResults();
373 domPopupSearchResultsWindow.style.position = 'relative';
374 domPopupSearchResultsWindow.style.display = 'block';
375 var width = document.body.clientWidth - 8; // the -8 is for IE :-(
376 domPopupSearchResultsWindow.style.width = width + 'px';
377 domPopupSearchResults.style.width = width + 'px';
381 var domPopupSearchResults = this.DOMPopupSearchResults();
382 var left = getXPos(domSearchBox) + domSearchBox.offsetWidth;
383 var top = getYPos(domSearchBox) + domSearchBox.offsetHeight + 1;
384 domPopupSearchResultsWindow.style.display = 'block';
385 left -= domPopupSearchResults.offsetWidth;
386 domPopupSearchResultsWindow.style.top = top + 'px';
387 domPopupSearchResultsWindow.style.left = left + 'px';
391 this.lastSearchValue = searchValue;
392 this.lastResultsPage = resultsPage;
395 // -------- Activation Functions
397 // Activates or deactivates the search panel, resetting things to
398 // their default values if necessary.
399 this.Activate = function(isActive)
401 if (isActive || // open it
402 this.DOMPopupSearchResultsWindow().style.display == 'block'
405 this.DOMSearchBox().className = 'MSearchBoxActive';
407 var searchField = this.DOMSearchField();
409 if (searchField.value == this.searchLabel) // clear "Search" term upon entry
411 searchField.value = '';
412 this.searchActive = true;
415 else if (!isActive) // directly remove the panel
417 this.DOMSearchBox().className = 'MSearchBoxInactive';
418 this.DOMSearchField().value = this.searchLabel;
419 this.searchActive = false;
420 this.lastSearchValue = ''
421 this.lastResultsPage = '';
426 // -----------------------------------------------------------------------
428 // The class that handles everything on the search results page.
429 function SearchResults(name)
431 // The number of matches from the last run of <Search()>.
432 this.lastMatchCount = 0;
434 this.repeatOn = false;
436 // Toggles the visibility of the passed element ID.
437 this.FindChildElement = function(id)
439 var parentElement = document.getElementById(id);
440 var element = parentElement.firstChild;
442 while (element && element!=parentElement)
444 if (element.nodeName == 'DIV' && element.className == 'SRChildren')
449 if (element.nodeName == 'DIV' && element.hasChildNodes())
451 element = element.firstChild;
453 else if (element.nextSibling)
455 element = element.nextSibling;
461 element = element.parentNode;
463 while (element && element!=parentElement && !element.nextSibling);
465 if (element && element!=parentElement)
467 element = element.nextSibling;
473 this.Toggle = function(id)
475 var element = this.FindChildElement(id);
478 if (element.style.display == 'block')
480 element.style.display = 'none';
484 element.style.display = 'block';
489 // Searches for the passed string. If there is no parameter,
490 // it takes it from the URL query.
492 // Always returns true, since other documents may try to call it
493 // and that may or may not be possible.
494 this.Search = function(search)
496 if (!search) // get search word from URL
498 search = window.location.search;
499 search = search.substring(1); // Remove the leading '?'
500 search = unescape(search);
503 search = search.replace(/^ +/, ""); // strip leading spaces
504 search = search.replace(/ +$/, ""); // strip trailing spaces
505 search = search.toLowerCase();
506 search = convertToId(search);
508 var resultRows = document.getElementsByTagName("div");
512 while (i < resultRows.length)
514 var row = resultRows.item(i);
515 if (row.className == "SRResult")
517 var rowMatchName = row.id.toLowerCase();
518 rowMatchName = rowMatchName.replace(/^sr\d*_/, ''); // strip 'sr123_'
520 if (search.length<=rowMatchName.length &&
521 rowMatchName.substr(0, search.length)==search)
523 row.style.display = 'block';
528 row.style.display = 'none';
533 document.getElementById("Searching").style.display='none';
534 if (matches == 0) // no results
536 document.getElementById("NoMatches").style.display='block';
538 else // at least one result
540 document.getElementById("NoMatches").style.display='none';
542 this.lastMatchCount = matches;
546 // return the first item with index index or higher that is visible
547 this.NavNext = function(index)
552 var focusName = 'Item'+index;
553 focusItem = document.getElementById(focusName);
554 if (focusItem && focusItem.parentNode.parentNode.style.display=='block')
558 else if (!focusItem) // last element
568 this.NavPrev = function(index)
573 var focusName = 'Item'+index;
574 focusItem = document.getElementById(focusName);
575 if (focusItem && focusItem.parentNode.parentNode.style.display=='block')
579 else if (!focusItem) // last element
589 this.ProcessKeys = function(e)
591 if (e.type == "keydown")
593 this.repeatOn = false;
594 this.lastKey = e.keyCode;
596 else if (e.type == "keypress")
600 if (this.lastKey) this.repeatOn = true;
601 return false; // ignore first keypress after keydown
604 else if (e.type == "keyup")
607 this.repeatOn = false;
609 return this.lastKey!=0;
612 this.Nav = function(evt,itemIndex)
614 var e = (evt) ? evt : window.event; // for IE
615 if (e.keyCode==13) return true;
616 if (!this.ProcessKeys(e)) return false;
618 if (this.lastKey==38) // Up
620 var newIndex = itemIndex-1;
621 var focusItem = this.NavPrev(newIndex);
624 var child = this.FindChildElement(focusItem.parentNode.parentNode.id);
625 if (child && child.style.display == 'block') // children visible
629 while (1) // search for last child
631 tmpElem = document.getElementById('Item'+newIndex+'_c'+n);
648 else // return focus to search field
650 parent.document.getElementById("MSearchField").focus();
653 else if (this.lastKey==40) // Down
655 var newIndex = itemIndex+1;
657 var item = document.getElementById('Item'+itemIndex);
658 var elem = this.FindChildElement(item.parentNode.parentNode.id);
659 if (elem && elem.style.display == 'block') // children visible
661 focusItem = document.getElementById('Item'+itemIndex+'_c0');
663 if (!focusItem) focusItem = this.NavNext(newIndex);
664 if (focusItem) focusItem.focus();
666 else if (this.lastKey==39) // Right
668 var item = document.getElementById('Item'+itemIndex);
669 var elem = this.FindChildElement(item.parentNode.parentNode.id);
670 if (elem) elem.style.display = 'block';
672 else if (this.lastKey==37) // Left
674 var item = document.getElementById('Item'+itemIndex);
675 var elem = this.FindChildElement(item.parentNode.parentNode.id);
676 if (elem) elem.style.display = 'none';
678 else if (this.lastKey==27) // Escape
680 parent.searchBox.CloseResultsWindow();
681 parent.document.getElementById("MSearchField").focus();
683 else if (this.lastKey==13) // Enter
690 this.NavChild = function(evt,itemIndex,childIndex)
692 var e = (evt) ? evt : window.event; // for IE
693 if (e.keyCode==13) return true;
694 if (!this.ProcessKeys(e)) return false;
696 if (this.lastKey==38) // Up
700 var newIndex = childIndex-1;
701 document.getElementById('Item'+itemIndex+'_c'+newIndex).focus();
703 else // already at first child, jump to parent
705 document.getElementById('Item'+itemIndex).focus();
708 else if (this.lastKey==40) // Down
710 var newIndex = childIndex+1;
711 var elem = document.getElementById('Item'+itemIndex+'_c'+newIndex);
712 if (!elem) // last child, jump to parent next parent
714 elem = this.NavNext(itemIndex+1);
721 else if (this.lastKey==27) // Escape
723 parent.searchBox.CloseResultsWindow();
724 parent.document.getElementById("MSearchField").focus();
726 else if (this.lastKey==13) // Enter