Class: Browser::Window
- Includes:
- Event::Target, NativeCachedWrapper
- Defined in:
- opal/browser/window.rb,
opal/browser/dom.rb,
opal/browser/delay.rb,
opal/browser/crypto.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/visual_viewport.rb more...
Overview
Wrapper class for the window
object, an instance of it gets
set to $window
.
Defined Under Namespace
Instance Attribute Summary collapse
-
#crypto ⇒ Crypto
readonly
The crypto interface of this window.
-
#history ⇒ History
readonly
The history for this window.
-
#location ⇒ Location
readonly
The location for the window.
-
#navigator ⇒ Navigator
readonly
The navigator.
-
#opener ⇒ Window
readonly
Reference to the window that opened the window using
open
. -
#parent ⇒ Window
readonly
Parent of the current window or subframe.
-
#screen ⇒ Screen
readonly
The screen for the window.
-
#top ⇒ Window
readonly
Reference to the topmost window in the window hierarchy.
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, 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.
-
#scroll ⇒ DOM::Element::Scroll
Get the DOM::Element::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.
- #visual_viewport ⇒ Object
Methods included from Event::Target
#off, #on, #on!, #one, #trigger, #trigger!
Methods included from NativeCachedWrapper
#restricted?, #set_native_reference
Instance Attribute Details
permalink #crypto ⇒ Crypto (readonly)
Returns the crypto interface of this window.
75 76 77 |
# File 'opal/browser/crypto.rb', line 75 def crypto @crypto ||= Crypto.new(`#@native.crypto`) end |
permalink #history ⇒ History (readonly)
Returns the history for this window.
82 83 84 |
# File 'opal/browser/history.rb', line 82 def history History.new(`#@native.history`) if `#@native.history` end |
permalink #location ⇒ Location (readonly)
Returns the location for the window.
81 82 83 |
# File 'opal/browser/location.rb', line 81 def location Location.new(`#@native.location`) if `#@native.location` end |
permalink #navigator ⇒ Navigator (readonly)
Returns the navigator.
270 271 272 |
# File 'opal/browser/navigator.rb', line 270 def navigator @navigator ||= Navigator.new(`#@native.navigator`) if `#@native.navigator` end |
permalink #opener ⇒ Window (readonly)
Returns reference to the window that opened the window using open
.
71 72 73 |
# File 'opal/browser/window.rb', line 71 def opener @opener ||= Browser::Window.new(`#@native.opener`) end |
permalink #parent ⇒ Window (readonly)
Returns parent of the current window or subframe.
59 60 61 |
# File 'opal/browser/window.rb', line 59 def parent @parent ||= Browser::Window.new(`#@native.parent`) end |
Class Method Details
permalink .open(url, options) ⇒ Object
[View source]
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
permalink #after(time, &block) ⇒ Delay
Execute a block after the given seconds.
40 41 42 |
# File 'opal/browser/delay.rb', line 40 def after(time, &block) Delay.new(@native, time, &block).tap(&:start) end |
permalink #after!(time, &block) ⇒ Delay
Execute a block after the given seconds, you have to call [#start] on it yourself.
50 51 52 |
# File 'opal/browser/delay.rb', line 50 def after!(time, &block) Delay.new(@native, time, &block) end |
permalink #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 |
permalink #close ⇒ Object
[View source]
110 111 112 |
# File 'opal/browser/window.rb', line 110 def close `#{@native}.close()` end |
permalink #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 |
permalink #console ⇒ Console
Get the Console for this window.
99 100 101 |
# File 'opal/browser/console.rb', line 99 def console Console.new(`#@native.console`) end |
permalink #document ⇒ DOM::Document
Get the DOM::Document for this window.
111 112 113 |
# File 'opal/browser/dom.rb', line 111 def document DOM(`#@native.document`) end |
permalink #every(time, &block) ⇒ Interval
Execute the block every given seconds.
73 74 75 |
# File 'opal/browser/interval.rb', line 73 def every(time, &block) Interval.new(@native, time, &block).tap(&:start) end |
permalink #every!(time, &block) ⇒ Interval
Execute the block every given seconds, you have to call [#start] on it yourself.
83 84 85 |
# File 'opal/browser/interval.rb', line 83 def every!(time, &block) Interval.new(@native, time, &block) end |
permalink #prompt(value, default = nil) ⇒ Object
Display a prompt dialog with the passed string as text.
48 49 50 |
# File 'opal/browser/window.rb', line 48 def prompt(value, default=nil) `#@native.prompt(value, #{default || ""}) || nil` end |
permalink #resolve_after(time) ⇒ Promise
Returns a promise that will resolve after the given seconds.
59 60 61 62 63 |
# File 'opal/browser/delay.rb', line 59 def resolve_after(time) promise = Promise.new Delay.new(@native, time) { promise.resolve }.start promise end |
permalink #scroll ⇒ DOM::Element::Scroll
Get the DOM::Element::Scroll for this window.
92 93 94 |
# File 'opal/browser/window.rb', line 92 def scroll @scroll ||= DOM::Element::Scroll.new(self) end |
permalink #send(message, options = {}) ⇒ Object
Send a message to the window.
105 106 107 |
# File 'opal/browser/window.rb', line 105 def send(, = {}) `#@native.postMessage(#{}, #{[:to] || '*'})` end |
permalink #session_storage(name = :default) ⇒ SessionStorage
Get a session storage with the given name.
248 249 250 |
# File 'opal/browser/storage.rb', line 248 def session_storage(name = :default) SessionStorage.new(to_n, name) end |
permalink #size ⇒ Size
Get the Size for this window.
85 86 87 |
# File 'opal/browser/window.rb', line 85 def size @size ||= Size.new(self) end |
permalink #storage(name = :default) ⇒ Storage
Get a storage with the given name.
239 240 241 |
# File 'opal/browser/storage.rb', line 239 def storage(name = :default) Storage.new(to_n, name) end |
permalink #view ⇒ View
Get the View for the window.
78 79 80 |
# File 'opal/browser/window.rb', line 78 def view @view ||= View.new(self) end |
permalink #visual_viewport ⇒ Object
[View source]
31 32 33 34 35 36 37 38 |
# File 'opal/browser/visual_viewport.rb', line 31 def @visual_viewport ||= VisualViewport.new(`#@native.visualViewport`) # Polyfill can take some time to load @visual_viewport.native ||= `#@native.visualViewport` @visual_viewport end |