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

Side by Side Diff: chrome/common/extensions/docs/js/sample_search.js

Issue 2957009: Change the existing extension samples page to an automatically-generated searchable directory. (Closed) Base URL: http://src.chromium.org/git/chromium.git
Patch Set: Make changes suggested by Antony Created 10 years, 4 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
OLDNEW
(Empty)
1 /**
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
4 * LICENSE file.
5 */
6
7 function testSearchSupport() {
8 var i = document.createElement("input");
9 i.setAttribute("type", "search");
10 return i.type !== "text";
11 };
12
13 function filterSamples() {
14 var clearlink = document.getElementById('clearlink');
15 var searchinput = document.getElementById('searchinput');
16 var noresults = document.getElementById('noresults');
17
18 var searchtext = searchinput.value.toUpperCase();
19 if (!canclear && searchtext != "" ) {
20 clearlink.style.display = "inline";
21 } else {
22 clearlink.style.display = "none";
23 }
24 if (searchtext == currentfilter) {
25 return;
26 } else {
27 currentfilter = searchtext;
28 }
29
30 noresults.style.display = 'none';
31 var num_found = 0;
32 for (var key in search_data) {
33 if (search_data.hasOwnProperty(key)) {
34 var sampleentry = document.getElementById(key);
35 if (search_data[key].indexOf(searchtext) == -1) {
36 sampleentry.style.display = "none";
37 } else {
38 sampleentry.style.display = "block";
39 num_found += 1;
40 }
41 }
42 }
43 if (num_found == 0) {
44 noresults.style.display = 'block';
45 }
46 removeSelected();
47 };
48
49 function removeSelected() {
50 var anchors = document.getElementsByTagName('a');
51 for (var i = 0, anchor; anchor = anchors[i]; i++) {
52 if (anchor.className == "selected") {
53 anchor.className = "";
54 }
55 }
56 };
57
58 function setFilter(text, target) {
59 var searchinput = document.getElementById('searchinput');
60 searchinput.value = text;
61 filterSamples();
62 target.className = "selected";
63 searchinput.focus();
64 };
65
66 function clearFilter() {
67 var searchinput = document.getElementById('searchinput');
68 searchinput.value = "";
69 filterSamples();
70 searchinput.focus();
71 };
72
73 function initSearch() {
74 var searchinput = document.getElementById('searchinput');
75 if (canclear) {
76 searchinput.addEventListener('click', filterSamples, false);
77 }
78 };
79
80 var currentfilter = "";
81 var canclear = testSearchSupport();
82 window.addEventListener('load', initSearch, false);
OLDNEW
« no previous file with comments | « chrome/common/extensions/docs/js/api_page_generator.js ('k') | chrome/common/extensions/docs/samples.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698