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 OptionsPage = options.OptionsPage; | 6 const OptionsPage = options.OptionsPage; |
7 const ArrayDataModel = cr.ui.ArrayDataModel; | 7 const ArrayDataModel = cr.ui.ArrayDataModel; |
8 const RepeatingButton = cr.ui.RepeatingButton; | 8 const RepeatingButton = cr.ui.RepeatingButton; |
9 | 9 |
10 // | 10 // |
(...skipping 10 matching lines...) Expand all Loading... |
21 | 21 |
22 BrowserOptions.prototype = { | 22 BrowserOptions.prototype = { |
23 // Inherit BrowserOptions from OptionsPage. | 23 // Inherit BrowserOptions from OptionsPage. |
24 __proto__: options.OptionsPage.prototype, | 24 __proto__: options.OptionsPage.prototype, |
25 | 25 |
26 // State variables. | 26 // State variables. |
27 syncEnabled: false, | 27 syncEnabled: false, |
28 syncSetupCompleted: false, | 28 syncSetupCompleted: false, |
29 | 29 |
30 /** | 30 /** |
31 * An autocomplete list that can be attached to the homepage URL text field | 31 * The value attribute of the most recently selected option in the home page |
| 32 * selector. |
| 33 * @type {string} (One of: 'none', 'ntp', 'url') |
| 34 */ |
| 35 previousHomePageSelection_: null, |
| 36 |
| 37 showHomeButton_: false, |
| 38 homePageIsNtp_: false, |
| 39 |
| 40 /** |
| 41 * An autocomplete list that can be attached to the home page URL text field |
32 * during editing. | 42 * during editing. |
33 * @type {HTMLElement} | 43 * @type {HTMLElement} |
34 * @private | 44 * @private |
35 */ | 45 */ |
36 autocompleteList_: null, | 46 autocompleteList_: null, |
37 | 47 |
38 // The cached value of the instant.confirm_dialog_shown preference. | 48 // The cached value of the instant.confirm_dialog_shown preference. |
39 instantConfirmDialogShown_: false, | 49 instantConfirmDialogShown_: false, |
40 | 50 |
41 /** | 51 /** |
(...skipping 27 matching lines...) Expand all Loading... |
69 ['Options_InternetOptions']); | 79 ['Options_InternetOptions']); |
70 }); | 80 }); |
71 } | 81 } |
72 | 82 |
73 // On Startup section. | 83 // On Startup section. |
74 $('startupSetPages').addEventListener('click', function() { | 84 $('startupSetPages').addEventListener('click', function() { |
75 OptionsPage.navigateToPage('startup'); | 85 OptionsPage.navigateToPage('startup'); |
76 }); | 86 }); |
77 | 87 |
78 // Appearance section. | 88 // Appearance section. |
79 $('change-home-page').addEventListener('click', function(event) { | 89 $('homepage-select').addEventListener( |
80 OptionsPage.navigateToPage('homePageOverlay'); | 90 'change', this.onHomePageSelectChange_.bind(this)); |
| 91 |
| 92 ['browser.show_home_button', |
| 93 'homepage', |
| 94 'homepage_is_newtabpage'].forEach(function(pref) { |
| 95 Preferences.getInstance().addEventListener( |
| 96 pref, |
| 97 self.onHomePagePrefChanged_.bind(self)); |
81 }); | 98 }); |
| 99 |
82 $('themes-gallery').addEventListener('click', function(event) { | 100 $('themes-gallery').addEventListener('click', function(event) { |
83 window.open(localStrings.getString('themesGalleryURL')); | 101 window.open(localStrings.getString('themesGalleryURL')); |
84 }); | 102 }); |
85 $('themes-reset').addEventListener('click', function(event) { | 103 $('themes-reset').addEventListener('click', function(event) { |
86 chrome.send('themesReset'); | 104 chrome.send('themesReset'); |
87 }); | 105 }); |
88 | 106 |
89 // Device section (ChromeOS only). | 107 // Device section (ChromeOS only). |
90 if (cr.isChromeOS) { | 108 if (cr.isChromeOS) { |
91 $('keyboard-settings-button').addEventListener('click', function(evt) { | 109 $('keyboard-settings-button').addEventListener('click', function(evt) { |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 /** | 325 /** |
308 * Get the start/stop sync button DOM element. | 326 * Get the start/stop sync button DOM element. |
309 * @return {DOMElement} The start/stop sync button. | 327 * @return {DOMElement} The start/stop sync button. |
310 * @private | 328 * @private |
311 */ | 329 */ |
312 getStartStopSyncButton_: function() { | 330 getStartStopSyncButton_: function() { |
313 return $('start-stop-sync'); | 331 return $('start-stop-sync'); |
314 }, | 332 }, |
315 | 333 |
316 /** | 334 /** |
317 * Sets the label for the 'Show Home page' input. | 335 * Returns the <option> element with the given |value|. |
318 * @param {string} label The HTML of the input label. | 336 * @param {string} value One of 'none', 'ntp', 'url', 'choose'. |
319 * @private | 337 * @return {HTMLOptionElement} the specified <option> element. |
320 */ | 338 */ |
321 updateHomePageLabel_: function(label) { | 339 getHomePageOption_: function(value) { |
322 $('home-page-label').innerHTML = label; | 340 var select = $('homepage-select'); |
| 341 return select.querySelector('option[value=' + value + ']'); |
323 }, | 342 }, |
324 | 343 |
325 /** | 344 /** |
| 345 * Selects the <option> element with the given |value|. |
| 346 * @private |
| 347 */ |
| 348 selectHomePageOption_: function(value) { |
| 349 var select = $('homepage-select'); |
| 350 var option = this.getHomePageOption_(value); |
| 351 if (!option.selected) |
| 352 option.selected = true; |
| 353 }, |
| 354 |
| 355 /** |
| 356 * Event listener for the |change| event on the homepage <select> element. |
| 357 * @private |
| 358 */ |
| 359 onHomePageSelectChange_: function() { |
| 360 var option = $('homepage-select').value; |
| 361 if (option == 'choose') { |
| 362 OptionsPage.navigateToPage('homePageOverlay'); |
| 363 return; |
| 364 } |
| 365 |
| 366 this.previousHomePageSelection_ = option; |
| 367 |
| 368 var showHomeButton = (option != 'none'); |
| 369 Preferences.setBooleanPref('browser.show_home_button', showHomeButton); |
| 370 |
| 371 if (option == 'ntp') |
| 372 Preferences.setBooleanPref('homepage_is_newtabpage', true); |
| 373 else if (option == 'url') |
| 374 Preferences.setBooleanPref('homepage_is_newtabpage', false); |
| 375 }, |
| 376 |
| 377 /** |
| 378 * Event listener called when any homepage-related preferences change. |
| 379 * @private |
| 380 */ |
| 381 onHomePagePrefChanged_: function(event) { |
| 382 switch (event.type) { |
| 383 case 'homepage': |
| 384 this.getHomePageOption_('url').textContent = event.value['value']; |
| 385 break; |
| 386 case 'browser.show_home_button': |
| 387 this.showHomeButton_ = event.value['value']; |
| 388 break; |
| 389 case 'homepage_is_newtabpage': |
| 390 this.homePageIsNtp_ = event.value['value']; |
| 391 break; |
| 392 default: |
| 393 console.error('Unexpected pref change event:', event.type); |
| 394 } |
| 395 this.updateHomePageSelector(); |
| 396 }, |
| 397 |
| 398 /** |
| 399 * Updates the homepage <select> element to have the appropriate option |
| 400 * selected. |
| 401 */ |
| 402 updateHomePageSelector: function() { |
| 403 if (this.showHomeButton_) { |
| 404 if (this.homePageIsNtp_) |
| 405 this.selectHomePageOption_('ntp'); |
| 406 else |
| 407 this.selectHomePageOption_('url'); |
| 408 } else { |
| 409 this.selectHomePageOption_('none'); |
| 410 } |
| 411 }, |
| 412 |
| 413 /** |
| 414 * Sets the home page selector to the 'url' option.Called when user clicks |
| 415 * OK in the "Choose another..." dialog. |
| 416 */ |
| 417 homePageSelectUrl: function() { |
| 418 this.selectHomePageOption_('url'); |
| 419 }, |
| 420 |
| 421 /** |
326 * Called when the value of the instant.confirm_dialog_shown preference | 422 * Called when the value of the instant.confirm_dialog_shown preference |
327 * changes. Cache this value. | 423 * changes. Cache this value. |
328 * @param {Event} event Change event. | 424 * @param {Event} event Change event. |
329 * @private | 425 * @private |
330 */ | 426 */ |
331 onInstantConfirmDialogShownChanged_: function(event) { | 427 onInstantConfirmDialogShownChanged_: function(event) { |
332 this.instantConfirmDialogShown_ = event.value['value']; | 428 this.instantConfirmDialogShown_ = event.value['value']; |
333 }, | 429 }, |
334 | 430 |
335 /** | 431 /** |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
397 var option = new Option(engine['name'], engine['index']); | 493 var option = new Option(engine['name'], engine['index']); |
398 if (defaultValue == option.value) | 494 if (defaultValue == option.value) |
399 defaultIndex = i; | 495 defaultIndex = i; |
400 engineSelect.appendChild(option); | 496 engineSelect.appendChild(option); |
401 } | 497 } |
402 if (defaultIndex >= 0) | 498 if (defaultIndex >= 0) |
403 engineSelect.selectedIndex = defaultIndex; | 499 engineSelect.selectedIndex = defaultIndex; |
404 }, | 500 }, |
405 | 501 |
406 /** | 502 /** |
407 * Returns true if the custom startup page control block should | |
408 * be enabled. | |
409 * @returns {boolean} Whether the startup page controls should be | |
410 * enabled. | |
411 */ | |
412 shouldEnableCustomStartupPageControls: function(pages) { | |
413 return $('startupShowPagesButton').checked && | |
414 !this.startup_pages_pref_.disabled; | |
415 }, | |
416 | |
417 /** | |
418 * Sets the enabled state of the custom startup page list controls | |
419 * based on the current startup radio button selection. | |
420 * @private | |
421 */ | |
422 updateCustomStartupPageControlStates_: function() { | |
423 var disable = !this.shouldEnableCustomStartupPageControls(); | |
424 var startupPagesList = $('startupPagesList'); | |
425 startupPagesList.disabled = disable; | |
426 startupPagesList.setAttribute('tabindex', disable ? -1 : 0); | |
427 // Explicitly set disabled state for input text elements. | |
428 var inputs = startupPagesList.querySelectorAll("input[type='text']"); | |
429 for (var i = 0; i < inputs.length; i++) | |
430 inputs[i].disabled = disable; | |
431 $('startupUseCurrentButton').disabled = disable; | |
432 }, | |
433 | |
434 /** | |
435 * Set the default search engine based on the popup selection. | 503 * Set the default search engine based on the popup selection. |
436 * @private | 504 * @private |
437 */ | 505 */ |
438 setDefaultSearchEngine_: function() { | 506 setDefaultSearchEngine_: function() { |
439 var engineSelect = $('defaultSearchEngine'); | 507 var engineSelect = $('defaultSearchEngine'); |
440 var selectedIndex = engineSelect.selectedIndex; | 508 var selectedIndex = engineSelect.selectedIndex; |
441 if (selectedIndex >= 0) { | 509 if (selectedIndex >= 0) { |
442 var selection = engineSelect.options[selectedIndex]; | 510 var selection = engineSelect.options[selectedIndex]; |
443 chrome.send('setDefaultSearchEngine', [String(selection.value)]); | 511 chrome.send('setDefaultSearchEngine', [String(selection.value)]); |
444 } | 512 } |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
580 'setStartStopButtonVisible', | 648 'setStartStopButtonVisible', |
581 'setSyncActionLinkEnabled', | 649 'setSyncActionLinkEnabled', |
582 'setSyncActionLinkLabel', | 650 'setSyncActionLinkLabel', |
583 'setSyncEnabled', | 651 'setSyncEnabled', |
584 'setSyncSetupCompleted', | 652 'setSyncSetupCompleted', |
585 'setSyncStatus', | 653 'setSyncStatus', |
586 'setSyncStatusErrorVisible', | 654 'setSyncStatusErrorVisible', |
587 'setThemesResetButtonEnabled', | 655 'setThemesResetButtonEnabled', |
588 'updateAccountPicture', | 656 'updateAccountPicture', |
589 'updateAutocompleteSuggestions', | 657 'updateAutocompleteSuggestions', |
590 'updateHomePageLabel', | |
591 'updateSearchEngines', | 658 'updateSearchEngines', |
592 'updateStartupPages', | 659 'updateStartupPages', |
593 ].forEach(function(name) { | 660 ].forEach(function(name) { |
594 BrowserOptions[name] = function(value) { | 661 BrowserOptions[name] = function(value) { |
595 return BrowserOptions.getInstance()[name + '_'](value); | 662 return BrowserOptions.getInstance()[name + '_'](value); |
596 }; | 663 }; |
597 }); | 664 }); |
598 | 665 |
599 BrowserOptions.updateDefaultBrowserState = function(statusString, isDefault, | 666 BrowserOptions.updateDefaultBrowserState = function(statusString, isDefault, |
600 canBeDefault) { | 667 canBeDefault) { |
(...skipping 14 matching lines...) Expand all Loading... |
615 return BrowserOptions.getInstance().username_; | 682 return BrowserOptions.getInstance().username_; |
616 }; | 683 }; |
617 } | 684 } |
618 | 685 |
619 // Export | 686 // Export |
620 return { | 687 return { |
621 BrowserOptions: BrowserOptions | 688 BrowserOptions: BrowserOptions |
622 }; | 689 }; |
623 | 690 |
624 }); | 691 }); |
OLD | NEW |