OLD | NEW |
1 function createShadowRoot() | 1 function createShadowRoot() |
2 { | 2 { |
3 var children = Array.prototype.slice.call(arguments); | 3 var children = Array.prototype.slice.call(arguments); |
4 if ((children[0] instanceof Object) && !(children[0] instanceof Node)) | 4 if ((children[0] instanceof Object) && !(children[0] instanceof Node)) |
5 return attachShadow.apply(null, children); | 5 return attachShadow.apply(null, children); |
6 return {'isShadowRoot': true, | 6 return {'isShadowRoot': true, |
7 'children': children}; | 7 'children': children}; |
8 } | 8 } |
9 | 9 |
10 // TODO(kochi): This is not pure attachShadow wrapper, but also handles createSh
adowRoot() | 10 // TODO(kochi): This is not pure attachShadow wrapper, but also handles createSh
adowRoot() |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 } | 59 } |
60 } | 60 } |
61 for (var j = 0; j < child.children.length; ++j) | 61 for (var j = 0; j < child.children.length; ++j) |
62 shadowRoot.appendChild(child.children[j]); | 62 shadowRoot.appendChild(child.children[j]); |
63 } else | 63 } else |
64 element.appendChild(child); | 64 element.appendChild(child); |
65 } | 65 } |
66 return element; | 66 return element; |
67 } | 67 } |
68 | 68 |
| 69 function removeWhiteSpaceOnlyTextNodes(node) |
| 70 { |
| 71 for (var i = 0; i < node.childNodes.length; i++) { |
| 72 var child = node.childNodes[i]; |
| 73 if (child.nodeType === Node.TEXT_NODE && child.nodeValue.trim().length =
= 0) { |
| 74 node.removeChild(child); |
| 75 i--; |
| 76 } else if (child.nodeType === Node.ELEMENT_NODE || child.nodeType === No
de.DOCUMENT_FRAGMENT_NODE) { |
| 77 removeWhiteSpaceOnlyTextNodes(child); |
| 78 } |
| 79 } |
| 80 if (node.shadowRoot) { |
| 81 removeWhiteSpaceOnlyTextNodes(node.shadowRoot); |
| 82 } |
| 83 } |
| 84 |
69 function convertTemplatesToShadowRootsWithin(node) { | 85 function convertTemplatesToShadowRootsWithin(node) { |
70 var nodes = node.querySelectorAll("template"); | 86 var nodes = node.querySelectorAll("template"); |
71 for (var i = 0; i < nodes.length; ++i) { | 87 for (var i = 0; i < nodes.length; ++i) { |
72 var template = nodes[i]; | 88 var template = nodes[i]; |
73 var mode = template.getAttribute("data-mode"); | 89 var mode = template.getAttribute("data-mode"); |
74 var parent = template.parentNode; | 90 var parent = template.parentNode; |
75 parent.removeChild(template); | 91 parent.removeChild(template); |
76 var shadowRoot; | 92 var shadowRoot; |
77 if (!mode) { | 93 if (!mode) { |
78 shadowRoot = parent.createShadowRoot(); | 94 shadowRoot = parent.createShadowRoot(); |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
335 return node; | 351 return node; |
336 } | 352 } |
337 | 353 |
338 return null; | 354 return null; |
339 }; | 355 }; |
340 | 356 |
341 if (!window.internals) | 357 if (!window.internals) |
342 return null; | 358 return null; |
343 return iter(root, id); | 359 return iter(root, id); |
344 } | 360 } |
OLD | NEW |