summaryrefslogtreecommitdiffstats
path: root/chrome/browser/resources/options/language_add_language_overlay.js
blob: 9ea8904b1a294726f43c9476c97ffd32578d0204 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

///////////////////////////////////////////////////////////////////////////////
// AddLanguageOverlay class:

/**
 * @typedef {{
 *   code: string,
 *   displayName: string,
 *   textDirection: string,
 *   nativeDisplayName: string
 * }}
 */
options.LanguageData;

cr.define('options', function() {
  /** @const */ var Page = cr.ui.pageManager.Page;
  /** @const */ var PageManager = cr.ui.pageManager.PageManager;

  /**
   * Encapsulated handling of ChromeOS add language overlay page.
   * @constructor
   * @extends {cr.ui.pageManager.Page}
   */
  function AddLanguageOverlay() {
    Page.call(this, 'addLanguage',
              loadTimeData.getString('addButton'),
              'add-language-overlay-page');
  }

  cr.addSingletonGetter(AddLanguageOverlay);

  AddLanguageOverlay.prototype = {
    // Inherit AddLanguageOverlay from Page.
    __proto__: Page.prototype,

    /** @override */
    initializePage: function() {
      Page.prototype.initializePage.call(this);

      // Set up the cancel button.
      $('add-language-overlay-cancel-button').onclick = function(e) {
        PageManager.closeOverlay();
      };

      // Create the language list with which users can add a language.
      var addLanguageList = $('add-language-overlay-language-list');

      /**
       * @type {!Array<!options.LanguageData>}
       * @see chrome/browser/ui/webui/options/language_options_handler.cc
       */
      var languageListData = /** @type {!Array<!options.LanguageData>} */(
          loadTimeData.getValue('languageList'));
      for (var i = 0; i < languageListData.length; i++) {
        var language = languageListData[i];
        var displayText = language.displayName;
        // If the native name is different, add it.
        if (language.displayName != language.nativeDisplayName)
          displayText += ' - ' + language.nativeDisplayName;

        var option = cr.doc.createElement('option');
        option.value = language.code;
        option.textContent = displayText;
        addLanguageList.appendChild(option);
      }
    },
  };

  return {
    AddLanguageOverlay: AddLanguageOverlay
  };
});