LEFT | RIGHT |
(no file at all) | |
| 1 /* |
| 2 * This Source Code is subject to the terms of the Mozilla Public License |
| 3 * version 2.0 (the "License"). You can obtain a copy of the License at |
| 4 * http://mozilla.org/MPL/2.0/. |
| 5 */ |
| 6 |
| 7 let {Prefs} = require("prefs"); |
| 8 |
| 9 let TypoActions = |
| 10 { |
| 11 init: function() |
| 12 { |
| 13 TypoActions.updateState(); |
| 14 TypoActions.updateList(); |
| 15 |
| 16 Prefs.addListener(TypoActions.onPrefChange); |
| 17 window.addEventListener("unload", function() Prefs.removeListener(TypoAction
s.onPrefChange), false); |
| 18 }, |
| 19 |
| 20 onPrefChange: function(name) |
| 21 { |
| 22 if (name == "whitelist") |
| 23 TypoActions.updateList(); |
| 24 else if (name == "correctTypos") |
| 25 TypoActions.updateState(); |
| 26 }, |
| 27 |
| 28 setEnabled: function(checked) |
| 29 { |
| 30 Prefs.correctTypos = checked; |
| 31 }, |
| 32 |
| 33 onItemSelected: function(list) |
| 34 { |
| 35 let button = E(list.getAttribute("_removeButton")); |
| 36 let items = list.selectedItems; |
| 37 button.disabled = (items.length == 0 || (items.length == 1 && !items[0].valu
e)); |
| 38 }, |
| 39 |
| 40 removeRule: function(btn, pref) |
| 41 { |
| 42 let list = E(btn.getAttribute("_list")); |
| 43 let items = list.selectedItems; |
| 44 |
| 45 let {onWhitelistEntryRemoved} = require("typoRules"); |
| 46 |
| 47 for (let i = items.length - 1; i >= 0; i--) |
| 48 { |
| 49 let searchString = items[i].getAttribute("value"); |
| 50 delete Prefs[pref][searchString]; |
| 51 |
| 52 if (pref == "whitelist") |
| 53 onWhitelistEntryRemoved(searchString); |
| 54 } |
| 55 Prefs[pref] = JSON.parse(JSON.stringify(Prefs[pref])); |
| 56 }, |
| 57 |
| 58 updateList: function() |
| 59 { |
| 60 let whitelistElement = E("typo_whitelist"); |
| 61 |
| 62 // Remove existing list entries |
| 63 for (let i = whitelistElement.getRowCount() - 1; i >= 0; i--) |
| 64 whitelistElement.removeItemAt(i); |
| 65 |
| 66 // Build a list of exceptions and sort it alphabetically |
| 67 let whitelist = Object.keys(Prefs.whitelist); |
| 68 whitelist.sort(); |
| 69 |
| 70 // Add the rules to the list |
| 71 if (whitelist.length > 0) |
| 72 { |
| 73 for (let i = 0; i < whitelist.length; i++) |
| 74 { |
| 75 let option = document.createElement("listitem"); |
| 76 option.setAttribute("value", whitelist[i]); |
| 77 option.setAttribute("label", whitelist[i]); |
| 78 |
| 79 whitelistElement.appendChild(option); |
| 80 } |
| 81 } |
| 82 else |
| 83 { |
| 84 let option = document.createElement("listitem"); |
| 85 option.setAttribute("class", "auto-entry"); |
| 86 option.setAttribute("label", whitelistElement.getAttribute("_emptyLabel"))
; |
| 87 |
| 88 whitelistElement.appendChild(option); |
| 89 } |
| 90 }, |
| 91 |
| 92 updateState: function() |
| 93 { |
| 94 let enabled = Prefs.correctTypos; |
| 95 E("typo_enable").checked = enabled; |
| 96 E("typo_whitelist_container").hidden = !enabled; |
| 97 } |
| 98 }; |
| 99 |
| 100 window.addEventListener("load", function() |
| 101 { |
| 102 TypoActions.init(); |
| 103 }, false); |
LEFT | RIGHT |