search.js 20 KB

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