search.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731
  1. // Search script generated by doxygen
  2. // Copyright (C) 2009 by Dimitri van Heesch.
  3. // The code in this file is loosly based on main.js, part of Natural Docs,
  4. // which is Copyright (C) 2003-2008 Greg Valure
  5. // Natural Docs is licensed under the GPL.
  6. var indexSectionsWithContent =
  7. {
  8. 0: "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000101101000000000010100100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
  9. 1: "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000101001000000000010000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
  10. 2: "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
  11. };
  12. var indexSectionNames =
  13. {
  14. 0: "all",
  15. 1: "classes",
  16. 2: "functions"
  17. };
  18. function convertToId(search)
  19. {
  20. var result = '';
  21. for (i=0;i<search.length;i++)
  22. {
  23. var c = search.charAt(i);
  24. var cn = c.charCodeAt(0);
  25. if (c.match(/[a-z0-9]/))
  26. {
  27. result+=c;
  28. }
  29. else if (cn<16)
  30. {
  31. result+="_0"+cn.toString(16);
  32. }
  33. else
  34. {
  35. result+="_"+cn.toString(16);
  36. }
  37. }
  38. return result;
  39. }
  40. function getXPos(item)
  41. {
  42. var x = 0;
  43. if (item.offsetWidth)
  44. {
  45. while (item && item!=document.body)
  46. {
  47. x += item.offsetLeft;
  48. item = item.offsetParent;
  49. }
  50. }
  51. return x;
  52. }
  53. function getYPos(item)
  54. {
  55. var y = 0;
  56. if (item.offsetWidth)
  57. {
  58. while (item && item!=document.body)
  59. {
  60. y += item.offsetTop;
  61. item = item.offsetParent;
  62. }
  63. }
  64. return y;
  65. }
  66. /* A class handling everything associated with the search panel.
  67. Parameters:
  68. name - The name of the global variable that will be
  69. storing this instance. Is needed to be able to set timeouts.
  70. resultPath - path to use for external files
  71. */
  72. function SearchBox(name, resultsPath, inFrame, label)
  73. {
  74. if (!name || !resultsPath) { alert("Missing parameters to SearchBox."); }
  75. // ---------- Instance variables
  76. this.name = name;
  77. this.resultsPath = resultsPath;
  78. this.keyTimeout = 0;
  79. this.keyTimeoutLength = 500;
  80. this.closeSelectionTimeout = 300;
  81. this.lastSearchValue = "";
  82. this.lastResultsPage = "";
  83. this.hideTimeout = 0;
  84. this.searchIndex = 0;
  85. this.searchActive = false;
  86. this.insideFrame = inFrame;
  87. this.searchLabel = label;
  88. // ----------- DOM Elements
  89. this.DOMSearchField = function()
  90. { return document.getElementById("MSearchField"); }
  91. this.DOMSearchSelect = function()
  92. { return document.getElementById("MSearchSelect"); }
  93. this.DOMSearchSelectWindow = function()
  94. { return document.getElementById("MSearchSelectWindow"); }
  95. this.DOMPopupSearchResults = function()
  96. { return document.getElementById("MSearchResults"); }
  97. this.DOMPopupSearchResultsWindow = function()
  98. { return document.getElementById("MSearchResultsWindow"); }
  99. this.DOMSearchClose = function()
  100. { return document.getElementById("MSearchClose"); }
  101. this.DOMSearchBox = function()
  102. { return document.getElementById("MSearchBox"); }
  103. // ------------ Event Handlers
  104. // Called when focus is added or removed from the search field.
  105. this.OnSearchFieldFocus = function(isActive)
  106. {
  107. this.Activate(isActive);
  108. }
  109. this.OnSearchSelectShow = function()
  110. {
  111. var searchSelectWindow = this.DOMSearchSelectWindow();
  112. var searchField = this.DOMSearchSelect();
  113. if (this.insideFrame)
  114. {
  115. var left = getXPos(searchField);
  116. var top = getYPos(searchField);
  117. left += searchField.offsetWidth + 6;
  118. top += searchField.offsetHeight;
  119. // show search selection popup
  120. searchSelectWindow.style.display='block';
  121. left -= searchSelectWindow.offsetWidth;
  122. searchSelectWindow.style.left = left + 'px';
  123. searchSelectWindow.style.top = top + 'px';
  124. }
  125. else
  126. {
  127. var left = getXPos(searchField);
  128. var top = getYPos(searchField);
  129. top += searchField.offsetHeight;
  130. // show search selection popup
  131. searchSelectWindow.style.display='block';
  132. searchSelectWindow.style.left = left + 'px';
  133. searchSelectWindow.style.top = top + 'px';
  134. }
  135. // stop selection hide timer
  136. if (this.hideTimeout)
  137. {
  138. clearTimeout(this.hideTimeout);
  139. this.hideTimeout=0;
  140. }
  141. return false; // to avoid "image drag" default event
  142. }
  143. this.OnSearchSelectHide = function()
  144. {
  145. this.hideTimeout = setTimeout(this.name +".CloseSelectionWindow()",
  146. this.closeSelectionTimeout);
  147. }
  148. // Called when the content of the search field is changed.
  149. this.OnSearchFieldChange = function(evt)
  150. {
  151. if (this.keyTimeout) // kill running timer
  152. {
  153. clearTimeout(this.keyTimeout);
  154. this.keyTimeout = 0;
  155. }
  156. var e = (evt) ? evt : window.event; // for IE
  157. if (e.keyCode==40 || e.keyCode==13)
  158. {
  159. if (e.shiftKey==1)
  160. {
  161. this.OnSearchSelectShow();
  162. var win=this.DOMSearchSelectWindow();
  163. for (i=0;i<win.childNodes.length;i++)
  164. {
  165. var child = win.childNodes[i]; // get span within a
  166. if (child.className=='SelectItem')
  167. {
  168. child.focus();
  169. return;
  170. }
  171. }
  172. return;
  173. }
  174. else if (window.frames.MSearchResults.searchResults)
  175. {
  176. var elem = window.frames.MSearchResults.searchResults.NavNext(0);
  177. if (elem) elem.focus();
  178. }
  179. }
  180. else if (e.keyCode==27) // Escape out of the search field
  181. {
  182. this.DOMSearchField().blur();
  183. this.DOMPopupSearchResultsWindow().style.display = 'none';
  184. this.DOMSearchClose().style.display = 'none';
  185. this.lastSearchValue = '';
  186. this.Activate(false);
  187. return;
  188. }
  189. // strip whitespaces
  190. var searchValue = this.DOMSearchField().value.replace(/ +/g, "");
  191. if (searchValue != this.lastSearchValue) // search value has changed
  192. {
  193. if (searchValue != "") // non-empty search
  194. {
  195. // set timer for search update
  196. this.keyTimeout = setTimeout(this.name + '.Search()',
  197. this.keyTimeoutLength);
  198. }
  199. else // empty search field
  200. {
  201. this.DOMPopupSearchResultsWindow().style.display = 'none';
  202. this.DOMSearchClose().style.display = 'none';
  203. this.lastSearchValue = '';
  204. }
  205. }
  206. }
  207. this.SelectItemCount = function(id)
  208. {
  209. var count=0;
  210. var win=this.DOMSearchSelectWindow();
  211. for (i=0;i<win.childNodes.length;i++)
  212. {
  213. var child = win.childNodes[i]; // get span within a
  214. if (child.className=='SelectItem')
  215. {
  216. count++;
  217. }
  218. }
  219. return count;
  220. }
  221. this.SelectItemSet = function(id)
  222. {
  223. var i,j=0;
  224. var win=this.DOMSearchSelectWindow();
  225. for (i=0;i<win.childNodes.length;i++)
  226. {
  227. var child = win.childNodes[i]; // get span within a
  228. if (child.className=='SelectItem')
  229. {
  230. var node = child.firstChild;
  231. if (j==id)
  232. {
  233. node.innerHTML='&bull;';
  234. }
  235. else
  236. {
  237. node.innerHTML='&nbsp;';
  238. }
  239. j++;
  240. }
  241. }
  242. }
  243. // Called when an search filter selection is made.
  244. // set item with index id as the active item
  245. this.OnSelectItem = function(id)
  246. {
  247. this.searchIndex = id;
  248. this.SelectItemSet(id);
  249. var searchValue = this.DOMSearchField().value.replace(/ +/g, "");
  250. if (searchValue!="" && this.searchActive) // something was found -> do a search
  251. {
  252. this.Search();
  253. }
  254. }
  255. this.OnSearchSelectKey = function(evt)
  256. {
  257. var e = (evt) ? evt : window.event; // for IE
  258. if (e.keyCode==40 && this.searchIndex<this.SelectItemCount()) // Down
  259. {
  260. this.searchIndex++;
  261. this.OnSelectItem(this.searchIndex);
  262. }
  263. else if (e.keyCode==38 && this.searchIndex>0) // Up
  264. {
  265. this.searchIndex--;
  266. this.OnSelectItem(this.searchIndex);
  267. }
  268. else if (e.keyCode==13 || e.keyCode==27)
  269. {
  270. this.OnSelectItem(this.searchIndex);
  271. this.CloseSelectionWindow();
  272. this.DOMSearchField().focus();
  273. }
  274. return false;
  275. }
  276. // --------- Actions
  277. // Closes the results window.
  278. this.CloseResultsWindow = function()
  279. {
  280. this.DOMPopupSearchResultsWindow().style.display = 'none';
  281. this.DOMSearchClose().style.display = 'none';
  282. this.Activate(false);
  283. }
  284. this.CloseSelectionWindow = function()
  285. {
  286. this.DOMSearchSelectWindow().style.display = 'none';
  287. }
  288. // Performs a search.
  289. this.Search = function()
  290. {
  291. this.keyTimeout = 0;
  292. // strip leading whitespace
  293. var searchValue = this.DOMSearchField().value.replace(/^ +/, "");
  294. var code = searchValue.toLowerCase().charCodeAt(0);
  295. var hexCode;
  296. if (code<16)
  297. {
  298. hexCode="0"+code.toString(16);
  299. }
  300. else
  301. {
  302. hexCode=code.toString(16);
  303. }
  304. var resultsPage;
  305. var resultsPageWithSearch;
  306. var hasResultsPage;
  307. if (indexSectionsWithContent[this.searchIndex].charAt(code) == '1')
  308. {
  309. resultsPage = this.resultsPath + '/' + indexSectionNames[this.searchIndex] + '_' + hexCode + '.html';
  310. resultsPageWithSearch = resultsPage+'?'+escape(searchValue);
  311. hasResultsPage = true;
  312. }
  313. else // nothing available for this search term
  314. {
  315. resultsPage = this.resultsPath + '/nomatches.html';
  316. resultsPageWithSearch = resultsPage;
  317. hasResultsPage = false;
  318. }
  319. window.frames.MSearchResults.location.href = resultsPageWithSearch;
  320. var domPopupSearchResultsWindow = this.DOMPopupSearchResultsWindow();
  321. if (domPopupSearchResultsWindow.style.display!='block')
  322. {
  323. var domSearchBox = this.DOMSearchBox();
  324. this.DOMSearchClose().style.display = 'inline';
  325. if (this.insideFrame)
  326. {
  327. var domPopupSearchResults = this.DOMPopupSearchResults();
  328. domPopupSearchResultsWindow.style.position = 'relative';
  329. domPopupSearchResultsWindow.style.display = 'block';
  330. var width = document.body.clientWidth - 8; // the -8 is for IE :-(
  331. domPopupSearchResultsWindow.style.width = width + 'px';
  332. domPopupSearchResults.style.width = width + 'px';
  333. }
  334. else
  335. {
  336. var domPopupSearchResults = this.DOMPopupSearchResults();
  337. var left = getXPos(domSearchBox) + 150; // domSearchBox.offsetWidth;
  338. var top = getYPos(domSearchBox) + 20; // domSearchBox.offsetHeight + 1;
  339. domPopupSearchResultsWindow.style.display = 'block';
  340. left -= domPopupSearchResults.offsetWidth;
  341. domPopupSearchResultsWindow.style.top = top + 'px';
  342. domPopupSearchResultsWindow.style.left = left + 'px';
  343. }
  344. }
  345. this.lastSearchValue = searchValue;
  346. this.lastResultsPage = resultsPage;
  347. }
  348. // -------- Activation Functions
  349. // Activates or deactivates the search panel, resetting things to
  350. // their default values if necessary.
  351. this.Activate = function(isActive)
  352. {
  353. if (isActive || // open it
  354. this.DOMPopupSearchResultsWindow().style.display == 'block'
  355. )
  356. {
  357. this.DOMSearchBox().className = 'MSearchBoxActive';
  358. var searchField = this.DOMSearchField();
  359. if (searchField.value == this.searchLabel) // clear "Search" term upon entry
  360. {
  361. searchField.value = '';
  362. this.searchActive = true;
  363. }
  364. }
  365. else if (!isActive) // directly remove the panel
  366. {
  367. this.DOMSearchBox().className = 'MSearchBoxInactive';
  368. this.DOMSearchField().value = this.searchLabel;
  369. this.searchActive = false;
  370. this.lastSearchValue = ''
  371. this.lastResultsPage = '';
  372. }
  373. }
  374. }
  375. // -----------------------------------------------------------------------
  376. // The class that handles everything on the search results page.
  377. function SearchResults(name)
  378. {
  379. // The number of matches from the last run of <Search()>.
  380. this.lastMatchCount = 0;
  381. this.lastKey = 0;
  382. this.repeatOn = false;
  383. // Toggles the visibility of the passed element ID.
  384. this.FindChildElement = function(id)
  385. {
  386. var parentElement = document.getElementById(id);
  387. var element = parentElement.firstChild;
  388. while (element && element!=parentElement)
  389. {
  390. if (element.nodeName == 'DIV' && element.className == 'SRChildren')
  391. {
  392. return element;
  393. }
  394. if (element.nodeName == 'DIV' && element.hasChildNodes())
  395. {
  396. element = element.firstChild;
  397. }
  398. else if (element.nextSibling)
  399. {
  400. element = element.nextSibling;
  401. }
  402. else
  403. {
  404. do
  405. {
  406. element = element.parentNode;
  407. }
  408. while (element && element!=parentElement && !element.nextSibling);
  409. if (element && element!=parentElement)
  410. {
  411. element = element.nextSibling;
  412. }
  413. }
  414. }
  415. }
  416. this.Toggle = function(id)
  417. {
  418. var element = this.FindChildElement(id);
  419. if (element)
  420. {
  421. if (element.style.display == 'block')
  422. {
  423. element.style.display = 'none';
  424. }
  425. else
  426. {
  427. element.style.display = 'block';
  428. }
  429. }
  430. }
  431. // Searches for the passed string. If there is no parameter,
  432. // it takes it from the URL query.
  433. //
  434. // Always returns true, since other documents may try to call it
  435. // and that may or may not be possible.
  436. this.Search = function(search)
  437. {
  438. if (!search) // get search word from URL
  439. {
  440. search = window.location.search;
  441. search = search.substring(1); // Remove the leading '?'
  442. search = unescape(search);
  443. }
  444. search = search.replace(/^ +/, ""); // strip leading spaces
  445. search = search.replace(/ +$/, ""); // strip trailing spaces
  446. search = search.toLowerCase();
  447. search = convertToId(search);
  448. var resultRows = document.getElementsByTagName("div");
  449. var matches = 0;
  450. var i = 0;
  451. while (i < resultRows.length)
  452. {
  453. var row = resultRows.item(i);
  454. if (row.className == "SRResult")
  455. {
  456. var rowMatchName = row.id.toLowerCase();
  457. rowMatchName = rowMatchName.replace(/^sr\d*_/, ''); // strip 'sr123_'
  458. if (search.length<=rowMatchName.length &&
  459. rowMatchName.substr(0, search.length)==search)
  460. {
  461. row.style.display = 'block';
  462. matches++;
  463. }
  464. else
  465. {
  466. row.style.display = 'none';
  467. }
  468. }
  469. i++;
  470. }
  471. document.getElementById("Searching").style.display='none';
  472. if (matches == 0) // no results
  473. {
  474. document.getElementById("NoMatches").style.display='block';
  475. }
  476. else // at least one result
  477. {
  478. document.getElementById("NoMatches").style.display='none';
  479. }
  480. this.lastMatchCount = matches;
  481. return true;
  482. }
  483. // return the first item with index index or higher that is visible
  484. this.NavNext = function(index)
  485. {
  486. var focusItem;
  487. while (1)
  488. {
  489. var focusName = 'Item'+index;
  490. focusItem = document.getElementById(focusName);
  491. if (focusItem && focusItem.parentNode.parentNode.style.display=='block')
  492. {
  493. break;
  494. }
  495. else if (!focusItem) // last element
  496. {
  497. break;
  498. }
  499. focusItem=null;
  500. index++;
  501. }
  502. return focusItem;
  503. }
  504. this.NavPrev = function(index)
  505. {
  506. var focusItem;
  507. while (1)
  508. {
  509. var focusName = 'Item'+index;
  510. focusItem = document.getElementById(focusName);
  511. if (focusItem && focusItem.parentNode.parentNode.style.display=='block')
  512. {
  513. break;
  514. }
  515. else if (!focusItem) // last element
  516. {
  517. break;
  518. }
  519. focusItem=null;
  520. index--;
  521. }
  522. return focusItem;
  523. }
  524. this.ProcessKeys = function(e)
  525. {
  526. if (e.type == "keydown")
  527. {
  528. this.repeatOn = false;
  529. this.lastKey = e.keyCode;
  530. }
  531. else if (e.type == "keypress")
  532. {
  533. if (!this.repeatOn)
  534. {
  535. if (this.lastKey) this.repeatOn = true;
  536. return false; // ignore first keypress after keydown
  537. }
  538. }
  539. else if (e.type == "keyup")
  540. {
  541. this.lastKey = 0;
  542. this.repeatOn = false;
  543. }
  544. return this.lastKey!=0;
  545. }
  546. this.Nav = function(evt,itemIndex)
  547. {
  548. var e = (evt) ? evt : window.event; // for IE
  549. if (e.keyCode==13) return true;
  550. if (!this.ProcessKeys(e)) return false;
  551. if (this.lastKey==38) // Up
  552. {
  553. var newIndex = itemIndex-1;
  554. var focusItem = this.NavPrev(newIndex);
  555. if (focusItem)
  556. {
  557. var child = this.FindChildElement(focusItem.parentNode.parentNode.id);
  558. if (child && child.style.display == 'block') // children visible
  559. {
  560. var n=0;
  561. var tmpElem;
  562. while (1) // search for last child
  563. {
  564. tmpElem = document.getElementById('Item'+newIndex+'_c'+n);
  565. if (tmpElem)
  566. {
  567. focusItem = tmpElem;
  568. }
  569. else // found it!
  570. {
  571. break;
  572. }
  573. n++;
  574. }
  575. }
  576. }
  577. if (focusItem)
  578. {
  579. focusItem.focus();
  580. }
  581. else // return focus to search field
  582. {
  583. parent.document.getElementById("MSearchField").focus();
  584. }
  585. }
  586. else if (this.lastKey==40) // Down
  587. {
  588. var newIndex = itemIndex+1;
  589. var focusItem;
  590. var item = document.getElementById('Item'+itemIndex);
  591. var elem = this.FindChildElement(item.parentNode.parentNode.id);
  592. if (elem && elem.style.display == 'block') // children visible
  593. {
  594. focusItem = document.getElementById('Item'+itemIndex+'_c0');
  595. }
  596. if (!focusItem) focusItem = this.NavNext(newIndex);
  597. if (focusItem) focusItem.focus();
  598. }
  599. else if (this.lastKey==39) // Right
  600. {
  601. var item = document.getElementById('Item'+itemIndex);
  602. var elem = this.FindChildElement(item.parentNode.parentNode.id);
  603. if (elem) elem.style.display = 'block';
  604. }
  605. else if (this.lastKey==37) // Left
  606. {
  607. var item = document.getElementById('Item'+itemIndex);
  608. var elem = this.FindChildElement(item.parentNode.parentNode.id);
  609. if (elem) elem.style.display = 'none';
  610. }
  611. else if (this.lastKey==27) // Escape
  612. {
  613. parent.searchBox.CloseResultsWindow();
  614. parent.document.getElementById("MSearchField").focus();
  615. }
  616. else if (this.lastKey==13) // Enter
  617. {
  618. return true;
  619. }
  620. return false;
  621. }
  622. this.NavChild = function(evt,itemIndex,childIndex)
  623. {
  624. var e = (evt) ? evt : window.event; // for IE
  625. if (e.keyCode==13) return true;
  626. if (!this.ProcessKeys(e)) return false;
  627. if (this.lastKey==38) // Up
  628. {
  629. if (childIndex>0)
  630. {
  631. var newIndex = childIndex-1;
  632. document.getElementById('Item'+itemIndex+'_c'+newIndex).focus();
  633. }
  634. else // already at first child, jump to parent
  635. {
  636. document.getElementById('Item'+itemIndex).focus();
  637. }
  638. }
  639. else if (this.lastKey==40) // Down
  640. {
  641. var newIndex = childIndex+1;
  642. var elem = document.getElementById('Item'+itemIndex+'_c'+newIndex);
  643. if (!elem) // last child, jump to parent next parent
  644. {
  645. elem = this.NavNext(itemIndex+1);
  646. }
  647. if (elem)
  648. {
  649. elem.focus();
  650. }
  651. }
  652. else if (this.lastKey==27) // Escape
  653. {
  654. parent.searchBox.CloseResultsWindow();
  655. parent.document.getElementById("MSearchField").focus();
  656. }
  657. else if (this.lastKey==13) // Enter
  658. {
  659. return true;
  660. }
  661. return false;
  662. }
  663. }