annotate C++/api/html/search/search.js @ 629:47c488dc7a01

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