Left: | ||
Right: |
LEFT | RIGHT |
---|---|
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-2014 Eyeo GmbH | 3 * Copyright (C) 2006-2014 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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
47 { | 47 { |
48 return s.replace(/^[\d\-]|[^\w\-\u0080-\uFFFF]/g, escapeChar); | 48 return s.replace(/^[\d\-]|[^\w\-\u0080-\uFFFF]/g, escapeChar); |
49 } | 49 } |
50 | 50 |
51 function highlightElement(element, shadowColor, backgroundColor) | 51 function highlightElement(element, shadowColor, backgroundColor) |
52 { | 52 { |
53 unhighlightElement(element); | 53 unhighlightElement(element); |
54 | 54 |
55 var highlightWithOverlay = function() | 55 var highlightWithOverlay = function() |
56 { | 56 { |
57 var overlay = addElementOverlay(element); | |
58 | |
57 highlightElement(overlay, shadowColor, backgroundColor); | 59 highlightElement(overlay, shadowColor, backgroundColor); |
58 overlay.style.pointerEvents = "none"; | 60 overlay.style.pointerEvents = "none"; |
59 | 61 |
60 element._unhighlight = function() | 62 element._unhighlight = function() |
kzar
2015/01/13 11:04:24
Could this cause a memory leak as _unhighlight fun
Sebastian Noack
2015/01/13 13:03:53
It is actually removed, see unhighlightElement().
| |
61 { | 63 { |
62 overlay.parentNode.removeChild(overlay); | 64 overlay.parentNode.removeChild(overlay); |
63 }; | 65 }; |
64 }; | 66 }; |
65 | 67 |
66 var highlightWithStyleAttribute = function() | 68 var highlightWithStyleAttribute = function() |
67 { | 69 { |
68 var originalBoxShadow = element.style.getPropertyValue ("box -shadow"); | 70 var originalBoxShadow = element.style.getPropertyValue("box-shadow"); |
kzar
2015/01/13 11:04:24
Why extra spacing before opening bracket? (Maybe i
Sebastian Noack
2015/01/13 13:03:53
I find it more readable, when similar code is alig
| |
69 var originalBoxShadowPriority = element.style.getPropertyPriority("box -shadow"); | 71 var originalBoxShadowPriority = element.style.getPropertyPriority("box-shado w"); |
70 var originalBackgroundColor = element.style.getPropertyValue ("bac kground-color"); | 72 var originalBackgroundColor = element.style.getPropertyValue("background-col or"); |
71 var originalBackgroundColorPriority = element.style.getPropertyPriority("bac kground-color"); | 73 var originalBackgroundColorPriority = element.style.getPropertyPriority("bac kground-color"); |
72 | 74 |
73 element.style.setProperty("box-shadow", "inset 0px 0px 5px " + shadowColor, "important"); | 75 element.style.setProperty("box-shadow", "inset 0px 0px 5px " + shadowColor, "important"); |
74 element.style.setProperty("background-color", backgroundColor, "important"); | 76 element.style.setProperty("background-color", backgroundColor, "important"); |
75 | 77 |
76 element._unhighlight = function() | 78 element._unhighlight = function() |
77 { | 79 { |
78 this.style.removeProperty("box-shadow"); | 80 this.style.removeProperty("box-shadow"); |
79 this.style.setProperty( | 81 this.style.setProperty( |
80 "box-shadow", | 82 "box-shadow", |
81 originalBoxShadow, | 83 originalBoxShadow, |
82 originalBoxShadowPriority | 84 originalBoxShadowPriority |
83 ); | 85 ); |
84 | 86 |
85 this.style.removeProperty("background-color"); | 87 this.style.removeProperty("background-color"); |
86 this.style.setProperty( | 88 this.style.setProperty( |
87 "background-color", | 89 "background-color", |
88 originalBackgroundColor, | 90 originalBackgroundColor, |
89 originalBackgroundColorPriority | 91 originalBackgroundColorPriority |
90 ); | 92 ); |
91 }; | 93 }; |
92 }; | 94 }; |
93 | 95 |
94 var overlay; | 96 if ("prisoner" in element) |
kzar
2015/01/13 11:04:24
Seems confusing to me that overlay is declared her
Sebastian Noack
2015/01/13 13:03:53
I moved the declaration into highlightWithOverlay(
| |
95 if (!("prisoner" in element) && (overlay = addElementOverlay(element))) | 97 highlightWithStyleAttribute(); |
kzar
2015/01/13 11:04:24
Could you add a comment before this if statement e
Sebastian Noack
2015/01/13 13:03:53
We only highlight elements with style attributes i
| |
98 else | |
96 highlightWithOverlay(); | 99 highlightWithOverlay(); |
97 else | |
98 highlightWithStyleAttribute(); | |
99 } | 100 } |
100 | 101 |
101 | 102 |
102 function unhighlightElement(element) | 103 function unhighlightElement(element) |
103 { | 104 { |
104 if ("_unhighlight" in element) | 105 if ("_unhighlight" in element) |
105 { | 106 { |
106 element._unhighlight(); | 107 element._unhighlight(); |
107 delete element._unhighlight; | 108 delete element._unhighlight; |
108 } | 109 } |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
253 function addElementOverlay(elt) { | 254 function addElementOverlay(elt) { |
254 // If the element isn't rendered (since its or one of its ancestor's | 255 // If the element isn't rendered (since its or one of its ancestor's |
255 // "display" property is "none"), the overlay wouldn't match the element. | 256 // "display" property is "none"), the overlay wouldn't match the element. |
256 if (!elt.offsetParent) | 257 if (!elt.offsetParent) |
257 return; | 258 return; |
258 | 259 |
259 var thisStyle = getComputedStyle(elt, null); | 260 var thisStyle = getComputedStyle(elt, null); |
260 var overlay = document.createElement('div'); | 261 var overlay = document.createElement('div'); |
261 overlay.prisoner = elt; | 262 overlay.prisoner = elt; |
262 overlay.className = "__adblockplus__overlay"; | 263 overlay.className = "__adblockplus__overlay"; |
263 overlay.setAttribute('style', 'opacity:0.4; display:inline-box; position:absol ute; overflow:hidden; box-sizing:border-box;'); | 264 overlay.setAttribute('style', 'opacity:0.4; display:inline-box; position:absol ute; overflow:hidden; box-sizing:border-box;'); |
kzar
2015/01/13 11:04:24
Are these changes relevant to the issue?
kzar
2015/01/13 13:26:34
What about these changes?
Sebastian Noack
2015/01/13 13:36:11
Kinda; it already prior to my changes here, it wer
| |
264 var pos = getAbsolutePosition(elt); | 265 var pos = getAbsolutePosition(elt); |
265 overlay.style.width = elt.offsetWidth + "px"; | 266 overlay.style.width = elt.offsetWidth + "px"; |
266 overlay.style.height = elt.offsetHeight + "px"; | 267 overlay.style.height = elt.offsetHeight + "px"; |
267 overlay.style.left = pos[0] + "px"; | 268 overlay.style.left = pos[0] + "px"; |
268 overlay.style.top = pos[1] + "px"; | 269 overlay.style.top = pos[1] + "px"; |
269 | 270 |
270 if (thisStyle.position != "static") | 271 if (thisStyle.position != "static") |
271 overlay.style.zIndex = thisStyle.zIndex; | 272 overlay.style.zIndex = thisStyle.zIndex; |
272 else | 273 else |
273 overlay.style.zIndex = getComputedStyle(elt.offsetParent).zIndex; | 274 overlay.style.zIndex = getComputedStyle(elt.offsetParent).zIndex; |
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
663 case "clickhide-close": | 664 case "clickhide-close": |
664 if (clickHideFiltersDialog && msg.remove) | 665 if (clickHideFiltersDialog && msg.remove) |
665 { | 666 { |
666 // Explicitly get rid of currentElement | 667 // Explicitly get rid of currentElement |
667 var element = currentElement.prisoner || currentElement; | 668 var element = currentElement.prisoner || currentElement; |
668 if (element && element.parentNode) | 669 if (element && element.parentNode) |
669 element.parentNode.removeChild(element); | 670 element.parentNode.removeChild(element); |
670 } | 671 } |
671 clickHide_deactivate(); | 672 clickHide_deactivate(); |
672 break; | 673 break; |
673 default: | |
674 sendResponse({}); | |
675 break; | |
676 } | 674 } |
677 }); | 675 }); |
678 | 676 |
679 if (window == window.top) | 677 if (window == window.top) |
680 ext.backgroundPage.sendMessage({type: "report-html-page"}); | 678 ext.backgroundPage.sendMessage({type: "report-html-page"}); |
681 } | 679 } |
LEFT | RIGHT |