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

Side by Side Diff: include.postload.js

Issue 5744307206094848: Issue 1658 - Preserve original "style" atribute for generated filters (Closed)
Patch Set: Created Dec. 4, 2014, 5:25 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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 // author created shadow roots, but ignore insertion points. 69 // author created shadow roots, but ignore insertion points.
70 var child = document.createTextNode(""); 70 var child = document.createTextNode("");
71 clone.appendChild(child); 71 clone.appendChild(child);
72 72
73 var shadow = document.createElement("shadow"); 73 var shadow = document.createElement("shadow");
74 clone.shadowRoot.appendChild(shadow); 74 clone.shadowRoot.appendChild(shadow);
75 75
76 return shadow.getDistributedNodes()[0] == child; 76 return shadow.getDistributedNodes()[0] == child;
77 } 77 }
78 78
79 function getOriginalStyle(element)
80 {
81 if ("_originalStyle" in element)
82 return element._originalStyle;
83
84 return element.getAttribute("style");
85 }
86
79 function highlightElement(element, shadowColor, backgroundColor) 87 function highlightElement(element, shadowColor, backgroundColor)
80 { 88 {
81 unhighlightElement(element); 89 unhighlightElement(element);
82 90
83 var originalBoxShadowPriority = element.style.getPropertyPriority("box-shadow" ); 91 var originalBoxShadowPriority = element.style.getPropertyPriority("box-shadow" );
84 var originalBackgroundColorPriority = element.style.getPropertyPriority("backg round-color"); 92 var originalBackgroundColorPriority = element.style.getPropertyPriority("backg round-color");
85 93
86 var boxShadow = "inset 0px 0px 5px " + shadowColor; 94 var boxShadow = "inset 0px 0px 5px " + shadowColor;
87 95
88 var highlightWithShadowDOM = function() 96 var highlightWithShadowDOM = function()
(...skipping 12 matching lines...) Expand all
101 { 109 {
102 root.removeChild(style); 110 root.removeChild(style);
103 }; 111 };
104 }; 112 };
105 113
106 var highlightWithStyleAttribute = function() 114 var highlightWithStyleAttribute = function()
107 { 115 {
108 var originalBoxShadow = element.style.getPropertyValue("box-shadow"); 116 var originalBoxShadow = element.style.getPropertyValue("box-shadow");
109 var originalBackgroundColor = element.style.getPropertyValue("background-col or"); 117 var originalBackgroundColor = element.style.getPropertyValue("background-col or");
110 118
119 element._originalStyle = getOriginalStyle(element);
120
111 element.style.setProperty("box-shadow", boxShadow, "important"); 121 element.style.setProperty("box-shadow", boxShadow, "important");
112 element.style.setProperty("background-color", backgroundColor, "important"); 122 element.style.setProperty("background-color", backgroundColor, "important");
113 123
114 element._unhighlight = function() 124 element._unhighlight = function()
115 { 125 {
116 this.style.removeProperty("box-shadow"); 126 this.style.removeProperty("box-shadow");
117 this.style.setProperty( 127 this.style.setProperty(
118 "box-shadow", 128 "box-shadow",
119 originalBoxShadow, 129 originalBoxShadow,
120 originalBoxShadowPriority 130 originalBoxShadowPriority
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 clickHide_mouseClick(ev); 345 clickHide_mouseClick(ev);
336 } 346 }
337 347
338 // Hovering over an element so highlight it 348 // Hovering over an element so highlight it
339 function clickHide_mouseOver(e) 349 function clickHide_mouseOver(e)
340 { 350 {
341 if (clickHide_activated == false) 351 if (clickHide_activated == false)
342 return; 352 return;
343 353
344 var target = e.target; 354 var target = e.target;
345 while (target.parentNode && !(target.id || target.className || target.src || / :.+:/.test(target.getAttribute("style")))) 355 while (target.parentNode && !(target.id || target.className || target.src || / :.+:/.test(getOriginalStyle(target))))
346 target = target.parentNode; 356 target = target.parentNode;
347 if (target == document.documentElement || target == document.body) 357 if (target == document.documentElement || target == document.body)
348 target = null; 358 target = null;
349 359
350 if (target && target instanceof HTMLElement) 360 if (target && target instanceof HTMLElement)
351 { 361 {
352 currentElement = target; 362 currentElement = target;
353 363
354 highlightElement(target, "#d6d84b", "#f8fa47"); 364 highlightElement(target, "#d6d84b", "#f8fa47");
355 target.addEventListener("contextmenu", clickHide_elementClickHandler, true); 365 target.addEventListener("contextmenu", clickHide_elementClickHandler, true);
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
435 { 445 {
436 clickHideFilters.push(url.replace(/^[\w\-]+:\/+(?:www\.)?/, "||")); 446 clickHideFilters.push(url.replace(/^[\w\-]+:\/+(?:www\.)?/, "||"));
437 447
438 if (selector) 448 if (selector)
439 selectorList.push(selector); 449 selectorList.push(selector);
440 } 450 }
441 else if (selector) 451 else if (selector)
442 addSelector(selector); 452 addSelector(selector);
443 } 453 }
444 454
445 // restore the original style, before generating the fallback filter that
446 // will include the style, and to prevent highlightElements from saving those
447 unhighlightElement(currentElement);
448
449 // as last resort, create a filter based on inline styles 455 // as last resort, create a filter based on inline styles
450 if (clickHideFilters.length == 0) 456 if (clickHideFilters.length == 0)
451 { 457 {
452 var style = elt.getAttribute("style"); 458 var style = getOriginalStyle(elt);
453 if (style) 459 if (style)
454 addSelector(escapeCSS(elt.localName) + '[style=' + quote(style) + ']'); 460 addSelector(escapeCSS(elt.localName) + '[style=' + quote(style) + ']');
455 } 461 }
456 462
457 // Show popup 463 // Show popup
458 clickHide_showDialog(e.clientX, e.clientY, clickHideFilters); 464 clickHide_showDialog(e.clientX, e.clientY, clickHideFilters);
459 465
460 // Highlight the elements specified by selector in yellow 466 // Highlight the elements specified by selector in yellow
461 if (selectorList.length > 0) 467 if (selectorList.length > 0)
462 highlightElements(selectorList.join(",")); 468 highlightElements(selectorList.join(","));
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
685 break; 691 break;
686 default: 692 default:
687 sendResponse({}); 693 sendResponse({});
688 break; 694 break;
689 } 695 }
690 }); 696 });
691 697
692 if (window == window.top) 698 if (window == window.top)
693 ext.backgroundPage.sendMessage({type: "report-html-page"}); 699 ext.backgroundPage.sendMessage({type: "report-html-page"});
694 } 700 }
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