Class: Hyalite::DOM::Element

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

Defined Under Namespace

Classes: Attributes

Instance Attribute Summary

Attributes included from Node

#native

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Node

#<<, #==, #attr, #children, #clear, #data, #document?, #insert_before, #next_sibling, #node_name, #parent, #remove, #text?

Methods included from EventTarget

#on

Class Method Details

.create(tag) ⇒ Object



97
98
99
# File 'lib/hyalite/dom/element.rb', line 97

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)
  `#@native[#{prop_name}]`
end

#add_child(child) ⇒ Object



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

def add_child(child)
  `#@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)
  `#@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(`#@native.classList`).to_a
end

#client_rectObject



62
63
64
# File 'lib/hyalite/dom/element.rb', line 62

def client_rect
  Native(`#@native.getBoundingClientRect()`)
end

#documentObject



89
90
91
# File 'lib/hyalite/dom/element.rb', line 89

def document
  $document
end

#element?Boolean

Returns:

  • (Boolean)


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

def element?
  true
end

#heightObject



50
51
52
# File 'lib/hyalite/dom/element.rb', line 50

def height
  `#@native.clientHeight`
end

#inner_dom=(dom) ⇒ Object



84
85
86
87
# File 'lib/hyalite/dom/element.rb', line 84

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

#inner_htmlObject



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

def inner_html
  `#@native.innerHTML`
end

#inner_html=(html) ⇒ Object



80
81
82
# File 'lib/hyalite/dom/element.rb', line 80

def inner_html=(html)
  `#@native.innerHTML = html`
end

#input_typeObject



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

def input_type
  `#@native.type`
end

#leftObject



58
59
60
# File 'lib/hyalite/dom/element.rb', line 58

def left
  `#@native.clientLeft`
end

#style(hash) ⇒ Object



66
67
68
69
70
# File 'lib/hyalite/dom/element.rb', line 66

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

#textObject



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

def text
  `#@native.textContent`
end

#text=(text) ⇒ Object



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

def text=(text)
  `#@native.textContent = text`
end

#to_sObject



93
94
95
# File 'lib/hyalite/dom/element.rb', line 93

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

#topObject



54
55
56
# File 'lib/hyalite/dom/element.rb', line 54

def top
  `#@native.clientTop`
end

#widthObject



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

def width
  `#@native.clientWidth`
end