Class: Hyalite::DOM::Document

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

Instance Attribute Summary

Attributes included from Node

#native

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Node

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

Methods included from EventTarget

#on

Class Method Details

.singletonObject



22
23
24
# File 'lib/hyalite/dom/document.rb', line 22

def self.singleton
  @singleton ||= self.new(`window.document`)
end

Instance Method Details

#[](q) ⇒ Object



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

def [](q)
  Collection.new `self.native.querySelectorAll(#{q})`
end

#bodyObject



14
15
16
# File 'lib/hyalite/dom/document.rb', line 14

def body
  Body.new `self.native.body`
end

#create_element(tag) ⇒ Object



6
7
8
# File 'lib/hyalite/dom/document.rb', line 6

def create_element(tag)
  Element.new `self.native.createElement(tag)`
end

#create_text(text) ⇒ Object



10
11
12
# File 'lib/hyalite/dom/document.rb', line 10

def create_text(text)
  Text.new `self.native.createTextNode(text)`
end

#document?Boolean

Returns:

  • (Boolean)


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

def document?
  true
end

#ready(&block) ⇒ Object



18
19
20
# File 'lib/hyalite/dom/document.rb', line 18

def ready(&block)
  `self.native.addEventListener('DOMContentLoaded', block)`
end