Class: Browser::DOM::Document
- Defined in:
- opal/browser/effects.rb,
opal/browser/location.rb,
opal/browser/dom/document.rb
Constant Summary
Constants inherited from Element
Constants inherited from Node
Node::ATTRIBUTE_NODE, Node::CDATA_SECTION_NODE, Node::COMMENT_NODE, Node::DOCUMENT_FRAGMENT_NODE, Node::DOCUMENT_NODE, Node::DOCUMENT_TYPE_NODE, Node::ELEMENT_NODE, Node::ENTITY_NODE, Node::ENTITY_REFERENCE_NOCE, Node::NOTATION_NODE, Node::PROCESSING_INSTRUCTION_NODE, Node::TEXT_NODE
Instance Attribute Summary collapse
-
#active_element ⇒ Element
readonly
The element with focus.
-
#body ⇒ Element?
readonly
The body element of the document.
-
#head ⇒ Element?
readonly
The head element of the document.
-
#location ⇒ Location
readonly
The location for the document.
-
#root ⇒ Element?
The root element of the document.
-
#style_sheets ⇒ Array<CSS::StyleSheet>
readonly
The style sheets for the document.
-
#title ⇒ String
The document title.
-
#window ⇒ Window
readonly
The window for the document.
Attributes inherited from Element
#attribute_nodes, #attributes, #class_name, #class_names, #height, #id, #offset, #position, #scroll, #size, #style!, #width
Attributes inherited from Node
#child, #children, #element_children, #first_element_child, #inner_html, #last_element_child, #name, #namespace, #next, #next_element, #node_type, #parent, #previous, #previous_element, #value
Instance Method Summary collapse
-
#[](what) ⇒ Element?
(also: #at)
Get the first element matching the given ID, CSS selector or XPath.
-
#create_element(name, options = {}) ⇒ Element
Create a new element for the document.
-
#create_text(content) ⇒ Text
Create a new text node for the document.
- #document ⇒ Object
- #inspect ⇒ Object
-
#ready(&block) ⇒ Object
Wait for the document to be ready and call the block.
-
#ready? ⇒ Boolean
Check if the document is ready.
Methods inherited from Element
#/, #=~, #[]=, #add_class, #at_css, #at_xpath, #blur, create, #css, #data, #focus, #focused?, #hide, #inner_dom, #inner_dom=, new, #remove_attribute, #remove_class, #search, #show, #style, #toggle, #xpath
Methods included from Event::Target
#off, #on, #on!, #trigger, #trigger!
Methods inherited from Node
#<<, #==, #>>, #add_child, #add_next_sibling, #add_previous_sibling, #ancestors, #append_to, #blank?, #cdata?, #clear, #comment?, #content, #content=, #document?, #elem?, #fragment?, new, #parse, #path, #prepend_to, #remove, #remove_child, #replace, #text?, #traverse
Instance Attribute Details
#active_element ⇒ Element (readonly)
Returns the element with focus.
6 7 8 |
# File 'opal/browser/effects.rb', line 6 def active_element DOM(`#@native.activeElement`) end |
#body ⇒ Element? (readonly)
Returns the body element of the document.
25 26 27 |
# File 'opal/browser/dom/document.rb', line 25 def body DOM(`#@native.body`) end |
#head ⇒ Element? (readonly)
Returns the head element of the document.
58 59 60 |
# File 'opal/browser/dom/document.rb', line 58 def head DOM(`#@native.getElementsByTagName("head")[0]`) end |
#location ⇒ Location (readonly)
Returns the location for the document.
82 83 84 |
# File 'opal/browser/location.rb', line 82 def location Location.new(`#@native.location`) if `#@native.location` end |
#root ⇒ Element?
Returns the root element of the document.
106 107 108 |
# File 'opal/browser/dom/document.rb', line 106 def root DOM(`#@native.documentElement`) end |
#style_sheets ⇒ Array<CSS::StyleSheet> (readonly)
Returns the style sheets for the document.
116 117 118 119 120 |
# File 'opal/browser/dom/document.rb', line 116 def style_sheets Native::Array.new(`#@native.styleSheets`) {|e| CSS::StyleSheet.new(e) } end |
#title ⇒ String
Returns the document title.
124 125 126 |
# File 'opal/browser/dom/document.rb', line 124 def title `#@native.title` end |
Instance Method Details
#[](what) ⇒ Element? Also known as: at
Get the first element matching the given ID, CSS selector or XPath.
9 10 11 12 13 14 15 16 17 18 19 |
# File 'opal/browser/dom/document.rb', line 9 def [](what) %x{ var result = #@native.getElementById(what); if (result) { return #{DOM(`result`)}; } } css(what).first || xpath(what).first end |
#create_element(name, options = {}) ⇒ Element
Create a new element for the document.
35 36 37 38 39 40 41 |
# File 'opal/browser/dom/document.rb', line 35 def create_element(name, = {}) if ns = [:namespace] DOM(`#@native.createElementNS(#{ns}, #{name})`) else DOM(`#@native.createElement(name)`) end end |
#create_text(content) ⇒ Text
Create a new text node for the document.
48 49 50 |
# File 'opal/browser/dom/document.rb', line 48 def create_text(content) DOM(`#@native.createTextNode(#{content})`) end |
#document ⇒ Object
52 53 54 |
# File 'opal/browser/dom/document.rb', line 52 def document self end |
#inspect ⇒ Object
62 63 64 |
# File 'opal/browser/dom/document.rb', line 62 def inspect "#<DOM::Document>" end |
#ready(&block) ⇒ Object
Wait for the document to be ready and call the block.
94 95 96 97 98 99 100 101 102 103 104 |
# File 'opal/browser/dom/document.rb', line 94 def ready(&block) raise ArgumentError, 'no block given' unless block return block.call if ready? on 'dom:load' do |e| e.off block.call end end |
#ready? ⇒ Boolean
Check if the document is ready.
100 101 102 |
# File 'opal/browser/dom/document.rb', line 100 def ready? `#@native.readyState === "complete"` end |