annotate trunk/C++/api/html/search/search.js @ 597:359bcd461dd1

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