1// Copyright (c) 2011 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5/////////////////////////////////////////////////////////////////////////////// 6// AddLanguageOverlay class: 7 8cr.define('options', function() { 9 const OptionsPage = options.OptionsPage; 10 11 /** 12 * Encapsulated handling of ChromeOS add language overlay page. 13 * @constructor 14 */ 15 function AddLanguageOverlay() { 16 OptionsPage.call(this, 'addLanguage', 17 localStrings.getString('add_button'), 18 'add-language-overlay-page'); 19 } 20 21 cr.addSingletonGetter(AddLanguageOverlay); 22 23 AddLanguageOverlay.prototype = { 24 // Inherit AddLanguageOverlay from OptionsPage. 25 __proto__: OptionsPage.prototype, 26 27 /** 28 * Initializes AddLanguageOverlay page. 29 * Calls base class implementation to starts preference initialization. 30 */ 31 initializePage: function() { 32 // Call base class implementation to starts preference initialization. 33 OptionsPage.prototype.initializePage.call(this); 34 35 // Set up the cancel button. 36 $('add-language-overlay-cancel-button').onclick = function(e) { 37 OptionsPage.closeOverlay(); 38 }; 39 40 // Create the language list with which users can add a language. 41 var addLanguageList = $('add-language-overlay-language-list'); 42 var languageListData = templateData.languageList; 43 for (var i = 0; i < languageListData.length; i++) { 44 var language = languageListData[i]; 45 var displayText = language.displayName; 46 // If the native name is different, add it. 47 if (language.displayName != language.nativeDisplayName) { 48 displayText += ' - ' + language.nativeDisplayName; 49 } 50 if (cr.isChromeOS) { 51 var button = document.createElement('button'); 52 button.className = 'link-button'; 53 button.textContent = displayText; 54 button.languageCode = language.code; 55 var li = document.createElement('li'); 56 li.languageCode = language.code; 57 li.appendChild(button); 58 addLanguageList.appendChild(li); 59 } else { 60 var option = document.createElement('option'); 61 option.value = language.code; 62 option.textContent = displayText; 63 addLanguageList.appendChild(option); 64 } 65 } 66 }, 67 }; 68 69 return { 70 AddLanguageOverlay: AddLanguageOverlay 71 }; 72}); 73