Sha256: 7b1069c5fb61ca9d7f195c37e82eb1dc702729262cf26bad4f967db5cba83074

Contents?: true

Size: 1.54 KB

Versions: 13

Compression:

Stored size: 1.54 KB

Contents

# @mixin
Joosy.Modules.Page_Scrolling =

  included: ->
    #
    # Sets the position where page will be scrolled to after load.
    #
    # @note If you use animated scroll joosy will atempt to temporarily fix the
    #   height of your document while scrolling to prevent jump effect.
    #
    # @param [jQuery] element         Element to scroll to
    # @param [Hash] options
    #
    # @option options [Integer] speed       Sets the animation duration (500 is default)
    # @option options [Integer] margin      Defines the margin from element position.
    #   Can be negative.
    #
    @scroll = (element, options={}) ->
      @::__scrollElement = element
      @::__scrollSpeed = options.speed || 500
      @::__scrollMargin = options.margin || 0

    @paint (complete) ->
      @__fixHeight() if @__scrollElement && @__scrollSpeed != 0
      complete()

    @afterLoad ->
      @__performScrolling() if @__scrollElement

  #
  # Scrolls page to stored positions
  #
  __performScrolling: ->
    scroll = $(@__extractSelector @__scrollElement).offset()?.top + @__scrollMargin
    Joosy.Modules.Log.debugAs @, "Scrolling to #{@__extractSelector @__scrollElement}"
    $('html, body').animate {scrollTop: scroll}, @__scrollSpeed, =>
      if @__scrollSpeed != 0
        @__releaseHeight()

  #
  # Freezes the page height through $(html).
  #
  # Required to implement better {Joosy.Page.scroll} behavior.
  #
  __fixHeight: ->
    $('html').css 'min-height', $(document).height()

  #
  # Undo {#__fixHeight}
  #
  __releaseHeight: ->
    $('html').css 'min-height', ''

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
joosy-1.2.0.alpha.70 source/joosy/modules/page/scrolling.coffee
joosy-1.2.0.alpha.68 source/joosy/modules/page/scrolling.coffee
joosy-1.2.0.alpha.67 source/joosy/modules/page/scrolling.coffee
joosy-1.2.0.alpha.66 source/joosy/modules/page/scrolling.coffee
joosy-1.2.0.alpha.65 source/joosy/modules/page/scrolling.coffee
joosy-1.2.0.alpha.64 source/joosy/modules/page/scrolling.coffee
joosy-1.2.0.alpha.63 source/joosy/modules/page/scrolling.coffee
joosy-1.2.0.alpha.62 source/joosy/modules/page/scrolling.coffee
joosy-1.2.0.alpha.59 source/joosy/modules/page/scrolling.coffee
joosy-1.2.0.alpha.58 source/joosy/modules/page/scrolling.coffee
joosy-1.2.0.alpha.57 source/joosy/modules/page/scrolling.coffee
joosy-1.2.0.alpha.56 source/joosy/modules/page/scrolling.coffee
joosy-1.2.0.alpha.55 source/joosy/modules/page/scrolling.coffee