| OLD | NEW |
| 1 /** | 1 /** |
| 2 * Copyright (c) 2010 The Chromium Authors. All rights reserved. Use of this | 2 * Copyright (c) 2010 The Chromium Authors. All rights reserved. Use of this |
| 3 * source code is governed by a BSD-style license that can be found in the | 3 * source code is governed by a BSD-style license that can be found in the |
| 4 * LICENSE file. | 4 * LICENSE file. |
| 5 */ | 5 */ |
| 6 | 6 |
| 7 function testSearchSupport() { | 7 function testSearchSupport() { |
| 8 var i = document.createElement("input"); | 8 var i = document.createElement("input"); |
| 9 i.setAttribute("type", "search"); | 9 i.setAttribute("type", "search"); |
| 10 return i.type !== "text"; | 10 return i.type !== "text"; |
| 11 }; | 11 }; |
| 12 | 12 |
| 13 function filterSamples() { | 13 function filterSamples() { |
| 14 var clearlink = document.getElementById('clearlink'); | 14 var clearlink = document.getElementById('clearlink'); |
| 15 var searchinput = document.getElementById('searchinput'); | 15 var searchinput = document.getElementById('searchinput'); |
| 16 var noresults = document.getElementById('noresults'); | 16 var noresults = document.getElementById('noresults'); |
| 17 | 17 |
| 18 var searchtext = searchinput.value.toUpperCase(); | 18 var searchtext = searchinput.value.toUpperCase(); |
| 19 if (!canclear && searchtext != "" ) { | 19 if (!canclear && searchtext != "" ) { |
| 20 clearlink.style.display = "inline"; | 20 clearlink.style.display = "inline"; |
| 21 } else { | 21 } else { |
| 22 clearlink.style.display = "none"; | 22 clearlink.style.display = "none"; |
| 23 } | 23 } |
| 24 if (searchtext == currentfilter) { | 24 if (searchtext == currentfilter) { |
| 25 return; | 25 return; |
| 26 } else { | 26 } else { |
| 27 currentfilter = searchtext; | 27 currentfilter = searchtext; |
| 28 window.location.hash = searchinput.value; |
| 28 } | 29 } |
| 29 | 30 |
| 30 noresults.style.display = 'none'; | 31 noresults.style.display = 'none'; |
| 31 var num_found = 0; | 32 var num_found = 0; |
| 32 for (var key in search_data) { | 33 for (var key in search_data) { |
| 33 if (search_data.hasOwnProperty(key)) { | 34 if (search_data.hasOwnProperty(key)) { |
| 34 var sampleentry = document.getElementById(key); | 35 var sampleentry = document.getElementById(key); |
| 35 if (search_data[key].indexOf(searchtext) == -1) { | 36 if (search_data[key].indexOf(searchtext) == -1) { |
| 36 sampleentry.style.display = "none"; | 37 sampleentry.style.display = "none"; |
| 37 } else { | 38 } else { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 searchinput.focus(); | 71 searchinput.focus(); |
| 71 }; | 72 }; |
| 72 | 73 |
| 73 function initSearch() { | 74 function initSearch() { |
| 74 var searchinput = document.getElementById('searchinput'); | 75 var searchinput = document.getElementById('searchinput'); |
| 75 if (canclear) { | 76 if (canclear) { |
| 76 searchinput.addEventListener('click', filterSamples, false); | 77 searchinput.addEventListener('click', filterSamples, false); |
| 77 } | 78 } |
| 78 | 79 |
| 79 if (window.location.hash.length > 1) { | 80 if (window.location.hash.length > 1) { |
| 80 setFilter(window.location.hash.substring(1)); | 81 var hash = window.location.hash.substring(1); |
| 82 var elem = document.getElementById(hash); |
| 83 if (elem) { |
| 84 elem.scrollIntoView(); |
| 85 } else { |
| 86 setFilter(hash); |
| 87 } |
| 81 } | 88 } |
| 82 }; | 89 }; |
| 83 | 90 |
| 84 var currentfilter = ""; | 91 var currentfilter = ""; |
| 85 var canclear = testSearchSupport(); | 92 var canclear = testSearchSupport(); |
| 86 window.addEventListener('load', initSearch, false); | 93 window.addEventListener('load', initSearch, false); |
| OLD | NEW |