Module: Hyalite::DOM::Node
- Includes:
- EventTarget
- Defined in:
- lib/hyalite/dom/node.rb
Instance Attribute Summary collapse
-
#native ⇒ Object
readonly
Returns the value of attribute native.
Class Method Summary collapse
Instance Method Summary collapse
- #<<(child) ⇒ Object
- #==(other) ⇒ Object
- #attr(name) ⇒ Object
- #children ⇒ Object
- #clear ⇒ Object
- #document? ⇒ Boolean
- #element? ⇒ Boolean
- #next_sibling ⇒ Object
- #node_name ⇒ Object
- #parent ⇒ Object
- #remove ⇒ Object
- #text? ⇒ Boolean
Methods included from EventTarget
Instance Attribute Details
#native ⇒ Object (readonly)
Returns the value of attribute native.
5 6 7 |
# File 'lib/hyalite/dom/node.rb', line 5 def native @native end |
Class Method Details
.create(node) ⇒ Object
7 8 9 10 11 12 13 14 15 |
# File 'lib/hyalite/dom/node.rb', line 7 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
37 38 39 |
# File 'lib/hyalite/dom/node.rb', line 37 def <<(child) `self.native.appendChild(child.native)` end |
#==(other) ⇒ Object
69 70 71 |
# File 'lib/hyalite/dom/node.rb', line 69 def ==(other) `self.native === other.native` end |
#attr(name) ⇒ Object
29 30 31 |
# File 'lib/hyalite/dom/node.rb', line 29 def attr(name) `self.native[name]` end |
#children ⇒ Object
56 57 58 |
# File 'lib/hyalite/dom/node.rb', line 56 def children Collection.new `self.native.childNodes` end |
#clear ⇒ Object
41 42 43 44 45 46 47 48 |
# File 'lib/hyalite/dom/node.rb', line 41 def clear %x( var len = self.native.childNodes.length; for (var i = 0; i < len; i++) { self.native.childNodes[0].remove(); } ) end |
#document? ⇒ Boolean
17 18 19 |
# File 'lib/hyalite/dom/node.rb', line 17 def document? false end |
#element? ⇒ Boolean
21 22 23 |
# File 'lib/hyalite/dom/node.rb', line 21 def element? false end |
#next_sibling ⇒ Object
64 65 66 67 |
# File 'lib/hyalite/dom/node.rb', line 64 def next_sibling sib = `self.native.nextSibling` Node.create(sib) if sib end |
#node_name ⇒ Object
33 34 35 |
# File 'lib/hyalite/dom/node.rb', line 33 def node_name `self.native.tagName` end |
#parent ⇒ Object
50 51 52 53 54 |
# File 'lib/hyalite/dom/node.rb', line 50 def parent if parent = `self.native.parentNode` Node.create(parent) end end |
#remove ⇒ Object
60 61 62 |
# File 'lib/hyalite/dom/node.rb', line 60 def remove `self.native.remove()` end |
#text? ⇒ Boolean
25 26 27 |
# File 'lib/hyalite/dom/node.rb', line 25 def text? false end |