OLD | NEW |
1 // TODO(hayato): Have both createShadowRoot and attachShadow. | 1 // TODO(hayato): Have both createShadowRoot and attachShadow. |
2 function createShadowRoot() | 2 function createShadowRoot() |
3 { | 3 { |
4 var children = Array.prototype.slice.call(arguments); | 4 var children = Array.prototype.slice.call(arguments); |
5 if ((children[0] instanceof Object) && !(children[0] instanceof Node)) { | 5 if ((children[0] instanceof Object) && !(children[0] instanceof Node)) { |
6 var attributes = {}; | 6 var attributes = {}; |
7 var parameter = {}; | 7 var parameter = {}; |
8 for (var key in children[0]) { | 8 for (var key in children[0]) { |
9 if (key == 'mode' || key == 'delegatesFocus') | 9 if (key == 'mode' || key == 'delegatesFocus') |
10 parameter[key] = children[0][key]; | 10 parameter[key] = children[0][key]; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 } else | 57 } else |
58 element.appendChild(child); | 58 element.appendChild(child); |
59 } | 59 } |
60 return element; | 60 return element; |
61 } | 61 } |
62 | 62 |
63 function convertTemplatesToShadowRootsWithin(node) { | 63 function convertTemplatesToShadowRootsWithin(node) { |
64 var nodes = node.querySelectorAll("template"); | 64 var nodes = node.querySelectorAll("template"); |
65 for (var i = 0; i < nodes.length; ++i) { | 65 for (var i = 0; i < nodes.length; ++i) { |
66 var template = nodes[i]; | 66 var template = nodes[i]; |
67 | 67 var mode = template.getAttribute("data-mode"); |
68 var parent = template.parentNode; | 68 var parent = template.parentNode; |
69 parent.removeChild(template); | 69 parent.removeChild(template); |
70 var shadowRoot = parent.createShadowRoot(); | 70 var shadowRoot; |
| 71 if (!mode) { |
| 72 shadowRoot = parent.createShadowRoot(); |
| 73 } else { |
| 74 shadowRoot = parent.attachShadow({'mode': mode}); |
| 75 } |
71 if (template.id) | 76 if (template.id) |
72 shadowRoot.id = template.id; | 77 shadowRoot.id = template.id; |
73 var fragments = document.importNode(template.content, true); | 78 var fragments = document.importNode(template.content, true); |
74 shadowRoot.appendChild(fragments); | 79 shadowRoot.appendChild(fragments); |
75 | 80 |
76 convertTemplatesToShadowRootsWithin(shadowRoot); | 81 convertTemplatesToShadowRootsWithin(shadowRoot); |
77 } | 82 } |
78 } | 83 } |
79 | 84 |
80 function isShadowHost(node) | 85 function isShadowHost(node) |
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
324 return node; | 329 return node; |
325 } | 330 } |
326 | 331 |
327 return null; | 332 return null; |
328 }; | 333 }; |
329 | 334 |
330 if (!window.internals) | 335 if (!window.internals) |
331 return null; | 336 return null; |
332 return iter(root, id); | 337 return iter(root, id); |
333 } | 338 } |
OLD | NEW |