summaryrefslogtreecommitdiffstats
path: root/chrome/browser/resources/options/chromeos_language_add_language_overlay.js
blob: 090b69aca8f447a8a1fbee23757f06be5b4ad878 (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
// Copyright (c) 2010 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:

cr.define('options.language', function() {

  const OptionsPage = options.OptionsPage;

  /**
   * Encapsulated handling of ChromeOS add language overlay page.
   * @constructor
   */
  function AddLanguageOverlay() {
    OptionsPage.call(this, 'addLanguageOverlay',
                     localStrings.getString('add_button'),
                     'add-language-overlay-page');
  }

  cr.addSingletonGetter(AddLanguageOverlay);

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

    /**
     * Initializes AddLanguageOverlay page.
     * Calls base class implementation to starts preference initialization.
     */
    initializePage: function() {
      // Call base class implementation to starts preference initialization.
      OptionsPage.prototype.initializePage.call(this);

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

      // Create the language list with which users can add a language.
      // Note that we have about 40 languages.
      var addLanguageList = $('add-language-overlay-language-list');
      var languageListData = templateData.languageList;
      for (var i = 0; i < languageListData.length; i++) {
        var language = languageListData[i];
        var button = document.createElement('button');
        button.className = 'link-button';
        button.textContent = language.displayName;
        // If the native name is different, add it.
        if (language.displayName != language.nativeDisplayName) {
          button.textContent += ' - ' + language.nativeDisplayName;
        }
        button.languageCode = language.code;
        // Listen to user clicks.
        button.addEventListener('click', this.handleLanguageClick_.bind(this));
        var li = document.createElement('li');
        li.languageCode = language.code;
        li.appendChild(button);
        addLanguageList.appendChild(li);
      }
    },
  };

  return {
    AddLanguageOverlay: AddLanguageOverlay
  };
});