History

Optimize scrolling code during page transitions

Thibaut Courouble committed 9 years ago

Commit f891e161 parent 6587b7d1 file · +8 −3Browse files

Unified · Split

assets/javascripts/views/content/content.coffee+8−3
@@ -99,14 +99,12 @@ class app.views.Content extends app.View · 98 unmodified lines
9999 return
100100
101101 scrollToTarget: ->
102− return if @isLoading()
103102 if @routeCtx.hash and el = @findTargetByHash @routeCtx.hash
104103 $.scrollToWithImageLock el, @scrollEl, 'top',
105104 margin: if @scrollEl is @el then 0 else $.offset(@el).top
106105 $.highlight el, className: '_highlight'
107106 else
108107 @scrollTo @scrollMap[@routeCtx.state.id]
109− clearTimeout @scrollTimeout
110108 return
111109
112110 onReady: =>
@@ -120,21 +118,28 @@ class app.views.Content extends app.View · 7 unmodified lines
120118
121119 onEntryLoading: =>
122120 @showLoading()
121+ if @scrollToTargetTimeout
122+ clearTimeout @scrollToTargetTimeout
123+ @scrollToTargetTimeout = null
123124 return
124125
125126 onEntryLoaded: =>
126127 @hideLoading()
128+ if @scrollToTargetTimeout
129+ clearTimeout @scrollToTargetTimeout
130+ @scrollToTargetTimeout = null
127131 @scrollToTarget()
128132 return
129133
130134 beforeRoute: (context) =>
131135 @cacheScrollPosition()
132136 @routeCtx = context
133− @scrollTimeout = @delay @scrollToTarget
137+ @scrollToTargetTimeout = @delay @scrollToTarget
134138 return
135139
136140 cacheScrollPosition: ->
137141 return if not @routeCtx or @routeCtx.hash
142+ return if @routeCtx.path is '/'
138143
139144 unless @scrollMap[@routeCtx.state.id]?
140145 @scrollStack.push @routeCtx.state.id