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

Side by Side Diff: block.js

Issue 5766275812818944: Issue 2173 - Fixed: "Block element" dialog isn't moved to correct position when dragging (Closed)
Patch Set: Created March 19, 2015, 2:45 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
« no previous file with comments | « block.html ('k') | no next file » | 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 <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);
24 window.addEventListener("dragend", onDragEnd, false); 23 window.addEventListener("dragend", onDragEnd, false);
25 24
26 $("#addButton").click(addFilters); 25 $("#addButton").click(addFilters);
27 $("#cancelButton").click(closeDialog.bind(null, false)); 26 $("#cancelButton").click(closeDialog.bind(null, false));
28 27
29 // Apply jQuery UI styles 28 // Apply jQuery UI styles
30 $("button").button(); 29 $("button").button();
31 30
32 ext.backgroundPage.sendMessage( 31 ext.backgroundPage.sendMessage(
33 { 32 {
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 type: "forward", 87 type: "forward",
89 payload: 88 payload:
90 { 89 {
91 type: "clickhide-close", 90 type: "clickhide-close",
92 remove: (typeof success == "boolean" ? success : false) 91 remove: (typeof success == "boolean" ? success : false)
93 } 92 }
94 } 93 }
95 ); 94 );
96 } 95 }
97 96
98 var dragCoords = null; 97 var dragStartX;
kzar 2015/03/19 16:15:15 Nit: probably should set the start coords to null
Sebastian Noack 2015/03/19 16:52:14 Note that we explicitly check for null when access
kzar 2015/03/19 16:55:01 Wow, it never occurred to me that `10 - null` woul
98 var dragStartY;
99 var dragEndX = null;
100 var dragEndY = null;
101
99 function onDragStart(event) 102 function onDragStart(event)
100 { 103 {
101 dragCoords = [event.screenX, event.screenY]; 104 dragStartX = event.screenX;
102 } 105 dragStartY = event.screenY;
103
104 function onDrag(event)
105 {
106 if (!dragCoords)
107 return;
108
109 if (!event.screenX && !event.screenY)
110 return;
111
112 var diff = [event.screenX - dragCoords[0], event.screenY - dragCoords[1]];
113 if (diff[0] || diff[1])
114 {
115 ext.backgroundPage.sendMessage(
116 {
117 type: "forward",
118 payload:
119 {
120 type: "clickhide-move",
121 x: diff[0],
122 y: diff[1]
123 }
124 }
125 );
126 dragCoords = [event.screenX, event.screenY];
127 }
128 } 106 }
129 107
130 function onDragEnd(event) 108 function onDragEnd(event)
131 { 109 {
132 onDrag(event); 110 if (dragEndX == null)
133 dragCoords = null; 111 dragEndX = event.screenX;
112 if (dragEndY == null)
113 dragEndY = event.screenY;
114
115 ext.backgroundPage.sendMessage({
116 type: "forward",
117 payload:
118 {
119 type: "clickhide-move",
120 x: dragEndX - dragStartX,
121 y: dragEndY - dragStartY
122 }
123 });
124
125 dragStartX = null;
126 dragStartY = null;
127 dragEndX = null;
128 dragEndY = null;
134 } 129 }
130
131 // The coordinates in the dragend event are unreliable on Safari. So we
132 // need to get the destination coordinates from the drag event instead.
133 // However on Chrome, the coordinates in the drag event are unreliable.
134 // So we need to get the coordinates from dragend event there.
135 if (navigator.userAgent.indexOf(" Version/") != -1)
136 {
137 window.addEventListener("drag", function(event)
138 {
139 dragEndX = event.screenX;
140 dragEndY = event.screenY;
141 }, false);
142 }
OLDNEW
« no previous file with comments | « block.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld