Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: block.js

Issue 5838948538515456: Issue 370 - Make "Block element" hide elements for added filters (Closed)
Patch Set: Created March 4, 2015, 10:19 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2015 Eyeo GmbH 3 * Copyright (C) 2006-2015 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, false, []));
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 expectsResponse: true, 35 expectsResponse: true,
36 payload: 36 payload:
37 { 37 {
38 type: "clickhide-init", 38 type: "clickhide-init",
39 width: Math.max(document.body.offsetWidth || document.body.scrollWidth), 39 width: Math.max(document.body.offsetWidth || document.body.scrollWidth),
40 height: Math.max(document.body.offsetHeight || document.body.scrollHeight) 40 height: Math.max(document.body.offsetHeight || document.body.scrollHeight)
41 } 41 }
42 }, 42 },
43 function(response) 43 function(response)
44 { 44 {
45 document.getElementById("filters").value = response.filters.join("\n"); 45 document.getElementById("filters").value = response.filters.join("\n");
46 }); 46 });
47 47
48 document.getElementById("filters").focus(); 48 document.getElementById("filters").focus();
49 } 49 }
50 window.addEventListener("load", init, false); 50 window.addEventListener("load", init, false);
51 51
52 function onKeyDown(event) 52 function onKeyDown(event)
53 { 53 {
54 if (event.keyCode == 27) 54 if (event.keyCode == 27)
55 { 55 {
56 event.preventDefault(); 56 event.preventDefault();
57 closeDialog(); 57 closeDialog(false, []);
58 } 58 }
59 else if (event.keyCode == 13 && !event.shiftKey && !event.ctrlKey) 59 else if (event.keyCode == 13 && !event.shiftKey && !event.ctrlKey)
60 { 60 {
61 event.preventDefault(); 61 event.preventDefault();
62 addFilters(); 62 addFilters();
63 } 63 }
64 } 64 }
65 65
66 function addFilters() 66 function addFilters()
67 { 67 {
68 ext.backgroundPage.sendMessage( 68 ext.backgroundPage.sendMessage(
69 { 69 {
70 type: "add-filters", 70 type: "add-filters",
71 text: document.getElementById("filters").value 71 text: document.getElementById("filters").value
72 }, 72 },
73 73
74 function(response) 74 function(response)
75 { 75 {
76 if (response.status == "ok") 76 if (response.status == "ok")
77 closeDialog(true); 77 closeDialog(true, response.selectors);
78 else 78 else
79 alert(response.error); 79 alert(response.error);
80 } 80 }
81 ); 81 );
82 } 82 }
83 83
84 function closeDialog(success) 84 function closeDialog(success, selectors)
85 { 85 {
86 ext.backgroundPage.sendMessage( 86 ext.backgroundPage.sendMessage(
87 { 87 {
88 type: "forward", 88 type: "forward",
89 payload: 89 payload:
90 { 90 {
91 type: "clickhide-close", 91 type: "clickhide-close",
92 remove: (typeof success == "boolean" ? success : false) 92 remove: (typeof success == "boolean" ? success : false),
93 selectors: selectors
93 } 94 }
94 } 95 }
95 ); 96 );
96 } 97 }
97 98
98 var dragCoords = null; 99 var dragCoords = null;
99 function onDragStart(event) 100 function onDragStart(event)
100 { 101 {
101 dragCoords = [event.screenX, event.screenY]; 102 dragCoords = [event.screenX, event.screenY];
102 } 103 }
(...skipping 22 matching lines...) Expand all
125 ); 126 );
126 dragCoords = [event.screenX, event.screenY]; 127 dragCoords = [event.screenX, event.screenY];
127 } 128 }
128 } 129 }
129 130
130 function onDragEnd(event) 131 function onDragEnd(event)
131 { 132 {
132 onDrag(event); 133 onDrag(event);
133 dragCoords = null; 134 dragCoords = null;
134 } 135 }
OLDNEW
« no previous file with comments | « background.js ('k') | include.postload.js » ('j') | include.postload.js » ('J')

Powered by Google App Engine
This is Rietveld