X Tutup
Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions modules/angular2/src/platform/dom/dom_renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -346,11 +346,13 @@ function resolveInternalDomFragment(fragmentRef: RenderFragmentRef): Node[] {
}

function moveNodesAfterSibling(sibling, nodes) {
if (nodes.length > 0 && isPresent(DOM.parentElement(sibling))) {
let sib = sibling;
let parent = DOM.parentElement(sib);
if (nodes.length > 0 && isPresent(parent)) {
for (var i = 0; i < nodes.length; i++) {
DOM.insertBefore(sibling, nodes[i]);
parent.insertBefore(nodes[i], sib.nextSibling);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to update sib and can't just always use sibling as the second argument?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well we need to make sure each node is appended after the one before it. I'd have to see what you're thinking exactly but my first thought is, keeping sibling.nextSibling fixed would mean the nodes get appended in reverse order.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Max, keeping sibling.nextSibling the same works / does not skrew up the order. Try this snippet:

function moveNodesAfterSibling(sibling, nodes) {
  var parent = sibling.parentElement;
  var nextSibling = sibling.nextSibling;
  for (var i = 0; i < nodes.length; i++) {
    parent.insertBefore(nodes[i], nextSibling);
  }    
}

var parent = document.createElement('div');
parent.innerHTML = '<script></script>';
var nodes = [document.createElement('div'), document.createElement('a'), document.createElement('b')];
moveNodesAfterSibling(parent.firstChild, nodes);
console.log(parent.innerHTML);

sib = nodes[i];
}
DOM.insertBefore(nodes[0], sibling);
}
}

Expand Down
X Tutup