| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 /** | 5 /** |
| 6 * @fileoverview 'settings-edit-dictionary-page' is a sub-page for editing | 6 * @fileoverview 'settings-edit-dictionary-page' is a sub-page for editing |
| 7 * the "dictionary" of custom words used for spell check. | 7 * the "dictionary" of custom words used for spell check. |
| 8 */ | 8 */ |
| 9 Polymer({ | 9 Polymer({ |
| 10 is: 'settings-edit-dictionary-page', | 10 is: 'settings-edit-dictionary-page', |
| 11 | 11 |
| 12 properties: { | 12 properties: { |
| 13 /** @private {string} */ | 13 /** @private {string} */ |
| 14 newWordValue_: String, | 14 newWordValue_: String, |
| 15 | 15 |
| 16 /** @private {!Array<string>} */ | 16 /** @private {!Array<string>} */ |
| 17 words_: { | 17 words_: { |
| 18 type: Array, | 18 type: Array, |
| 19 value: function() { return []; }, | 19 value: function() { return []; }, |
| 20 }, | 20 }, |
| 21 }, | 21 }, |
| 22 | 22 |
| 23 /** @type {LanguageSettingsPrivate} */ |
| 24 languageSettingsPrivate: null, |
| 25 |
| 23 ready: function() { | 26 ready: function() { |
| 24 chrome.languageSettingsPrivate.getSpellcheckWords(function(words) { | 27 this.languageSettingsPrivate = |
| 28 settings.languageSettingsPrivateApiForTest || |
| 29 /** @type {!LanguageSettingsPrivate} */(chrome.languageSettingsPrivate); |
| 30 |
| 31 this.languageSettingsPrivate.getSpellcheckWords(function(words) { |
| 25 this.words_ = words; | 32 this.words_ = words; |
| 26 }.bind(this)); | 33 }.bind(this)); |
| 27 | 34 |
| 28 // Updates are applied locally so they appear immediately, but we should | 35 // Updates are applied locally so they appear immediately, but we should |
| 29 // listen for changes in case they come from elsewhere. | 36 // listen for changes in case they come from elsewhere. |
| 30 chrome.languageSettingsPrivate.onCustomDictionaryChanged.addListener( | 37 this.languageSettingsPrivate.onCustomDictionaryChanged.addListener( |
| 31 this.onCustomDictionaryChanged_.bind(this)); | 38 this.onCustomDictionaryChanged_.bind(this)); |
| 32 | 39 |
| 33 // Add a key handler for the paper-input. | 40 // Add a key handler for the paper-input. |
| 34 this.$.keys.target = this.$.newWord; | 41 this.$.keys.target = this.$.newWord; |
| 35 }, | 42 }, |
| 36 | 43 |
| 37 /** | 44 /** |
| 38 * Check if the new word text-field is empty. | 45 * Check if the new word text-field is empty. |
| 39 * @private | 46 * @private |
| 40 * @param {string} value | 47 * @param {string} value |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 onAddWordTap_: function(e) { | 85 onAddWordTap_: function(e) { |
| 79 this.addWordFromInput_(); | 86 this.addWordFromInput_(); |
| 80 this.$.newWord.focus(); | 87 this.$.newWord.focus(); |
| 81 }, | 88 }, |
| 82 | 89 |
| 83 /** | 90 /** |
| 84 * Handles tapping on a paper-item's Remove Word icon button. | 91 * Handles tapping on a paper-item's Remove Word icon button. |
| 85 * @param {!{model: !{item: string}}} e | 92 * @param {!{model: !{item: string}}} e |
| 86 */ | 93 */ |
| 87 onRemoveWordTap_: function(e) { | 94 onRemoveWordTap_: function(e) { |
| 88 chrome.languageSettingsPrivate.removeSpellcheckWord(e.model.item); | 95 this.languageSettingsPrivate.removeSpellcheckWord(e.model.item); |
| 89 this.arrayDelete('words_', e.model.item); | 96 this.arrayDelete('words_', e.model.item); |
| 90 }, | 97 }, |
| 91 | 98 |
| 92 /** | 99 /** |
| 93 * Adds the word in the paper-input to the dictionary, also appending it | 100 * Adds the word in the paper-input to the dictionary, also appending it |
| 94 * to the end of the list of words shown to the user. | 101 * to the end of the list of words shown to the user. |
| 95 */ | 102 */ |
| 96 addWordFromInput_: function() { | 103 addWordFromInput_: function() { |
| 97 // Spaces are allowed, but removing leading and trailing whitespace. | 104 // Spaces are allowed, but removing leading and trailing whitespace. |
| 98 var word = this.newWordValue_.trim(); | 105 var word = this.newWordValue_.trim(); |
| 99 this.newWordValue_ = ''; | 106 this.newWordValue_ = ''; |
| 100 if (!word) | 107 if (!word) |
| 101 return; | 108 return; |
| 102 | 109 |
| 103 var index = this.words_.indexOf(word); | 110 var index = this.words_.indexOf(word); |
| 104 if (index == -1) { | 111 if (index == -1) { |
| 105 chrome.languageSettingsPrivate.addSpellcheckWord(word); | 112 this.languageSettingsPrivate.addSpellcheckWord(word); |
| 106 this.push('words_', word); | 113 this.push('words_', word); |
| 114 index = this.words_.length - 1; |
| 107 } | 115 } |
| 108 | 116 |
| 109 // Scroll to the word (usually the bottom, or to the index if the word | 117 // Scroll to the word (usually the bottom, or to the index if the word |
| 110 // is already present). | 118 // is already present). |
| 111 this.$.list.scrollToIndex(index); | 119 this.async(function(){ |
| 120 this.root.querySelector('#list').scrollToIndex(index); |
| 121 }); |
| 112 }, | 122 }, |
| 123 |
| 124 /** |
| 125 * Checks if any words exists in the dictionary. |
| 126 * @private |
| 127 * @return {!boolean} |
| 128 */ |
| 129 hasWords_: function() { |
| 130 return !!(this.words_ && this.words_.length); |
| 131 } |
| 113 }); | 132 }); |
| OLD | NEW |