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.
70 71 72 |
# File 'opal/browser/delay.rb', line 70 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.
75 76 77 |
# File 'opal/browser/delay.rb', line 75 def after!(time, &block) $window.after!(time, &block) end |
#alert(value) ⇒ Object
Alert the passed string.
121 122 123 |
# File 'opal/browser/window.rb', line 121 def alert(value) $window.alert(value) end |
#animation_frame(&block) ⇒ Object
102 103 104 |
# File 'opal/browser/animation_frame.rb', line 102 def animation_frame(&block) Browser::AnimationFrame.new($window, &block) end |
#confirm(value) ⇒ Object
Display a confirmation dialog with the passed string as text.
131 132 133 |
# File 'opal/browser/window.rb', line 131 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
135 136 137 |
# File 'opal/browser/immediate.rb', line 135 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
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 102 |
# File 'opal/browser/dom.rb', line 65 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.
92 93 94 |
# File 'opal/browser/interval.rb', line 92 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.
97 98 99 |
# File 'opal/browser/interval.rb', line 97 def every!(time, &block) $window.every!(time, &block) end |
#prompt(value, default = nil) ⇒ Object
Display a prompt dialog with the passed string as text.
126 127 128 |
# File 'opal/browser/window.rb', line 126 def prompt(value, default=nil) $window.prompt(value, default) end |
#resolve_after(time) ⇒ Promise
Returns a promise that will resolve after the given seconds.
80 81 82 |
# File 'opal/browser/delay.rb', line 80 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
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'opal/browser/dom.rb', line 21 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 |