2
0

search.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816
  1. /*
  2. @licstart The following is the entire license notice for the JavaScript code in this file.
  3. The MIT License (MIT)
  4. Copyright (C) 1997-2020 by Dimitri van Heesch
  5. Permission is hereby granted, free of charge, to any person obtaining a copy of this software
  6. and associated documentation files (the "Software"), to deal in the Software without restriction,
  7. including without limitation the rights to use, copy, modify, merge, publish, distribute,
  8. sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
  9. furnished to do so, subject to the following conditions:
  10. The above copyright notice and this permission notice shall be included in all copies or
  11. substantial portions of the Software.
  12. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
  13. BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  14. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  15. DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  16. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  17. @licend The above is the entire license notice for the JavaScript code in this file
  18. */
  19. function convertToId(search)
  20. {
  21. var result = '';
  22. for (i=0;i<search.length;i++)
  23. {
  24. var c = search.charAt(i);
  25. var cn = c.charCodeAt(0);
  26. if (c.match(/[a-z0-9\u0080-\uFFFF]/))
  27. {
  28. result+=c;
  29. }
  30. else if (cn<16)
  31. {
  32. result+="_0"+cn.toString(16);
  33. }
  34. else
  35. {
  36. result+="_"+cn.toString(16);
  37. }
  38. }
  39. return result;
  40. }
  41. function getXPos(item)
  42. {
  43. var x = 0;
  44. if (item.offsetWidth)
  45. {
  46. while (item && item!=document.body)
  47. {
  48. x += item.offsetLeft;
  49. item = item.offsetParent;
  50. }
  51. }
  52. return x;
  53. }
  54. function getYPos(item)
  55. {
  56. var y = 0;
  57. if (item.offsetWidth)
  58. {
  59. while (item && item!=document.body)
  60. {
  61. y += item.offsetTop;
  62. item = item.offsetParent;
  63. }
  64. }
  65. return y;
  66. }
  67. /* A class handling everything associated with the search panel.
  68. Parameters:
  69. name - The name of the global variable that will be
  70. storing this instance. Is needed to be able to set timeouts.
  71. resultPath - path to use for external files
  72. */
  73. function SearchBox(name, resultsPath, inFrame, label, extension)
  74. {
  75. if (!name || !resultsPath) { alert("Missing parameters to SearchBox."); }
  76. if (!extension || extension == "") { extension = ".html"; }
  77. // ---------- Instance variables
  78. this.name = name;
  79. this.resultsPath = resultsPath;
  80. this.keyTimeout = 0;
  81. this.keyTimeoutLength = 500;
  82. this.closeSelectionTimeout = 300;
  83. this.lastSearchValue = "";
  84. this.lastResultsPage = "";
  85. this.hideTimeout = 0;
  86. this.searchIndex = 0;
  87. this.searchActive = false;
  88. this.insideFrame = inFrame;
  89. this.searchLabel = label;
  90. this.extension = extension;
  91. // ----------- DOM Elements
  92. this.DOMSearchField = function()
  93. { return document.getElementById("MSearchField"); }
  94. this.DOMSearchSelect = function()
  95. { return document.getElementById("MSearchSelect"); }
  96. this.DOMSearchSelectWindow = function()
  97. { return document.getElementById("MSearchSelectWindow"); }
  98. this.DOMPopupSearchResults = function()
  99. { return document.getElementById("MSearchResults"); }
  100. this.DOMPopupSearchResultsWindow = function()
  101. { return document.getElementById("MSearchResultsWindow"); }
  102. this.DOMSearchClose = function()
  103. { return document.getElementById("MSearchClose"); }
  104. this.DOMSearchBox = function()
  105. { return document.getElementById("MSearchBox"); }
  106. // ------------ Event Handlers
  107. // Called when focus is added or removed from the search field.
  108. this.OnSearchFieldFocus = function(isActive)
  109. {
  110. this.Activate(isActive);
  111. }
  112. this.OnSearchSelectShow = function()
  113. {
  114. var searchSelectWindow = this.DOMSearchSelectWindow();
  115. var searchField = this.DOMSearchSelect();
  116. if (this.insideFrame)
  117. {
  118. var left = getXPos(searchField);
  119. var top = getYPos(searchField);
  120. left += searchField.offsetWidth + 6;
  121. top += searchField.offsetHeight;
  122. // show search selection popup
  123. searchSelectWindow.style.display='block';
  124. left -= searchSelectWindow.offsetWidth;
  125. searchSelectWindow.style.left = left + 'px';
  126. searchSelectWindow.style.top = top + 'px';
  127. }
  128. else
  129. {
  130. var left = getXPos(searchField);
  131. var top = getYPos(searchField);
  132. top += searchField.offsetHeight;
  133. // show search selection popup
  134. searchSelectWindow.style.display='block';
  135. searchSelectWindow.style.left = left + 'px';
  136. searchSelectWindow.style.top = top + 'px';
  137. }
  138. // stop selection hide timer
  139. if (this.hideTimeout)
  140. {
  141. clearTimeout(this.hideTimeout);
  142. this.hideTimeout=0;
  143. }
  144. return false; // to avoid "image drag" default event
  145. }
  146. this.OnSearchSelectHide = function()
  147. {
  148. this.hideTimeout = setTimeout(this.name +".CloseSelectionWindow()",
  149. this.closeSelectionTimeout);
  150. }
  151. // Called when the content of the search field is changed.
  152. this.OnSearchFieldChange = function(evt)
  153. {
  154. if (this.keyTimeout) // kill running timer
  155. {
  156. clearTimeout(this.keyTimeout);
  157. this.keyTimeout = 0;
  158. }
  159. var e = (evt) ? evt : window.event; // for IE
  160. if (e.keyCode==40 || e.keyCode==13)
  161. {
  162. if (e.shiftKey==1)
  163. {
  164. this.OnSearchSelectShow();
  165. var win=this.DOMSearchSelectWindow();
  166. for (i=0;i<win.childNodes.length;i++)
  167. {
  168. var child = win.childNodes[i]; // get span within a
  169. if (child.className=='SelectItem')
  170. {
  171. child.focus();
  172. return;
  173. }
  174. }
  175. return;
  176. }
  177. else
  178. {
  179. window.frames.MSearchResults.postMessage("take_focus", "*");
  180. }
  181. }
  182. else if (e.keyCode==27) // Escape out of the search field
  183. {
  184. this.DOMSearchField().blur();
  185. this.DOMPopupSearchResultsWindow().style.display = 'none';
  186. this.DOMSearchClose().style.display = 'none';
  187. this.lastSearchValue = '';
  188. this.Activate(false);
  189. return;
  190. }
  191. // strip whitespaces
  192. var searchValue = this.DOMSearchField().value.replace(/ +/g, "");
  193. if (searchValue != this.lastSearchValue) // search value has changed
  194. {
  195. if (searchValue != "") // non-empty search
  196. {
  197. // set timer for search update
  198. this.keyTimeout = setTimeout(this.name + '.Search()',
  199. this.keyTimeoutLength);
  200. }
  201. else // empty search field
  202. {
  203. this.DOMPopupSearchResultsWindow().style.display = 'none';
  204. this.DOMSearchClose().style.display = 'none';
  205. this.lastSearchValue = '';
  206. }
  207. }
  208. }
  209. this.SelectItemCount = function(id)
  210. {
  211. var count=0;
  212. var win=this.DOMSearchSelectWindow();
  213. for (i=0;i<win.childNodes.length;i++)
  214. {
  215. var child = win.childNodes[i]; // get span within a
  216. if (child.className=='SelectItem')
  217. {
  218. count++;
  219. }
  220. }
  221. return count;
  222. }
  223. this.SelectItemSet = function(id)
  224. {
  225. var i,j=0;
  226. var win=this.DOMSearchSelectWindow();
  227. for (i=0;i<win.childNodes.length;i++)
  228. {
  229. var child = win.childNodes[i]; // get span within a
  230. if (child.className=='SelectItem')
  231. {
  232. var node = child.firstChild;
  233. if (j==id)
  234. {
  235. node.innerHTML='&#8226;';
  236. }
  237. else
  238. {
  239. node.innerHTML='&#160;';
  240. }
  241. j++;
  242. }
  243. }
  244. }
  245. // Called when an search filter selection is made.
  246. // set item with index id as the active item
  247. this.OnSelectItem = function(id)
  248. {
  249. this.searchIndex = id;
  250. this.SelectItemSet(id);
  251. var searchValue = this.DOMSearchField().value.replace(/ +/g, "");
  252. if (searchValue!="" && this.searchActive) // something was found -> do a search
  253. {
  254. this.Search();
  255. }
  256. }
  257. this.OnSearchSelectKey = function(evt)
  258. {
  259. var e = (evt) ? evt : window.event; // for IE
  260. if (e.keyCode==40 && this.searchIndex<this.SelectItemCount()) // Down
  261. {
  262. this.searchIndex++;
  263. this.OnSelectItem(this.searchIndex);
  264. }
  265. else if (e.keyCode==38 && this.searchIndex>0) // Up
  266. {
  267. this.searchIndex--;
  268. this.OnSelectItem(this.searchIndex);
  269. }
  270. else if (e.keyCode==13 || e.keyCode==27)
  271. {
  272. this.OnSelectItem(this.searchIndex);
  273. this.CloseSelectionWindow();
  274. this.DOMSearchField().focus();
  275. }
  276. return false;
  277. }
  278. // --------- Actions
  279. // Closes the results window.
  280. this.CloseResultsWindow = function()
  281. {
  282. this.DOMPopupSearchResultsWindow().style.display = 'none';
  283. this.DOMSearchClose().style.display = 'none';
  284. this.Activate(false);
  285. }
  286. this.CloseSelectionWindow = function()
  287. {
  288. this.DOMSearchSelectWindow().style.display = 'none';
  289. }
  290. // Performs a search.
  291. this.Search = function()
  292. {
  293. this.keyTimeout = 0;
  294. // strip leading whitespace
  295. var searchValue = this.DOMSearchField().value.replace(/^ +/, "");
  296. var code = searchValue.toLowerCase().charCodeAt(0);
  297. var idxChar = searchValue.substr(0, 1).toLowerCase();
  298. if ( 0xD800 <= code && code <= 0xDBFF && searchValue > 1) // surrogate pair
  299. {
  300. idxChar = searchValue.substr(0, 2);
  301. }
  302. var resultsPage;
  303. var resultsPageWithSearch;
  304. var hasResultsPage;
  305. var idx = indexSectionsWithContent[this.searchIndex].indexOf(idxChar);
  306. if (idx!=-1)
  307. {
  308. var hexCode=idx.toString(16);
  309. resultsPage = this.resultsPath + '/' + indexSectionNames[this.searchIndex] + '_' + hexCode + this.extension;
  310. resultsPageWithSearch = resultsPage+'?'+escape(searchValue);
  311. hasResultsPage = true;
  312. }
  313. else // nothing available for this search term
  314. {
  315. resultsPage = this.resultsPath + '/nomatches' + this.extension;
  316. resultsPageWithSearch = resultsPage;
  317. hasResultsPage = false;
  318. }
  319. window.frames.MSearchResults.location = resultsPageWithSearch;
  320. var domPopupSearchResultsWindow = this.DOMPopupSearchResultsWindow();
  321. if (domPopupSearchResultsWindow.style.display!='block')
  322. {
  323. var domSearchBox = this.DOMSearchBox();
  324. this.DOMSearchClose().style.display = 'inline-block';
  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.toLowerCase() == 'div' && element.className == 'SRChildren')
  391. {
  392. return element;
  393. }
  394. if (element.nodeName.toLowerCase() == '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. }
  664. function setKeyActions(elem,action)
  665. {
  666. elem.setAttribute('onkeydown',action);
  667. elem.setAttribute('onkeypress',action);
  668. elem.setAttribute('onkeyup',action);
  669. }
  670. function setClassAttr(elem,attr)
  671. {
  672. elem.setAttribute('class',attr);
  673. elem.setAttribute('className',attr);
  674. }
  675. function createResults()
  676. {
  677. var results = document.getElementById("SRResults");
  678. for (var e=0; e<searchData.length; e++)
  679. {
  680. var id = searchData[e][0];
  681. var srResult = document.createElement('div');
  682. srResult.setAttribute('id','SR_'+id);
  683. setClassAttr(srResult,'SRResult');
  684. var srEntry = document.createElement('div');
  685. setClassAttr(srEntry,'SREntry');
  686. var srLink = document.createElement('a');
  687. srLink.setAttribute('id','Item'+e);
  688. setKeyActions(srLink,'return searchResults.Nav(event,'+e+')');
  689. setClassAttr(srLink,'SRSymbol');
  690. srLink.innerHTML = searchData[e][1][0];
  691. srEntry.appendChild(srLink);
  692. if (searchData[e][1].length==2) // single result
  693. {
  694. srLink.setAttribute('href',searchData[e][1][1][0]);
  695. if (searchData[e][1][1][1])
  696. {
  697. srLink.setAttribute('target','_parent');
  698. }
  699. var srScope = document.createElement('span');
  700. setClassAttr(srScope,'SRScope');
  701. srScope.innerHTML = searchData[e][1][1][2];
  702. srEntry.appendChild(srScope);
  703. }
  704. else // multiple results
  705. {
  706. srLink.setAttribute('href','javascript:searchResults.Toggle("SR_'+id+'")');
  707. var srChildren = document.createElement('div');
  708. setClassAttr(srChildren,'SRChildren');
  709. for (var c=0; c<searchData[e][1].length-1; c++)
  710. {
  711. var srChild = document.createElement('a');
  712. srChild.setAttribute('id','Item'+e+'_c'+c);
  713. setKeyActions(srChild,'return searchResults.NavChild(event,'+e+','+c+')');
  714. setClassAttr(srChild,'SRScope');
  715. srChild.setAttribute('href',searchData[e][1][c+1][0]);
  716. if (searchData[e][1][c+1][1])
  717. {
  718. srChild.setAttribute('target','_parent');
  719. }
  720. srChild.innerHTML = searchData[e][1][c+1][2];
  721. srChildren.appendChild(srChild);
  722. }
  723. srEntry.appendChild(srChildren);
  724. }
  725. srResult.appendChild(srEntry);
  726. results.appendChild(srResult);
  727. }
  728. }
  729. function init_search()
  730. {
  731. var results = document.getElementById("MSearchSelectWindow");
  732. for (var key in indexSectionLabels)
  733. {
  734. var link = document.createElement('a');
  735. link.setAttribute('class','SelectItem');
  736. link.setAttribute('onclick','searchBox.OnSelectItem('+key+')');
  737. link.href='javascript:void(0)';
  738. link.innerHTML='<span class="SelectionMark">&#160;</span>'+indexSectionLabels[key];
  739. results.appendChild(link);
  740. }
  741. searchBox.OnSelectItem(0);
  742. }
  743. /* @license-end */