| 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 // TODO(kochi): Generalize the notification as a component and put it | 5 // TODO(kochi): Generalize the notification as a component and put it |
| 6 // in js/cr/ui/notification.js . | 6 // in js/cr/ui/notification.js . |
| 7 | 7 |
| 8 cr.define('options', function() { | 8 cr.define('options', function() { |
| 9 const OptionsPage = options.OptionsPage; | 9 const OptionsPage = options.OptionsPage; |
| 10 const LanguageList = options.LanguageList; | 10 const LanguageList = options.LanguageList; |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 // The preference is a boolean that enables/disables spell checking. | 119 // The preference is a boolean that enables/disables spell checking. |
| 120 enableSpellCheckPref: 'browser.enable_spellchecking', | 120 enableSpellCheckPref: 'browser.enable_spellchecking', |
| 121 // The preference is a CSV string that describes preload engines | 121 // The preference is a CSV string that describes preload engines |
| 122 // (i.e. active input methods). | 122 // (i.e. active input methods). |
| 123 preloadEnginesPref: 'settings.language.preload_engines', | 123 preloadEnginesPref: 'settings.language.preload_engines', |
| 124 // The list of preload engines, like ['mozc', 'pinyin']. | 124 // The list of preload engines, like ['mozc', 'pinyin']. |
| 125 preloadEngines_: [], | 125 preloadEngines_: [], |
| 126 // The preference is a string that describes the spell check | 126 // The preference is a string that describes the spell check |
| 127 // dictionary language, like "en-US". | 127 // dictionary language, like "en-US". |
| 128 spellCheckDictionaryPref: 'spellcheck.dictionary', | 128 spellCheckDictionaryPref: 'spellcheck.dictionary', |
| 129 spellCheckDictionary_: "", | 129 spellCheckDictionary_: '', |
| 130 // The map of language code to input method IDs, like: | 130 // The map of language code to input method IDs, like: |
| 131 // {'ja': ['mozc', 'mozc-jp'], 'zh-CN': ['pinyin'], ...} | 131 // {'ja': ['mozc', 'mozc-jp'], 'zh-CN': ['pinyin'], ...} |
| 132 languageCodeToInputMethodIdsMap_: {}, | 132 languageCodeToInputMethodIdsMap_: {}, |
| 133 | 133 |
| 134 /** | 134 /** |
| 135 * Initializes the input method list. | 135 * Initializes the input method list. |
| 136 */ | 136 */ |
| 137 initializeInputMethodList_: function() { | 137 initializeInputMethodList_: function() { |
| 138 var inputMethodList = $('language-options-input-method-list'); | 138 var inputMethodList = $('language-options-input-method-list'); |
| 139 var inputMethodListData = templateData.inputMethodList; | 139 var inputMethodListData = templateData.inputMethodList; |
| (...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 506 this.preloadEngines_ = this.filterBadPreloadEngines_(value.split(',')); | 506 this.preloadEngines_ = this.filterBadPreloadEngines_(value.split(',')); |
| 507 this.updateCheckboxesFromPreloadEngines_(); | 507 this.updateCheckboxesFromPreloadEngines_(); |
| 508 $('language-options-list').updateDeletable(); | 508 $('language-options-list').updateDeletable(); |
| 509 }, | 509 }, |
| 510 | 510 |
| 511 /** | 511 /** |
| 512 * Handles input method checkbox's click event. | 512 * Handles input method checkbox's click event. |
| 513 * @param {Event} e Click event. | 513 * @param {Event} e Click event. |
| 514 * @private | 514 * @private |
| 515 */ | 515 */ |
| 516 handleCheckboxClick_ : function(e) { | 516 handleCheckboxClick_: function(e) { |
| 517 var checkbox = e.target; | 517 var checkbox = e.target; |
| 518 if (this.preloadEngines_.length == 1 && !checkbox.checked) { | 518 if (this.preloadEngines_.length == 1 && !checkbox.checked) { |
| 519 // Don't allow disabling the last input method. | 519 // Don't allow disabling the last input method. |
| 520 this.showNotification_( | 520 this.showNotification_( |
| 521 localStrings.getString('please_add_another_input_method'), | 521 localStrings.getString('please_add_another_input_method'), |
| 522 localStrings.getString('ok_button')); | 522 localStrings.getString('ok_button')); |
| 523 checkbox.checked = true; | 523 checkbox.checked = true; |
| 524 return; | 524 return; |
| 525 } | 525 } |
| 526 if (checkbox.checked) { | 526 if (checkbox.checked) { |
| 527 chrome.send('inputMethodEnable', [checkbox.inputMethodId]); | 527 chrome.send('inputMethodEnable', [checkbox.inputMethodId]); |
| 528 } else { | 528 } else { |
| 529 chrome.send('inputMethodDisable', [checkbox.inputMethodId]); | 529 chrome.send('inputMethodDisable', [checkbox.inputMethodId]); |
| 530 } | 530 } |
| 531 this.updatePreloadEnginesFromCheckboxes_(); | 531 this.updatePreloadEnginesFromCheckboxes_(); |
| 532 this.preloadEngines_ = this.sortPreloadEngines_(this.preloadEngines_); | 532 this.preloadEngines_ = this.sortPreloadEngines_(this.preloadEngines_); |
| 533 this.savePreloadEnginesPref_(); | 533 this.savePreloadEnginesPref_(); |
| 534 }, | 534 }, |
| 535 | 535 |
| 536 /** | 536 /** |
| 537 * Handles add language list's click event. | 537 * Handles add language list's click event. |
| 538 * @param {Event} e Click event. | 538 * @param {Event} e Click event. |
| 539 */ | 539 */ |
| 540 handleAddLanguageListClick_ : function(e) { | 540 handleAddLanguageListClick_: function(e) { |
| 541 var languageOptionsList = $('language-options-list'); | 541 var languageOptionsList = $('language-options-list'); |
| 542 var languageCode = e.target.languageCode; | 542 var languageCode = e.target.languageCode; |
| 543 // languageCode can be undefined, if click was made on some random | 543 // languageCode can be undefined, if click was made on some random |
| 544 // place in the overlay, rather than a button. Ignore it. | 544 // place in the overlay, rather than a button. Ignore it. |
| 545 if (!languageCode) { | 545 if (!languageCode) { |
| 546 return; | 546 return; |
| 547 } | 547 } |
| 548 languageOptionsList.addLanguage(languageCode); | 548 languageOptionsList.addLanguage(languageCode); |
| 549 var inputMethodIds = this.languageCodeToInputMethodIdsMap_[languageCode]; | 549 var inputMethodIds = this.languageCodeToInputMethodIdsMap_[languageCode]; |
| 550 // Enable the first input method for the language added. | 550 // Enable the first input method for the language added. |
| 551 if (inputMethodIds && inputMethodIds[0] && | 551 if (inputMethodIds && inputMethodIds[0] && |
| 552 // Don't add the input method it's already present. This can | 552 // Don't add the input method it's already present. This can |
| 553 // happen if the same input method is shared among multiple | 553 // happen if the same input method is shared among multiple |
| 554 // languages (ex. English US keyboard is used for English US and | 554 // languages (ex. English US keyboard is used for English US and |
| 555 // Filipino). | 555 // Filipino). |
| 556 this.preloadEngines_.indexOf(inputMethodIds[0]) == -1) { | 556 this.preloadEngines_.indexOf(inputMethodIds[0]) == -1) { |
| 557 this.preloadEngines_.push(inputMethodIds[0]); | 557 this.preloadEngines_.push(inputMethodIds[0]); |
| 558 this.updateCheckboxesFromPreloadEngines_(); | 558 this.updateCheckboxesFromPreloadEngines_(); |
| 559 this.savePreloadEnginesPref_(); | 559 this.savePreloadEnginesPref_(); |
| 560 } | 560 } |
| 561 OptionsPage.closeOverlay(); | 561 OptionsPage.closeOverlay(); |
| 562 }, | 562 }, |
| 563 | 563 |
| 564 /** | 564 /** |
| 565 * Handles add language dialog ok button. | 565 * Handles add language dialog ok button. |
| 566 */ | 566 */ |
| 567 handleAddLanguageOkButtonClick_ : function() { | 567 handleAddLanguageOkButtonClick_: function() { |
| 568 var languagesSelect = $('add-language-overlay-language-list'); | 568 var languagesSelect = $('add-language-overlay-language-list'); |
| 569 var selectedIndex = languagesSelect.selectedIndex; | 569 var selectedIndex = languagesSelect.selectedIndex; |
| 570 if (selectedIndex >= 0) { | 570 if (selectedIndex >= 0) { |
| 571 var selection = languagesSelect.options[selectedIndex]; | 571 var selection = languagesSelect.options[selectedIndex]; |
| 572 $('language-options-list').addLanguage(String(selection.value)); | 572 $('language-options-list').addLanguage(String(selection.value)); |
| 573 OptionsPage.closeOverlay(); | 573 OptionsPage.closeOverlay(); |
| 574 } | 574 } |
| 575 }, | 575 }, |
| 576 | 576 |
| 577 /** | 577 /** |
| (...skipping 18 matching lines...) Expand all Loading... |
| 596 | 596 |
| 597 $('language-options-spell-check-language-button').disabled = value; | 597 $('language-options-spell-check-language-button').disabled = value; |
| 598 }, | 598 }, |
| 599 | 599 |
| 600 /** | 600 /** |
| 601 * Handles spellCheckDictionaryPref change. | 601 * Handles spellCheckDictionaryPref change. |
| 602 * @param {Event} e Change event. | 602 * @param {Event} e Change event. |
| 603 * @private | 603 * @private |
| 604 */ | 604 */ |
| 605 handleSpellCheckDictionaryPrefChange_: function(e) { | 605 handleSpellCheckDictionaryPrefChange_: function(e) { |
| 606 var languageCode = e.value.value | 606 var languageCode = e.value.value; |
| 607 this.spellCheckDictionary_ = languageCode; | 607 this.spellCheckDictionary_ = languageCode; |
| 608 var languageOptionsList = $('language-options-list'); | 608 var languageOptionsList = $('language-options-list'); |
| 609 var selectedLanguageCode = languageOptionsList.getSelectedLanguageCode(); | 609 var selectedLanguageCode = languageOptionsList.getSelectedLanguageCode(); |
| 610 this.updateSpellCheckLanguageButton_(selectedLanguageCode); | 610 this.updateSpellCheckLanguageButton_(selectedLanguageCode); |
| 611 }, | 611 }, |
| 612 | 612 |
| 613 /** | 613 /** |
| 614 * Handles spellCheckLanguageButton click. | 614 * Handles spellCheckLanguageButton click. |
| 615 * @param {Event} e Click event. | 615 * @param {Event} e Click event. |
| 616 * @private | 616 * @private |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 747 }, | 747 }, |
| 748 | 748 |
| 749 // TODO(kochi): This is an adapted copy from new_tab.js. | 749 // TODO(kochi): This is an adapted copy from new_tab.js. |
| 750 // If this will go as final UI, refactor this to share the component with | 750 // If this will go as final UI, refactor this to share the component with |
| 751 // new new tab page. | 751 // new new tab page. |
| 752 /** | 752 /** |
| 753 * Shows notification | 753 * Shows notification |
| 754 * @private | 754 * @private |
| 755 */ | 755 */ |
| 756 notificationTimeout_: null, | 756 notificationTimeout_: null, |
| 757 showNotification_ : function(text, actionText, opt_delay) { | 757 showNotification_: function(text, actionText, opt_delay) { |
| 758 var notificationElement = $('notification'); | 758 var notificationElement = $('notification'); |
| 759 var actionLink = notificationElement.querySelector('.link-color'); | 759 var actionLink = notificationElement.querySelector('.link-color'); |
| 760 var delay = opt_delay || 10000; | 760 var delay = opt_delay || 10000; |
| 761 | 761 |
| 762 function show() { | 762 function show() { |
| 763 window.clearTimeout(this.notificationTimeout_); | 763 window.clearTimeout(this.notificationTimeout_); |
| 764 notificationElement.classList.add('show'); | 764 notificationElement.classList.add('show'); |
| 765 document.body.classList.add('notification-shown'); | 765 document.body.classList.add('notification-shown'); |
| 766 } | 766 } |
| 767 | 767 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 810 LanguageOptions.uiLanguageSaved = function() { | 810 LanguageOptions.uiLanguageSaved = function() { |
| 811 $('language-options-ui-language-button').style.display = 'none'; | 811 $('language-options-ui-language-button').style.display = 'none'; |
| 812 $('language-options-ui-notification-bar').style.display = 'block'; | 812 $('language-options-ui-notification-bar').style.display = 'block'; |
| 813 }; | 813 }; |
| 814 | 814 |
| 815 // Export | 815 // Export |
| 816 return { | 816 return { |
| 817 LanguageOptions: LanguageOptions | 817 LanguageOptions: LanguageOptions |
| 818 }; | 818 }; |
| 819 }); | 819 }); |
| OLD | NEW |