Sfoglia il codice sorgente

use timeout instead of requestAnimationFrame in pdf scroll handler

for simplicity as the time delay is large compared with rAF
Brian Gough 12 anni fa
parent
commit
c167e86ba5

+ 8 - 14
services/web/public/coffee/ide/pdfng/directives/pdfViewer.coffee

@@ -18,7 +18,7 @@ define [
 
 
 	# App = angular.module 'pdfViewerApp', ['pdfPage', 'PDFRenderer', 'pdfHighlights']
 	# App = angular.module 'pdfViewerApp', ['pdfPage', 'PDFRenderer', 'pdfHighlights']
 
 
-	App.controller 'pdfViewerController', ['$scope', '$q', 'PDFRenderer', '$element', 'pdfHighlights', ($scope, $q, PDFRenderer, $element, pdfHighlights) ->
+	App.controller 'pdfViewerController', ['$scope', '$q', '$timeout', 'PDFRenderer', '$element', 'pdfHighlights', ($scope, $q, $timeout, PDFRenderer, $element, pdfHighlights) ->
 		@load = () ->
 		@load = () ->
 			$scope.document = new PDFRenderer($scope.pdfSrc, {
 			$scope.document = new PDFRenderer($scope.pdfSrc, {
 				scale: 1,
 				scale: 1,
@@ -258,25 +258,19 @@ define [
 					#scope.$apply()
 					#scope.$apply()
 
 
 				element.on 'scroll', () ->
 				element.on 'scroll', () ->
+					#console.log 'scroll event', element.scrollTop(), 'adjusting?', scope.adjustingScroll
 					if scope.adjustingScroll
 					if scope.adjustingScroll
 						updateContainer()
 						updateContainer()
 						scope.$apply()
 						scope.$apply()
 						scope.adjustingScroll = false
 						scope.adjustingScroll = false
 						return
 						return
 					scope.scrolled = true
 					scope.scrolled = true
-					return if scope.handler?
-					scope.handler = requestAnimationFrame(scrollHandler)
-
-				scrollStart = null
-				SCROLL_TIMEOUT = 50
-				scrollHandler = (timestamp) ->
-					scrollStart = timestamp if !scrollStart?
-					progress = timestamp - scrollStart
-					if (progress < SCROLL_TIMEOUT)
-						scope.handler = requestAnimationFrame(scrollHandler)
-						return
-					scrollStart = null
-					scope.handler = null
+					if scope.scrollHandlerTimeout
+						$timeout.cancel(scope.scrollHandlerTimeout)
+					scope.scrollHandlerTimeout = $timeout scrollHandler, 100
+
+				scrollHandler = () ->
+					scope.scrollHandlerTimeout = null
 					updateContainer()
 					updateContainer()
 					scope.$apply()
 					scope.$apply()
 					scope.position = ctrl.getPdfPosition()
 					scope.position = ctrl.getPdfPosition()