Class: Browser::Window::View

Inherits:
Object
  • Object
show all
Defined in:
opal/browser/window/view.rb

Instance Method Summary collapse

Constructor Details

#initialize(window) ⇒ View

Returns a new instance of View.


4
5
6
7
# File 'opal/browser/window/view.rb', line 4

def initialize(window)
  @window = window
  @native = window.to_n
end

Instance Method Details

#heightObject

Raises:

  • (NotImplementedError)

14
15
16
# File 'opal/browser/window/view.rb', line 14

def height
  `#@native.innerHeight`
end

#on_zoom(&block) ⇒ Object

Handle #pixel_ratio changes. This will trigger a block on zoom.


43
44
45
46
47
48
# File 'opal/browser/window/view.rb', line 43

def on_zoom &block
  %x{
    var mqString = "(resolution: " + #@native.devicePixelRatio + "dppx)";
    #@native.matchMedia(mqString).addListener(#{block.to_n});
  }
end

#widthObject

Raises:

  • (NotImplementedError)

10
11
12
# File 'opal/browser/window/view.rb', line 10

def width
  `#@native.innerWidth`
end

#zoomObject

Get a device pixel ratio. Can be used to handle desktop browser zoom, retina devices and custom screen scale for mobile devices. Use $window.visual_viewport.scale to handle mobile zoom.


38
39
40
# File 'opal/browser/window/view.rb', line 38

def zoom
  `#@native.devicePixelRatio`
end