annotate C++/api/html/search/search.js @ 592:76c6b3fd0a05

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