Home | History | Annotate | Download | only in js
      1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 // This is used for the search box on the left navigation bar. The APIs are
      6 // filtered and displayed based on what the user is typing in the box.
      7 (function() {
      8   var search_box = document.getElementById('api_search');
      9   var filtered_apis = document.getElementById('filtered_apis');
     10 
     11   function filterAPIs() {
     12     var search_text = search_box.value.toLowerCase();
     13     var apis = window.bootstrap.api_names;
     14     if (!search_text) {
     15       filtered_apis.style.display = 'none';
     16       return;
     17     }
     18     var api_list = ''
     19     for (var i = 0; i < apis.length; ++i) {
     20       if (apis[i].name.toLowerCase().indexOf(search_text) != -1)
     21         api_list += '<li class="filtered_item"><a href="' + apis[i].name +
     22             '.html">' + apis[i].name + '</a></li>'
     23     }
     24     if (api_list != filtered_apis.innerHtml)
     25       filtered_apis.innerHTML = api_list;
     26     if (!api_list)
     27       filtered_apis.style.display = 'none';
     28     else
     29       filtered_apis.style.display = '';
     30   }
     31 
     32   filtered_apis.style.display = 'none';
     33   search_box.addEventListener('search', filterAPIs);
     34   search_box.addEventListener('keyup', filterAPIs);
     35 })();
     36