Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Complete steps for ChildNode::before #6536

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

@@ -809,20 +809,48 @@ impl<'a> NodeHelpers for &'a Node {

// https://dom.spec.whatwg.org/#dom-childnode-before
fn before(self, nodes: Vec<NodeOrString>) -> ErrorResult {
match self.parent_node.get() {
None => {
// Step 1.
Ok(())
},
Some(ref parent_node) => {
// Step 2.
let doc = self.owner_doc();
let node = try!(doc.r().node_from_nodes_and_strings(nodes));
// Step 3.
Node::pre_insert(node.r(), parent_node.root().r(),
Some(self)).map(|_| ())
},
// Step 1.
let parent = &self.parent_node;

// Step 2.
let parent = match parent.get() {
None => return Ok(()),
Some(ref parent) => parent.root(),
};

// Step 3.
let mut viable_previous_sibling = None;
for sibling in self.preceding_siblings() {
let mut only_nodes = nodes.iter().filter_map(|ref n| {
match *n {
&NodeOrString::eNode(ref x) => Some(x),
_ => None,
}
});
if only_nodes.all(|n| *n != sibling) {
viable_previous_sibling = Some(sibling);
break;
}
}

// Step 4.
let node = try!(self.owner_doc().node_from_nodes_and_strings(nodes));

// Step 5.
let viable_previous_sibling = match viable_previous_sibling {
Some(ref viable_previous_sibling) => viable_previous_sibling.next_sibling.get(),
None => parent.first_child.get(),
}.map(|s| s.root());

// Step 6.
try!(match viable_previous_sibling {
Some(viable_previous_sibling) =>
Node::pre_insert(&node, &parent, Some(&viable_previous_sibling)),
None =>
Node::pre_insert(&node, &parent, None),
});

Ok(())
}

// https://dom.spec.whatwg.org/#dom-childnode-after

This file was deleted.

@@ -85,6 +85,20 @@
assert_equals(parent.innerHTML, expected);
}, nodeName + '.before() with all siblings of child as arguments.');

test(function() {
var parent = document.createElement('div')
var x = document.createElement('x');
var y = document.createElement('y');
var z = document.createElement('z');
parent.appendChild(x);
parent.appendChild(y);
parent.appendChild(z);
parent.appendChild(child);
child.before(y, z);
var expected = '<x></x><y></y><z></z>' + innerHTML;
assert_equals(parent.innerHTML, expected);
}, nodeName + '.before() with all siblings of child as arguments; no changes in tree.');

test(function() {
var parent = document.createElement('div');
var x = document.createElement('x');
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.