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

Unified 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, 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 side-by-side diff with in-line comments
Download patch
« 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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/common/extensions/docs/js/sample_search.js
diff --git a/chrome/common/extensions/docs/js/sample_search.js b/chrome/common/extensions/docs/js/sample_search.js
new file mode 100644
index 0000000000000000000000000000000000000000..7e834d64f5222280a5e386146ce2fd186ccc5c79
--- /dev/null
+++ b/chrome/common/extensions/docs/js/sample_search.js
@@ -0,0 +1,82 @@
+/**
+ * Copyright (c) 2010 The Chromium Authors. All rights reserved. Use of this
+ * source code is governed by a BSD-style license that can be found in the
+ * LICENSE file.
+ */
+
+function testSearchSupport() {
+ var i = document.createElement("input");
+ i.setAttribute("type", "search");
+ return i.type !== "text";
+};
+
+function filterSamples() {
+ var clearlink = document.getElementById('clearlink');
+ var searchinput = document.getElementById('searchinput');
+ var noresults = document.getElementById('noresults');
+
+ var searchtext = searchinput.value.toUpperCase();
+ if (!canclear && searchtext != "" ) {
+ clearlink.style.display = "inline";
+ } else {
+ clearlink.style.display = "none";
+ }
+ if (searchtext == currentfilter) {
+ return;
+ } else {
+ currentfilter = searchtext;
+ }
+
+ noresults.style.display = 'none';
+ var num_found = 0;
+ for (var key in search_data) {
+ if (search_data.hasOwnProperty(key)) {
+ var sampleentry = document.getElementById(key);
+ if (search_data[key].indexOf(searchtext) == -1) {
+ sampleentry.style.display = "none";
+ } else {
+ sampleentry.style.display = "block";
+ num_found += 1;
+ }
+ }
+ }
+ if (num_found == 0) {
+ noresults.style.display = 'block';
+ }
+ removeSelected();
+};
+
+function removeSelected() {
+ var anchors = document.getElementsByTagName('a');
+ for (var i = 0, anchor; anchor = anchors[i]; i++) {
+ if (anchor.className == "selected") {
+ anchor.className = "";
+ }
+ }
+};
+
+function setFilter(text, target) {
+ var searchinput = document.getElementById('searchinput');
+ searchinput.value = text;
+ filterSamples();
+ target.className = "selected";
+ searchinput.focus();
+};
+
+function clearFilter() {
+ var searchinput = document.getElementById('searchinput');
+ searchinput.value = "";
+ filterSamples();
+ searchinput.focus();
+};
+
+function initSearch() {
+ var searchinput = document.getElementById('searchinput');
+ if (canclear) {
+ searchinput.addEventListener('click', filterSamples, false);
+ }
+};
+
+var currentfilter = "";
+var canclear = testSearchSupport();
+window.addEventListener('load', initSearch, false);
« 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