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.



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

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

Instance Method Details

#heightObject

Raises:

  • (NotImplementedError)


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

def height
  `#@native.innerHeight`
end

#on_zoom(&block) ⇒ Object

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



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

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

#widthObject

Raises:

  • (NotImplementedError)


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

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.



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

def zoom
  `#@native.devicePixelRatio`
end