annotate trunk/C++/api/html/search/search.js @ 613:c14c83f3d5d6

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