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

Side by Side Diff: include.postload.js

Issue 6463903206735872: Issue 1606 - Don't create overlays for hidden elements (Closed)
Patch Set: Created Nov. 25, 2014, 4:30 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 | « no previous file | 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 <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 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 function getAbsolutePosition(elt) { 183 function getAbsolutePosition(elt) {
184 var l = 0; 184 var l = 0;
185 var t = 0; 185 var t = 0;
186 for(; elt; elt = elt.offsetParent) { 186 for(; elt; elt = elt.offsetParent) {
187 l += elt.offsetLeft; 187 l += elt.offsetLeft;
188 t += elt.offsetTop; 188 t += elt.offsetTop;
189 } 189 }
190 return [l, t]; 190 return [l, t];
191 } 191 }
192 192
193 function isDisplayed(element)
194 {
195 while (element)
196 {
197 if (getComputedStyle(element).display == "none")
198 return false;
199
200 element = element.parentElement;
201 }
202
203 return true;
204 }
205
193 // Adds an overlay to an element, which is probably a Flash object 206 // Adds an overlay to an element, which is probably a Flash object
194 function addElementOverlay(elt) { 207 function addElementOverlay(elt) {
195 // If this element is enclosed in an object tag, we prefer to block that inste ad 208 // If this element is enclosed in an object tag, we prefer to block that inste ad
196 if(!elt) 209 if(!elt)
197 return null; 210 return null;
198 211
199 // If element doesn't have at least one of class name, ID or URL, give up 212 // If element doesn't have at least one of class name, ID or URL, give up
200 // because we don't know how to construct a filter rule for it 213 // because we don't know how to construct a filter rule for it
201 if(!hasFilters(elt)) 214 if(!hasFilters(elt))
202 return; 215 return;
216
217 // If the element isn't rendered (since its or one of its ancestor's
218 // "diplay" property is "none"), the overlay wouldn't match the element.
219 if (!isDisplayed(elt))
220 return;
221
203 var thisStyle = getComputedStyle(elt, null); 222 var thisStyle = getComputedStyle(elt, null);
204 var overlay = document.createElement('div'); 223 var overlay = document.createElement('div');
205 overlay.prisoner = elt; 224 overlay.prisoner = elt;
206 overlay.className = "__adblockplus__overlay"; 225 overlay.className = "__adblockplus__overlay";
207 overlay.setAttribute('style', 'opacity:0.4; background-color:#ffffff; display: inline-box; ' + 'width:' + thisStyle.width + '; height:' + thisStyle.height + '; position:absolute; overflow:hidden; -webkit-box-sizing:border-box; z-index: 999 99'); 226 overlay.setAttribute('style', 'opacity:0.4; background-color:#ffffff; display: inline-box; ' + 'width:' + thisStyle.width + '; height:' + thisStyle.height + '; position:absolute; overflow:hidden; -webkit-box-sizing:border-box; z-index: 999 99');
208 var pos = getAbsolutePosition(elt); 227 var pos = getAbsolutePosition(elt);
209 overlay.style.left = pos[0] + "px"; 228 overlay.style.left = pos[0] + "px";
210 overlay.style.top = pos[1] + "px"; 229 overlay.style.top = pos[1] + "px";
211 // elt.parentNode.appendChild(overlay, elt); 230 // elt.parentNode.appendChild(overlay, elt);
212 document.body.appendChild(overlay); 231 document.body.appendChild(overlay);
(...skipping 533 matching lines...) Expand 10 before | Expand all | Expand 10 after
746 break; 765 break;
747 default: 766 default:
748 sendResponse({}); 767 sendResponse({});
749 break; 768 break;
750 } 769 }
751 }); 770 });
752 771
753 if (window == window.top) 772 if (window == window.top)
754 ext.backgroundPage.sendMessage({type: "report-html-page"}); 773 ext.backgroundPage.sendMessage({type: "report-html-page"});
755 } 774 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld