Module: Kernel
- Defined in:
- lib/diamonds/opal/browser/css.rb,
lib/diamonds/opal/browser/dom.rb,
lib/diamonds/opal/browser/delay.rb,
lib/diamonds/opal/browser/window.rb,
lib/diamonds/opal/browser/interval.rb,
lib/diamonds/opal/browser/immediate.rb,
lib/diamonds/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(text = nil, &block) ⇒ Browser::DOM::Element
Create a <style> element from a string or a block using the Browser::CSS::Builder DSL.
- #defer(*args, &block) ⇒ Object
-
#DOM(*args, &block) ⇒ Browser::DOM::Node
Wrap a native element or create a DOM tree using the Paggio::HTML DSL.
-
#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) ⇒ Object
Display a prompt dialog with the passed string as text.
-
#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.
58 59 60 |
# File 'lib/diamonds/opal/browser/delay.rb', line 58 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.
63 64 65 |
# File 'lib/diamonds/opal/browser/delay.rb', line 63 def after!(time, &block) $window.after!(time, &block) end |
#alert(value) ⇒ Object
Alert the passed string.
107 108 109 |
# File 'lib/diamonds/opal/browser/window.rb', line 107 def alert(value) $window.alert(value) end |
#animation_frame(&block) ⇒ Object
101 102 103 |
# File 'lib/diamonds/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.
117 118 119 |
# File 'lib/diamonds/opal/browser/window.rb', line 117 def confirm(value) $window.confirm(value) end |
#CSS(text = nil, &block) ⇒ Browser::DOM::Element
Create a <style> element from a string or a block using the Browser::CSS::Builder DSL.
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/diamonds/opal/browser/css.rb', line 12 def CSS(text = nil, &block) style = $document.create_element(:style) style[:type] = 'text/css' if block style.inner_text = Paggio.css(&block) else style.inner_text = text end style end |
#defer(*args, &block) ⇒ Object
136 137 138 |
# File 'lib/diamonds/opal/browser/immediate.rb', line 136 def defer(*args, &block) Browser::Immediate.new(block, args).tap(&:dispatch) end |
#DOM(*args, &block) ⇒ Browser::DOM::Node
Wrap a native element or create a DOM tree using the Paggio::HTML DSL.
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/diamonds/opal/browser/dom.rb', line 39 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 if native?(what) Browser::DOM::Node.new(what) elsif Browser::DOM::Node === what what 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 not DOM convertible" end end end |
#every(time, &block) ⇒ Interval
Execute the block every given seconds.
91 92 93 |
# File 'lib/diamonds/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 'lib/diamonds/opal/browser/interval.rb', line 96 def every!(time, &block) $window.every!(time, &block) end |
#prompt(value) ⇒ Object
Display a prompt dialog with the passed string as text.
112 113 114 |
# File 'lib/diamonds/opal/browser/window.rb', line 112 def prompt(value) $window.prompt(value) end |
#XML(what) ⇒ Browser::DOM::Document
Parse an XML string into a DOM usable Browser::DOM::Document
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/diamonds/opal/browser/dom.rb', line 19 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 |