Module: Hyalite::DOM::Node
Class Method Summary collapse
Instance Method Summary collapse
- #<<(child) ⇒ Object
- #==(other) ⇒ Object
- #children ⇒ Object
- #clear ⇒ Object
- #document? ⇒ Boolean
- #element? ⇒ Boolean
- #next_sibling ⇒ Object
- #node_name ⇒ Object
- #on(name, &block) ⇒ Object
- #parent ⇒ Object
- #remove ⇒ Object
- #text? ⇒ Boolean
Class Method Details
.create(node) ⇒ Object
4 5 6 7 8 9 10 11 12 |
# File 'lib/hyalite/dom/node.rb', line 4 def self.create(node) @classes ||= [nil, Element, nil, Text, nil, nil, nil, nil, nil, Document, nil, nil] if klass = @classes[`node.nodeType`] klass.new(node) else raise ArgumentError, 'cannot instantiate a non derived Node object' end end |
Instance Method Details
#<<(child) ⇒ Object
30 31 32 |
# File 'lib/hyalite/dom/node.rb', line 30 def <<(child) `self.native.appendChild(child.native)` end |
#==(other) ⇒ Object
67 68 69 |
# File 'lib/hyalite/dom/node.rb', line 67 def ==(other) `self.native === other.native` end |
#children ⇒ Object
49 50 51 |
# File 'lib/hyalite/dom/node.rb', line 49 def children Collection.new `self.native.childNodes` end |
#clear ⇒ Object
34 35 36 37 38 39 40 41 |
# File 'lib/hyalite/dom/node.rb', line 34 def clear %x( var len = self.native.childNodes.length; for (var i = 0; i < len; i++) { self.native.childNodes[0].remove(); } ) end |
#document? ⇒ Boolean
14 15 16 |
# File 'lib/hyalite/dom/node.rb', line 14 def document? false end |
#element? ⇒ Boolean
18 19 20 |
# File 'lib/hyalite/dom/node.rb', line 18 def element? false end |
#next_sibling ⇒ Object
57 58 59 60 |
# File 'lib/hyalite/dom/node.rb', line 57 def next_sibling sib = `self.native.nextSibling` Node.create(sib) if sib end |
#node_name ⇒ Object
26 27 28 |
# File 'lib/hyalite/dom/node.rb', line 26 def node_name `self.native.tagName` end |
#on(name, &block) ⇒ Object
62 63 64 65 |
# File 'lib/hyalite/dom/node.rb', line 62 def on(name, &block) callback = Proc.new{|event| block.call(Event.create(event))} `self.native.addEventListener(name, callback)` end |
#parent ⇒ Object
43 44 45 46 47 |
# File 'lib/hyalite/dom/node.rb', line 43 def parent if parent = `self.native.parentNode` Node.create(parent) end end |
#remove ⇒ Object
53 54 55 |
# File 'lib/hyalite/dom/node.rb', line 53 def remove `self.native.remove()` end |
#text? ⇒ Boolean
22 23 24 |
# File 'lib/hyalite/dom/node.rb', line 22 def text? false end |