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

Unified Diff: chrome/browser/resources/options/search_page.js

Issue 6360016: dom-ui settings: Improve search field behavior.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: rebase Created 9 years, 11 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/browser/resources/options/search_page.html ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/resources/options/search_page.js
===================================================================
--- chrome/browser/resources/options/search_page.js (revision 72525)
+++ chrome/browser/resources/options/search_page.js (working copy)
@@ -111,12 +111,20 @@
// Replace the contents of the navigation tab with the search field.
self.tab.textContent = '';
self.tab.appendChild(searchField);
+ self.tab.onclick = self.tab.onkeypress = undefined;
// Handle search events. (No need to throttle, WebKit's search field
// will do that automatically.)
searchField.onsearch = function(e) {
self.setSearchText_(this.value);
};
+
+ // Install handler for key presses.
+ document.addEventListener('keydown',
+ this.keyDownEventHandler_.bind(this));
+
+ // Focus the search field by default.
+ searchField.focus();
},
/**
@@ -160,10 +168,7 @@
if (this.searchActive_ != active) {
this.searchActive_ = active;
- if (active) {
- // Reset the search criteria, effectively hiding all the sections.
- this.setSearchText_('');
- } else {
+ if (!active) {
// Just wipe out any active search text since it's no longer relevant.
$('search-field').value = '';
}
@@ -208,6 +213,20 @@
* @private
*/
setSearchText_: function(text) {
+ // Consider whitespace-only strings as empty.
+ if (!text.replace(/^\s+/, '').length)
+ text = '';
+
+ // Toggle the search page if necessary.
+ if (text.length) {
+ if (!this.searchActive_)
+ OptionsPage.showPageByName(this.name);
+ } else {
+ if (this.searchActive_)
+ OptionsPage.showDefaultPage();
+ return;
+ }
+
var foundMatches = false;
var bubbleControls = [];
@@ -287,16 +306,10 @@
}
// Configure elements on the search results page based on search results.
- if (searchText.length == 0) {
- $('searchPageInfo').classList.remove('search-hidden');
+ if (foundMatches)
$('searchPageNoMatches').classList.add('search-hidden');
- } else if (foundMatches) {
- $('searchPageInfo').classList.add('search-hidden');
- $('searchPageNoMatches').classList.add('search-hidden');
- } else {
- $('searchPageInfo').classList.add('search-hidden');
+ else
$('searchPageNoMatches').classList.remove('search-hidden');
- }
// Create search balloons for sub-page results.
length = bubbleControls.length;
@@ -444,6 +457,21 @@
pages.push(page);
}
return pages;
+ },
+
+ /**
+ * A function to handle key press events.
+ * @return {Event} a keydown event.
+ * @private
+ */
+ keyDownEventHandler_: function(event) {
+ // Focus the search field on an unused forward-slash.
+ if (event.keyCode == 191 &&
+ !/INPUT|SELECT|BUTTON|TEXTAREA/.test(event.target.tagName)) {
+ $('search-field').focus();
+ event.stopPropagation();
+ event.preventDefault();
+ }
}
};
« no previous file with comments | « chrome/browser/resources/options/search_page.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698