| 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 16 matching lines...) Expand all Loading... | |
| 27 function supportsShadowRoot(element) | 27 function supportsShadowRoot(element) |
| 28 { | 28 { |
| 29 if (!("createShadowRoot" in element)) | 29 if (!("createShadowRoot" in element)) |
| 30 return false; | 30 return false; |
| 31 | 31 |
| 32 // There are some elements (e.g. <textarea>), which don't | 32 // There are some elements (e.g. <textarea>), which don't |
| 33 // support author created shadow roots and throw an exception. | 33 // support author created shadow roots and throw an exception. |
| 34 var clone = element.cloneNode(false); | 34 var clone = element.cloneNode(false); |
| 35 try | 35 try |
| 36 { | 36 { |
| 37 var root = clone.createShadowRoot(); | 37 clone.createShadowRoot(); |
|
Wladimir Palant
2014/09/22 18:31:09
Please don't use variables outside the block where
Sebastian Noack
2014/09/23 11:30:07
Done, though I don't like that policy. :/
Wladimir Palant
2014/09/23 13:29:03
I think I explained my reasoning before - doing th
Sebastian Noack
2014/09/23 15:11:39
Yes, we did. And I think it is pointless to repeat
Wladimir Palant
2014/09/23 15:41:45
You are wrong about Perl, and in Python and PHP lo
Sebastian Noack
2014/09/23 16:37:33
I don't think so. Run following code if you don't
Wladimir Palant
2014/09/23 23:07:39
Please add "use strict;" at the top.
| |
| 38 } | 38 } |
| 39 catch (e) | 39 catch (e) |
| 40 { | 40 { |
| 41 return false; | 41 return false; |
| 42 } | 42 } |
| 43 | 43 |
| 44 // There are some elements (e.g. <input>), which support | 44 // There are some elements (e.g. <input>), which support |
| 45 // author created shadow roots, but ignore insertion points. | 45 // author created shadow roots, but ignore insertion points. |
| 46 var child = document.createTextNode(''); | 46 var child = document.createTextNode(""); |
|
Wladimir Palant
2014/09/22 18:31:09
Double quotation marks please (same two lines belo
Sebastian Noack
2014/09/23 11:30:07
Done.
| |
| 47 clone.appendChild(child); | 47 clone.appendChild(child); |
| 48 | 48 |
| 49 var shadow = document.createElement('shadow'); | 49 var shadow = document.createElement("shadow"); |
| 50 root.appendChild(shadow); | 50 clone.shadowRoot.appendChild(shadow); |
| 51 | 51 |
| 52 return shadow.getDistributedNodes()[0] == child; | 52 return shadow.getDistributedNodes()[0] == child; |
| 53 } | 53 } |
| 54 | 54 |
| 55 function highlightElement(element, shadowColor, backgroundColor) | 55 function highlightElement(element, shadowColor, backgroundColor) |
| 56 { | 56 { |
| 57 unhighlightElement(element); | 57 unhighlightElement(element); |
| 58 | 58 |
| 59 var originalBoxShadowPriority = element.style.getPropertyPriority("box-shadow" ); | 59 var originalBoxShadowPriority = element.style.getPropertyPriority("box-shadow" ); |
| 60 var originalBackgroundColorPriority = element.style.getPropertyPriority("backg round-color"); | 60 var originalBackgroundColorPriority = element.style.getPropertyPriority("backg round-color"); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 97 var root = element.createShadowRoot(); | 97 var root = element.createShadowRoot(); |
| 98 root.appendChild(document.createElement("shadow")); | 98 root.appendChild(document.createElement("shadow")); |
| 99 root.appendChild(style); | 99 root.appendChild(style); |
| 100 | 100 |
| 101 element._unhighlight = function() | 101 element._unhighlight = function() |
| 102 { | 102 { |
| 103 root.removeChild(style); | 103 root.removeChild(style); |
| 104 }; | 104 }; |
| 105 }; | 105 }; |
| 106 | 106 |
| 107 if (supportsShadowRoot(element) && // Use Shadow DOM if posibble to avoid | 107 // Use shadow DOM if posibble to avoid side effects when the |
| 108 // side effects when the web page updates | 108 // web page updates style while highlighted. However, if the |
| 109 // style while highlighted. | 109 // element has important styles we can't override them with shadow DOM. |
|
Wladimir Palant
2014/09/22 18:31:09
Please put this comment before the line you are co
Sebastian Noack
2014/09/23 11:30:07
Done.
| |
| 110 | 110 if (supportsShadowRoot(element) && originalBoxShadowPriority != "importa nt" && |
| 111 // However, if the element has important styles we have to replace | 111 originalBackgroundColorPriority != "importa nt") |
| 112 // the style attribute, and can't override them with shadow DOM. | |
| 113 originalBoxShadowPriority != "important" && | |
| 114 originalBackgroundColorPriority != "important") | |
| 115 highlightWithShadowDOM(); | 112 highlightWithShadowDOM(); |
| 116 else | 113 else |
| 117 highlightWithStyleAttribute(); | 114 highlightWithStyleAttribute(); |
| 118 } | 115 } |
| 119 | 116 |
| 120 | 117 |
| 121 function unhighlightElement(element) | 118 function unhighlightElement(element) |
| 122 { | 119 { |
| 123 if ("_unhighlight" in element) | 120 if ("_unhighlight" in element) |
| 124 { | 121 { |
| (...skipping 518 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 643 | 640 |
| 644 clickHide_deactivate(); | 641 clickHide_deactivate(); |
| 645 } | 642 } |
| 646 break; | 643 break; |
| 647 default: | 644 default: |
| 648 sendResponse({}); | 645 sendResponse({}); |
| 649 break; | 646 break; |
| 650 } | 647 } |
| 651 }); | 648 }); |
| 652 } | 649 } |
| LEFT | RIGHT |