| 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 */ var OptionsPage = options.OptionsPage; | 9 /** @const */ var OptionsPage = options.OptionsPage; |
| 10 /** @const */ var LanguageList = options.LanguageList; | 10 /** @const */ var LanguageList = options.LanguageList; |
| 11 | 11 |
| 12 // Some input methods like Chinese Pinyin have config pages. | |
| 13 // This is the map of the input method names to their config page names. | |
| 14 /** @const */ var INPUT_METHOD_ID_TO_CONFIG_PAGE_NAME = { | |
| 15 'mozc': 'languageMozc', | |
| 16 'mozc-chewing': 'languageChewing', | |
| 17 'mozc-dv': 'languageMozc', | |
| 18 'mozc-hangul': 'languageHangul', | |
| 19 'mozc-jp': 'languageMozc', | |
| 20 'pinyin': 'languagePinyin', | |
| 21 'pinyin-dv': 'languagePinyin', | |
| 22 }; | |
| 23 | |
| 24 /** | 12 /** |
| 25 * Spell check dictionary download status. | 13 * Spell check dictionary download status. |
| 26 * @type {Enum} | 14 * @type {Enum} |
| 27 */ | 15 */ |
| 28 /** @const*/ var DOWNLOAD_STATUS = { | 16 /** @const*/ var DOWNLOAD_STATUS = { |
| 29 IN_PROGRESS: 1, | 17 IN_PROGRESS: 1, |
| 30 FAILED: 2 | 18 FAILED: 2 |
| 31 }; | 19 }; |
| 32 | 20 |
| 33 /** | 21 /** |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 this.handleLanguageOptionsListChange_.bind(this)); | 154 this.handleLanguageOptionsListChange_.bind(this)); |
| 167 languageOptionsList.addEventListener('save', | 155 languageOptionsList.addEventListener('save', |
| 168 this.handleLanguageOptionsListSave_.bind(this)); | 156 this.handleLanguageOptionsListSave_.bind(this)); |
| 169 | 157 |
| 170 this.prospectiveUiLanguageCode_ = | 158 this.prospectiveUiLanguageCode_ = |
| 171 loadTimeData.getString('prospectiveUiLanguageCode'); | 159 loadTimeData.getString('prospectiveUiLanguageCode'); |
| 172 this.addEventListener('visibleChange', | 160 this.addEventListener('visibleChange', |
| 173 this.handleVisibleChange_.bind(this)); | 161 this.handleVisibleChange_.bind(this)); |
| 174 | 162 |
| 175 if (cr.isChromeOS) { | 163 if (cr.isChromeOS) { |
| 176 $('chewing-confirm').onclick = $('hangul-confirm').onclick = | |
| 177 $('mozc-confirm').onclick = $('pinyin-confirm').onclick = | |
| 178 OptionsPage.closeOverlay.bind(OptionsPage); | |
| 179 | |
| 180 this.initializeInputMethodList_(); | 164 this.initializeInputMethodList_(); |
| 181 this.initializeLanguageCodeToInputMethodIdsMap_(); | 165 this.initializeLanguageCodeToInputMethodIdsMap_(); |
| 182 } | 166 } |
| 183 | 167 |
| 184 var checkbox = $('offer-to-translate-in-this-language'); | 168 var checkbox = $('offer-to-translate-in-this-language'); |
| 185 checkbox.addEventListener('click', | 169 checkbox.addEventListener('click', |
| 186 this.handleOfferToTranslateCheckboxClick_.bind(this)); | 170 this.handleOfferToTranslateCheckboxClick_.bind(this)); |
| 187 | 171 |
| 188 Preferences.getInstance().addEventListener( | 172 Preferences.getInstance().addEventListener( |
| 189 TRANSLATE_BLOCKED_LANGUAGES_PREF, | 173 TRANSLATE_BLOCKED_LANGUAGES_PREF, |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 314 var inputMethod = inputMethods[i]; | 298 var inputMethod = inputMethods[i]; |
| 315 var element = inputMethodTemplate.cloneNode(true); | 299 var element = inputMethodTemplate.cloneNode(true); |
| 316 element.id = ''; | 300 element.id = ''; |
| 317 element.languageCodeSet = inputMethod.languageCodeSet; | 301 element.languageCodeSet = inputMethod.languageCodeSet; |
| 318 | 302 |
| 319 var input = element.querySelector('input'); | 303 var input = element.querySelector('input'); |
| 320 input.inputMethodId = inputMethod.id; | 304 input.inputMethodId = inputMethod.id; |
| 321 var span = element.querySelector('span'); | 305 var span = element.querySelector('span'); |
| 322 span.textContent = inputMethod.displayName; | 306 span.textContent = inputMethod.displayName; |
| 323 | 307 |
| 324 // Add the configure button if the config page is present for this | |
| 325 // input method. | |
| 326 if (inputMethod.id in INPUT_METHOD_ID_TO_CONFIG_PAGE_NAME) { | |
| 327 var pageName = INPUT_METHOD_ID_TO_CONFIG_PAGE_NAME[inputMethod.id]; | |
| 328 var button = this.createConfigureInputMethodButton_(inputMethod.id, | |
| 329 pageName); | |
| 330 element.appendChild(button); | |
| 331 } | |
| 332 | |
| 333 if (inputMethod.optionsPage) { | 308 if (inputMethod.optionsPage) { |
| 334 var button = document.createElement('button'); | 309 var button = document.createElement('button'); |
| 335 button.textContent = loadTimeData.getString('configure'); | 310 button.textContent = loadTimeData.getString('configure'); |
| 336 button.inputMethodId = inputMethod.id; | 311 button.inputMethodId = inputMethod.id; |
| 337 button.onclick = function(optionsPage, e) { | 312 button.onclick = function(optionsPage, e) { |
| 338 window.open(optionsPage); | 313 window.open(optionsPage); |
| 339 }.bind(this, inputMethod.optionsPage); | 314 }.bind(this, inputMethod.optionsPage); |
| 340 element.appendChild(button); | 315 element.appendChild(button); |
| 341 } | 316 } |
| 342 | 317 |
| 343 // Listen to user clicks. | 318 // Listen to user clicks. |
| 344 input.addEventListener('click', | 319 input.addEventListener('click', |
| 345 this.handleCheckboxClick_.bind(this)); | 320 this.handleCheckboxClick_.bind(this)); |
| 346 inputMethodList.appendChild(element); | 321 inputMethodList.appendChild(element); |
| 347 } | 322 } |
| 348 }, | 323 }, |
| 349 | 324 |
| 350 /** | 325 /** |
| 351 * Creates a configure button for the given input method ID. | |
| 352 * @param {string} inputMethodId Input method ID (ex. "pinyin"). | |
| 353 * @param {string} pageName Name of the config page (ex. "languagePinyin"). | |
| 354 * @private | |
| 355 */ | |
| 356 createConfigureInputMethodButton_: function(inputMethodId, pageName) { | |
| 357 var button = document.createElement('button'); | |
| 358 button.textContent = loadTimeData.getString('configure'); | |
| 359 button.onclick = function(e) { | |
| 360 // Prevent the default action (i.e. changing the checked property | |
| 361 // of the checkbox). The button click here should not be handled | |
| 362 // as checkbox click. | |
| 363 e.preventDefault(); | |
| 364 chrome.send('inputMethodOptionsOpen', [inputMethodId]); | |
| 365 OptionsPage.navigateToPage(pageName); | |
| 366 }; | |
| 367 return button; | |
| 368 }, | |
| 369 | |
| 370 /** | |
| 371 * Adds a language to the preference 'translate_blocked_languages'. If | 326 * Adds a language to the preference 'translate_blocked_languages'. If |
| 372 * |langCode| is already added, nothing happens. |langCode| is converted | 327 * |langCode| is already added, nothing happens. |langCode| is converted |
| 373 * to a Translate language synonym before added. | 328 * to a Translate language synonym before added. |
| 374 * @param {string} langCode A language code like 'en' | 329 * @param {string} langCode A language code like 'en' |
| 375 * @private | 330 * @private |
| 376 */ | 331 */ |
| 377 addBlockedLanguage_: function(langCode) { | 332 addBlockedLanguage_: function(langCode) { |
| 378 langCode = this.convertLangCodeForTranslation_(langCode); | 333 langCode = this.convertLangCodeForTranslation_(langCode); |
| 379 if (this.translateBlockedLanguages_.indexOf(langCode) == -1) { | 334 if (this.translateBlockedLanguages_.indexOf(langCode) == -1) { |
| 380 this.translateBlockedLanguages_.push(langCode); | 335 this.translateBlockedLanguages_.push(langCode); |
| (...skipping 917 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1298 | 1253 |
| 1299 LanguageOptions.onComponentManagerInitialized = function(componentImes) { | 1254 LanguageOptions.onComponentManagerInitialized = function(componentImes) { |
| 1300 LanguageOptions.getInstance().appendComponentExtensionIme_(componentImes); | 1255 LanguageOptions.getInstance().appendComponentExtensionIme_(componentImes); |
| 1301 }; | 1256 }; |
| 1302 | 1257 |
| 1303 // Export | 1258 // Export |
| 1304 return { | 1259 return { |
| 1305 LanguageOptions: LanguageOptions | 1260 LanguageOptions: LanguageOptions |
| 1306 }; | 1261 }; |
| 1307 }); | 1262 }); |
| OLD | NEW |