From 40edbd7a1ce7f0ee26588371bb1d7856ed42fdb4 Mon Sep 17 00:00:00 2001 From: Grant Echols Date: Wed, 28 Oct 2015 17:07:51 -0600 Subject: [PATCH] Updates as per code review requests --- src/openseadragon.js | 4 ++-- src/viewer.js | 15 ++++++++------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/openseadragon.js b/src/openseadragon.js index ff677fdc..c0111b2b 100644 --- a/src/openseadragon.js +++ b/src/openseadragon.js @@ -255,7 +255,7 @@ * @property {Boolean} [preserveImageSizeOnResize=false] * Set to true to have the image size preserved when the viewer is resized. This requires autoResize=true (default). * - * @property {Number} [minScrollDeltaMS=3] + * @property {Number} [minScrollDeltaTime=50] * Number of milliseconds between canvas-scroll events. This value helps normalize the rate of canvas-scroll * events between different devices, causing the faster devices to slow down enough to make the zoom control * more manageable. @@ -1008,7 +1008,7 @@ if (typeof define === 'function' && define.amd) { pixelsPerWheelLine: 40, autoResize: true, preserveImageSizeOnResize: false, // requires autoResize=true - minScrollDeltaMS: 3, + minScrollDeltaTime: 50, //DEFAULT CONTROL SETTINGS showSequenceControl: true, //SEQUENCE diff --git a/src/viewer.js b/src/viewer.js index 3005a850..aad68718 100644 --- a/src/viewer.js +++ b/src/viewer.js @@ -203,6 +203,8 @@ $.Viewer = function( options ) { this._loadQueue = []; this.currentOverlays = []; + this._lastScrollTime = $.now(); // variable used to help normalize the scroll event speed of different devices + //Inherit some behaviors and properties $.EventSource.call( this ); @@ -2735,20 +2737,19 @@ function onCanvasPinch( event ) { return false; } -var lastScroll = new Date().getTime(); function onCanvasScroll( event ) { var gestureSettings, factor, - thisScroll, - deltaScroll; + thisScrollTime, + deltaScrollTime; /* Certain scroll devices fire the scroll event way too fast so we are injecting a simple adjustment to keep things * partially normalized. If we have already fired an event within the last 'minScrollDelta' milliseconds we skip * this one and wait for the next event. */ - thisScroll = new Date().getTime(); - deltaScroll = thisScroll - lastScroll; - if (deltaScroll > this.minScrollDeltaMS) { - lastScroll = thisScroll; + thisScrollTime = $.now(); + deltaScrollTime = thisScrollTime - this._lastScrollTime; + if (deltaScrollTime > this.minScrollDeltaTime) { + this._lastScrollTime = thisScrollTime; if ( !event.preventDefaultAction && this.viewport ) { gestureSettings = this.gestureSettingsByDeviceType( event.pointerType );