Optimize scrolling code during page transitions

pull/647/merge
Thibaut Courouble 8 years ago
parent 6587b7d878
commit f891e16f39

@ -99,14 +99,12 @@ class app.views.Content extends app.View
return return
scrollToTarget: -> scrollToTarget: ->
return if @isLoading()
if @routeCtx.hash and el = @findTargetByHash @routeCtx.hash if @routeCtx.hash and el = @findTargetByHash @routeCtx.hash
$.scrollToWithImageLock el, @scrollEl, 'top', $.scrollToWithImageLock el, @scrollEl, 'top',
margin: if @scrollEl is @el then 0 else $.offset(@el).top margin: if @scrollEl is @el then 0 else $.offset(@el).top
$.highlight el, className: '_highlight' $.highlight el, className: '_highlight'
else else
@scrollTo @scrollMap[@routeCtx.state.id] @scrollTo @scrollMap[@routeCtx.state.id]
clearTimeout @scrollTimeout
return return
onReady: => onReady: =>
@ -120,21 +118,28 @@ class app.views.Content extends app.View
onEntryLoading: => onEntryLoading: =>
@showLoading() @showLoading()
if @scrollToTargetTimeout
clearTimeout @scrollToTargetTimeout
@scrollToTargetTimeout = null
return return
onEntryLoaded: => onEntryLoaded: =>
@hideLoading() @hideLoading()
if @scrollToTargetTimeout
clearTimeout @scrollToTargetTimeout
@scrollToTargetTimeout = null
@scrollToTarget() @scrollToTarget()
return return
beforeRoute: (context) => beforeRoute: (context) =>
@cacheScrollPosition() @cacheScrollPosition()
@routeCtx = context @routeCtx = context
@scrollTimeout = @delay @scrollToTarget @scrollToTargetTimeout = @delay @scrollToTarget
return return
cacheScrollPosition: -> cacheScrollPosition: ->
return if not @routeCtx or @routeCtx.hash return if not @routeCtx or @routeCtx.hash
return if @routeCtx.path is '/'
unless @scrollMap[@routeCtx.state.id]? unless @scrollMap[@routeCtx.state.id]?
@scrollStack.push @routeCtx.state.id @scrollStack.push @routeCtx.state.id

Loading…
Cancel
Save