Sha256: 8b539e417faf4bd3ca8ae0b560cd6f5602e074512a93fbdbf85d722bb1351102

Contents?: true

Size: 1.27 KB

Versions: 6

Compression:

Stored size: 1.27 KB

Contents

# Firefox browsers need either a flag or a polyfill
require "browser/polyfill/visual_viewport"

module Browser
  # The mobile web contains two viewports, the Layout and Visual viewport.
  # The Layout viewport is what a page lays out its elements into and the
  # Visual viewport is what is actually visible on the screen. When the user
  # pinch-zooms into the page, the visual viewport shrinks but the layout viewport
  # is unchanged. UI like the on-screen keyboard (OSK) can also shrink the visual
  # viewport without affecting the layout viewport.
  #
  # https://github.com/WICG/visual-viewport
  # https://developer.mozilla.org/en-US/docs/Web/API/VisualViewport
  class VisualViewport
    include Native::Wrapper
    include Event::Target

    alias_native :offset_left, :offsetLeft
    alias_native :offset_top, :offsetTop
    alias_native :page_left, :pageLeft
    alias_native :page_top, :pageTop
    alias_native :width, :width
    alias_native :height, :height
    alias_native :scale, :scale

    attr_accessor :native
  end

  class Window
    def visual_viewport
      @visual_viewport ||= VisualViewport.new(`#@native.visualViewport`)

      # Polyfill can take some time to load
      @visual_viewport.native ||= `#@native.visualViewport`

      @visual_viewport
    end
  end
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
opal-browser-0.3.4 opal/browser/visual_viewport.rb
atome-opal-browser-0.3.9.5 opal/browser/visual_viewport.rb
opal-browser-0.3.3 opal/browser/visual_viewport.rb
opal-browser-0.3.2 opal/browser/visual_viewport.rb
opal-browser-0.3.1 opal/browser/visual_viewport.rb
opal-browser-0.3.0 opal/browser/visual_viewport.rb