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: Created Oct. 21, 2013, 8:11 p.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 <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({
Felix Dahlke 2013/10/24 16:30:34 Opening braces should go on their own line, likewi
Sebastian Noack 2013/10/25 09:55:03 I though except for object literals, as we have he
Felix Dahlke 2013/10/25 14:43:08 Um, yes, nevermind :)
33 type: "forward",
34 payload:
33 { 35 {
34 reqtype: "forward", 36 type: "clickhide-init",
35 request: 37 width: Math.max(document.body.offsetWidth || document.body.scrollWidth),
36 { 38 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 } 39 }
46 ); 40 },
41 function(response) {
42 document.getElementById("filters").value = response.filters.join("\n");
43 });
47 44
48 document.getElementById("filters").focus(); 45 document.getElementById("filters").focus();
49 } 46 }
50 $(init); 47 $(init);
51 48
52 function onKeyDown(event) 49 function onKeyDown(event)
53 { 50 {
54 if (event.keyCode == 27) 51 if (event.keyCode == 27)
55 { 52 {
56 event.preventDefault(); 53 event.preventDefault();
57 closeDialog(); 54 closeDialog();
58 } 55 }
59 else if (event.keyCode == 13 && !event.shiftKey && !event.ctrlKey) 56 else if (event.keyCode == 13 && !event.shiftKey && !event.ctrlKey)
60 { 57 {
61 event.preventDefault(); 58 event.preventDefault();
62 addFilters(); 59 addFilters();
63 } 60 }
64 } 61 }
65 62
66 function addFilters() 63 function addFilters()
67 { 64 {
68 // Tell the background page to add the filters 65 // Tell the background page to add the filters
69 var filters = document.getElementById("filters").value.split(/[\r\n]+/) 66 var filters = document.getElementById("filters").value.split(/[\r\n]+/)
70 .map(function(f) {return f.replace(/^\s+/, "").replace(/ \s+$/, "");}) 67 .map(function(f) {return f.replace(/^\s+/, "").replace(/ \s+$/, "");})
71 .filter(function(f) {return f != "";}); 68 .filter(function(f) {return f != "";});
72 chrome.extension.sendRequest({reqtype: "add-filters", filters: filters}); 69 ext.backgroundPage.sendMessage({type: "add-filters", filters: filters});
73 closeDialog(true); 70 closeDialog(true);
74 } 71 }
75 72
76 function closeDialog(success) 73 function closeDialog(success)
77 { 74 {
78 chrome.extension.sendRequest( 75 ext.backgroundPage.sendMessage(
79 { 76 {
80 reqtype: "forward", 77 type: "forward",
81 request: 78 payload:
82 { 79 {
83 reqtype: "clickhide-close", 80 type: "clickhide-close",
84 remove: (typeof success == "boolean" ? success : false) 81 remove: (typeof success == "boolean" ? success : false)
85 } 82 }
86 } 83 }
87 ); 84 );
88 } 85 }
89 86
90 var dragCoords = null; 87 var dragCoords = null;
91 function onDragStart(event) 88 function onDragStart(event)
92 { 89 {
93 dragCoords = [event.screenX, event.screenY]; 90 dragCoords = [event.screenX, event.screenY];
94 } 91 }
95 92
96 function onDrag(event) 93 function onDrag(event)
97 { 94 {
98 if (!dragCoords) 95 if (!dragCoords)
99 return; 96 return;
100 97
101 if (!event.screenX && !event.screenY) 98 if (!event.screenX && !event.screenY)
102 return; 99 return;
103 100
104 var diff = [event.screenX - dragCoords[0], event.screenY - dragCoords[1]]; 101 var diff = [event.screenX - dragCoords[0], event.screenY - dragCoords[1]];
105 if (diff[0] || diff[1]) 102 if (diff[0] || diff[1])
106 { 103 {
107 chrome.extension.sendRequest( 104 ext.backgroundPage.sendMessage(
108 { 105 {
109 reqtype: "forward", 106 type: "forward",
110 request: 107 payload:
111 { 108 {
112 reqtype: "clickhide-move", 109 type: "clickhide-move",
113 x: diff[0], 110 x: diff[0],
114 y: diff[1] 111 y: diff[1]
115 } 112 }
116 } 113 }
117 ); 114 );
118 dragCoords = [event.screenX, event.screenY]; 115 dragCoords = [event.screenX, event.screenY];
119 } 116 }
120 } 117 }
121 118
122 function onDragEnd(event) 119 function onDragEnd(event)
123 { 120 {
124 onDrag(event); 121 onDrag(event);
125 dragCoords = null; 122 dragCoords = null;
126 } 123 }
OLDNEW

Powered by Google App Engine
This is Rietveld