Sha256: 76119030b6351542600e56085f0bf429b6ab14aff8464baa6e744c50698f30b6

Contents?: true

Size: 1.33 KB

Versions: 21

Compression:

Stored size: 1.33 KB

Contents

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

21 entries across 21 versions & 1 rubygems

Version Path
isomorfeus-preact-23.7.0.rc5 lib/browser/window.rb
isomorfeus-preact-23.7.0.rc4 lib/browser/window.rb
isomorfeus-preact-23.7.0.rc3 lib/browser/window.rb
isomorfeus-preact-23.7.0.rc2 lib/browser/window.rb
isomorfeus-preact-23.7.0.rc1 lib/browser/window.rb
isomorfeus-preact-23.6.0.rc5 lib/browser/window.rb
isomorfeus-preact-23.6.0.rc4 lib/browser/window.rb
isomorfeus-preact-23.6.0.rc3 lib/browser/window.rb
isomorfeus-preact-23.6.0.rc2 lib/browser/window.rb
isomorfeus-preact-23.6.0.rc1 lib/browser/window.rb
isomorfeus-preact-23.1.0.rc2 lib/browser/window.rb
isomorfeus-preact-23.1.0.rc1 lib/browser/window.rb
isomorfeus-preact-22.11.0.rc1 lib/browser/window.rb
isomorfeus-preact-22.10.0.rc2 lib/browser/window.rb
isomorfeus-preact-22.10.0.rc1 lib/browser/window.rb
isomorfeus-preact-22.9.0.rc9 lib/browser/window.rb
isomorfeus-preact-22.9.0.rc8 lib/browser/window.rb
isomorfeus-preact-22.9.0.rc7 lib/browser/window.rb
isomorfeus-preact-22.9.0.rc6 lib/browser/window.rb
isomorfeus-preact-22.9.0.rc5 lib/browser/window.rb