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;
11 * Adding and removing words in custom spelling dictionary.
13 * @extends {options.OptionsPage}
15 function EditDictionaryOverlay() {
16 OptionsPage.call(this, 'editDictionary',
17 loadTimeData.getString('languageDictionaryOverlayPage'),
18 'language-dictionary-overlay-page');
21 cr.addSingletonGetter(EditDictionaryOverlay);
23 EditDictionaryOverlay.prototype = {
24 __proto__: OptionsPage.prototype,
27 * A list of words in the dictionary.
28 * @type {DictionaryWordsList}
34 * The input field for searching for words in the dictionary.
41 * The paragraph of text that indicates that search returned no results.
45 noMatchesLabel_: null,
48 * Initializes the edit dictionary overlay.
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_();
60 this.searchField_ = $('language-dictionary-overlay-search-field');
61 this.searchField_.onsearch = function(e) {
62 this.wordList_.search(e.currentTarget.value);
64 this.searchField_.onkeydown = function(e) {
65 // Don't propagate enter key events. Otherwise the default button will
67 if (e.keyIdentifier == 'Enter')
71 this.noMatchesLabel_ = getRequiredElement(
72 'language-dictionary-overlay-no-matches');
74 $('language-dictionary-overlay-done-button').onclick = function(e) {
75 OptionsPage.closeOverlay();
80 * Refresh the dictionary words when the page is displayed.
83 didShowPage: function() {
84 chrome.send('refreshDictionaryWords');
88 * Update the view based on the changes in the word list.
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');
96 this.noMatchesLabel_.hidden = true;
97 this.wordList_.classList.remove('no-search-matches');
102 EditDictionaryOverlay.setWordList = function(entries) {
103 EditDictionaryOverlay.getInstance().wordList_.setWordList(entries);
106 EditDictionaryOverlay.updateWords = function(add_words, remove_words) {
107 EditDictionaryOverlay.getInstance().wordList_.addWords(add_words);
108 EditDictionaryOverlay.getInstance().wordList_.removeWords(remove_words);
111 EditDictionaryOverlay.getWordListForTesting = function() {
112 return EditDictionaryOverlay.getInstance().wordList_;
116 EditDictionaryOverlay: EditDictionaryOverlay