| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // require: cr.js | 5 // require: cr.js |
| 6 | 6 |
| 7 cr.define('chrome.sync', function() { | 7 cr.define('chrome.sync', function() { |
| 8 var currSearchId = 0; | 8 var currSearchId = 0; |
| 9 | 9 |
| 10 var setQueryString = function(queryControl, query) { |
| 11 queryControl.value = query; |
| 12 }; |
| 13 |
| 14 var createDoQueryFunction = function(queryControl, submitControl, query) { |
| 15 return function() { |
| 16 setQueryString(queryControl, query); |
| 17 submitControl.click(); |
| 18 }; |
| 19 }; |
| 20 |
| 21 /** |
| 22 * Decorates the quick search controls |
| 23 * |
| 24 * @param {Array of DOM elements} quickLinkArray The <a> object which |
| 25 * will be given a link to a quick filter option. |
| 26 * @param {!HTMLInputElement} queryControl The <input> object of |
| 27 * type=search where the user types in his query. |
| 28 */ |
| 29 var decorateQuickQueryControls = function(quickLinkArray, submitControl, |
| 30 queryControl) { |
| 31 for (var index = 0; index < allLinks.length; ++index) { |
| 32 var quickQuery = allLinks[index].getAttribute('data-query'); |
| 33 var quickQueryFunction = createDoQueryFunction(queryControl, |
| 34 submitControl, quickQuery); |
| 35 allLinks[index].addEventListener('click', quickQueryFunction); |
| 36 } |
| 37 }; |
| 38 |
| 10 /** | 39 /** |
| 11 * Runs a search with the given query. | 40 * Runs a search with the given query. |
| 12 * | 41 * |
| 13 * @param {string} query The regex to do the search with. | 42 * @param {string} query The regex to do the search with. |
| 14 * @param {function} callback The callback called with the search results; | 43 * @param {function} callback The callback called with the search results; |
| 15 * not called if doSearch() is called again while the search is running. | 44 * not called if doSearch() is called again while the search is running. |
| 16 */ | 45 */ |
| 17 var doSearch = function(query, callback) { | 46 var doSearch = function(query, callback) { |
| 18 var searchId = ++currSearchId; | 47 var searchId = ++currSearchId; |
| 19 try { | 48 try { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 31 // be caught and handled here. | 60 // be caught and handled here. |
| 32 callback([], err); | 61 callback([], err); |
| 33 } | 62 } |
| 34 }; | 63 }; |
| 35 | 64 |
| 36 /** | 65 /** |
| 37 * Decorates the various search controls. | 66 * Decorates the various search controls. |
| 38 * | 67 * |
| 39 * @param {!HTMLInputElement} queryControl The <input> object of | 68 * @param {!HTMLInputElement} queryControl The <input> object of |
| 40 * type=search where the user types in his query. | 69 * type=search where the user types in his query. |
| 41 * @param {!HTMLButtonElement} submitControl The <button> object of | 70 * @param {!HTMLButtonElement} submitControl The <button> object |
| 42 * where the user can click to do his query. | 71 * where the user can click to do his query. |
| 43 * @param {!HTMLElement} statusControl The <span> object display the | 72 * @param {!HTMLElement} statusControl The <span> object display the |
| 44 * search status. | 73 * search status. |
| 45 * @param {!HTMLElement} listControl The <list> object which holds | 74 * @param {!HTMLElement} listControl The <list> object which holds |
| 46 * the list of returned results. | 75 * the list of returned results. |
| 47 * @param {!HTMLPreElement} detailsControl The <pre> object which | 76 * @param {!HTMLPreElement} detailsControl The <pre> object which |
| 48 * holds the details of the selected result. | 77 * holds the details of the selected result. |
| 49 */ | 78 */ |
| 50 function decorateSearchControls(queryControl, submitControl, statusControl, | 79 function decorateSearchControls(queryControl, submitControl, statusControl, |
| 51 resultsControl, detailsControl) { | 80 resultsControl, detailsControl) { |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 resultsControl.selectionModel.addEventListener('change', function(event) { | 124 resultsControl.selectionModel.addEventListener('change', function(event) { |
| 96 detailsControl.textContent = ''; | 125 detailsControl.textContent = ''; |
| 97 var selected = resultsControl.selectedItem; | 126 var selected = resultsControl.selectedItem; |
| 98 if (selected) { | 127 if (selected) { |
| 99 detailsControl.textContent = JSON.stringify(selected, null, 2); | 128 detailsControl.textContent = JSON.stringify(selected, null, 2); |
| 100 } | 129 } |
| 101 }); | 130 }); |
| 102 } | 131 } |
| 103 | 132 |
| 104 return { | 133 return { |
| 105 decorateSearchControls: decorateSearchControls | 134 decorateSearchControls: decorateSearchControls, |
| 135 decorateQuickQueryControls: decorateQuickQueryControls |
| 106 }; | 136 }; |
| 107 }); | 137 }); |
| OLD | NEW |