Module: Situated::Viewport

Includes:
PositionAndSize
Included in:
Document, Window
Defined in:
lib/source/redshift/situated.rb

Instance Method Summary collapse

Methods included from PositionAndSize

#height, #left, #scroll_height, #scroll_left, #scroll_top, #scroll_width, #top, #width

Instance Method Details

#coordinatesObject

call-seq:

viewport.position -> hash

returns the coordinates of the viewport in pixesl as integers within a hash with the keys :top :left :bottom :right :height :width

For example, a viewport that is 500px wide and 800px tall will return viewport.coordinates {:top => 0,

:left    => 0,
:bottom  => 800,
:right   => 500,
:height  => 800,
:width   => 500 }


289
290
291
292
# File 'lib/source/redshift/situated.rb', line 289

def coordinates
  size = self.size
  return {:top => 0, :left => 0, :bottom => size[:y], :right => size[:x], :height => size[:y], :width => size[:x]}
end

#positionObject

call-seq:

viewport.position -> hash

returns the position of the viewport, which is always => 0, :y => 0



265
266
267
# File 'lib/source/redshift/situated.rb', line 265

def position
  return {:x => 0, :y => 0}
end

#scrollObject



249
250
251
252
253
# File 'lib/source/redshift/situated.rb', line 249

def scroll
  win = self.window
  doc = Situated::Utilities.native_compat_element(self)
  return {:x => `#{win}.__native__.pageXOffset` || `#{doc}.__native__.scrollLeft`, :y => `#{win}.__native__pageYOffset` || `#{doc}.__native__.scrollTop`}
end

#scroll_sizeObject



255
256
257
258
259
# File 'lib/source/redshift/situated.rb', line 255

def scroll_size
  doc = Situated::Utilities.native_compat_element(self)
  min = self.size
  return {:x => `Math.max(#{doc}.__native__.scrollWidth, #{min[:x]})`, :y => `Math.max(#{doc}.__native__.scrollHeight,#{ min[:y]})`}
end

#sizeObject



242
243
244
245
246
247
# File 'lib/source/redshift/situated.rb', line 242

def size
  win = self.window
  return {:x => `#{win}.__native__.innerWidth`, :y => `#{win}.__native__.innerHeight`} if (presto? || webkit?)
  doc = Situated::Utilities.native_compat_element(self)
  return {:x => `#{doc}.__native__.clientWidth`, :y => `#{doc}.__native__.clientHeight`}
end