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

Side by Side Diff: chrome/browser/resources/options/search_page.js

Issue 8353022: [web-ui settings] Fixes and improvements for settings page searching. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 2 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 cr.define('options', function() { 5 cr.define('options', function() {
6 const OptionsPage = options.OptionsPage; 6 const OptionsPage = options.OptionsPage;
7 7
8 /** 8 /**
9 * Encapsulated handling of a search bubble. 9 * Encapsulated handling of a search bubble.
10 * @constructor 10 * @constructor
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 } 98 }
99 } 99 }
100 100
101 /** 101 /**
102 * Encapsulated handling of the search page. 102 * Encapsulated handling of the search page.
103 * @constructor 103 * @constructor
104 */ 104 */
105 function SearchPage() { 105 function SearchPage() {
106 OptionsPage.call(this, 'search', templateData.searchPageTabTitle, 106 OptionsPage.call(this, 'search', templateData.searchPageTabTitle,
107 'searchPage'); 107 'searchPage');
108 this.searchActive = false;
109 } 108 }
110 109
111 cr.addSingletonGetter(SearchPage); 110 cr.addSingletonGetter(SearchPage);
112 111
113 SearchPage.prototype = { 112 SearchPage.prototype = {
114 // Inherit SearchPage from OptionsPage. 113 // Inherit SearchPage from OptionsPage.
115 __proto__: OptionsPage.prototype, 114 __proto__: OptionsPage.prototype,
116 115
117 /** 116 /**
118 * Initialize the page. 117 * Initialize the page.
(...skipping 19 matching lines...) Expand all
138 self.tab.onclick = self.tab.onkeydown = self.tab.onkeypress = undefined; 137 self.tab.onclick = self.tab.onkeydown = self.tab.onkeypress = undefined;
139 self.tab.tabIndex = -1; 138 self.tab.tabIndex = -1;
140 self.tab.setAttribute('role', ''); 139 self.tab.setAttribute('role', '');
141 140
142 // Don't allow the focus on the search navbar. http://crbug.com/77989 141 // Don't allow the focus on the search navbar. http://crbug.com/77989
143 self.tab.onfocus = self.tab.blur; 142 self.tab.onfocus = self.tab.blur;
144 143
145 // Handle search events. (No need to throttle, WebKit's search field 144 // Handle search events. (No need to throttle, WebKit's search field
146 // will do that automatically.) 145 // will do that automatically.)
147 searchField.onsearch = function(e) { 146 searchField.onsearch = function(e) {
148 self.setSearchText_(SearchPage.canonicalizeQuery(this.value)); 147 self.setSearchText_(this.value);
149 }; 148 };
150 149
151 // We update the history stack every time the search field blurs. This way 150 // We update the history stack every time the search field blurs. This way
152 // we get a history entry for each search, roughly, but not each letter 151 // we get a history entry for each search, roughly, but not each letter
153 // typed. 152 // typed.
154 searchField.onblur = function(e) { 153 searchField.onblur = function(e) {
155 var query = SearchPage.canonicalizeQuery(searchField.value); 154 var query = SearchPage.canonicalizeQuery(searchField.value);
156 if (!query) 155 if (!query)
157 return; 156 return;
158 157
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 this.removeSearchBubbles_(); 276 this.removeSearchBubbles_();
278 } 277 }
279 }, 278 },
280 279
281 /** 280 /**
282 * Set the current search criteria. 281 * Set the current search criteria.
283 * @param {string} text Search text. 282 * @param {string} text Search text.
284 * @private 283 * @private
285 */ 284 */
286 setSearchText_: function(text) { 285 setSearchText_: function(text) {
286 // Prevent recursive execution of this method.
287 if (this.insideSetSearchText_) return;
288 this.insideSetSearchText_ = true;
289
290 // Cleanup the search query string.
291 text = SearchPage.canonicalizeQuery(text);
292
293 // Notify listeners about the new search query, some pages may wish to
294 // show/hide elements based on the query.
295 var event = new cr.Event('searchChanged');
296 event.searchText = text;
297 this.dispatchEvent(event);
298
287 // Toggle the search page if necessary. 299 // Toggle the search page if necessary.
288 if (text.length) { 300 if (text.length) {
289 if (!this.searchActive_) 301 if (!this.searchActive_)
290 OptionsPage.navigateToPage(this.name); 302 OptionsPage.navigateToPage(this.name);
291 } else { 303 } else {
292 if (this.searchActive_) 304 if (this.searchActive_)
293 OptionsPage.showDefaultPage(); 305 OptionsPage.showDefaultPage();
306
307 this.insideSetSearchText_ = false;
294 return; 308 return;
295 } 309 }
296 310
297 var foundMatches = false; 311 var foundMatches = false;
298 var bubbleControls = []; 312 var bubbleControls = [];
299 313
300 // Remove any prior search results. 314 // Remove any prior search results.
301 this.unhighlightMatches_(); 315 this.unhighlightMatches_();
302 this.removeSearchBubbles_(); 316 this.removeSearchBubbles_();
303 317
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 // Configure elements on the search results page based on search results. 388 // Configure elements on the search results page based on search results.
375 if (foundMatches) 389 if (foundMatches)
376 $('searchPageNoMatches').classList.add('search-hidden'); 390 $('searchPageNoMatches').classList.add('search-hidden');
377 else 391 else
378 $('searchPageNoMatches').classList.remove('search-hidden'); 392 $('searchPageNoMatches').classList.remove('search-hidden');
379 393
380 // Create search balloons for sub-page results. 394 // Create search balloons for sub-page results.
381 length = bubbleControls.length; 395 length = bubbleControls.length;
382 for (var i = 0; i < length; i++) 396 for (var i = 0; i < length; i++)
383 this.createSearchBubble_(bubbleControls[i], text); 397 this.createSearchBubble_(bubbleControls[i], text);
398
399 // Cleanup the recursion-prevension variable.
Finnur 2011/10/20 10:00:59 nit: typo: prevention, not prevension.
csilv 2011/10/20 17:49:13 Done.
400 this.insideSetSearchText_ = false;
384 }, 401 },
385 402
386 /** 403 /**
387 * Performs a string replacement based on a regex and replace string. 404 * Performs a string replacement based on a regex and replace string.
388 * @param {RegEx} regex A regular expression for finding search matches. 405 * @param {RegEx} regex A regular expression for finding search matches.
389 * @param {String} replace A string to apply the replace operation. 406 * @param {String} replace A string to apply the replace operation.
390 * @param {Element} element An HTML container element. 407 * @param {Element} element An HTML container element.
391 * @returns {Boolean} true if the element was changed. 408 * @returns {Boolean} true if the element was changed.
392 * @private 409 * @private
393 */ 410 */
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
565 // Trim beginning and ending whitespace. 582 // Trim beginning and ending whitespace.
566 return text.replace(/^\s+|\s+$/g, ''); 583 return text.replace(/^\s+|\s+$/g, '');
567 }; 584 };
568 585
569 // Export 586 // Export
570 return { 587 return {
571 SearchPage: SearchPage 588 SearchPage: SearchPage
572 }; 589 };
573 590
574 }); 591 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698