Sha256: d50ebdfb66d79e2842518724b448ba44a4c53630017f3f90508dbc494d3439bd

Contents?: true

Size: 1.02 KB

Versions: 2

Compression:

Stored size: 1.02 KB

Contents

module Browser; class Window

# Allows access and manipulation of the {Window} size.
class Size
  # @private
  def initialize(window)
    @window = window
    @native = window.to_n
  end

  def set(*args)
    if Hash === args.first
      width, height = args.first.values_at(:width, :height)
    else
      width, height = args
    end

    width  ||= self.width
    height ||= self.height

    `#@native.resizeTo(#{width}, #{height})`

    self
  end

  # @!attribute width
  # @return [Integer] the width of the window

  # @!attribute height
  # @return [Integer] the height of the window

  if Browser.supports? 'Window.outerSize'
    def width
      `#@native.outerWidth`
    end

    def height
      `#@native.outerHeight`
    end
  else
    def width
      raise NotImplementedError, 'window outer size not supported'
    end

    def height
      raise NotImplementedError, 'window outer size not supported'
    end
  end

  def width=(value)
    set(width: value)
  end

  def height=(value)
    set(height: value)
  end
end

end; end

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
diamonds-0.1.5 lib/diamonds/opal/browser/window/size.rb
opal-browser-0.2.0 opal/browser/window/size.rb