Module: Kernel
- Defined in:
- opal/browser/css.rb,
opal/browser/dom.rb,
opal/browser/delay.rb,
opal/browser/window.rb,
opal/browser/interval.rb,
opal/browser/immediate.rb,
opal/browser/animation_frame.rb
Instance Method Summary collapse
-
#after(time, &block) ⇒ Delay
Execute a block after the given seconds.
-
#after!(time, &block) ⇒ Delay
Execute a block after the given seconds, you have to call [#start] on it yourself.
-
#alert(value) ⇒ Object
Alert the passed string.
- #animation_frame(&block) ⇒ Object
-
#confirm(value) ⇒ Object
Display a confirmation dialog with the passed string as text.
- #CSS(*args, &block) ⇒ Object
- #defer(*args, &block) ⇒ Object
- #DOM(*args, &block) ⇒ Object
-
#every(time, &block) ⇒ Interval
Execute the block every given seconds.
-
#every!(time, &block) ⇒ Interval
Execute the block every given seconds, you have to call [#start] on it yourself.
-
#prompt(value, default = nil) ⇒ Object
Display a prompt dialog with the passed string as text.
-
#resolve_after(time) ⇒ Promise
Returns a promise that will resolve after the given seconds.
-
#XML(what) ⇒ Browser::DOM::Document
Parse an XML string into a DOM usable Browser::DOM::Document.
Instance Method Details
#after(time, &block) ⇒ Delay
Execute a block after the given seconds.
69 70 71 |
# File 'opal/browser/delay.rb', line 69 def after(time, &block) $window.after(time, &block) end |
#after!(time, &block) ⇒ Delay
Execute a block after the given seconds, you have to call [#start] on it yourself.
74 75 76 |
# File 'opal/browser/delay.rb', line 74 def after!(time, &block) $window.after!(time, &block) end |
#alert(value) ⇒ Object
Alert the passed string.
120 121 122 |
# File 'opal/browser/window.rb', line 120 def alert(value) $window.alert(value) end |
#animation_frame(&block) ⇒ Object
101 102 103 |
# File 'opal/browser/animation_frame.rb', line 101 def animation_frame(&block) Browser::AnimationFrame.new($window, &block) end |
#confirm(value) ⇒ Object
Display a confirmation dialog with the passed string as text.
130 131 132 |
# File 'opal/browser/window.rb', line 130 def confirm(value) $window.confirm(value) end |
#CSS(document = $document, &block) ⇒ Browser::DOM::Element #CSS(string, document = $document) ⇒ Browser::DOM::Element
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'opal/browser/css.rb', line 24 def CSS(*args, &block) document = if args.length > 1 || block_given? args.pop end || $document style = document.create_element(:style) style[:type] = 'text/css' if block style.inner_text = Paggio.css(&block) else style.inner_text = args.join("") end style end |
#defer(*args, &block) ⇒ Object
134 135 136 |
# File 'opal/browser/immediate.rb', line 134 def defer(*args, &block) Browser::Immediate.new(block, args).tap(&:dispatch) end |
#DOM(document = $document, &block) ⇒ Browser::DOM::Node, Browser::DOM::NodeSet #DOM(string, document = $document) ⇒ Browser::DOM::Node #DOM(native) ⇒ Browser::DOM::Node
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'opal/browser/dom.rb', line 64 def DOM(*args, &block) if block document = args.shift || $document roots = Browser::DOM::Builder.new(document, &block).to_a if roots.length == 1 roots.first else Browser::DOM::NodeSet.new(roots) end else what = args.shift document = args.shift || $document what = what.to_dom(document) if Opal.respond_to? what, :to_dom if `typeof(#{what}) === 'undefined' || #{what} === null` raise ArgumentError, 'argument is null' elsif native?(what) Browser::DOM::Node.new(what) elsif Browser::DOM::Node === what what elsif Opal.respond_to? what, :each # eg. NodeSet, Array document.create_element("DIV").tap do |div| div << what end elsif String === what %x{ var doc = #{Native.try_convert(document)}.createElement('div'); doc.innerHTML = what; return #{DOM(`doc.childNodes.length == 1 ? doc.childNodes[0] : doc`)}; } else raise ArgumentError, 'argument is not DOM convertible' end end end |
#every(time, &block) ⇒ Interval
Execute the block every given seconds.
91 92 93 |
# File 'opal/browser/interval.rb', line 91 def every(time, &block) $window.every(time, &block) end |
#every!(time, &block) ⇒ Interval
Execute the block every given seconds, you have to call [#start] on it yourself.
96 97 98 |
# File 'opal/browser/interval.rb', line 96 def every!(time, &block) $window.every!(time, &block) end |
#prompt(value, default = nil) ⇒ Object
Display a prompt dialog with the passed string as text.
125 126 127 |
# File 'opal/browser/window.rb', line 125 def prompt(value, default=nil) $window.prompt(value, default) end |
#resolve_after(time) ⇒ Promise
Returns a promise that will resolve after the given seconds.
79 80 81 |
# File 'opal/browser/delay.rb', line 79 def resolve_after(time) $window.resolve_after(time) end |
#XML(what) ⇒ Browser::DOM::Document
Parse an XML string into a DOM usable Browser::DOM::Document
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'opal/browser/dom.rb', line 20 def XML(what) %x{ var doc; if (window.DOMParser) { doc = new DOMParser().parseFromString(what, 'text/xml'); } else { doc = new ActiveXObject('Microsoft.XMLDOM'); doc.async = 'false'; doc.loadXML(what); } } DOM(`doc`) end |