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.
6 var searchBox = document.getElementById('search_input');
7 var samples = document.getElementsByClassName('sample');
9 function filterSamples() {
10 var searchText = searchBox.value.toLowerCase();
11 for (var i = 0; i < samples.length; ++i) {
12 var sample = samples[i];
14 if (sample.getElementsByTagName('h2').length > 0)
15 sampleTitle = sample.getElementsByTagName('h2')[0].textContent;
16 if (sample.getAttribute('tags').toLowerCase().indexOf(searchText) < 0 &&
17 sampleTitle.toLowerCase().indexOf(searchText) < 0)
18 sample.style.display = 'none';
20 sample.style.display = '';
23 searchBox.addEventListener('search', filterSamples);
24 searchBox.addEventListener('keyup', filterSamples);
26 var apiFilterItems = document.getElementById('api_filter_items');
27 apiFilterItems.addEventListener('click', function(event) {
28 if (event.target instanceof HTMLAnchorElement) {
29 searchBox.value = event.target.innerText;