Sha256: aae44faedb44d82127877785ae2f8d0ef351e111ea624b054e9c95af9d9abb72

Contents?: true

Size: 940 Bytes

Versions: 6

Compression:

Stored size: 940 Bytes

Contents

require 'opal/jquery/element'

module Browser
  # {Window} instances are {Native} objects used to wrap native window instances.
  #
  # Generally, you will want to use the top level {::Window} instance, which
  # wraps `window` from the main page.
  class Window
    include Native

    # Returns this {Window} instance wrapped as an {Element}. Useful for
    # delegating jQuery events, which allows the use of `window` as target.
    #
    # @return [Element]
    def element
      @element ||= Element.find(`window`)
    end

    # @see Element#on
    def on(*args, &block)
      element.on(*args, &block)
    end

    # @see Element#off
    def off(*args, &block)
      element.off(*args, &block)
    end

    # @see Element#trigger
    def trigger(*args)
      element.trigger(*args)
    end
  end
end

# Top level {Browser::Window} instance.
Window = Browser::Window.new(`window`)

# TODO: this will be removed soon.
$window = Window

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
opal-jquery-0.4.3 lib/opal/jquery/window.rb
opal-jquery-0.4.2 lib/opal/jquery/window.rb
opal-jquery-0.4.1 lib/opal/jquery/window.rb
opal-jquery-0.4.0 lib/opal/jquery/window.rb
opal-jquery-0.3.0 lib/opal/jquery/window.rb
opal-jquery-0.3.0.beta2 lib/opal/jquery/window.rb