History

Avoid calling scrollToTarget twice when rendering entry pages

Thibaut Courouble committed 10 years ago

Commit ebdfd4e1 parent 75b80a01 file · +6 −1Browse files

Showing the changes to assets/javascripts (1 of 1 file). Show all

Unified · Split

assets/javascripts/views/content/content.coffee+6−1
@@ -51,6 +51,9 @@ class app.views.Content extends app.View · 50 unmodified lines
5151 @addClass @constructor.loadingClass
5252 return
5353
54+ isLoading: ->
55+ @el.classList.contains @constructor.loadingClass
56+
5457 hideLoading: ->
5558 @removeClass @constructor.loadingClass
5659 return
@@ -92,12 +95,14 @@ class app.views.Content extends app.View · 35 unmodified lines
9295 return
9396
9497 scrollToTarget: ->
98+ return if @isLoading()
9599 if @routeCtx.hash and el = @findTargetByHash @routeCtx.hash
96100 $.scrollToWithImageLock el, @scrollEl, 'top',
97101 margin: 20 + if @scrollEl is @el then 0 else $.offset(@el).top
98102 $.highlight el, className: '_highlight'
99103 else
100104 @scrollTo @scrollMap[@routeCtx.state.id]
105+ clearTimeout @scrollTimeout
101106 return
102107
103108 onReady: =>
@@ -121,7 +126,7 @@ class app.views.Content extends app.View · 17 unmodified lines
121126 beforeRoute: (context) =>
122127 @cacheScrollPosition()
123128 @routeCtx = context
124− @delay @scrollToTarget
129+ @scrollTimeout = @delay @scrollToTarget
125130 return
126131
127132 cacheScrollPosition: ->