Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1332)

Side by Side Diff: chrome/common/extensions/docs/server2/static/js/samples.js

Issue 10824003: addEventListener stuff. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | chrome/common/extensions/docs/server2/templates/public/samples.html » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. Use of this 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. Use of this
2 // source code is governed by a BSD-style license that can be found in the 2 // source code is governed by a BSD-style license that can be found in the
3 // LICENSE file. 3 // LICENSE file.
4 4
5 (function() { 5 (function() {
6 var search_box = document.getElementById('search_input'); 6 var search_box = document.getElementById('search_input');
7 var apis = document.getElementsByClassName('sample'); 7 var samples = document.getElementsByClassName('sample');
8 for (var i = 0; i < apis.length; ++i)
9 apis[i].tags = apis[i].getAttribute('tags').toUpperCase();
10 8
11 function filterSamples() { 9 function filterSamples() {
12 var search_text = search_box.value.toUpperCase(); 10 var search_text = search_box.value.toLowerCase();
13 for (var i = 0; i < apis.length; ++i) { 11 for (var i = 0; i < samples.length; ++i) {
14 if (apis[i].tags.indexOf(search_text) < 0) 12 var sample = samples[i];
15 apis[i].style.display = 'none'; 13 if (sample.getAttribute('tags').indexOf(search_text) < 0)
14 sample.style.display = 'none';
16 else 15 else
17 apis[i].style.display = ''; 16 sample.style.display = '';
18 } 17 }
19 } 18 }
20 19
21 function setFilter() { 20 search_box.addEventListener('search', filterSamples);
22 search_box.value = 'chrome.' + this.innerHTML; 21 search_box.addEventListener('keyup', filterSamples);
23 filterSamples();
24 }
25 22
26 var api_filter_items = document.getElementsByClassName('api_filter_item'); 23 var api_filter_items = document.getElementById('api_filter_items');
27 for (var i = 0; i < api_filter_items.length; ++i) 24 api_filter_items.addEventListener('click', function(event) {
28 api_filter_items[i].addEventListener('click', setFilter, true); 25 if (event.target instanceof HTMLAnchorElement) {
29 26 search_box.value = 'chrome.' + event.target.innerText;
30 search_box.onsearch = filterSamples; 27 filterSamples();
31 search_box.onkeyup = filterSamples; 28 }
29 });
32 })(); 30 })();
OLDNEW
« no previous file with comments | « no previous file | chrome/common/extensions/docs/server2/templates/public/samples.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698