docs/api-2.1/search/search.js

changeset 390
d345541018fa
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/docs/api-2.1/search/search.js	Sat Feb 06 19:11:44 2021 +0100
     1.3 @@ -0,0 +1,791 @@
     1.4 +function convertToId(search)
     1.5 +{
     1.6 +  var result = '';
     1.7 +  for (i=0;i<search.length;i++)
     1.8 +  {
     1.9 +    var c = search.charAt(i);
    1.10 +    var cn = c.charCodeAt(0);
    1.11 +    if (c.match(/[a-z0-9\u0080-\uFFFF]/))
    1.12 +    {
    1.13 +      result+=c;
    1.14 +    }
    1.15 +    else if (cn<16)
    1.16 +    {
    1.17 +      result+="_0"+cn.toString(16);
    1.18 +    }
    1.19 +    else
    1.20 +    {
    1.21 +      result+="_"+cn.toString(16);
    1.22 +    }
    1.23 +  }
    1.24 +  return result;
    1.25 +}
    1.26 +
    1.27 +function getXPos(item)
    1.28 +{
    1.29 +  var x = 0;
    1.30 +  if (item.offsetWidth)
    1.31 +  {
    1.32 +    while (item && item!=document.body)
    1.33 +    {
    1.34 +      x   += item.offsetLeft;
    1.35 +      item = item.offsetParent;
    1.36 +    }
    1.37 +  }
    1.38 +  return x;
    1.39 +}
    1.40 +
    1.41 +function getYPos(item)
    1.42 +{
    1.43 +  var y = 0;
    1.44 +  if (item.offsetWidth)
    1.45 +  {
    1.46 +     while (item && item!=document.body)
    1.47 +     {
    1.48 +       y   += item.offsetTop;
    1.49 +       item = item.offsetParent;
    1.50 +     }
    1.51 +  }
    1.52 +  return y;
    1.53 +}
    1.54 +
    1.55 +/* A class handling everything associated with the search panel.
    1.56 +
    1.57 +   Parameters:
    1.58 +   name - The name of the global variable that will be
    1.59 +          storing this instance.  Is needed to be able to set timeouts.
    1.60 +   resultPath - path to use for external files
    1.61 +*/
    1.62 +function SearchBox(name, resultsPath, inFrame, label)
    1.63 +{
    1.64 +  if (!name || !resultsPath) {  alert("Missing parameters to SearchBox."); }
    1.65 +
    1.66 +  // ---------- Instance variables
    1.67 +  this.name                  = name;
    1.68 +  this.resultsPath           = resultsPath;
    1.69 +  this.keyTimeout            = 0;
    1.70 +  this.keyTimeoutLength      = 500;
    1.71 +  this.closeSelectionTimeout = 300;
    1.72 +  this.lastSearchValue       = "";
    1.73 +  this.lastResultsPage       = "";
    1.74 +  this.hideTimeout           = 0;
    1.75 +  this.searchIndex           = 0;
    1.76 +  this.searchActive          = false;
    1.77 +  this.insideFrame           = inFrame;
    1.78 +  this.searchLabel           = label;
    1.79 +
    1.80 +  // ----------- DOM Elements
    1.81 +
    1.82 +  this.DOMSearchField = function()
    1.83 +  {  return document.getElementById("MSearchField");  }
    1.84 +
    1.85 +  this.DOMSearchSelect = function()
    1.86 +  {  return document.getElementById("MSearchSelect");  }
    1.87 +
    1.88 +  this.DOMSearchSelectWindow = function()
    1.89 +  {  return document.getElementById("MSearchSelectWindow");  }
    1.90 +
    1.91 +  this.DOMPopupSearchResults = function()
    1.92 +  {  return document.getElementById("MSearchResults");  }
    1.93 +
    1.94 +  this.DOMPopupSearchResultsWindow = function()
    1.95 +  {  return document.getElementById("MSearchResultsWindow");  }
    1.96 +
    1.97 +  this.DOMSearchClose = function()
    1.98 +  {  return document.getElementById("MSearchClose"); }
    1.99 +
   1.100 +  this.DOMSearchBox = function()
   1.101 +  {  return document.getElementById("MSearchBox");  }
   1.102 +
   1.103 +  // ------------ Event Handlers
   1.104 +
   1.105 +  // Called when focus is added or removed from the search field.
   1.106 +  this.OnSearchFieldFocus = function(isActive)
   1.107 +  {
   1.108 +    this.Activate(isActive);
   1.109 +  }
   1.110 +
   1.111 +  this.OnSearchSelectShow = function()
   1.112 +  {
   1.113 +    var searchSelectWindow = this.DOMSearchSelectWindow();
   1.114 +    var searchField        = this.DOMSearchSelect();
   1.115 +
   1.116 +    if (this.insideFrame)
   1.117 +    {
   1.118 +      var left = getXPos(searchField);
   1.119 +      var top  = getYPos(searchField);
   1.120 +      left += searchField.offsetWidth + 6;
   1.121 +      top += searchField.offsetHeight;
   1.122 +
   1.123 +      // show search selection popup
   1.124 +      searchSelectWindow.style.display='block';
   1.125 +      left -= searchSelectWindow.offsetWidth;
   1.126 +      searchSelectWindow.style.left =  left + 'px';
   1.127 +      searchSelectWindow.style.top  =  top  + 'px';
   1.128 +    }
   1.129 +    else
   1.130 +    {
   1.131 +      var left = getXPos(searchField);
   1.132 +      var top  = getYPos(searchField);
   1.133 +      top += searchField.offsetHeight;
   1.134 +
   1.135 +      // show search selection popup
   1.136 +      searchSelectWindow.style.display='block';
   1.137 +      searchSelectWindow.style.left =  left + 'px';
   1.138 +      searchSelectWindow.style.top  =  top  + 'px';
   1.139 +    }
   1.140 +
   1.141 +    // stop selection hide timer
   1.142 +    if (this.hideTimeout)
   1.143 +    {
   1.144 +      clearTimeout(this.hideTimeout);
   1.145 +      this.hideTimeout=0;
   1.146 +    }
   1.147 +    return false; // to avoid "image drag" default event
   1.148 +  }
   1.149 +
   1.150 +  this.OnSearchSelectHide = function()
   1.151 +  {
   1.152 +    this.hideTimeout = setTimeout(this.name +".CloseSelectionWindow()",
   1.153 +                                  this.closeSelectionTimeout);
   1.154 +  }
   1.155 +
   1.156 +  // Called when the content of the search field is changed.
   1.157 +  this.OnSearchFieldChange = function(evt)
   1.158 +  {
   1.159 +    if (this.keyTimeout) // kill running timer
   1.160 +    {
   1.161 +      clearTimeout(this.keyTimeout);
   1.162 +      this.keyTimeout = 0;
   1.163 +    }
   1.164 +
   1.165 +    var e  = (evt) ? evt : window.event; // for IE
   1.166 +    if (e.keyCode==40 || e.keyCode==13)
   1.167 +    {
   1.168 +      if (e.shiftKey==1)
   1.169 +      {
   1.170 +        this.OnSearchSelectShow();
   1.171 +        var win=this.DOMSearchSelectWindow();
   1.172 +        for (i=0;i<win.childNodes.length;i++)
   1.173 +        {
   1.174 +          var child = win.childNodes[i]; // get span within a
   1.175 +          if (child.className=='SelectItem')
   1.176 +          {
   1.177 +            child.focus();
   1.178 +            return;
   1.179 +          }
   1.180 +        }
   1.181 +        return;
   1.182 +      }
   1.183 +      else if (window.frames.MSearchResults.searchResults)
   1.184 +      {
   1.185 +        var elem = window.frames.MSearchResults.searchResults.NavNext(0);
   1.186 +        if (elem) elem.focus();
   1.187 +      }
   1.188 +    }
   1.189 +    else if (e.keyCode==27) // Escape out of the search field
   1.190 +    {
   1.191 +      this.DOMSearchField().blur();
   1.192 +      this.DOMPopupSearchResultsWindow().style.display = 'none';
   1.193 +      this.DOMSearchClose().style.display = 'none';
   1.194 +      this.lastSearchValue = '';
   1.195 +      this.Activate(false);
   1.196 +      return;
   1.197 +    }
   1.198 +
   1.199 +    // strip whitespaces
   1.200 +    var searchValue = this.DOMSearchField().value.replace(/ +/g, "");
   1.201 +
   1.202 +    if (searchValue != this.lastSearchValue) // search value has changed
   1.203 +    {
   1.204 +      if (searchValue != "") // non-empty search
   1.205 +      {
   1.206 +        // set timer for search update
   1.207 +        this.keyTimeout = setTimeout(this.name + '.Search()',
   1.208 +                                     this.keyTimeoutLength);
   1.209 +      }
   1.210 +      else // empty search field
   1.211 +      {
   1.212 +        this.DOMPopupSearchResultsWindow().style.display = 'none';
   1.213 +        this.DOMSearchClose().style.display = 'none';
   1.214 +        this.lastSearchValue = '';
   1.215 +      }
   1.216 +    }
   1.217 +  }
   1.218 +
   1.219 +  this.SelectItemCount = function(id)
   1.220 +  {
   1.221 +    var count=0;
   1.222 +    var win=this.DOMSearchSelectWindow();
   1.223 +    for (i=0;i<win.childNodes.length;i++)
   1.224 +    {
   1.225 +      var child = win.childNodes[i]; // get span within a
   1.226 +      if (child.className=='SelectItem')
   1.227 +      {
   1.228 +        count++;
   1.229 +      }
   1.230 +    }
   1.231 +    return count;
   1.232 +  }
   1.233 +
   1.234 +  this.SelectItemSet = function(id)
   1.235 +  {
   1.236 +    var i,j=0;
   1.237 +    var win=this.DOMSearchSelectWindow();
   1.238 +    for (i=0;i<win.childNodes.length;i++)
   1.239 +    {
   1.240 +      var child = win.childNodes[i]; // get span within a
   1.241 +      if (child.className=='SelectItem')
   1.242 +      {
   1.243 +        var node = child.firstChild;
   1.244 +        if (j==id)
   1.245 +        {
   1.246 +          node.innerHTML='&#8226;';
   1.247 +        }
   1.248 +        else
   1.249 +        {
   1.250 +          node.innerHTML='&#160;';
   1.251 +        }
   1.252 +        j++;
   1.253 +      }
   1.254 +    }
   1.255 +  }
   1.256 +
   1.257 +  // Called when an search filter selection is made.
   1.258 +  // set item with index id as the active item
   1.259 +  this.OnSelectItem = function(id)
   1.260 +  {
   1.261 +    this.searchIndex = id;
   1.262 +    this.SelectItemSet(id);
   1.263 +    var searchValue = this.DOMSearchField().value.replace(/ +/g, "");
   1.264 +    if (searchValue!="" && this.searchActive) // something was found -> do a search
   1.265 +    {
   1.266 +      this.Search();
   1.267 +    }
   1.268 +  }
   1.269 +
   1.270 +  this.OnSearchSelectKey = function(evt)
   1.271 +  {
   1.272 +    var e = (evt) ? evt : window.event; // for IE
   1.273 +    if (e.keyCode==40 && this.searchIndex<this.SelectItemCount()) // Down
   1.274 +    {
   1.275 +      this.searchIndex++;
   1.276 +      this.OnSelectItem(this.searchIndex);
   1.277 +    }
   1.278 +    else if (e.keyCode==38 && this.searchIndex>0) // Up
   1.279 +    {
   1.280 +      this.searchIndex--;
   1.281 +      this.OnSelectItem(this.searchIndex);
   1.282 +    }
   1.283 +    else if (e.keyCode==13 || e.keyCode==27)
   1.284 +    {
   1.285 +      this.OnSelectItem(this.searchIndex);
   1.286 +      this.CloseSelectionWindow();
   1.287 +      this.DOMSearchField().focus();
   1.288 +    }
   1.289 +    return false;
   1.290 +  }
   1.291 +
   1.292 +  // --------- Actions
   1.293 +
   1.294 +  // Closes the results window.
   1.295 +  this.CloseResultsWindow = function()
   1.296 +  {
   1.297 +    this.DOMPopupSearchResultsWindow().style.display = 'none';
   1.298 +    this.DOMSearchClose().style.display = 'none';
   1.299 +    this.Activate(false);
   1.300 +  }
   1.301 +
   1.302 +  this.CloseSelectionWindow = function()
   1.303 +  {
   1.304 +    this.DOMSearchSelectWindow().style.display = 'none';
   1.305 +  }
   1.306 +
   1.307 +  // Performs a search.
   1.308 +  this.Search = function()
   1.309 +  {
   1.310 +    this.keyTimeout = 0;
   1.311 +
   1.312 +    // strip leading whitespace
   1.313 +    var searchValue = this.DOMSearchField().value.replace(/^ +/, "");
   1.314 +
   1.315 +    var code = searchValue.toLowerCase().charCodeAt(0);
   1.316 +    var idxChar = searchValue.substr(0, 1).toLowerCase();
   1.317 +    if ( 0xD800 <= code && code <= 0xDBFF && searchValue > 1) // surrogate pair
   1.318 +    {
   1.319 +      idxChar = searchValue.substr(0, 2);
   1.320 +    }
   1.321 +
   1.322 +    var resultsPage;
   1.323 +    var resultsPageWithSearch;
   1.324 +    var hasResultsPage;
   1.325 +
   1.326 +    var idx = indexSectionsWithContent[this.searchIndex].indexOf(idxChar);
   1.327 +    if (idx!=-1)
   1.328 +    {
   1.329 +       var hexCode=idx.toString(16);
   1.330 +       resultsPage = this.resultsPath + '/' + indexSectionNames[this.searchIndex] + '_' + hexCode + '.html';
   1.331 +       resultsPageWithSearch = resultsPage+'?'+escape(searchValue);
   1.332 +       hasResultsPage = true;
   1.333 +    }
   1.334 +    else // nothing available for this search term
   1.335 +    {
   1.336 +       resultsPage = this.resultsPath + '/nomatches.html';
   1.337 +       resultsPageWithSearch = resultsPage;
   1.338 +       hasResultsPage = false;
   1.339 +    }
   1.340 +
   1.341 +    window.frames.MSearchResults.location = resultsPageWithSearch;
   1.342 +    var domPopupSearchResultsWindow = this.DOMPopupSearchResultsWindow();
   1.343 +
   1.344 +    if (domPopupSearchResultsWindow.style.display!='block')
   1.345 +    {
   1.346 +       var domSearchBox = this.DOMSearchBox();
   1.347 +       this.DOMSearchClose().style.display = 'inline';
   1.348 +       if (this.insideFrame)
   1.349 +       {
   1.350 +         var domPopupSearchResults = this.DOMPopupSearchResults();
   1.351 +         domPopupSearchResultsWindow.style.position = 'relative';
   1.352 +         domPopupSearchResultsWindow.style.display  = 'block';
   1.353 +         var width = document.body.clientWidth - 8; // the -8 is for IE :-(
   1.354 +         domPopupSearchResultsWindow.style.width    = width + 'px';
   1.355 +         domPopupSearchResults.style.width          = width + 'px';
   1.356 +       }
   1.357 +       else
   1.358 +       {
   1.359 +         var domPopupSearchResults = this.DOMPopupSearchResults();
   1.360 +         var left = getXPos(domSearchBox) + 150; // domSearchBox.offsetWidth;
   1.361 +         var top  = getYPos(domSearchBox) + 20;  // domSearchBox.offsetHeight + 1;
   1.362 +         domPopupSearchResultsWindow.style.display = 'block';
   1.363 +         left -= domPopupSearchResults.offsetWidth;
   1.364 +         domPopupSearchResultsWindow.style.top     = top  + 'px';
   1.365 +         domPopupSearchResultsWindow.style.left    = left + 'px';
   1.366 +       }
   1.367 +    }
   1.368 +
   1.369 +    this.lastSearchValue = searchValue;
   1.370 +    this.lastResultsPage = resultsPage;
   1.371 +  }
   1.372 +
   1.373 +  // -------- Activation Functions
   1.374 +
   1.375 +  // Activates or deactivates the search panel, resetting things to
   1.376 +  // their default values if necessary.
   1.377 +  this.Activate = function(isActive)
   1.378 +  {
   1.379 +    if (isActive || // open it
   1.380 +        this.DOMPopupSearchResultsWindow().style.display == 'block'
   1.381 +       )
   1.382 +    {
   1.383 +      this.DOMSearchBox().className = 'MSearchBoxActive';
   1.384 +
   1.385 +      var searchField = this.DOMSearchField();
   1.386 +
   1.387 +      if (searchField.value == this.searchLabel) // clear "Search" term upon entry
   1.388 +      {
   1.389 +        searchField.value = '';
   1.390 +        this.searchActive = true;
   1.391 +      }
   1.392 +    }
   1.393 +    else if (!isActive) // directly remove the panel
   1.394 +    {
   1.395 +      this.DOMSearchBox().className = 'MSearchBoxInactive';
   1.396 +      this.DOMSearchField().value   = this.searchLabel;
   1.397 +      this.searchActive             = false;
   1.398 +      this.lastSearchValue          = ''
   1.399 +      this.lastResultsPage          = '';
   1.400 +    }
   1.401 +  }
   1.402 +}
   1.403 +
   1.404 +// -----------------------------------------------------------------------
   1.405 +
   1.406 +// The class that handles everything on the search results page.
   1.407 +function SearchResults(name)
   1.408 +{
   1.409 +    // The number of matches from the last run of <Search()>.
   1.410 +    this.lastMatchCount = 0;
   1.411 +    this.lastKey = 0;
   1.412 +    this.repeatOn = false;
   1.413 +
   1.414 +    // Toggles the visibility of the passed element ID.
   1.415 +    this.FindChildElement = function(id)
   1.416 +    {
   1.417 +      var parentElement = document.getElementById(id);
   1.418 +      var element = parentElement.firstChild;
   1.419 +
   1.420 +      while (element && element!=parentElement)
   1.421 +      {
   1.422 +        if (element.nodeName == 'DIV' && element.className == 'SRChildren')
   1.423 +        {
   1.424 +          return element;
   1.425 +        }
   1.426 +
   1.427 +        if (element.nodeName == 'DIV' && element.hasChildNodes())
   1.428 +        {
   1.429 +           element = element.firstChild;
   1.430 +        }
   1.431 +        else if (element.nextSibling)
   1.432 +        {
   1.433 +           element = element.nextSibling;
   1.434 +        }
   1.435 +        else
   1.436 +        {
   1.437 +          do
   1.438 +          {
   1.439 +            element = element.parentNode;
   1.440 +          }
   1.441 +          while (element && element!=parentElement && !element.nextSibling);
   1.442 +
   1.443 +          if (element && element!=parentElement)
   1.444 +          {
   1.445 +            element = element.nextSibling;
   1.446 +          }
   1.447 +        }
   1.448 +      }
   1.449 +    }
   1.450 +
   1.451 +    this.Toggle = function(id)
   1.452 +    {
   1.453 +      var element = this.FindChildElement(id);
   1.454 +      if (element)
   1.455 +      {
   1.456 +        if (element.style.display == 'block')
   1.457 +        {
   1.458 +          element.style.display = 'none';
   1.459 +        }
   1.460 +        else
   1.461 +        {
   1.462 +          element.style.display = 'block';
   1.463 +        }
   1.464 +      }
   1.465 +    }
   1.466 +
   1.467 +    // Searches for the passed string.  If there is no parameter,
   1.468 +    // it takes it from the URL query.
   1.469 +    //
   1.470 +    // Always returns true, since other documents may try to call it
   1.471 +    // and that may or may not be possible.
   1.472 +    this.Search = function(search)
   1.473 +    {
   1.474 +      if (!search) // get search word from URL
   1.475 +      {
   1.476 +        search = window.location.search;
   1.477 +        search = search.substring(1);  // Remove the leading '?'
   1.478 +        search = unescape(search);
   1.479 +      }
   1.480 +
   1.481 +      search = search.replace(/^ +/, ""); // strip leading spaces
   1.482 +      search = search.replace(/ +$/, ""); // strip trailing spaces
   1.483 +      search = search.toLowerCase();
   1.484 +      search = convertToId(search);
   1.485 +
   1.486 +      var resultRows = document.getElementsByTagName("div");
   1.487 +      var matches = 0;
   1.488 +
   1.489 +      var i = 0;
   1.490 +      while (i < resultRows.length)
   1.491 +      {
   1.492 +        var row = resultRows.item(i);
   1.493 +        if (row.className == "SRResult")
   1.494 +        {
   1.495 +          var rowMatchName = row.id.toLowerCase();
   1.496 +          rowMatchName = rowMatchName.replace(/^sr\d*_/, ''); // strip 'sr123_'
   1.497 +
   1.498 +          if (search.length<=rowMatchName.length &&
   1.499 +             rowMatchName.substr(0, search.length)==search)
   1.500 +          {
   1.501 +            row.style.display = 'block';
   1.502 +            matches++;
   1.503 +          }
   1.504 +          else
   1.505 +          {
   1.506 +            row.style.display = 'none';
   1.507 +          }
   1.508 +        }
   1.509 +        i++;
   1.510 +      }
   1.511 +      document.getElementById("Searching").style.display='none';
   1.512 +      if (matches == 0) // no results
   1.513 +      {
   1.514 +        document.getElementById("NoMatches").style.display='block';
   1.515 +      }
   1.516 +      else // at least one result
   1.517 +      {
   1.518 +        document.getElementById("NoMatches").style.display='none';
   1.519 +      }
   1.520 +      this.lastMatchCount = matches;
   1.521 +      return true;
   1.522 +    }
   1.523 +
   1.524 +    // return the first item with index index or higher that is visible
   1.525 +    this.NavNext = function(index)
   1.526 +    {
   1.527 +      var focusItem;
   1.528 +      while (1)
   1.529 +      {
   1.530 +        var focusName = 'Item'+index;
   1.531 +        focusItem = document.getElementById(focusName);
   1.532 +        if (focusItem && focusItem.parentNode.parentNode.style.display=='block')
   1.533 +        {
   1.534 +          break;
   1.535 +        }
   1.536 +        else if (!focusItem) // last element
   1.537 +        {
   1.538 +          break;
   1.539 +        }
   1.540 +        focusItem=null;
   1.541 +        index++;
   1.542 +      }
   1.543 +      return focusItem;
   1.544 +    }
   1.545 +
   1.546 +    this.NavPrev = function(index)
   1.547 +    {
   1.548 +      var focusItem;
   1.549 +      while (1)
   1.550 +      {
   1.551 +        var focusName = 'Item'+index;
   1.552 +        focusItem = document.getElementById(focusName);
   1.553 +        if (focusItem && focusItem.parentNode.parentNode.style.display=='block')
   1.554 +        {
   1.555 +          break;
   1.556 +        }
   1.557 +        else if (!focusItem) // last element
   1.558 +        {
   1.559 +          break;
   1.560 +        }
   1.561 +        focusItem=null;
   1.562 +        index--;
   1.563 +      }
   1.564 +      return focusItem;
   1.565 +    }
   1.566 +
   1.567 +    this.ProcessKeys = function(e)
   1.568 +    {
   1.569 +      if (e.type == "keydown")
   1.570 +      {
   1.571 +        this.repeatOn = false;
   1.572 +        this.lastKey = e.keyCode;
   1.573 +      }
   1.574 +      else if (e.type == "keypress")
   1.575 +      {
   1.576 +        if (!this.repeatOn)
   1.577 +        {
   1.578 +          if (this.lastKey) this.repeatOn = true;
   1.579 +          return false; // ignore first keypress after keydown
   1.580 +        }
   1.581 +      }
   1.582 +      else if (e.type == "keyup")
   1.583 +      {
   1.584 +        this.lastKey = 0;
   1.585 +        this.repeatOn = false;
   1.586 +      }
   1.587 +      return this.lastKey!=0;
   1.588 +    }
   1.589 +
   1.590 +    this.Nav = function(evt,itemIndex)
   1.591 +    {
   1.592 +      var e  = (evt) ? evt : window.event; // for IE
   1.593 +      if (e.keyCode==13) return true;
   1.594 +      if (!this.ProcessKeys(e)) return false;
   1.595 +
   1.596 +      if (this.lastKey==38) // Up
   1.597 +      {
   1.598 +        var newIndex = itemIndex-1;
   1.599 +        var focusItem = this.NavPrev(newIndex);
   1.600 +        if (focusItem)
   1.601 +        {
   1.602 +          var child = this.FindChildElement(focusItem.parentNode.parentNode.id);
   1.603 +          if (child && child.style.display == 'block') // children visible
   1.604 +          {
   1.605 +            var n=0;
   1.606 +            var tmpElem;
   1.607 +            while (1) // search for last child
   1.608 +            {
   1.609 +              tmpElem = document.getElementById('Item'+newIndex+'_c'+n);
   1.610 +              if (tmpElem)
   1.611 +              {
   1.612 +                focusItem = tmpElem;
   1.613 +              }
   1.614 +              else // found it!
   1.615 +              {
   1.616 +                break;
   1.617 +              }
   1.618 +              n++;
   1.619 +            }
   1.620 +          }
   1.621 +        }
   1.622 +        if (focusItem)
   1.623 +        {
   1.624 +          focusItem.focus();
   1.625 +        }
   1.626 +        else // return focus to search field
   1.627 +        {
   1.628 +           parent.document.getElementById("MSearchField").focus();
   1.629 +        }
   1.630 +      }
   1.631 +      else if (this.lastKey==40) // Down
   1.632 +      {
   1.633 +        var newIndex = itemIndex+1;
   1.634 +        var focusItem;
   1.635 +        var item = document.getElementById('Item'+itemIndex);
   1.636 +        var elem = this.FindChildElement(item.parentNode.parentNode.id);
   1.637 +        if (elem && elem.style.display == 'block') // children visible
   1.638 +        {
   1.639 +          focusItem = document.getElementById('Item'+itemIndex+'_c0');
   1.640 +        }
   1.641 +        if (!focusItem) focusItem = this.NavNext(newIndex);
   1.642 +        if (focusItem)  focusItem.focus();
   1.643 +      }
   1.644 +      else if (this.lastKey==39) // Right
   1.645 +      {
   1.646 +        var item = document.getElementById('Item'+itemIndex);
   1.647 +        var elem = this.FindChildElement(item.parentNode.parentNode.id);
   1.648 +        if (elem) elem.style.display = 'block';
   1.649 +      }
   1.650 +      else if (this.lastKey==37) // Left
   1.651 +      {
   1.652 +        var item = document.getElementById('Item'+itemIndex);
   1.653 +        var elem = this.FindChildElement(item.parentNode.parentNode.id);
   1.654 +        if (elem) elem.style.display = 'none';
   1.655 +      }
   1.656 +      else if (this.lastKey==27) // Escape
   1.657 +      {
   1.658 +        parent.searchBox.CloseResultsWindow();
   1.659 +        parent.document.getElementById("MSearchField").focus();
   1.660 +      }
   1.661 +      else if (this.lastKey==13) // Enter
   1.662 +      {
   1.663 +        return true;
   1.664 +      }
   1.665 +      return false;
   1.666 +    }
   1.667 +
   1.668 +    this.NavChild = function(evt,itemIndex,childIndex)
   1.669 +    {
   1.670 +      var e  = (evt) ? evt : window.event; // for IE
   1.671 +      if (e.keyCode==13) return true;
   1.672 +      if (!this.ProcessKeys(e)) return false;
   1.673 +
   1.674 +      if (this.lastKey==38) // Up
   1.675 +      {
   1.676 +        if (childIndex>0)
   1.677 +        {
   1.678 +          var newIndex = childIndex-1;
   1.679 +          document.getElementById('Item'+itemIndex+'_c'+newIndex).focus();
   1.680 +        }
   1.681 +        else // already at first child, jump to parent
   1.682 +        {
   1.683 +          document.getElementById('Item'+itemIndex).focus();
   1.684 +        }
   1.685 +      }
   1.686 +      else if (this.lastKey==40) // Down
   1.687 +      {
   1.688 +        var newIndex = childIndex+1;
   1.689 +        var elem = document.getElementById('Item'+itemIndex+'_c'+newIndex);
   1.690 +        if (!elem) // last child, jump to parent next parent
   1.691 +        {
   1.692 +          elem = this.NavNext(itemIndex+1);
   1.693 +        }
   1.694 +        if (elem)
   1.695 +        {
   1.696 +          elem.focus();
   1.697 +        }
   1.698 +      }
   1.699 +      else if (this.lastKey==27) // Escape
   1.700 +      {
   1.701 +        parent.searchBox.CloseResultsWindow();
   1.702 +        parent.document.getElementById("MSearchField").focus();
   1.703 +      }
   1.704 +      else if (this.lastKey==13) // Enter
   1.705 +      {
   1.706 +        return true;
   1.707 +      }
   1.708 +      return false;
   1.709 +    }
   1.710 +}
   1.711 +
   1.712 +function setKeyActions(elem,action)
   1.713 +{
   1.714 +  elem.setAttribute('onkeydown',action);
   1.715 +  elem.setAttribute('onkeypress',action);
   1.716 +  elem.setAttribute('onkeyup',action);
   1.717 +}
   1.718 +
   1.719 +function setClassAttr(elem,attr)
   1.720 +{
   1.721 +  elem.setAttribute('class',attr);
   1.722 +  elem.setAttribute('className',attr);
   1.723 +}
   1.724 +
   1.725 +function createResults()
   1.726 +{
   1.727 +  var results = document.getElementById("SRResults");
   1.728 +  for (var e=0; e<searchData.length; e++)
   1.729 +  {
   1.730 +    var id = searchData[e][0];
   1.731 +    var srResult = document.createElement('div');
   1.732 +    srResult.setAttribute('id','SR_'+id);
   1.733 +    setClassAttr(srResult,'SRResult');
   1.734 +    var srEntry = document.createElement('div');
   1.735 +    setClassAttr(srEntry,'SREntry');
   1.736 +    var srLink = document.createElement('a');
   1.737 +    srLink.setAttribute('id','Item'+e);
   1.738 +    setKeyActions(srLink,'return searchResults.Nav(event,'+e+')');
   1.739 +    setClassAttr(srLink,'SRSymbol');
   1.740 +    srLink.innerHTML = searchData[e][1][0];
   1.741 +    srEntry.appendChild(srLink);
   1.742 +    if (searchData[e][1].length==2) // single result
   1.743 +    {
   1.744 +      srLink.setAttribute('href',searchData[e][1][1][0]);
   1.745 +      if (searchData[e][1][1][1])
   1.746 +      {
   1.747 +       srLink.setAttribute('target','_parent');
   1.748 +      }
   1.749 +      var srScope = document.createElement('span');
   1.750 +      setClassAttr(srScope,'SRScope');
   1.751 +      srScope.innerHTML = searchData[e][1][1][2];
   1.752 +      srEntry.appendChild(srScope);
   1.753 +    }
   1.754 +    else // multiple results
   1.755 +    {
   1.756 +      srLink.setAttribute('href','javascript:searchResults.Toggle("SR_'+id+'")');
   1.757 +      var srChildren = document.createElement('div');
   1.758 +      setClassAttr(srChildren,'SRChildren');
   1.759 +      for (var c=0; c<searchData[e][1].length-1; c++)
   1.760 +      {
   1.761 +        var srChild = document.createElement('a');
   1.762 +        srChild.setAttribute('id','Item'+e+'_c'+c);
   1.763 +        setKeyActions(srChild,'return searchResults.NavChild(event,'+e+','+c+')');
   1.764 +        setClassAttr(srChild,'SRScope');
   1.765 +        srChild.setAttribute('href',searchData[e][1][c+1][0]);
   1.766 +        if (searchData[e][1][c+1][1])
   1.767 +        {
   1.768 +         srChild.setAttribute('target','_parent');
   1.769 +        }
   1.770 +        srChild.innerHTML = searchData[e][1][c+1][2];
   1.771 +        srChildren.appendChild(srChild);
   1.772 +      }
   1.773 +      srEntry.appendChild(srChildren);
   1.774 +    }
   1.775 +    srResult.appendChild(srEntry);
   1.776 +    results.appendChild(srResult);
   1.777 +  }
   1.778 +}
   1.779 +
   1.780 +function init_search()
   1.781 +{
   1.782 +  var results = document.getElementById("MSearchSelectWindow");
   1.783 +  for (var key in indexSectionLabels)
   1.784 +  {
   1.785 +    var link = document.createElement('a');
   1.786 +    link.setAttribute('class','SelectItem');
   1.787 +    link.setAttribute('onclick','searchBox.OnSelectItem('+key+')');
   1.788 +    link.href='javascript:void(0)';
   1.789 +    link.innerHTML='<span class="SelectionMark">&#160;</span>'+indexSectionLabels[key];
   1.790 +    results.appendChild(link);
   1.791 +  }
   1.792 +  searchBox.OnSelectItem(0);
   1.793 +}
   1.794 +

mercurial