|
64 | 64 | // container to container.host. |
65 | 65 | // 3. node is <content> (host of container needs distribution) |
66 | 66 | appendChild: function(node) { |
67 | | - var handled; |
68 | 67 | this._removeNodeFromHost(node, true); |
69 | | - if (this._nodeIsInLogicalTree(this.node)) { |
70 | | - // if a <content> is added, make sure it's parent has logical info. |
| 68 | + // if a <content> is added, make sure it's parent has logical info. |
| 69 | + if (this.getOwnerRoot()) { |
71 | 70 | this._ensureContentLogicalInfo(node); |
| 71 | + } |
| 72 | + if (this._nodeIsInLogicalTree(this.node)) { |
72 | 73 | this._addLogicalInfo(node, this.node); |
73 | | - this._addNodeToHost(node); |
74 | | - handled = this._maybeDistribute(node, this.node); |
75 | | - } else { |
76 | | - this._addNodeToHost(node); |
77 | 74 | } |
| 75 | + this._addNodeToHost(node); |
78 | 76 | // if not distributing and not adding to host, do a fast path addition |
79 | | - if (!handled && !this._tryRemoveUndistributedNode(node)) { |
| 77 | + if (!this._maybeDistribute(node, this.node) && |
| 78 | + !this._tryRemoveUndistributedNode(node)) { |
80 | 79 | // if adding to a shadyRoot, add to host instead |
81 | 80 | var container = this.node._isShadyRoot ? this.node.host : this.node; |
82 | 81 | addToComposedParent(container, node); |
|
89 | 88 | if (!ref_node) { |
90 | 89 | return this.appendChild(node); |
91 | 90 | } |
92 | | - var handled; |
93 | 91 | this._removeNodeFromHost(node, true); |
94 | | - if (this._nodeIsInLogicalTree(this.node)) { |
95 | | - // if a <content> is added, make sure it's parent has logical info. |
| 92 | + // if a <content> is added, make sure it's parent has logical info. |
| 93 | + if (this.getOwnerRoot()) { |
96 | 94 | this._ensureContentLogicalInfo(node); |
| 95 | + } |
| 96 | + if (this._nodeIsInLogicalTree(this.node)) { |
97 | 97 | var children = this.childNodes; |
98 | 98 | var index = children.indexOf(ref_node); |
99 | 99 | if (index < 0) { |
100 | 100 | throw Error('The ref_node to be inserted before is not a child ' + |
101 | 101 | 'of this node'); |
102 | 102 | } |
103 | 103 | this._addLogicalInfo(node, this.node, index); |
104 | | - this._addNodeToHost(node); |
105 | | - handled = this._maybeDistribute(node, this.node); |
106 | | - } else { |
107 | | - this._addNodeToHost(node); |
108 | 104 | } |
| 105 | + this._addNodeToHost(node); |
109 | 106 | // if not distributing and not adding to host, do a fast path addition |
110 | | - if (!handled && !this._tryRemoveUndistributedNode(node)) { |
| 107 | + if (!this._maybeDistribute(node, this.node) && |
| 108 | + !this._tryRemoveUndistributedNode(node)) { |
111 | 109 | // if ref_node is <content> replace with first distributed node |
112 | 110 | ref_node = ref_node.localName === CONTENT ? |
113 | 111 | this._firstComposedNode(ref_node) : ref_node; |
|
128 | 126 | console.warn('The node to be removed is not a child of this node', |
129 | 127 | node); |
130 | 128 | } |
131 | | - var handled; |
132 | | - if (this._nodeIsInLogicalTree(this.node)) { |
133 | | - this._removeNodeFromHost(node); |
134 | | - handled = this._maybeDistribute(node, this.node); |
135 | | - } else { |
136 | | - this._removeNodeFromHost(node); |
137 | | - } |
138 | | - if (!handled) { |
| 129 | + this._removeNodeFromHost(node); |
| 130 | + if (!this._maybeDistribute(node, this.node)) { |
139 | 131 | // if removing from a shadyRoot, remove form host instead |
140 | 132 | var container = this.node._isShadyRoot ? this.node.host : this.node; |
141 | 133 | // not guaranteed to physically be in container; e.g. |
|
249 | 241 | }, |
250 | 242 |
|
251 | 243 | _ensureContentLogicalInfo: function(node) { |
252 | | - if (node.nodeType === Node.DOCUMENT_FRAGMENT_NODE) { |
253 | | - saveLightChildrenIfNeeded(this.node); |
254 | | - var c$ = Array.prototype.slice.call(node.childNodes); |
| 244 | + if (node.nodeType === Node.DOCUMENT_FRAGMENT_NODE && |
| 245 | + !node.__noContent) { |
| 246 | + var c$ = factory(node).querySelectorAll(CONTENT); |
255 | 247 | for (var i=0, n; (i<c$.length) && (n=c$[i]); i++) { |
256 | 248 | this._ensureContentLogicalInfo(n); |
257 | 249 | } |
|
0 commit comments