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
51 @addClass @constructor.loadingClass51 @addClass @constructor.loadingClass
52 return52 return
53 53
54 isLoading: ->
55 @el.classList.contains @constructor.loadingClass
56
54 hideLoading: ->57 hideLoading: ->
55 @removeClass @constructor.loadingClass58 @removeClass @constructor.loadingClass
56 return59 return
@@ -92,12 +95,14 @@ class app.views.Content extends app.View · 35 unmodified lines
92 return95 return
93 96
94 scrollToTarget: ->97 scrollToTarget: ->
98 return if @isLoading()
95 if @routeCtx.hash and el = @findTargetByHash @routeCtx.hash99 if @routeCtx.hash and el = @findTargetByHash @routeCtx.hash
96 $.scrollToWithImageLock el, @scrollEl, 'top',100 $.scrollToWithImageLock el, @scrollEl, 'top',
97 margin: 20 + if @scrollEl is @el then 0 else $.offset(@el).top101 margin: 20 + if @scrollEl is @el then 0 else $.offset(@el).top
98 $.highlight el, className: '_highlight'102 $.highlight el, className: '_highlight'
99 else103 else
100 @scrollTo @scrollMap[@routeCtx.state.id]104 @scrollTo @scrollMap[@routeCtx.state.id]
105 clearTimeout @scrollTimeout
101 return106 return
102 107
103 onReady: =>108 onReady: =>
@@ -121,7 +126,7 @@ class app.views.Content extends app.View · 17 unmodified lines
121 beforeRoute: (context) =>126 beforeRoute: (context) =>
122 @cacheScrollPosition()127 @cacheScrollPosition()
123 @routeCtx = context128 @routeCtx = context
124 @delay @scrollToTarget129 @scrollTimeout = @delay @scrollToTarget
125 return130 return
126 131
127 cacheScrollPosition: ->132 cacheScrollPosition: ->