Sha256: d2a896d97225322e675423a699305086dd4845cb8a6cb6f4cb7fa3dcd5533e64

Contents?: true

Size: 1.36 KB

Versions: 15

Compression:

Stored size: 1.36 KB

Contents

# backtick_javascript: true

module Browser
  module Window
    extend DelegateNative
    extend EventTarget

    @native = `window`

    module_function

    if `#@native.requestAnimationFrame !== undefined`
      # Add the given block to the current iteration of the event loop. If this
      # is called from another `animation_frame` call, the block is run in the
      # following iteration of the event loop.
      def animation_frame &block
        `requestAnimationFrame(function(now) { #{block.call `now`} })`
        self
      end
    else
      def animation_frame &block
        after(0, &block)
        self
      end
    end

    # Run the given block every `duration` seconds
    #
    # @param duration [Numeric] the number of seconds between runs
    def set_interval duration, &block
      `setInterval(function() { #{block.call} }, duration)`
    end

    def set_timeout duration, &block
      `setTimeout(function() { #{block.call} }, duration)`
    end

    # return [History] the browser's History object
    def history
      Browser::History.new(`window.history`)
    end

    # @return [Location] the browser's Location object
    def location
      Browser::Location.new(`window.location`)
    end

    # Scroll to the specified (x,y) coordinates
    def scroll x, y
      `window.scrollTo(x, y)`
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
isomorfeus-preact-23.9.0.rc12 lib/browser_auto/browser/window.rb
isomorfeus-preact-23.9.0.rc11 lib/browser_auto/browser/window.rb
isomorfeus-preact-23.9.0.rc10 lib/browser_auto/browser/window.rb
isomorfeus-preact-23.9.0.rc9 lib/browser_auto/browser/window.rb
isomorfeus-preact-23.9.0.rc8 lib/browser_auto/browser/window.rb
isomorfeus-preact-23.9.0.rc7 lib/browser_auto/browser/window.rb
isomorfeus-preact-23.9.0.rc6 lib/browser_auto/browser/window.rb
isomorfeus-preact-23.9.0.rc5 lib/browser_auto/browser/window.rb
isomorfeus-preact-23.9.0.rc4 lib/browser_auto/browser/window.rb
isomorfeus-preact-23.9.0.rc3 lib/browser_auto/browser/window.rb
isomorfeus-preact-23.9.0.rc2 lib/browser_auto/browser/window.rb
isomorfeus-preact-23.9.0.rc1 lib/browser_auto/browser/window.rb
isomorfeus-preact-23.8.0.rc3 lib/browser/window.rb
isomorfeus-preact-23.8.0.rc2 lib/browser/window.rb
isomorfeus-preact-23.8.0.rc1 lib/browser/window.rb