From 248852c15f7ef3957aa25106c47c0c929ea34da8 Mon Sep 17 00:00:00 2001 From: Kevin Ewing Date: Thu, 20 Jun 2013 13:15:04 -0700 Subject: [PATCH 1/3] Implementing OpenSeadragon.now() Replacing both `+new Date()` and `new Date().getTime()` with `$.now()` --- src/button.js | 4 ++-- src/controldock.js | 2 +- src/drawer.js | 4 ++-- src/mousetracker.js | 4 ++-- src/navigator.js | 2 +- src/openseadragon.js | 4 ++-- src/profiler.js | 4 ++-- src/referencestrip.js | 6 +++--- src/spring.js | 4 ++-- src/viewer.js | 10 +++++----- 10 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/button.js b/src/button.js index d3b55291..7eead5da 100644 --- a/src/button.js +++ b/src/button.js @@ -287,7 +287,7 @@ function updateFade( button ) { opacity; if ( button.shouldFade ) { - currentTime = +new Date(); + currentTime = $.now(); deltaTime = currentTime - button.fadeBeginTime; opacity = 1.0 - deltaTime / button.fadeLength; opacity = Math.min( 1.0, opacity ); @@ -305,7 +305,7 @@ function updateFade( button ) { function beginFading( button ) { button.shouldFade = true; - button.fadeBeginTime = +new Date() + button.fadeDelay; + button.fadeBeginTime = $.now() + button.fadeDelay; window.setTimeout( function(){ scheduleFade( button ); }, button.fadeDelay ); diff --git a/src/controldock.js b/src/controldock.js index d7a17556..1102c244 100644 --- a/src/controldock.js +++ b/src/controldock.js @@ -46,7 +46,7 @@ i; $.extend( true, this, { - id: 'controldock-'+(+new Date())+'-'+Math.floor(Math.random()*1000000), + id: 'controldock-'+($.now())+'-'+Math.floor(Math.random()*1000000), container: $.makeNeutralElement('form'), controls: [] }, options ); diff --git a/src/drawer.js b/src/drawer.js index df644ece..032fa49b 100644 --- a/src/drawer.js +++ b/src/drawer.js @@ -299,7 +299,7 @@ $.Drawer.prototype = { */ reset: function() { clearTiles( this ); - this.lastResetTime = +new Date(); + this.lastResetTime = $.now(); this.updateAgain = true; return this; }, @@ -456,7 +456,7 @@ function updateViewport( drawer ) { level, best = null, haveDrawn = false, - currentTime = +new Date(), + currentTime = $.now(), viewportSize = drawer.viewport.getContainerSize(), viewportBounds = drawer.viewport.getBounds( true ), viewportTL = viewportBounds.getTopLeft(), diff --git a/src/mousetracker.js b/src/mousetracker.js index e4fd6c00..c7a937f4 100644 --- a/src/mousetracker.js +++ b/src/mousetracker.js @@ -677,7 +677,7 @@ delegate.lastPoint = getMouseAbsolute( event ); delegate.lastMouseDownPoint = delegate.lastPoint; - delegate.lastMouseDownTime = +new Date(); + delegate.lastMouseDownTime = $.now(); if ( tracker.pressHandler ) { propagate = tracker.pressHandler( @@ -920,7 +920,7 @@ return; } - var time = +new Date() - delegate.lastMouseDownTime, + var time = $.now() - delegate.lastMouseDownTime, point = getMouseAbsolute( event ), distance = delegate.lastMouseDownPoint.distanceTo( point ), quick = time <= tracker.clickTimeThreshold && diff --git a/src/navigator.js b/src/navigator.js index 25753509..957520d2 100644 --- a/src/navigator.js +++ b/src/navigator.js @@ -57,7 +57,7 @@ $.Navigator = function( options ){ //We may need to create a new element and id if they did not //provide the id for the existing element if( !options.id ){ - options.id = 'navigator-' + (+new Date()); + options.id = 'navigator-' + ($.now()); this.element = $.makeNeutralElement( "div" ); options.controlOptions = {anchor: $.ControlAnchor.TOP_RIGHT, attachToViewer: true, diff --git a/src/openseadragon.js b/src/openseadragon.js index 5b7b52a2..986f79b8 100644 --- a/src/openseadragon.js +++ b/src/openseadragon.js @@ -1386,7 +1386,7 @@ window.OpenSeadragon = window.OpenSeadragon || function( options ){ head = document.head || document.getElementsByTagName( "head" )[ 0 ] || document.documentElement, - jsonpCallback = options.callbackName || 'openseadragon' + (+new Date()), + jsonpCallback = options.callbackName || 'openseadragon' + ($.now), previous = window[ jsonpCallback ], replace = "$1" + jsonpCallback + "$2", callbackParam = options.param || 'callback', @@ -1700,7 +1700,7 @@ window.OpenSeadragon = window.OpenSeadragon || function( options ){ if ( !iIntervalId ) { iIntervalId = setInterval( function() { if ( aAnimQueue.length ) { - var time = new Date().getTime(); + var time = $.now(); // Process all of the currently outstanding frame // requests, but none that get added during the // processing. diff --git a/src/profiler.js b/src/profiler.js index 32dc7487..b7ed0712 100644 --- a/src/profiler.js +++ b/src/profiler.js @@ -77,7 +77,7 @@ $.Profiler.prototype = { } this.midUpdate = true; - this.lastBeginTime = new Date().getTime(); + this.lastBeginTime = $.now(); if (this.numUpdates < 1) { return; // this is the first update @@ -103,7 +103,7 @@ $.Profiler.prototype = { return; } - this.lastEndTime = new Date().getTime(); + this.lastEndTime = $.now(); this.midUpdate = false; var time = this.lastEndTime - this.lastBeginTime; diff --git a/src/referencestrip.js b/src/referencestrip.js index e9d778a0..c4325789 100644 --- a/src/referencestrip.js +++ b/src/referencestrip.js @@ -70,7 +70,7 @@ $.ReferenceStrip = function( options ){ //We may need to create a new element and id if they did not //provide the id for the existing element if( !options.id ){ - options.id = 'referencestrip-' + (+new Date()); + options.id = 'referencestrip-' + ($.now()); this.element = $.makeNeutralElement( "div" ); this.element.id = options.id; this.element.className = 'referencestrip'; @@ -192,12 +192,12 @@ $.ReferenceStrip = function( options ){ clickTimeThreshold: this.clickTimeThreshold, clickDistThreshold: this.clickDistThreshold, pressHandler: function( tracker ){ - tracker.dragging = +new Date(); + tracker.dragging = $.now(); }, releaseHandler: function( tracker, position, insideElementPress, insideElementRelease ){ var id = tracker.element.id, page = Number( id.split( '-' )[ 2 ] ), - now = +new Date(); + now = $.now(); if ( insideElementPress && insideElementRelease && diff --git a/src/spring.js b/src/spring.js index d2a77e6c..2ef2d220 100644 --- a/src/spring.js +++ b/src/spring.js @@ -76,7 +76,7 @@ $.Spring = function( options ) { value: typeof ( this.initial ) == "number" ? this.initial : 0, - time: new Date().getTime() // always work in milliseconds + time: $.now() // always work in milliseconds }; this.start = { @@ -127,7 +127,7 @@ $.Spring.prototype = { * @function */ update: function() { - this.current.time = new Date().getTime(); + this.current.time = $.now(); this.current.value = (this.current.time >= this.target.time) ? this.target.value : this.start.value + diff --git a/src/viewer.js b/src/viewer.js index 47cb9072..bad60ef9 100644 --- a/src/viewer.js +++ b/src/viewer.js @@ -1263,7 +1263,7 @@ function beginControlsAutoHide( viewer ) { } viewer.controlsShouldFade = true; viewer.controlsFadeBeginTime = - +new Date() + + $.now() + viewer.controlsFadeDelay; window.setTimeout( function(){ @@ -1279,7 +1279,7 @@ function updateControlsFade( viewer ) { opacity, i; if ( viewer.controlsShouldFade ) { - currentTime = new Date().getTime(); + currentTime = $.now(); deltaTime = currentTime - viewer.controlsFadeBeginTime; opacity = 1.0 - deltaTime / viewer.controlsFadeLength; @@ -1528,7 +1528,7 @@ function resolveUrl( prefix, url ) { function beginZoomingIn() { - THIS[ this.hash ].lastZoomTime = +new Date(); + THIS[ this.hash ].lastZoomTime = $.now(); THIS[ this.hash ].zoomFactor = this.zoomPerSecond; THIS[ this.hash ].zooming = true; scheduleZoom( this ); @@ -1536,7 +1536,7 @@ function beginZoomingIn() { function beginZoomingOut() { - THIS[ this.hash ].lastZoomTime = +new Date(); + THIS[ this.hash ].lastZoomTime = $.now(); THIS[ this.hash ].zoomFactor = 1.0 / this.zoomPerSecond; THIS[ this.hash ].zooming = true; scheduleZoom( this ); @@ -1559,7 +1559,7 @@ function doZoom() { adjustFactor; if ( THIS[ this.hash ].zooming && this.viewport) { - currentTime = +new Date(); + currentTime = $.now(); deltaTime = currentTime - THIS[ this.hash ].lastZoomTime; adjustedFactor = Math.pow( THIS[ this.hash ].zoomFactor, deltaTime / 1000 ); From 2ba3acda38030914dc24cab38fa442359805eaaa Mon Sep 17 00:00:00 2001 From: Kevin Ewing Date: Thu, 20 Jun 2013 13:23:16 -0700 Subject: [PATCH 2/3] Removed extra parens --- src/controldock.js | 2 +- src/navigator.js | 2 +- src/referencestrip.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/controldock.js b/src/controldock.js index 1102c244..50ae989b 100644 --- a/src/controldock.js +++ b/src/controldock.js @@ -46,7 +46,7 @@ i; $.extend( true, this, { - id: 'controldock-'+($.now())+'-'+Math.floor(Math.random()*1000000), + id: 'controldock-'+$.now()+'-'+Math.floor(Math.random()*1000000), container: $.makeNeutralElement('form'), controls: [] }, options ); diff --git a/src/navigator.js b/src/navigator.js index 957520d2..acd6da81 100644 --- a/src/navigator.js +++ b/src/navigator.js @@ -57,7 +57,7 @@ $.Navigator = function( options ){ //We may need to create a new element and id if they did not //provide the id for the existing element if( !options.id ){ - options.id = 'navigator-' + ($.now()); + options.id = 'navigator-' + $.now(); this.element = $.makeNeutralElement( "div" ); options.controlOptions = {anchor: $.ControlAnchor.TOP_RIGHT, attachToViewer: true, diff --git a/src/referencestrip.js b/src/referencestrip.js index c4325789..308bb6a4 100644 --- a/src/referencestrip.js +++ b/src/referencestrip.js @@ -70,7 +70,7 @@ $.ReferenceStrip = function( options ){ //We may need to create a new element and id if they did not //provide the id for the existing element if( !options.id ){ - options.id = 'referencestrip-' + ($.now()); + options.id = 'referencestrip-' + $.now(); this.element = $.makeNeutralElement( "div" ); this.element.id = options.id; this.element.className = 'referencestrip'; From 8896c2278dde4f6434a27ef44a3ea094ee239351 Mon Sep 17 00:00:00 2001 From: Kevin Ewing Date: Thu, 20 Jun 2013 13:31:04 -0700 Subject: [PATCH 3/3] Fixed mistake --- src/openseadragon.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/openseadragon.js b/src/openseadragon.js index 986f79b8..b9de0bda 100644 --- a/src/openseadragon.js +++ b/src/openseadragon.js @@ -1386,7 +1386,7 @@ window.OpenSeadragon = window.OpenSeadragon || function( options ){ head = document.head || document.getElementsByTagName( "head" )[ 0 ] || document.documentElement, - jsonpCallback = options.callbackName || 'openseadragon' + ($.now), + jsonpCallback = options.callbackName || 'openseadragon' + $.now(), previous = window[ jsonpCallback ], replace = "$1" + jsonpCallback + "$2", callbackParam = options.param || 'callback',