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

Side by Side Diff: chrome/browser/resources/options2/language_options.js

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

Powered by Google App Engine
This is Rietveld 408576698