Chromium Code Reviews| Index: chrome/browser/resources/options/search_page.js |
| =================================================================== |
| --- chrome/browser/resources/options/search_page.js (revision 70013) |
| +++ chrome/browser/resources/options/search_page.js (working copy) |
| @@ -49,6 +49,13 @@ |
| }, |
| /** |
| + * @inheritDoc |
| + */ |
| + get sticky() { |
| + return true; |
| + }, |
| + |
| + /** |
| * Called after this page has shown. |
| */ |
| didShowPage: function() { |
| @@ -91,22 +98,19 @@ |
| } |
| } |
| - var page, length, childDiv; |
| + var page, key, length, childDiv, i; |
| var pagesToSearch = this.getSearchablePages_(); |
| - for (var key in pagesToSearch) { |
| - var page = pagesToSearch[key]; |
| + for (key in pagesToSearch) { |
|
arv (Not doing code reviews)
2010/12/23 20:38:22
I find it easier to read with var but it is up to
csilv
2010/12/23 21:46:07
Moved a few vars inline that will have no or negli
|
| + page = pagesToSearch[key]; |
| - if (!active) { |
| + if (!active) |
| page.visible = false; |
| - this.unhighlightMatches_(page.tab); |
| - this.unhighlightMatches_(page.pageDiv); |
| - } |
| // Update the visible state of all top-level elements that are not |
| // sections (ie titles, button strips). We do this before changing |
| // the page visibility to avoid excessive re-draw. |
| length = page.pageDiv.childNodes.length; |
| - for (var i = 0; i < length; i++) { |
| + for (i = 0; i < length; i++) { |
| childDiv = page.pageDiv.childNodes[i]; |
| if (childDiv.nodeType == document.ELEMENT_NODE) { |
| if (active) { |
| @@ -118,13 +122,16 @@ |
| } |
| } |
| - // Toggle the visibility state of the page. |
| if (active) { |
| // When search is active, remove the 'hidden' tag. This tag may have |
| // been added by the OptionsPage. |
| page.pageDiv.classList.remove('hidden'); |
| } |
| } |
| + |
| + // After hiding all page content, remove any highlighted matches. |
| + if (!active) |
| + this.unhighlightMatches_(); |
| }, |
| /** |
| @@ -135,6 +142,9 @@ |
| setSearchText_: function(text) { |
| var foundMatches = false; |
| + // Remove any highlighted matches. |
| + this.unhighlightMatches_(); |
| + |
| // Generate search text by applying lowercase and escaping any characters |
| // that would be problematic for regular expressions. |
| var searchText = |
| @@ -147,19 +157,18 @@ |
| // Initialize all sections. If the search string matches a title page, |
| // show sections for that page. |
| + var page, key, pageMatch, childDiv, i; |
| var pagesToSearch = this.getSearchablePages_(); |
| - for (var key in pagesToSearch) { |
| - var page = pagesToSearch[key]; |
| - this.unhighlightMatches_(page.tab); |
| - this.unhighlightMatches_(page.pageDiv); |
| - var pageMatch = false; |
| + for (key in pagesToSearch) { |
| + page = pagesToSearch[key]; |
| + pageMatch = false; |
| if (searchText.length) { |
| pageMatch = this.performReplace_(regEx, replaceString, page.tab); |
| } |
| if (pageMatch) |
| foundMatches = true; |
| - for (var i = 0; i < page.pageDiv.childNodes.length; i++) { |
| - var childDiv = page.pageDiv.childNodes[i]; |
| + for (i = 0; i < page.pageDiv.childNodes.length; i++) { |
| + childDiv = page.pageDiv.childNodes[i]; |
| if (childDiv.nodeType == document.ELEMENT_NODE && |
| childDiv.nodeName.toLowerCase() == 'section') { |
| if (pageMatch) { |
| @@ -171,12 +180,31 @@ |
| } |
| } |
| - // Search all sections for anchored string matches. |
| if (searchText.length) { |
| - for (var key in pagesToSearch) { |
| - var page = pagesToSearch[key]; |
| - for (var i = 0; i < page.pageDiv.childNodes.length; i++) { |
| - var childDiv = page.pageDiv.childNodes[i]; |
| + // Search all sub-pages, generating an array of top-level sections that |
| + // we need to make visible. |
| + var subPagesToSearch = this.getSearchableSubPages_(); |
| + var control, node; |
| + for (key in subPagesToSearch) { |
| + page = subPagesToSearch[key]; |
| + if (this.performReplace_(regEx, replaceString, page.pageDiv)) { |
| + section = page.associatedSection; |
| + if (section) |
| + section.classList.remove('search-hidden'); |
| + controls = page.associatedControls; |
| + if (controls) { |
| + // TODO(csilv): highlight each control. |
| + } |
| + |
| + foundMatches = true; |
| + } |
| + } |
| + |
| + // Search all top-level sections for anchored string matches. |
| + for (key in pagesToSearch) { |
| + page = pagesToSearch[key]; |
| + for (i = 0; i < page.pageDiv.childNodes.length; i++) { |
| + childDiv = page.pageDiv.childNodes[i]; |
| if (childDiv.nodeType == document.ELEMENT_NODE && |
| childDiv.nodeName.toLowerCase() == 'section' && |
| this.performReplace_(regEx, replaceString, childDiv)) { |
| @@ -252,13 +280,12 @@ |
| }, |
| /** |
| - * Removes all search highlight tags from a container element. |
| - * @param {Element} element An HTML container element. |
| + * Removes all search highlight tags from the document. |
| * @private |
| */ |
| - unhighlightMatches_: function(element) { |
| + unhighlightMatches_: function() { |
| // Find all search highlight elements. |
| - var elements = element.querySelectorAll('.search-highlighted'); |
| + var elements = document.querySelectorAll('.search-highlighted'); |
| // For each element, remove the highlighting. |
| var node, parent, i, length = elements.length; |
| @@ -275,17 +302,42 @@ |
| }, |
| /** |
| - * Builds a list of pages to search. Omits the search page. |
| + * Builds a list of top-level pages to search. Omits the search page and |
| + * all sub-pages. |
| * @returns {Array} An array of pages to search. |
| * @private |
| */ |
| getSearchablePages_: function() { |
| - var pages = []; |
| - for (var name in OptionsPage.registeredPages) { |
| - if (name != this.name) |
| - pages.push(OptionsPage.registeredPages[name]); |
| + var name, page, pages = []; |
| + for (name in OptionsPage.registeredPages) { |
| + if (name != this.name) { |
| + page = OptionsPage.registeredPages[name]; |
| + if (!page.parentPage) |
| + pages.push(page); |
| + } |
| } |
| return pages; |
| + }, |
| + |
| + /** |
| + * Builds a list of sub-pages (and overlay pages) to search. Ignore pages |
| + * that have no associated controls. |
| + * @returns {Array} An array of pages to search. |
| + * @private |
| + */ |
| + getSearchableSubPages_: function() { |
| + var name, pageInfo, page, pages = []; |
| + for (name in OptionsPage.registeredPages) { |
| + page = OptionsPage.registeredPages[name]; |
| + if (page.parentPage && page.associatedSection) |
| + pages.push(page); |
| + } |
| + for (name in OptionsPage.registeredOverlayPages) { |
| + page = OptionsPage.registeredOverlayPages[name]; |
| + if (page.associatedSection && page.pageDiv != undefined) |
| + pages.push(page); |
| + } |
| + return pages; |
| } |
| }; |