Skip to content

Commit 7566410

Browse files
committedApr 18, 2015
dom/node: add DOM support to insertion methods
1 parent dff179f commit 7566410

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed
 

‎opal/browser/dom/node.rb

+17-3
Original file line numberDiff line numberDiff line change
@@ -97,14 +97,24 @@ def >>(node)
9797
self
9898
end
9999

100-
alias add_child <<
100+
def add_child(node = nil, &block)
101+
unless node
102+
node = DOM(&block)
103+
end
104+
105+
self << node
106+
end
101107

102108
# Add the passed node after this one.
103109
#
104110
# When passing a {String} a text node will be created.
105111
#
106112
# @param node [String, Node, #to_n] the node to add
107-
def add_next_sibling(node)
113+
def add_next_sibling(node = nil, &block)
114+
unless node
115+
node = DOM(&block)
116+
end
117+
108118
unless native?(node)
109119
if String === node
110120
node = `#@native.ownerDocument.createTextNode(node)`
@@ -121,7 +131,11 @@ def add_next_sibling(node)
121131
# When passing a {String} a text node will be created.
122132
#
123133
# @param node [String, Node, #to_n] the node to add
124-
def add_previous_sibling(node)
134+
def add_previous_sibling(node = nil, &block)
135+
unless node
136+
node = DOM(&block)
137+
end
138+
125139
unless native?(node)
126140
if String === node
127141
node = `#@native.ownerDocument.createTextNode(node)`

0 commit comments

Comments
 (0)
Please sign in to comment.