search.js 21 KB

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