Class: Browser::Window
- Includes:
- Event::Target, Native
- Defined in:
- opal/browser/window.rb,
opal/browser/dom.rb,
opal/browser/delay.rb,
opal/browser/screen.rb,
opal/browser/console.rb,
opal/browser/history.rb,
opal/browser/storage.rb,
opal/browser/interval.rb,
opal/browser/location.rb,
opal/browser/navigator.rb,
opal/browser/window/size.rb,
opal/browser/window/view.rb,
opal/browser/window/scroll.rb
Overview
Wrapper class for the window
object, an instance of it gets
set to $window
.
Defined Under Namespace
Instance Attribute Summary collapse
-
#history ⇒ History
readonly
The history for this window.
-
#location ⇒ Location
readonly
The location for the window.
-
#navigator ⇒ Navigator
readonly
The navigator.
-
#screen ⇒ Screen
readonly
The screen for the window.
Class Method Summary collapse
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.
- #close ⇒ Object
-
#confirm(value) ⇒ Object
Display a confirmation dialog with the passed string as text.
-
#console ⇒ Console
Get the Console for this window.
-
#document ⇒ DOM::Document
Get the DOM::Document for this window.
-
#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.
-
#scroll ⇒ Scroll
Get the Scroll for this window.
-
#send(message, options = {}) ⇒ Object
Send a message to the window.
-
#session_storage(name = :default) ⇒ SessionStorage
Get a session storage with the given name.
-
#size ⇒ Size
Get the Size for this window.
-
#storage(name = :default) ⇒ Storage
Get a storage with the given name.
-
#view ⇒ View
Get the View for the window.
Methods included from Event::Target
#off, #on, #on!, #trigger, #trigger!
Instance Attribute Details
#history ⇒ History (readonly)
Returns the history for this window.
85 86 87 |
# File 'opal/browser/history.rb', line 85 def history History.new(`#@native.history`) if `#@native.history` end |
#location ⇒ Location (readonly)
Returns the location for the window.
74 75 76 |
# File 'opal/browser/location.rb', line 74 def location Location.new(`#@native.location`) if `#@native.location` end |
Class Method Details
.open(url, options) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'opal/browser/window.rb', line 10 def self.open(url, ) name = .delete(:name) features = .map {|key, value| value = case value when true then :yes when false then :no else value end "#{key}=#{value}" }.join(?,) %x{ var win = window.open(#{url}, #{name}, #{features}); if (win == null) { return nil; } return #{new(`win`)}; } end |
Instance Method Details
#after(time, &block) ⇒ Delay
Execute a block after the given seconds.
39 40 41 |
# File 'opal/browser/delay.rb', line 39 def after(time, &block) Delay.new(@native, time, &block).tap(&:start) end |
#after!(time, &block) ⇒ Delay
Execute a block after the given seconds, you have to call [#start] on it yourself.
49 50 51 |
# File 'opal/browser/delay.rb', line 49 def after!(time, &block) Delay.new(@native, time, &block) end |
#alert(value) ⇒ Object
Alert the passed string.
41 42 43 44 45 |
# File 'opal/browser/window.rb', line 41 def alert(value) `#@native.alert(value)` value end |
#close ⇒ Object
92 93 94 95 96 97 98 |
# File 'opal/browser/window.rb', line 92 def close %x{ return (window.open('', '_self', '') && window.close()) || (window.opener = null && window.close()) || (window.opener = '' && window.close()); } end |
#confirm(value) ⇒ Object
Display a confirmation dialog with the passed string as text.
53 54 55 |
# File 'opal/browser/window.rb', line 53 def confirm(value) `#@native.confirm(value) || false` end |
#console ⇒ Console
Get the Console for this window.
96 97 98 |
# File 'opal/browser/console.rb', line 96 def console Console.new(`#@native.console`) end |
#document ⇒ DOM::Document
Get the DOM::Document for this window.
77 78 79 |
# File 'opal/browser/dom.rb', line 77 def document DOM(`#@native.document`) end |
#every(time, &block) ⇒ Interval
Execute the block every given seconds.
72 73 74 |
# File 'opal/browser/interval.rb', line 72 def every(time, &block) Interval.new(@native, time, &block).tap(&:start) end |
#every!(time, &block) ⇒ Interval
Execute the block every given seconds, you have to call [#start] on it yourself.
82 83 84 |
# File 'opal/browser/interval.rb', line 82 def every!(time, &block) Interval.new(@native, time, &block) end |
#prompt(value) ⇒ Object
Display a prompt dialog with the passed string as text.
48 49 50 |
# File 'opal/browser/window.rb', line 48 def prompt(value) `#@native.prompt(value) || nil` end |
#scroll ⇒ Scroll
Get the Scroll for this window.
74 75 76 |
# File 'opal/browser/window.rb', line 74 def scroll Scroll.new(self) end |
#send(message, options = {}) ⇒ Object
Send a message to the window.
87 88 89 |
# File 'opal/browser/window.rb', line 87 def send(, = {}) `#@native.postMessage(#{}, #{[:to] || '*'})` end |
#session_storage(name = :default) ⇒ SessionStorage
Get a session storage with the given name.
247 248 249 |
# File 'opal/browser/storage.rb', line 247 def session_storage(name = :default) SessionStorage.new(to_n, name) end |
#size ⇒ Size
Get the Size for this window.
67 68 69 |
# File 'opal/browser/window.rb', line 67 def size Size.new(self) end |