|
26 | 26 | * This updates the internal pointers for node, previousNode and nextNode. |
27 | 27 | */ |
28 | 28 | function collectNodes(node, parentNode, previousNode, nextNode) { |
29 | | - if (node.nodeType !== Node.DOCUMENT_FRAGMENT_NODE) { |
| 29 | + if (!(node instanceof DocumentFragment)) { |
30 | 30 | if (node.parentNode) |
31 | 31 | node.parentNode.removeChild(node); |
32 | 32 | node.parentNode_ = parentNode; |
|
60 | 60 | return nodes; |
61 | 61 | } |
62 | 62 |
|
| 63 | + function collectNodesNoNeedToUpdatePointers(node) { |
| 64 | + if (node instanceof DocumentFragment) { |
| 65 | + var nodes = []; |
| 66 | + var i = 0; |
| 67 | + for (var child = node.firstChild; child; child = child.nextSibling) { |
| 68 | + nodes[i++] = child; |
| 69 | + } |
| 70 | + return nodes; |
| 71 | + } |
| 72 | + return [node]; |
| 73 | + } |
| 74 | + |
| 75 | + function nodesWereAdded(nodes) { |
| 76 | + for (var i = 0; i < nodes.length; i++) { |
| 77 | + nodes[i].nodeWasAdded_(); |
| 78 | + } |
| 79 | + } |
| 80 | + |
63 | 81 | function ensureSameOwnerDocument(parent, child) { |
64 | 82 | var ownerDoc = parent.nodeType === Node.DOCUMENT_NODE ? |
65 | 83 | parent : parent.ownerDocument; |
|
188 | 206 | appendChild: function(childWrapper) { |
189 | 207 | assertIsNodeWrapper(childWrapper); |
190 | 208 |
|
| 209 | + var nodes; |
| 210 | + |
191 | 211 | if (this.invalidateShadowRenderer() || invalidateParent(childWrapper)) { |
192 | 212 | var previousNode = this.lastChild; |
193 | 213 | var nextNode = null; |
194 | | - var nodes = collectNodes(childWrapper, this, previousNode, nextNode); |
| 214 | + nodes = collectNodes(childWrapper, this, previousNode, nextNode); |
195 | 215 |
|
196 | 216 | this.lastChild_ = nodes[nodes.length - 1]; |
197 | 217 | if (!previousNode) |
198 | 218 | this.firstChild_ = nodes[0]; |
199 | 219 |
|
200 | 220 | originalAppendChild.call(this.impl, unwrapNodesForInsertion(this, nodes)); |
201 | 221 | } else { |
| 222 | + nodes = collectNodesNoNeedToUpdatePointers(childWrapper) |
202 | 223 | ensureSameOwnerDocument(this, childWrapper); |
203 | 224 | originalAppendChild.call(this.impl, unwrap(childWrapper)); |
204 | 225 | } |
205 | 226 |
|
206 | | - childWrapper.nodeWasAdded_(); |
| 227 | + nodesWereAdded(nodes); |
207 | 228 |
|
208 | 229 | return childWrapper; |
209 | 230 | }, |
|
217 | 238 | assertIsNodeWrapper(refWrapper); |
218 | 239 | assert(refWrapper.parentNode === this); |
219 | 240 |
|
| 241 | + var nodes; |
| 242 | + |
220 | 243 | if (this.invalidateShadowRenderer() || invalidateParent(childWrapper)) { |
221 | 244 | var previousNode = refWrapper.previousSibling; |
222 | 245 | var nextNode = refWrapper; |
223 | | - var nodes = collectNodes(childWrapper, this, previousNode, nextNode); |
| 246 | + nodes = collectNodes(childWrapper, this, previousNode, nextNode); |
224 | 247 |
|
225 | 248 | if (this.firstChild === refWrapper) |
226 | 249 | this.firstChild_ = nodes[0]; |
|
238 | 261 | adoptNodesIfNeeded(this, nodes); |
239 | 262 | } |
240 | 263 | } else { |
| 264 | + nodes = collectNodesNoNeedToUpdatePointers(childWrapper); |
241 | 265 | ensureSameOwnerDocument(this, childWrapper); |
242 | 266 | originalInsertBefore.call(this.impl, unwrap(childWrapper), |
243 | 267 | unwrap(refWrapper)); |
244 | 268 | } |
245 | 269 |
|
246 | | - childWrapper.nodeWasAdded_(); |
| 270 | + nodesWereAdded(nodes); |
247 | 271 |
|
248 | 272 | return childWrapper; |
249 | 273 | }, |
|
300 | 324 | } |
301 | 325 |
|
302 | 326 | var oldChildNode = unwrap(oldChildWrapper); |
| 327 | + var nodes; |
303 | 328 |
|
304 | 329 | if (this.invalidateShadowRenderer() || |
305 | 330 | invalidateParent(newChildWrapper)) { |
306 | 331 | var previousNode = oldChildWrapper.previousSibling; |
307 | 332 | var nextNode = oldChildWrapper.nextSibling; |
308 | 333 | if (nextNode === newChildWrapper) |
309 | 334 | nextNode = newChildWrapper.nextSibling; |
310 | | - var nodes = collectNodes(newChildWrapper, this, |
311 | | - previousNode, nextNode); |
| 335 | + nodes = collectNodes(newChildWrapper, this, previousNode, nextNode); |
312 | 336 |
|
313 | 337 | if (this.firstChild === oldChildWrapper) |
314 | 338 | this.firstChild_ = nodes[0]; |
|
326 | 350 | oldChildNode); |
327 | 351 | } |
328 | 352 | } else { |
| 353 | + nodes = collectNodesNoNeedToUpdatePointers(newChildWrapper); |
329 | 354 | ensureSameOwnerDocument(this, newChildWrapper); |
330 | 355 | originalReplaceChild.call(this.impl, unwrap(newChildWrapper), |
331 | 356 | oldChildNode); |
332 | 357 | } |
333 | 358 |
|
334 | | - newChildWrapper.nodeWasAdded_(); |
| 359 | + nodesWereAdded(nodes); |
335 | 360 |
|
336 | 361 | return oldChildWrapper; |
337 | 362 | }, |
|
0 commit comments