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
99 return99 return
100 100
101 scrollToTarget: ->101 scrollToTarget: ->
102 return if @isLoading()
103 if @routeCtx.hash and el = @findTargetByHash @routeCtx.hash102 if @routeCtx.hash and el = @findTargetByHash @routeCtx.hash
104 $.scrollToWithImageLock el, @scrollEl, 'top',103 $.scrollToWithImageLock el, @scrollEl, 'top',
105 margin: if @scrollEl is @el then 0 else $.offset(@el).top104 margin: if @scrollEl is @el then 0 else $.offset(@el).top
106 $.highlight el, className: '_highlight'105 $.highlight el, className: '_highlight'
107 else106 else
108 @scrollTo @scrollMap[@routeCtx.state.id]107 @scrollTo @scrollMap[@routeCtx.state.id]
109 clearTimeout @scrollTimeout
110 return108 return
111 109
112 onReady: =>110 onReady: =>
@@ -120,21 +118,28 @@ class app.views.Content extends app.View · 7 unmodified lines
120 118
121 onEntryLoading: =>119 onEntryLoading: =>
122 @showLoading()120 @showLoading()
121 if @scrollToTargetTimeout
122 clearTimeout @scrollToTargetTimeout
123 @scrollToTargetTimeout = null
123 return124 return
124 125
125 onEntryLoaded: =>126 onEntryLoaded: =>
126 @hideLoading()127 @hideLoading()
128 if @scrollToTargetTimeout
129 clearTimeout @scrollToTargetTimeout
130 @scrollToTargetTimeout = null
127 @scrollToTarget()131 @scrollToTarget()
128 return132 return
129 133
130 beforeRoute: (context) =>134 beforeRoute: (context) =>
131 @cacheScrollPosition()135 @cacheScrollPosition()
132 @routeCtx = context136 @routeCtx = context
133 @scrollTimeout = @delay @scrollToTarget137 @scrollToTargetTimeout = @delay @scrollToTarget
134 return138 return
135 139
136 cacheScrollPosition: ->140 cacheScrollPosition: ->
137 return if not @routeCtx or @routeCtx.hash141 return if not @routeCtx or @routeCtx.hash
142 return if @routeCtx.path is '/'
138 143
139 unless @scrollMap[@routeCtx.state.id]?144 unless @scrollMap[@routeCtx.state.id]?
140 @scrollStack.push @routeCtx.state.id145 @scrollStack.push @routeCtx.state.id