Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / resources / options / language_dictionary_overlay.js
blob6315299556907c85c7e124a47330e90f342a7790
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
3 // found in the LICENSE file.
5 cr.define('options', function() {
6   /** @const */ var DictionaryWordsList =
7       options.dictionary_words.DictionaryWordsList;
8   /** @const */ var OptionsPage = options.OptionsPage;
10   /**
11    * Adding and removing words in custom spelling dictionary.
12    * @constructor
13    * @extends {options.OptionsPage}
14    */
15   function EditDictionaryOverlay() {
16     OptionsPage.call(this, 'editDictionary',
17                      loadTimeData.getString('languageDictionaryOverlayPage'),
18                      'language-dictionary-overlay-page');
19   }
21   cr.addSingletonGetter(EditDictionaryOverlay);
23   EditDictionaryOverlay.prototype = {
24     __proto__: OptionsPage.prototype,
26     /**
27      * A list of words in the dictionary.
28      * @type {DictionaryWordsList}
29      * @private
30      */
31     wordList_: null,
33     /**
34      * The input field for searching for words in the dictionary.
35      * @type {HTMLElement}
36      * @private
37      */
38     searchField_: null,
40     /**
41      * The paragraph of text that indicates that search returned no results.
42      * @type {HTMLElement}
43      * @private
44      */
45     noMatchesLabel_: null,
47     /**
48      * Initializes the edit dictionary overlay.
49      * @override
50      */
51     initializePage: function() {
52       OptionsPage.prototype.initializePage.call(this);
54       this.wordList_ = $('language-dictionary-overlay-word-list');
55       DictionaryWordsList.decorate(this.wordList_);
56       this.wordList_.onWordListChanged = function() {
57         this.onWordListChanged_();
58       }.bind(this);
60       this.searchField_ = $('language-dictionary-overlay-search-field');
61       this.searchField_.onsearch = function(e) {
62         this.wordList_.search(e.currentTarget.value);
63       }.bind(this);
64       this.searchField_.onkeydown = function(e) {
65         // Don't propagate enter key events. Otherwise the default button will
66         // activate.
67         if (e.keyIdentifier == 'Enter')
68           e.stopPropagation();
69       };
71       this.noMatchesLabel_ = getRequiredElement(
72           'language-dictionary-overlay-no-matches');
74       $('language-dictionary-overlay-done-button').onclick = function(e) {
75         OptionsPage.closeOverlay();
76       };
77     },
79     /**
80      * Refresh the dictionary words when the page is displayed.
81      * @override
82      */
83     didShowPage: function() {
84       chrome.send('refreshDictionaryWords');
85     },
87     /**
88      * Update the view based on the changes in the word list.
89      * @private
90      */
91     onWordListChanged_: function() {
92       if (this.searchField_.value.length > 0 && this.wordList_.empty) {
93         this.noMatchesLabel_.hidden = false;
94         this.wordList_.classList.add('no-search-matches');
95       } else {
96         this.noMatchesLabel_.hidden = true;
97         this.wordList_.classList.remove('no-search-matches');
98       }
99     },
100   };
102   EditDictionaryOverlay.setWordList = function(entries) {
103     EditDictionaryOverlay.getInstance().wordList_.setWordList(entries);
104   };
106   EditDictionaryOverlay.updateWords = function(add_words, remove_words) {
107     EditDictionaryOverlay.getInstance().wordList_.addWords(add_words);
108     EditDictionaryOverlay.getInstance().wordList_.removeWords(remove_words);
109   };
111   EditDictionaryOverlay.getWordListForTesting = function() {
112     return EditDictionaryOverlay.getInstance().wordList_;
113   };
115   return {
116     EditDictionaryOverlay: EditDictionaryOverlay
117   };