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

Delta Between Two Patch Sets: include.postload.js

Issue 4998212691689472: Some click-hide improvements (Closed)
Left Patch Set: Created Dec. 18, 2013, 10:13 a.m.
Right Patch Set: Also fixed key handler Created Dec. 18, 2013, 10:58 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 151
152 // Add overlays for elements with URLs so user can easily click them 152 // Add overlays for elements with URLs so user can easily click them
153 var elts = document.querySelectorAll('object,embed,img,iframe'); 153 var elts = document.querySelectorAll('object,embed,img,iframe');
154 for(var i=0; i<elts.length; i++) 154 for(var i=0; i<elts.length; i++)
155 addElementOverlay(elts[i]); 155 addElementOverlay(elts[i]);
156 156
157 clickHide_activated = true; 157 clickHide_activated = true;
158 document.addEventListener("mouseover", clickHide_mouseOver, false); 158 document.addEventListener("mouseover", clickHide_mouseOver, false);
159 document.addEventListener("mouseout", clickHide_mouseOut, false); 159 document.addEventListener("mouseout", clickHide_mouseOut, false);
160 document.addEventListener("click", clickHide_mouseClick, false); 160 document.addEventListener("click", clickHide_mouseClick, false);
161 document.addEventListener("keyup", clickHide_keyUp, false); 161 document.addEventListener("keydown", clickHide_keyDown, false);
162 } 162 }
163 163
164 // Called when user has clicked on something and we are waiting for confirmation 164 // Called when user has clicked on something and we are waiting for confirmation
165 // on whether the user actually wants these filters 165 // on whether the user actually wants these filters
166 function clickHide_rulesPending() { 166 function clickHide_rulesPending() {
167 clickHide_activated = false; 167 clickHide_activated = false;
168 document.removeEventListener("mouseover", clickHide_mouseOver, false); 168 document.removeEventListener("mouseover", clickHide_mouseOver, false);
169 document.removeEventListener("mouseout", clickHide_mouseOut, false); 169 document.removeEventListener("mouseout", clickHide_mouseOut, false);
170 document.removeEventListener("click", clickHide_mouseClick, false); 170 document.removeEventListener("click", clickHide_mouseClick, false);
171 document.removeEventListener("keyup", clickHide_keyUp, false); 171 document.removeEventListener("keydown", clickHide_keyDown, false);
172 } 172 }
173 173
174 // Turn off click-to-hide 174 // Turn off click-to-hide
175 function clickHide_deactivate() 175 function clickHide_deactivate()
176 { 176 {
177 if (clickHideFiltersDialog) 177 if (clickHideFiltersDialog)
178 { 178 {
179 document.body.removeChild(clickHideFiltersDialog); 179 document.body.removeChild(clickHideFiltersDialog);
180 clickHideFiltersDialog = null; 180 clickHideFiltersDialog = null;
181 } 181 }
182 182
183 if(currentElement) { 183 if(currentElement) {
184 currentElement.removeEventListener("contextmenu", clickHide_elementClickHand ler, false); 184 currentElement.removeEventListener("contextmenu", clickHide_elementClickHand ler, false);
185 unhighlightElements(); 185 unhighlightElements();
186 currentElement.style.setProperty("-webkit-box-shadow", currentElement_boxSha dow); 186 currentElement.style.setProperty("-webkit-box-shadow", currentElement_boxSha dow);
187 currentElement.style.backgroundColor = currentElement_backgroundColor; 187 currentElement.style.backgroundColor = currentElement_backgroundColor;
188 currentElement = null; 188 currentElement = null;
189 clickHideFilters = null; 189 clickHideFilters = null;
190 } 190 }
191 unhighlightElements(); 191 unhighlightElements();
192 192
193 clickHide_activated = false; 193 clickHide_activated = false;
194 clickHide_filters = null; 194 clickHide_filters = null;
195 if(!document) 195 if(!document)
196 return; // This can happen inside a nuked iframe...I think 196 return; // This can happen inside a nuked iframe...I think
197 document.removeEventListener("mouseover", clickHide_mouseOver, false); 197 document.removeEventListener("mouseover", clickHide_mouseOver, false);
198 document.removeEventListener("mouseout", clickHide_mouseOut, false); 198 document.removeEventListener("mouseout", clickHide_mouseOut, false);
199 document.removeEventListener("click", clickHide_mouseClick, false); 199 document.removeEventListener("click", clickHide_mouseClick, false);
200 document.removeEventListener("keyup", clickHide_keyUp, false); 200 document.removeEventListener("keydown", clickHide_keyDown, false);
201 201
202 // Remove overlays 202 // Remove overlays
203 // For some reason iterating over the array returend by getElementsByClassName () doesn't work 203 // For some reason iterating over the array returend by getElementsByClassName () doesn't work
204 var elt; 204 var elt;
205 while(elt = document.querySelector('.__adblockplus__overlay')) 205 while(elt = document.querySelector('.__adblockplus__overlay'))
206 elt.parentNode.removeChild(elt); 206 elt.parentNode.removeChild(elt);
207 } 207 }
208 208
209 function clickHide_elementClickHandler(ev) { 209 function clickHide_elementClickHandler(ev) {
210 ev.preventDefault(); 210 ev.preventDefault();
211 ev.stopPropagation(); 211 ev.stopPropagation();
212 clickHide_mouseClick(ev); 212 clickHide_mouseClick(ev);
213 } 213 }
214 214
215 // Hovering over an element so highlight it 215 // Hovering over an element so highlight it
216 function clickHide_mouseOver(e) 216 function clickHide_mouseOver(e)
217 { 217 {
218 if (clickHide_activated == false) 218 if (clickHide_activated == false)
219 return; 219 return;
220 220
221 var target = e.target; 221 var target = e.target;
222 while (target.parentNode && !(target.id || target.className || target.src)) 222 while (target.parentNode && !(target.id || target.className || target.src))
223 target = target.parentNode; 223 target = target.parentNode;
224 if (target == document.documentElement || target == document.body)
225 target = null;
224 226
225 if (target && target instanceof HTMLElement) 227 if (target && target instanceof HTMLElement)
Thomas Greiner 2013/12/18 10:32:54 We don't want to hide the <body> element which can
226 { 228 {
227 currentElement = target; 229 currentElement = target;
228 currentElement_boxShadow = target.style.getPropertyValue("-webkit-box-shadow "); 230 currentElement_boxShadow = target.style.getPropertyValue("-webkit-box-shadow ");
229 currentElement_backgroundColor = target.style.backgroundColor; 231 currentElement_backgroundColor = target.style.backgroundColor;
230 target.style.setProperty("-webkit-box-shadow", "inset 0px 0px 5px #d6d84b"); 232 target.style.setProperty("-webkit-box-shadow", "inset 0px 0px 5px #d6d84b");
231 target.style.backgroundColor = "#f8fa47"; 233 target.style.backgroundColor = "#f8fa47";
232 234
233 target.addEventListener("contextmenu", clickHide_elementClickHandler, false) ; 235 target.addEventListener("contextmenu", clickHide_elementClickHandler, false) ;
234 } 236 }
235 } 237 }
236 238
237 // No longer hovering over this element so unhighlight it 239 // No longer hovering over this element so unhighlight it
238 function clickHide_mouseOut(e) 240 function clickHide_mouseOut(e)
239 { 241 {
240 if (!clickHide_activated || !currentElement) 242 if (!clickHide_activated || !currentElement)
241 return; 243 return;
242 244
243 currentElement.style.setProperty("-webkit-box-shadow", currentElement_boxShado w); 245 currentElement.style.setProperty("-webkit-box-shadow", currentElement_boxShado w);
244 currentElement.style.backgroundColor = currentElement_backgroundColor; 246 currentElement.style.backgroundColor = currentElement_backgroundColor;
245 247
246 currentElement.removeEventListener("contextmenu", clickHide_elementClickHandle r, false); 248 currentElement.removeEventListener("contextmenu", clickHide_elementClickHandle r, false);
247 } 249 }
248 250
249 // Selects the currently hovered-over filter 251 // Selects the currently hovered-over filter or cancels selection
250 function clickHide_keyUp(e) { 252 function clickHide_keyDown(e)
251 // Ctrl+Shift+E 253 {
252 if(e.ctrlKey && e.shiftKey && e.keyCode == 69) 254 if (!e.ctrlKey && !e.altKey && !e.shiftKey && e.keyCode == 13 /*DOM_VK_ENTER*/ )
Thomas Greiner 2013/12/18 11:17:12 Different sources mention different codes. Does it
Wladimir Palant 2013/12/18 11:39:57 Sure. The comment is wrong however, I meant VK_RET
253 clickHide_mouseClick(e); 255 clickHide_mouseClick(e);
256 else if (!e.ctrlKey && !e.altKey && !e.shiftKey && e.keyCode == 27 /*DOM_VK_ES CAPE*/)
257 {
258 clickHide_deactivate();
259 e.preventDefault();
260 e.stopPropagation();
261 }
254 } 262 }
255 263
256 // When the user clicks, the currentElement is the one we want. 264 // When the user clicks, the currentElement is the one we want.
257 // We should have ABP rules ready for when the 265 // We should have ABP rules ready for when the
258 // popup asks for them. 266 // popup asks for them.
259 function clickHide_mouseClick(e) 267 function clickHide_mouseClick(e)
260 { 268 {
261 if (!currentElement || !clickHide_activated) 269 if (!currentElement || !clickHide_activated)
262 return; 270 return;
263 271
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after
578 586
579 clickHide_deactivate(); 587 clickHide_deactivate();
580 } 588 }
581 break; 589 break;
582 default: 590 default:
583 sendResponse({}); 591 sendResponse({});
584 break; 592 break;
585 } 593 }
586 }); 594 });
587 } 595 }
LEFTRIGHT
« no previous file | no next file » | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

Powered by Google App Engine
This is Rietveld