source/joosy/modules/page/scrolling.coffee in joosy-1.2.0.beta.4 vs source/joosy/modules/page/scrolling.coffee in joosy-1.2.0.rc.1

- old
+ new

@@ -1,11 +1,24 @@ #= require ../page +# +# The auto-scrolling filters for Page (or possibly widgets) +# +# @see Joosy.Page # @mixin +# Joosy.Modules.Page.Scrolling = included: -> + @afterLoad -> + @__performScrolling() if @__scrollElement + + @paint (complete) -> + @__fixHeight() if @__scrollElement && @__scrollSpeed != 0 + complete() + + ClassMethods: # # 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. @@ -15,40 +28,44 @@ # # @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={}) -> + # @example + # class TestPage extends Joosy.Page + # @scroll '#header', speed: 300, margin: -100 + # + scroll: (element, options={}) -> @::__scrollElement = element @::__scrollSpeed = options.speed || 500 @::__scrollMargin = options.margin || 0 - @paint (complete) -> - @__fixHeight() if @__scrollElement && @__scrollSpeed != 0 - complete() + InstanceMethods: + # + # Scrolls page to stored positions + # + # @private + # + __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() - @afterLoad -> - @__performScrolling() if @__scrollElement + # + # Freezes the page height through $(html). + # + # Required to implement better {Joosy.Modules.Page.Scrolling.scroll} behavior. + # + # @private + # + __fixHeight: -> + $('html').css 'min-height', $(document).height() - # - # 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', '' + # + # Undoes {Joosy.Modules.Page.Scrolling#__fixHeight} + # + # @private + # + __releaseHeight: -> + $('html').css 'min-height', '' \ No newline at end of file