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

Side by Side Diff: block.js

Issue 16067002: Added Safari Support (Closed)
Patch Set: Bugfixes Created Nov. 15, 2013, 8:58 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
« no previous file with comments | « background.js ('k') | chrome/background.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
(...skipping 11 matching lines...) Expand all
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 chrome.extension.sendRequest( 32 ext.backgroundPage.sendMessage(
33 {
34 type: "forward",
35 payload:
33 { 36 {
34 reqtype: "forward", 37 type: "clickhide-init",
35 request: 38 width: Math.max(document.body.offsetWidth || document.body.scrollWidth),
36 { 39 height: Math.max(document.body.offsetHeight || document.body.scrollHeight)
37 reqtype: "clickhide-init",
38 width: Math.max(document.body.offsetWidth || document.body.scrollWidth),
39 height: Math.max(document.body.offsetHeight || document.body.scrollHeigh t)
40 }
41 },
42 function(response)
43 {
44 document.getElementById("filters").value = response.filters.join("\n");
45 } 40 }
46 ); 41 },
42 function(response)
43 {
44 document.getElementById("filters").value = response.filters.join("\n");
45 });
47 46
48 document.getElementById("filters").focus(); 47 document.getElementById("filters").focus();
49 } 48 }
50 $(init); 49 $(init);
51 50
52 function onKeyDown(event) 51 function onKeyDown(event)
53 { 52 {
54 if (event.keyCode == 27) 53 if (event.keyCode == 27)
55 { 54 {
56 event.preventDefault(); 55 event.preventDefault();
57 closeDialog(); 56 closeDialog();
58 } 57 }
59 else if (event.keyCode == 13 && !event.shiftKey && !event.ctrlKey) 58 else if (event.keyCode == 13 && !event.shiftKey && !event.ctrlKey)
60 { 59 {
61 event.preventDefault(); 60 event.preventDefault();
62 addFilters(); 61 addFilters();
63 } 62 }
64 } 63 }
65 64
66 function addFilters() 65 function addFilters()
67 { 66 {
68 // Tell the background page to add the filters 67 // Tell the background page to add the filters
69 var filters = document.getElementById("filters").value.split(/[\r\n]+/) 68 var filters = document.getElementById("filters").value.split(/[\r\n]+/)
70 .map(function(f) {return f.replace(/^\s+/, "").replace(/ \s+$/, "");}) 69 .map(function(f) {return f.replace(/^\s+/, "").replace(/ \s+$/, "");})
71 .filter(function(f) {return f != "";}); 70 .filter(function(f) {return f != "";});
72 chrome.extension.sendRequest({reqtype: "add-filters", filters: filters}); 71 ext.backgroundPage.sendMessage({type: "add-filters", filters: filters});
73 closeDialog(true); 72 closeDialog(true);
74 } 73 }
75 74
76 function closeDialog(success) 75 function closeDialog(success)
77 { 76 {
78 chrome.extension.sendRequest( 77 ext.backgroundPage.sendMessage(
79 { 78 {
80 reqtype: "forward", 79 type: "forward",
81 request: 80 payload:
82 { 81 {
83 reqtype: "clickhide-close", 82 type: "clickhide-close",
84 remove: (typeof success == "boolean" ? success : false) 83 remove: (typeof success == "boolean" ? success : false)
85 } 84 }
86 } 85 }
87 ); 86 );
88 } 87 }
89 88
90 var dragCoords = null; 89 var dragCoords = null;
91 function onDragStart(event) 90 function onDragStart(event)
92 { 91 {
93 dragCoords = [event.screenX, event.screenY]; 92 dragCoords = [event.screenX, event.screenY];
94 } 93 }
95 94
96 function onDrag(event) 95 function onDrag(event)
97 { 96 {
98 if (!dragCoords) 97 if (!dragCoords)
99 return; 98 return;
100 99
101 if (!event.screenX && !event.screenY) 100 if (!event.screenX && !event.screenY)
102 return; 101 return;
103 102
104 var diff = [event.screenX - dragCoords[0], event.screenY - dragCoords[1]]; 103 var diff = [event.screenX - dragCoords[0], event.screenY - dragCoords[1]];
105 if (diff[0] || diff[1]) 104 if (diff[0] || diff[1])
106 { 105 {
107 chrome.extension.sendRequest( 106 ext.backgroundPage.sendMessage(
108 { 107 {
109 reqtype: "forward", 108 type: "forward",
110 request: 109 payload:
111 { 110 {
112 reqtype: "clickhide-move", 111 type: "clickhide-move",
113 x: diff[0], 112 x: diff[0],
114 y: diff[1] 113 y: diff[1]
115 } 114 }
116 } 115 }
117 ); 116 );
118 dragCoords = [event.screenX, event.screenY]; 117 dragCoords = [event.screenX, event.screenY];
119 } 118 }
120 } 119 }
121 120
122 function onDragEnd(event) 121 function onDragEnd(event)
123 { 122 {
124 onDrag(event); 123 onDrag(event);
125 dragCoords = null; 124 dragCoords = null;
126 } 125 }
OLDNEW
« no previous file with comments | « background.js ('k') | chrome/background.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld