Class: Hyalite::DOM::Element

Inherits:
Object
  • Object
show all
Includes:
Node, Native
Defined in:
lib/hyalite/dom/element.rb

Defined Under Namespace

Classes: Attributes

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Node

#<<, #==, #children, #clear, #document?, #next_sibling, #node_name, #on, #parent, #remove, #text?

Class Method Details

.create(tag) ⇒ Object



77
78
79
# File 'lib/hyalite/dom/element.rb', line 77

def self.create(tag)
  $document.create_element(tag)
end

Instance Method Details

#[](prop_name) ⇒ Object



21
22
23
# File 'lib/hyalite/dom/element.rb', line 21

def [](prop_name)
  `self.native[#{prop_name}]`
end

#add_child(child) ⇒ Object



52
53
54
# File 'lib/hyalite/dom/element.rb', line 52

def add_child(child)
  `self.native.appendChild(child.native)`
end

#add_class(name) ⇒ Object



25
26
27
28
# File 'lib/hyalite/dom/element.rb', line 25

def add_class(name)
  `self.native.classList.add(name)`
  self
end

#attributesObject



34
35
36
# File 'lib/hyalite/dom/element.rb', line 34

def attributes
  @attributes ||= Attributes.new(self)
end

#class_namesObject



30
31
32
# File 'lib/hyalite/dom/element.rb', line 30

def class_names
  Array.new(`self.native.classList`).to_a
end

#documentObject



69
70
71
# File 'lib/hyalite/dom/element.rb', line 69

def document
  $document
end

#element?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/hyalite/dom/element.rb', line 13

def element?
  true
end

#inner_dom=(dom) ⇒ Object



64
65
66
67
# File 'lib/hyalite/dom/element.rb', line 64

def inner_dom=(dom)
  clear
  self << dom
end

#inner_htmlObject



56
57
58
# File 'lib/hyalite/dom/element.rb', line 56

def inner_html
  `self.native.innerHTML`
end

#inner_html=(html) ⇒ Object



60
61
62
# File 'lib/hyalite/dom/element.rb', line 60

def inner_html=(html)
  `self.native.innerHTML = html`
end

#input_typeObject



17
18
19
# File 'lib/hyalite/dom/element.rb', line 17

def input_type
  `self.native.type`
end

#style(hash) ⇒ Object



46
47
48
49
50
# File 'lib/hyalite/dom/element.rb', line 46

def style(hash)
  hash.each do |key, value|
    `self.native.style[key] = value`
  end
end

#textObject



38
39
40
# File 'lib/hyalite/dom/element.rb', line 38

def text
  `self.native.textContent`
end

#text=(text) ⇒ Object



42
43
44
# File 'lib/hyalite/dom/element.rb', line 42

def text=(text)
  `self.native.textContent = text`
end

#to_sObject



73
74
75
# File 'lib/hyalite/dom/element.rb', line 73

def to_s
  "<#{`self.native.tagName`} class='#{self.class_names.join(' ')}' id='#{self['id']}'/>"
end