Parcourir la source

Avoid calling scrollToTarget twice when rendering entry pages

Thibaut Courouble il y a 9 ans
Parent
commit
ebdfd4ea23
1 fichiers modifiés avec 6 ajouts et 1 suppressions
  1. 6 1
      assets/javascripts/views/content/content.coffee

+ 6 - 1
assets/javascripts/views/content/content.coffee

@@ -51,6 +51,9 @@ class app.views.Content extends app.View
     @addClass @constructor.loadingClass
     return
 
+  isLoading: ->
+    @el.classList.contains @constructor.loadingClass
+
   hideLoading: ->
     @removeClass @constructor.loadingClass
     return
@@ -92,12 +95,14 @@ class app.views.Content extends app.View
     return
 
   scrollToTarget: ->
+    return if @isLoading()
     if @routeCtx.hash and el = @findTargetByHash @routeCtx.hash
       $.scrollToWithImageLock el, @scrollEl, 'top',
         margin: 20 + if @scrollEl is @el then 0 else $.offset(@el).top
       $.highlight el, className: '_highlight'
     else
       @scrollTo @scrollMap[@routeCtx.state.id]
+    clearTimeout @scrollTimeout
     return
 
   onReady: =>
@@ -121,7 +126,7 @@ class app.views.Content extends app.View
   beforeRoute: (context) =>
     @cacheScrollPosition()
     @routeCtx = context
-    @delay @scrollToTarget
+    @scrollTimeout = @delay @scrollToTarget
     return
 
   cacheScrollPosition: ->