Skip to content

Commit ebdfd4e

Browse files
committed
Avoid calling scrollToTarget twice when rendering entry pages
1 parent 75b80a0 commit ebdfd4e

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

‎assets/javascripts/views/content/content.coffee‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ class app.views.Content extends app.View
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
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
121126
beforeRoute: (context) =>
122127
@cacheScrollPosition()
123128
@routeCtx = context
124-
@delay @scrollToTarget
129+
@scrollTimeout = @delay @scrollToTarget
125130
return
126131

127132
cacheScrollPosition: ->

0 commit comments

Comments
 (0)