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 cr.define('options', function() { | 5 cr.define('options', function() { |
6 /** @const */ var OptionsPage = options.OptionsPage; | 6 /** @const */ var Page = cr.ui.pageManager.Page; |
| 7 /** @const */ var PageManager = cr.ui.pageManager.PageManager; |
7 | 8 |
8 /** | 9 /** |
9 * Encapsulated handling of a search bubble. | 10 * Encapsulated handling of a search bubble. |
10 * @constructor | 11 * @constructor |
11 */ | 12 */ |
12 function SearchBubble(text) { | 13 function SearchBubble(text) { |
13 var el = cr.doc.createElement('div'); | 14 var el = cr.doc.createElement('div'); |
14 SearchBubble.decorate(el); | 15 SearchBubble.decorate(el); |
15 el.content = text; | 16 el.content = text; |
16 return el; | 17 return el; |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 this.lastTop = top; | 108 this.lastTop = top; |
108 } | 109 } |
109 }, | 110 }, |
110 }; | 111 }; |
111 | 112 |
112 /** | 113 /** |
113 * Encapsulated handling of the search page. | 114 * Encapsulated handling of the search page. |
114 * @constructor | 115 * @constructor |
115 */ | 116 */ |
116 function SearchPage() { | 117 function SearchPage() { |
117 OptionsPage.call(this, 'search', | 118 Page.call(this, 'search', |
118 loadTimeData.getString('searchPageTabTitle'), | 119 loadTimeData.getString('searchPageTabTitle'), |
119 'searchPage'); | 120 'searchPage'); |
120 } | 121 } |
121 | 122 |
122 cr.addSingletonGetter(SearchPage); | 123 cr.addSingletonGetter(SearchPage); |
123 | 124 |
124 SearchPage.prototype = { | 125 SearchPage.prototype = { |
125 // Inherit SearchPage from OptionsPage. | 126 // Inherit SearchPage from Page. |
126 __proto__: OptionsPage.prototype, | 127 __proto__: Page.prototype, |
127 | 128 |
128 /** | 129 /** |
129 * A boolean to prevent recursion. Used by setSearchText_(). | 130 * A boolean to prevent recursion. Used by setSearchText_(). |
130 * @type {boolean} | 131 * @type {boolean} |
131 * @private | 132 * @private |
132 */ | 133 */ |
133 insideSetSearchText_: false, | 134 insideSetSearchText_: false, |
134 | 135 |
135 /** | 136 /** |
136 * Initialize the page. | 137 * Initialize the page. |
137 */ | 138 */ |
138 initializePage: function() { | 139 initializePage: function() { |
139 // Call base class implementation to start preference initialization. | 140 Page.prototype.initializePage.call(this); |
140 OptionsPage.prototype.initializePage.call(this); | |
141 | 141 |
142 this.searchField = $('search-field'); | 142 this.searchField = $('search-field'); |
143 | 143 |
144 // Handle search events. (No need to throttle, WebKit's search field | 144 // Handle search events. (No need to throttle, WebKit's search field |
145 // will do that automatically.) | 145 // will do that automatically.) |
146 this.searchField.onsearch = function(e) { | 146 this.searchField.onsearch = function(e) { |
147 this.setSearchText_(e.currentTarget.value); | 147 this.setSearchText_(e.currentTarget.value); |
148 }.bind(this); | 148 }.bind(this); |
149 | 149 |
150 // Install handler for key presses. | 150 // Install handler for key presses. |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 this.searchActive_ = active; | 192 this.searchActive_ = active; |
193 | 193 |
194 if (active) { | 194 if (active) { |
195 var hash = location.hash; | 195 var hash = location.hash; |
196 if (hash) { | 196 if (hash) { |
197 this.searchField.value = | 197 this.searchField.value = |
198 decodeURIComponent(hash.slice(1).replace(/\+/g, ' ')); | 198 decodeURIComponent(hash.slice(1).replace(/\+/g, ' ')); |
199 } else if (!this.searchField.value) { | 199 } else if (!this.searchField.value) { |
200 // This should only happen if the user goes directly to | 200 // This should only happen if the user goes directly to |
201 // chrome://settings-frame/search | 201 // chrome://settings-frame/search |
202 OptionsPage.showDefaultPage(); | 202 PageManager.showDefaultPage(); |
203 return; | 203 return; |
204 } | 204 } |
205 | 205 |
206 // Move 'advanced' sections into the main settings page to allow | 206 // Move 'advanced' sections into the main settings page to allow |
207 // searching. | 207 // searching. |
208 if (!this.advancedSections_) { | 208 if (!this.advancedSections_) { |
209 this.advancedSections_ = | 209 this.advancedSections_ = |
210 $('advanced-settings-container').querySelectorAll('section'); | 210 $('advanced-settings-container').querySelectorAll('section'); |
211 for (var i = 0, section; section = this.advancedSections_[i]; i++) | 211 for (var i = 0, section; section = this.advancedSections_[i]; i++) |
212 $('settings').appendChild(section); | 212 $('settings').appendChild(section); |
(...skipping 14 matching lines...) Expand all Loading... |
227 if (active) { | 227 if (active) { |
228 if (childDiv.tagName != 'SECTION') | 228 if (childDiv.tagName != 'SECTION') |
229 childDiv.classList.add('search-hidden'); | 229 childDiv.classList.add('search-hidden'); |
230 } else { | 230 } else { |
231 childDiv.classList.remove('search-hidden'); | 231 childDiv.classList.remove('search-hidden'); |
232 } | 232 } |
233 } | 233 } |
234 | 234 |
235 if (active) { | 235 if (active) { |
236 // When search is active, remove the 'hidden' tag. This tag may have | 236 // When search is active, remove the 'hidden' tag. This tag may have |
237 // been added by the OptionsPage. | 237 // been added by the PageManager. |
238 page.pageDiv.hidden = false; | 238 page.pageDiv.hidden = false; |
239 } | 239 } |
240 } | 240 } |
241 | 241 |
242 if (active) { | 242 if (active) { |
243 this.setSearchText_(this.searchField.value); | 243 this.setSearchText_(this.searchField.value); |
244 this.searchField.focus(); | 244 this.searchField.focus(); |
245 } else { | 245 } else { |
246 // After hiding all page content, remove any search results. | 246 // After hiding all page content, remove any search results. |
247 this.unhighlightMatches_(); | 247 this.unhighlightMatches_(); |
(...skipping 22 matching lines...) Expand all Loading... |
270 text = SearchPage.canonicalizeQuery(text); | 270 text = SearchPage.canonicalizeQuery(text); |
271 | 271 |
272 // Set the hash on the current page, and the enclosing uber page | 272 // Set the hash on the current page, and the enclosing uber page |
273 var hash = text ? '#' + encodeURIComponent(text) : ''; | 273 var hash = text ? '#' + encodeURIComponent(text) : ''; |
274 var path = text ? this.name : ''; | 274 var path = text ? this.name : ''; |
275 uber.pushState({}, path + hash); | 275 uber.pushState({}, path + hash); |
276 | 276 |
277 // Toggle the search page if necessary. | 277 // Toggle the search page if necessary. |
278 if (text) { | 278 if (text) { |
279 if (!this.searchActive_) | 279 if (!this.searchActive_) |
280 OptionsPage.showPageByName(this.name, false); | 280 PageManager.showPageByName(this.name, false); |
281 } else { | 281 } else { |
282 if (this.searchActive_) | 282 if (this.searchActive_) |
283 OptionsPage.showPageByName(OptionsPage.getDefaultPage().name, false); | 283 PageManager.showPageByName(PageManager.getDefaultPage().name, false); |
284 | 284 |
285 this.insideSetSearchText_ = false; | 285 this.insideSetSearchText_ = false; |
286 return; | 286 return; |
287 } | 287 } |
288 | 288 |
289 var foundMatches = false; | 289 var foundMatches = false; |
290 | 290 |
291 // Remove any prior search results. | 291 // Remove any prior search results. |
292 this.unhighlightMatches_(); | 292 this.unhighlightMatches_(); |
293 this.removeSearchBubbles_(); | 293 this.removeSearchBubbles_(); |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
485 }, | 485 }, |
486 | 486 |
487 /** | 487 /** |
488 * Builds a list of top-level pages to search. Omits the search page and | 488 * Builds a list of top-level pages to search. Omits the search page and |
489 * all sub-pages. | 489 * all sub-pages. |
490 * @return {Array} An array of pages to search. | 490 * @return {Array} An array of pages to search. |
491 * @private | 491 * @private |
492 */ | 492 */ |
493 getSearchablePages_: function() { | 493 getSearchablePages_: function() { |
494 var name, page, pages = []; | 494 var name, page, pages = []; |
495 for (name in OptionsPage.registeredPages) { | 495 for (name in PageManager.registeredPages) { |
496 if (name != this.name) { | 496 if (name != this.name) { |
497 page = OptionsPage.registeredPages[name]; | 497 page = PageManager.registeredPages[name]; |
498 if (!page.parentPage) | 498 if (!page.parentPage) |
499 pages.push(page); | 499 pages.push(page); |
500 } | 500 } |
501 } | 501 } |
502 return pages; | 502 return pages; |
503 }, | 503 }, |
504 | 504 |
505 /** | 505 /** |
506 * Builds a list of sub-pages (and overlay pages) to search. Ignore pages | 506 * Builds a list of sub-pages (and overlay pages) to search. Ignore pages |
507 * that have no associated controls, or whose controls are hidden. | 507 * that have no associated controls, or whose controls are hidden. |
508 * @return {Array} An array of pages to search. | 508 * @return {Array} An array of pages to search. |
509 * @private | 509 * @private |
510 */ | 510 */ |
511 getSearchableSubPages_: function() { | 511 getSearchableSubPages_: function() { |
512 var name, pageInfo, page, pages = []; | 512 var name, pageInfo, page, pages = []; |
513 for (name in OptionsPage.registeredPages) { | 513 for (name in PageManager.registeredPages) { |
514 page = OptionsPage.registeredPages[name]; | 514 page = PageManager.registeredPages[name]; |
515 if (page.parentPage && | 515 if (page.parentPage && |
516 page.associatedSection && | 516 page.associatedSection && |
517 !page.associatedSection.hidden) { | 517 !page.associatedSection.hidden) { |
518 pages.push(page); | 518 pages.push(page); |
519 } | 519 } |
520 } | 520 } |
521 for (name in OptionsPage.registeredOverlayPages) { | 521 for (name in PageManager.registeredOverlayPages) { |
522 page = OptionsPage.registeredOverlayPages[name]; | 522 page = PageManager.registeredOverlayPages[name]; |
523 if (page.associatedSection && | 523 if (page.associatedSection && |
524 !page.associatedSection.hidden && | 524 !page.associatedSection.hidden && |
525 page.pageDiv != undefined) { | 525 page.pageDiv != undefined) { |
526 pages.push(page); | 526 pages.push(page); |
527 } | 527 } |
528 } | 528 } |
529 return pages; | 529 return pages; |
530 }, | 530 }, |
531 | 531 |
532 /** | 532 /** |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
568 // Trim beginning and ending whitespace. | 568 // Trim beginning and ending whitespace. |
569 return text.replace(/^\s+|\s+$/g, ''); | 569 return text.replace(/^\s+|\s+$/g, ''); |
570 }; | 570 }; |
571 | 571 |
572 // Export | 572 // Export |
573 return { | 573 return { |
574 SearchPage: SearchPage | 574 SearchPage: SearchPage |
575 }; | 575 }; |
576 | 576 |
577 }); | 577 }); |
OLD | NEW |