| Left: | ||
| Right: |
| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * This file is part of Adblock Plus <http://adblockplus.org/>, | 2 * This file is part of Adblock Plus <http://adblockplus.org/>, |
| 3 * Copyright (C) 2006-2013 Eyeo GmbH | 3 * Copyright (C) 2006-2013 Eyeo GmbH |
| 4 * | 4 * |
| 5 * Adblock Plus is free software: you can redistribute it and/or modify | 5 * Adblock Plus is free software: you can redistribute it and/or modify |
| 6 * it under the terms of the GNU General Public License version 3 as | 6 * it under the terms of the GNU General Public License version 3 as |
| 7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
| 8 * | 8 * |
| 9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
| 13 * | 13 * |
| 14 * You should have received a copy of the GNU General Public License | 14 * You should have received a copy of the GNU General Public License |
| 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
| 16 */ | 16 */ |
| 17 | 17 |
| 18 function init() | 18 function init() |
| 19 { | 19 { |
| 20 // Attach event listeners | 20 // Attach event listeners |
| 21 window.addEventListener("keydown", onKeyDown, false); | 21 window.addEventListener("keydown", onKeyDown, false); |
| 22 window.addEventListener("dragstart", onDragStart, false); | 22 window.addEventListener("dragstart", onDragStart, false); |
| 23 window.addEventListener("drag", onDrag, false); | 23 window.addEventListener("drag", onDrag, false); |
| 24 window.addEventListener("dragend", onDragEnd, false); | 24 window.addEventListener("dragend", onDragEnd, false); |
| 25 | 25 |
| 26 $("#addButton").click(addFilters); | 26 $("#addButton").click(addFilters); |
| 27 $("#cancelButton").click(closeDialog.bind(null, false)); | 27 $("#cancelButton").click(closeDialog.bind(null, null)); |
| 28 | 28 |
| 29 // Apply jQuery UI styles | 29 // Apply jQuery UI styles |
| 30 $("button").button(); | 30 $("button").button(); |
| 31 | 31 |
| 32 ext.backgroundPage.sendMessage( | 32 ext.backgroundPage.sendMessage( |
| 33 { | 33 { |
| 34 type: "forward", | 34 type: "forward", |
| 35 payload: | 35 payload: |
| 36 { | 36 { |
| 37 type: "clickhide-init", | 37 type: "clickhide-init", |
| 38 width: Math.max(document.body.offsetWidth || document.body.scrollWidth), | 38 width: Math.max(document.body.offsetWidth || document.body.scrollWidth), |
| 39 height: Math.max(document.body.offsetHeight || document.body.scrollHeight) | 39 height: Math.max(document.body.offsetHeight || document.body.scrollHeight) |
| 40 } | 40 } |
| 41 }, | 41 }, |
| 42 function(response) | 42 function(response) |
| 43 { | 43 { |
| 44 document.getElementById("filters").value = response.filters.join("\n"); | 44 document.getElementById("filters").value = response.filters.join("\n"); |
| 45 }); | 45 }); |
| 46 | 46 |
| 47 document.getElementById("filters").focus(); | 47 document.getElementById("filters").focus(); |
| 48 } | 48 } |
| 49 $(init); | 49 $(init); |
| 50 | 50 |
| 51 function onKeyDown(event) | 51 function onKeyDown(event) |
| 52 { | 52 { |
| 53 if (event.keyCode == 27) | 53 if (event.keyCode == 27) |
| 54 { | 54 { |
| 55 event.preventDefault(); | 55 event.preventDefault(); |
| 56 closeDialog(); | 56 closeDialog(null); |
| 57 } | 57 } |
| 58 else if (event.keyCode == 13 && !event.shiftKey && !event.ctrlKey) | 58 else if (event.keyCode == 13 && !event.shiftKey && !event.ctrlKey) |
| 59 { | 59 { |
| 60 event.preventDefault(); | 60 event.preventDefault(); |
| 61 addFilters(); | 61 addFilters(); |
| 62 } | 62 } |
| 63 } | 63 } |
| 64 | 64 |
| 65 function addFilters() | 65 function addFilters() |
| 66 { | 66 { |
| 67 // Tell the background page to add the filters | 67 // Tell the background page to add the filters |
| 68 var filters = document.getElementById("filters").value.split(/[\r\n]+/) | 68 var filters = document.getElementById("filters").value.split(/[\r\n]+/) |
| 69 .map(function(f) {return f.replace(/^\s+/, "").replace(/ \s+$/, "");}) | 69 .map(function(f) {return f.replace(/^\s+/, "").replace(/ \s+$/, "");}) |
| 70 .filter(function(f) {return f != "";}); | 70 .filter(function(f) {return f != "";}); |
| 71 ext.backgroundPage.sendMessage({type: "add-filters", filters: filters}); | 71 ext.backgroundPage.sendMessage({type: "add-filters", filters: filters}); |
| 72 closeDialog(true); | 72 closeDialog(filters); |
| 73 } | 73 } |
| 74 | 74 |
| 75 function closeDialog(success) | 75 function closeDialog(filters) |
| 76 { | 76 { |
| 77 ext.backgroundPage.sendMessage( | 77 ext.backgroundPage.sendMessage( |
| 78 { | 78 { |
| 79 type: "forward", | 79 type: "forward", |
| 80 payload: | 80 payload: |
| 81 { | 81 { |
| 82 type: "clickhide-close", | 82 type: "clickhide-close", |
| 83 remove: (typeof success == "boolean" ? success : false) | 83 filters: filters |
|
Wladimir Palant
2014/01/10 16:28:56
Why send the filters and have the other end ignore
Thomas Greiner
2014/07/17 15:35:49
You're right. This is code from earlier approaches
| |
| 84 } | 84 } |
| 85 } | 85 } |
| 86 ); | 86 ); |
| 87 } | 87 } |
| 88 | 88 |
| 89 var dragCoords = null; | 89 var dragCoords = null; |
| 90 function onDragStart(event) | 90 function onDragStart(event) |
| 91 { | 91 { |
| 92 dragCoords = [event.screenX, event.screenY]; | 92 dragCoords = [event.screenX, event.screenY]; |
| 93 } | 93 } |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 116 ); | 116 ); |
| 117 dragCoords = [event.screenX, event.screenY]; | 117 dragCoords = [event.screenX, event.screenY]; |
| 118 } | 118 } |
| 119 } | 119 } |
| 120 | 120 |
| 121 function onDragEnd(event) | 121 function onDragEnd(event) |
| 122 { | 122 { |
| 123 onDrag(event); | 123 onDrag(event); |
| 124 dragCoords = null; | 124 dragCoords = null; |
| 125 } | 125 } |
| OLD | NEW |