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 (function() { 6 var search_box = document.getElementById('search_input'); 7 var samples = document.getElementsByClassName('sample'); 8 9 function filterSamples() { 10 var search_text = search_box.value.toLowerCase(); 11 for (var i = 0; i < samples.length; ++i) { 12 var sample = samples[i] 13 if (sample.getAttribute('tags').toLowerCase().indexOf(search_text) < 0) 14 sample.style.display = 'none'; 15 else 16 sample.style.display = ''; 17 } 18 } 19 search_box.addEventListener('search', filterSamples); 20 search_box.addEventListener('keyup', filterSamples); 21 22 var api_filter_items = document.getElementById('api_filter_items'); 23 api_filter_items.addEventListener('click', function(event) { 24 if (event.target instanceof HTMLAnchorElement) { 25 search_box.value = event.target.innerText; 26 filterSamples(); 27 } 28 }); 29 })(); 30