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

Unified 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: Rebase for commit queue 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/resources/options/search_page.js
===================================================================
--- chrome/browser/resources/options/search_page.js (revision 107010)
+++ chrome/browser/resources/options/search_page.js (working copy)
@@ -105,7 +105,6 @@
function SearchPage() {
OptionsPage.call(this, 'search', templateData.searchPageTabTitle,
'searchPage');
- this.searchActive = false;
}
cr.addSingletonGetter(SearchPage);
@@ -115,6 +114,13 @@
__proto__: OptionsPage.prototype,
/**
+ * A boolean to prevent recursion. Used by setSearchText_().
+ * @type {Boolean}
+ * @private
+ */
+ insideSetSearchText_: false,
+
+ /**
* Initialize the page.
*/
initializePage: function() {
@@ -145,7 +151,7 @@
// Handle search events. (No need to throttle, WebKit's search field
// will do that automatically.)
searchField.onsearch = function(e) {
- self.setSearchText_(SearchPage.canonicalizeQuery(this.value));
+ self.setSearchText_(this.value);
};
// We update the history stack every time the search field blurs. This way
@@ -284,6 +290,19 @@
* @private
*/
setSearchText_: function(text) {
+ // Prevent recursive execution of this method.
+ if (this.insideSetSearchText_) return;
+ this.insideSetSearchText_ = true;
+
+ // Cleanup the search query string.
+ text = SearchPage.canonicalizeQuery(text);
+
+ // Notify listeners about the new search query, some pages may wish to
+ // show/hide elements based on the query.
+ var event = new cr.Event('searchChanged');
+ event.searchText = text;
+ this.dispatchEvent(event);
+
// Toggle the search page if necessary.
if (text.length) {
if (!this.searchActive_)
@@ -291,6 +310,8 @@
} else {
if (this.searchActive_)
OptionsPage.showDefaultPage();
+
+ this.insideSetSearchText_ = false;
return;
}
@@ -381,6 +402,9 @@
length = bubbleControls.length;
for (var i = 0; i < length; i++)
this.createSearchBubble_(bubbleControls[i], text);
+
+ // Cleanup the recursion-prevention variable.
+ this.insideSetSearchText_ = false;
},
/**
« no previous file with comments | « chrome/browser/resources/options/options_page.js ('k') | chrome/browser/ui/webui/options/extension_settings_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698