From dc81cde4ab31c42f358d054548c9fccb3d70b7fc Mon Sep 17 00:00:00 2001 From: Chris Adams Date: Tue, 18 Jun 2013 17:11:08 -0400 Subject: [PATCH 01/18] Grunt: stricter JSHint settings --- Gruntfile.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Gruntfile.js b/Gruntfile.js index 1c9f83c8..c568ccce 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -148,9 +148,14 @@ module.exports = function(grunt) { jshint: { options: { browser: true, + curly: true, eqeqeq: false, loopfunc: false, + noarg: true, trailing: true, + undef: true, + unused: true, + globals: { OpenSeadragon: true } From 6a214347d6c9480287529cc70a1fdefc4088308b Mon Sep 17 00:00:00 2001 From: Chris Adams Date: Tue, 18 Jun 2013 17:18:47 -0400 Subject: [PATCH 02/18] Upgrade to current JSHint This also allows us to move our settings to .jshintrc for better IDE & command-line integration - simply type "jshint" in the directory and it will use the same options. --- .jshintrc | 14 ++++++++++++++ Gruntfile.js | 13 +------------ package.json | 2 +- 3 files changed, 16 insertions(+), 13 deletions(-) create mode 100644 .jshintrc diff --git a/.jshintrc b/.jshintrc new file mode 100644 index 00000000..ef54d227 --- /dev/null +++ b/.jshintrc @@ -0,0 +1,14 @@ +{ + "browser": true, + "curly": true, + "eqeqeq": false, + "loopfunc": false, + "noarg": true, + "trailing": true, + "undef": true, + "unused": true, + + "globals": { + "OpenSeadragon": true + } +} diff --git a/Gruntfile.js b/Gruntfile.js index c568ccce..9e34ccd5 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -147,18 +147,7 @@ module.exports = function(grunt) { }, jshint: { options: { - browser: true, - curly: true, - eqeqeq: false, - loopfunc: false, - noarg: true, - trailing: true, - undef: true, - unused: true, - - globals: { - OpenSeadragon: true - } + jshintrc: '.jshintrc' }, beforeconcat: sources, afterconcat: [ distribution ] diff --git a/package.json b/package.json index 5f9dd1a4..8c653ab4 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "grunt": "~0.4.0", "grunt-contrib-compress": "~0.5.0", "grunt-contrib-concat": "~0.1.2", - "grunt-contrib-jshint": "~0.1.1", + "grunt-contrib-jshint": "~0.6.0", "grunt-contrib-uglify": "~0.2.2", "grunt-contrib-qunit": "~0.2.0", "grunt-contrib-connect": "~0.1.2", From 643ee211cad542a7f58116367f9793cb272d2b16 Mon Sep 17 00:00:00 2001 From: Chris Adams Date: Tue, 18 Jun 2013 17:55:19 -0400 Subject: [PATCH 03/18] Remove unused variables MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Mostly unused function arguments but there were also a fair number of legacy names which are now no longer used. One question which comes up – mostly in tilesource.js – is whether there is any value in leaving unused variables for functions which are intended to be overridden anyway. I'm inclined to say that the docs + tests need to be sufficient as there's no enforcement that whatever is in the base implementation will actually be followed by any of the real functions. --- src/controldock.js | 4 ---- src/drawer.js | 3 +-- src/dzitilesource.js | 6 +----- src/fullscreen.js | 3 +-- src/iiiftilesource.js | 7 +------ src/navigator.js | 5 ++--- src/openseadragon.js | 18 ++++++------------ src/referencestrip.js | 18 +++--------------- src/tilesource.js | 10 +++------- src/tilesourcecollection.js | 2 +- src/viewer.js | 7 ++----- src/viewport.js | 4 +--- 12 files changed, 22 insertions(+), 65 deletions(-) diff --git a/src/controldock.js b/src/controldock.js index d7a17556..2121966e 100644 --- a/src/controldock.js +++ b/src/controldock.js @@ -33,10 +33,6 @@ */ (function( $ ){ - - //id hash for private properties; - var THIS = {}; - /** * @class */ diff --git a/src/drawer.js b/src/drawer.js index df644ece..e0cba1d9 100644 --- a/src/drawer.js +++ b/src/drawer.js @@ -672,8 +672,7 @@ function updateTile( drawer, drawLevel, haveDrawn, x, y, level, levelOpacity, le numberOfTiles, drawer.normHeight ), - drawTile = drawLevel, - newbest; + drawTile = drawLevel; if( drawer.viewer ){ drawer.viewer.raiseEvent( 'update-tile', { diff --git a/src/dzitilesource.js b/src/dzitilesource.js index ea0b482b..7ca2a279 100644 --- a/src/dzitilesource.js +++ b/src/dzitilesource.js @@ -126,11 +126,7 @@ $.extend( $.DziTileSource.prototype, $.TileSource.prototype, { */ configure: function( data, url ){ - var dziPath, - dziName, - tilesUrl, - options, - host; + var options; if( !$.isPlainObject(data) ){ diff --git a/src/fullscreen.js b/src/fullscreen.js index c695283f..bde5b78c 100644 --- a/src/fullscreen.js +++ b/src/fullscreen.js @@ -112,7 +112,7 @@ element[this.prefix + 'RequestFullScreen'](); }; - fullScreenApi.cancelFullScreen = function( element ) { + fullScreenApi.cancelFullScreen = function() { return (this.prefix === '') ? document.cancelFullScreen() : document[this.prefix + 'CancelFullScreen'](); @@ -130,7 +130,6 @@ fullScreenApi.cancelFullScreen = fullScreenApi.requestFullScreen; } - // export api $.extend( $, fullScreenApi ); diff --git a/src/iiiftilesource.js b/src/iiiftilesource.js index cee77d0a..ae1896df 100644 --- a/src/iiiftilesource.js +++ b/src/iiiftilesource.js @@ -111,7 +111,6 @@ $.extend( $.IIIFTileSource.prototype, $.TileSource.prototype, { */ configure: function( data, url ){ var service, - identifier, options, host; @@ -236,11 +235,7 @@ function configureFromXml( tileSource, xmlDoc ){ var root = xmlDoc.documentElement, rootName = root.tagName, - configuration = null, - scale_factors, - formats, - qualities, - i; + configuration = null; if ( rootName == "info" ) { diff --git a/src/navigator.js b/src/navigator.js index 25753509..80d4a962 100644 --- a/src/navigator.js +++ b/src/navigator.js @@ -49,8 +49,7 @@ */ $.Navigator = function( options ){ - var _this = this, - viewer = options.viewer, + var viewer = options.viewer, viewerSize = $.getElementSize( viewer.element), unneededElement; @@ -199,7 +198,7 @@ $.extend( $.Navigator.prototype, $.EventHandler.prototype, $.Viewer.prototype, { bottomright = this.viewport.pixelFromPoint( bounds.getBottomRight()).minus(this.totalBorderWidths); //update style for navigator-box - (function(style, borderWidth){ + (function(style) { style.top = topleft.y + 'px'; style.left = topleft.x + 'px'; diff --git a/src/openseadragon.js b/src/openseadragon.js index 5b7b52a2..b6d7b5f2 100644 --- a/src/openseadragon.js +++ b/src/openseadragon.js @@ -747,11 +747,11 @@ window.OpenSeadragon = window.OpenSeadragon || function( options ){ */ getEvent: function( event ) { if( event ){ - $.getEvent = function( event ){ + $.getEvent = function( event ) { return event; }; } else { - $.getEvent = function( event ){ + $.getEvent = function() { return window.event; }; } @@ -1283,7 +1283,7 @@ window.OpenSeadragon = window.OpenSeadragon || function( options ){ request = new XMLHttpRequest(); } else if ( window.ActiveXObject ) { /*jshint loopfunc:true*/ - for ( i = 0; i < ACTIVEX.length; i++ ) { + for ( var i = 0; i < ACTIVEX.length; i++ ) { try { request = new ActiveXObject( ACTIVEX[ i ] ); $.createAjaxRequest = function( ){ @@ -1316,9 +1316,7 @@ window.OpenSeadragon = window.OpenSeadragon || function( options ){ var async = true, request = $.createAjaxRequest(), - actual, - options, - i; + options; if( $.isPlainObject( url ) ){ @@ -1453,12 +1451,9 @@ window.OpenSeadragon = window.OpenSeadragon || function( options ){ * Fully deprecated. Will throw an error. * @function * @name OpenSeadragon.createFromDZI - * @param {String} xmlUrl - * @param {String} xmlString - * @param {Function} callback * @deprecated - use OpenSeadragon.Viewer.prototype.open */ - createFromDZI: function( dzi, callback, tileHost ) { + createFromDZI: function() { throw "OpenSeadragon.createFromDZI is deprecated, use Viewer.open."; }, @@ -1476,8 +1471,7 @@ window.OpenSeadragon = window.OpenSeadragon || function( options ){ if ( window.ActiveXObject ) { $.parseXml = function( string ){ - var xmlDoc = null, - parser; + var xmlDoc = null; xmlDoc = new ActiveXObject( "Microsoft.XMLDOM" ); xmlDoc.async = false; diff --git a/src/referencestrip.js b/src/referencestrip.js index e9d778a0..800933da 100644 --- a/src/referencestrip.js +++ b/src/referencestrip.js @@ -61,8 +61,6 @@ $.ReferenceStrip = function( options ){ var _this = this, viewer = options.viewer, viewerSize = $.getElementSize( viewer.element ), - miniViewer, - minPixelRatio, element, style, i; @@ -273,14 +271,12 @@ $.extend( $.ReferenceStrip.prototype, $.EventHandler.prototype, $.Viewer.prototy * @function * @name OpenSeadragon.ReferenceStrip.prototype.update */ - update: function( viewport ){ - - if( THIS[ this.id ].animating ){ + update: function() { + if ( THIS[ this.id ].animating ) { $.console.log('image reference strip update'); return true; } return false; - } }); @@ -484,15 +480,7 @@ function onStripEnter( tracker ) { * @function */ function onStripExit( tracker ) { - - var viewerSize = $.getElementSize( this.viewer.element ); - - //$.setElementOpacity(tracker.element, 0.4); - //tracker.element.style.border = 'none'; - //tracker.element.style.background = '#fff'; - - - if( 'horizontal' == this.scroll ){ + if ( 'horizontal' == this.scroll ) { //tracker.element.style.paddingTop = "10px"; tracker.element.style.marginBottom = "-" + ( $.getElementSize( tracker.element ).y / 2 ) + "px"; diff --git a/src/tilesource.js b/src/tilesource.js index 717aecba..3168606e 100644 --- a/src/tilesource.js +++ b/src/tilesource.js @@ -84,9 +84,7 @@ * The maximum pyramid level this tile source supports or should attempt to load. */ $.TileSource = function( width, height, tileSize, tileOverlap, minLevel, maxLevel ) { - var _this = this, - callback = null, - readyHandler = null, + var callback = null, args = arguments, options, i; @@ -274,16 +272,14 @@ $.TileSource.prototype = { * @throws {Error} */ getImageInfo: function( url ) { - var _this = this, - error, + var _this = this, callbackName, callback, readySource, options, urlParts, filename, - lastDot, - tilesUrl; + lastDot; if( url ) { diff --git a/src/tilesourcecollection.js b/src/tilesourcecollection.js index dcf3b8df..218b2e4c 100644 --- a/src/tilesourcecollection.js +++ b/src/tilesourcecollection.js @@ -39,7 +39,7 @@ * @extends OpenSeadragon.TileSource */ $.TileSourceCollection = function( tileSize, tileSources, rows, layout ) { - + var options; if( $.isPlainObject( tileSize ) ){ options = tileSize; diff --git a/src/viewer.js b/src/viewer.js index 47cb9072..10b0735a 100644 --- a/src/viewer.js +++ b/src/viewer.js @@ -174,8 +174,7 @@ $.Viewer = function( options ) { $.ControlDock.call( this, options ); //Deal with tile sources - var initialTileSource, - customTileSource; + var initialTileSource; if ( this.xmlPath ){ //Deprecated option. Now it is preferred to use the tileSources option @@ -569,7 +568,6 @@ $.extend( $.Viewer.prototype, $.EventHandler.prototype, $.ControlDock.prototype, var body = document.body, bodyStyle = body.style, docStyle = document.documentElement.style, - containerStyle = this.element.style, canvasStyle = this.canvas.style, _this = this, oldBounds, @@ -635,7 +633,7 @@ $.extend( $.Viewer.prototype, $.EventHandler.prototype, $.ControlDock.prototype, body.appendChild( this.element ); if( $.supportsFullScreen ){ - THIS[ this.hash ].onfullscreenchange = function( event ) { + THIS[ this.hash ].onfullscreenchange = function() { // The event object doesn't carry information about the // fullscreen state of the browser, but it is possible to // retrieve it through the fullscreen API @@ -817,7 +815,6 @@ $.extend( $.Viewer.prototype, $.EventHandler.prototype, $.ControlDock.prototype, onNextHandler = $.delegate( this, onNext ), onPreviousHandler = $.delegate( this, onPrevious ), navImages = this.navImages, - buttons = [], useGroup = true ; if( this.showSequenceControl && THIS[ this.hash ].sequenced ){ diff --git a/src/viewport.js b/src/viewport.js index 5c6a95c2..3c560fd9 100644 --- a/src/viewport.js +++ b/src/viewport.js @@ -309,10 +309,8 @@ $.Viewport.prototype = { right, top, bottom, - center, dx = 0, - dy = 0, - dx1 = 0, dx2 = 0, dy1 = 0, dy2 = 0; + dy = 0; if ( actualZoom != constrainedZoom ) { this.zoomTo( constrainedZoom, this.zoomPoint, immediately ); From d644acd50b4c911f859633a2b8537ec6b5da06c2 Mon Sep 17 00:00:00 2001 From: Chris Adams Date: Tue, 18 Jun 2013 17:55:58 -0400 Subject: [PATCH 04/18] Fix lack of braces on if statements MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit JavaScript's most popular rack in the grass for maintenance coders… --- src/viewer.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/viewer.js b/src/viewer.js index 10b0735a..8b16b9dc 100644 --- a/src/viewer.js +++ b/src/viewer.js @@ -276,19 +276,21 @@ $.Viewer = function( options ) { case 119://w case 87://W case 38://up arrow - if (shiftKey) + if (shiftKey) { _this.viewport.zoomBy(1.1); - else + } else { _this.viewport.panBy(new $.Point(0, -0.05)); + } _this.viewport.applyConstraints(); return false; case 115://s case 83://S case 40://down arrow - if (shiftKey) + if (shiftKey) { _this.viewport.zoomBy(0.9); - else + } else { _this.viewport.panBy(new $.Point(0, 0.05)); + } _this.viewport.applyConstraints(); return false; case 97://a From f8c77f65d788f6828364cd8879de708a93a00518 Mon Sep 17 00:00:00 2001 From: Chris Adams Date: Tue, 18 Jun 2013 17:56:13 -0400 Subject: [PATCH 05/18] viewer.js: fix typos in variable declarations --- src/viewer.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/viewer.js b/src/viewer.js index 8b16b9dc..7c0183f2 100644 --- a/src/viewer.js +++ b/src/viewer.js @@ -1323,7 +1323,7 @@ function onBlur(){ } function onCanvasClick( tracker, position, quick, shift ) { - var zoomPreClick, + var zoomPerClick, factor; if ( this.viewport && quick ) { // ignore clicks where mouse moved zoomPerClick = this.zoomPerClick; @@ -1555,7 +1555,7 @@ function scheduleZoom( viewer ) { function doZoom() { var currentTime, deltaTime, - adjustFactor; + adjustedFactor; if ( THIS[ this.hash ].zooming && this.viewport) { currentTime = +new Date(); From 64d94ac2bd75b2a99aed10acd7064de3eaa22fd6 Mon Sep 17 00:00:00 2001 From: Chris Adams Date: Tue, 18 Jun 2013 17:56:39 -0400 Subject: [PATCH 06/18] referencestrip.js: declare undeclared variable --- src/referencestrip.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/referencestrip.js b/src/referencestrip.js index 800933da..ae20fdba 100644 --- a/src/referencestrip.js +++ b/src/referencestrip.js @@ -399,7 +399,7 @@ function loadPanels(strip, viewerSize, scroll){ activePanelsStart = activePanelsStart < 0 ? 0 : activePanelsStart; for( i = activePanelsStart; i < activePanelsEnd && i < strip.panels.length; i++ ){ - element = strip.panels[ i ]; + var element = strip.panels[ i ]; if ( !element.activePanel ){ miniViewer = new $.Viewer( { id: element.id, From e2bea810e383ea4c78d929c78785b8de4bf030ed Mon Sep 17 00:00:00 2001 From: Chris Adams Date: Tue, 18 Jun 2013 17:58:04 -0400 Subject: [PATCH 07/18] Replace gnarly ternary expression with if statement --- src/drawer.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/drawer.js b/src/drawer.js index e0cba1d9..86c1db90 100644 --- a/src/drawer.js +++ b/src/drawer.js @@ -1112,11 +1112,13 @@ function drawTiles( drawer, lastDrawn ){ position = collectionTileSource.layout == 'horizontal' ? tile.y + ( tile.x * collectionTileSource.rows ) : - tile.x + ( tile.y * collectionTileSource.rows ), + tile.x + ( tile.y * collectionTileSource.rows ); - tileSource = position < collectionTileSource.tileSources.length ? - collectionTileSource.tileSources[ position ] : - null; + if (position < collectionTileSource.tileSources.length) { + tileSource = collectionTileSource.tileSources[ position ]; + } else { + tileSource = null; + } //$.console.log("Rendering collection tile %s | %s | %s", tile.y, tile.y, position); if( tileSource ){ From 8c433ba81cf056b1a02a5a5adb93b84fe2e57138 Mon Sep 17 00:00:00 2001 From: Chris Adams Date: Tue, 18 Jun 2013 18:05:00 -0400 Subject: [PATCH 08/18] Declare assumed globals --- src/dzitilesource.js | 1 + src/fullscreen.js | 1 + src/openseadragon.js | 5 +++++ 3 files changed, 7 insertions(+) diff --git a/src/dzitilesource.js b/src/dzitilesource.js index 7ca2a279..9410ee68 100644 --- a/src/dzitilesource.js +++ b/src/dzitilesource.js @@ -31,6 +31,7 @@ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +/* global processDZIError:true */ (function( $ ){ diff --git a/src/fullscreen.js b/src/fullscreen.js index bde5b78c..feeab0b5 100644 --- a/src/fullscreen.js +++ b/src/fullscreen.js @@ -121,6 +121,7 @@ // Older IE. Support based on: // http://stackoverflow.com/questions/1125084/how-to-make-in-javascript-full-screen-windows-stretching-all-over-the-screen/7525760 fullScreenApi.requestFullScreen = function(){ + /* global ActiveXObject:true */ var wscript = new ActiveXObject("WScript.Shell"); if ( wscript !== null ) { wscript.SendKeys("{F11}"); diff --git a/src/openseadragon.js b/src/openseadragon.js index b6d7b5f2..dbd22e27 100644 --- a/src/openseadragon.js +++ b/src/openseadragon.js @@ -1283,6 +1283,7 @@ window.OpenSeadragon = window.OpenSeadragon || function( options ){ request = new XMLHttpRequest(); } else if ( window.ActiveXObject ) { /*jshint loopfunc:true*/ + /* global ActiveXObject:true */ for ( var i = 0; i < ACTIVEX.length; i++ ) { try { request = new ActiveXObject( ACTIVEX[ i ] ); @@ -1832,6 +1833,8 @@ window.OpenSeadragon = window.OpenSeadragon || function( options ){ * @deprecated */ function processDZI( imageNode, tilesUrl ) { + /* global imageFormatSupported:true */ + var fileFormat = imageNode.getAttribute( "Format" ), sizeNode = imageNode.getElementsByTagName( "Size" )[ 0 ], dispRectNodes = imageNode.getElementsByTagName( "DisplayRect" ), @@ -1883,6 +1886,8 @@ window.OpenSeadragon = window.OpenSeadragon || function( options ){ * @deprecated */ function processDZIJSON( imageData, tilesUrl ) { + /* global imageFormatSupported:true */ + var fileFormat = imageData.Format, sizeData = imageData.Size, dispRectData = imageData.DisplayRect || [], From eafc822aa8724d89668991e40618f4ca62835dcf Mon Sep 17 00:00:00 2001 From: Chris Adams Date: Tue, 18 Jun 2013 18:09:23 -0400 Subject: [PATCH 09/18] openseadragon.js: remove unused builtin aliases --- src/openseadragon.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/openseadragon.js b/src/openseadragon.js index dbd22e27..2eba0da9 100644 --- a/src/openseadragon.js +++ b/src/openseadragon.js @@ -291,11 +291,7 @@ window.OpenSeadragon = window.OpenSeadragon || function( options ){ }, // Save a reference to some core methods toString = Object.prototype.toString, - hasOwn = Object.prototype.hasOwnProperty, - push = Array.prototype.push, - slice = Array.prototype.slice, - trim = String.prototype.trim, - indexOf = Array.prototype.indexOf; + hasOwn = Object.prototype.hasOwnProperty; /** From 0d09183159d972f9b6784009095cb41f9e718c53 Mon Sep 17 00:00:00 2001 From: Chris Adams Date: Wed, 19 Jun 2013 14:14:09 -0400 Subject: [PATCH 10/18] referencestrip.js: move variable declaration to the top of loadPanels --- src/referencestrip.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/referencestrip.js b/src/referencestrip.js index ae20fdba..45c4c630 100644 --- a/src/referencestrip.js +++ b/src/referencestrip.js @@ -387,7 +387,8 @@ function loadPanels(strip, viewerSize, scroll){ activePanelsEnd, miniViewer, style, - i; + i, + element; if( 'horizontal' == strip.scroll ){ panelSize = strip.panelWidth; }else{ @@ -399,7 +400,7 @@ function loadPanels(strip, viewerSize, scroll){ activePanelsStart = activePanelsStart < 0 ? 0 : activePanelsStart; for( i = activePanelsStart; i < activePanelsEnd && i < strip.panels.length; i++ ){ - var element = strip.panels[ i ]; + element = strip.panels[ i ]; if ( !element.activePanel ){ miniViewer = new $.Viewer( { id: element.id, From 169244ed1a2c784be2bff16d5b504e7a332d0831 Mon Sep 17 00:00:00 2001 From: Chris Adams Date: Wed, 19 Jun 2013 15:15:26 -0400 Subject: [PATCH 11/18] navigator.js: omit unused borderWidth from func args --- src/navigator.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/navigator.js b/src/navigator.js index 80d4a962..60c775f5 100644 --- a/src/navigator.js +++ b/src/navigator.js @@ -209,7 +209,7 @@ $.extend( $.Navigator.prototype, $.EventHandler.prototype, $.Viewer.prototype, { style.width = Math.max( width, 0 ) + 'px'; style.height = Math.max( height, 0 ) + 'px'; - }( this.displayRegion.style, this.borderWidth)); + }( this.displayRegion.style )); } }, From 51bb8ca46ebce761d85e5666250c5976112880e0 Mon Sep 17 00:00:00 2001 From: Chris Adams Date: Wed, 19 Jun 2013 15:27:46 -0400 Subject: [PATCH 12/18] openseadragon.js: fix imageFormatSupported refs --- src/openseadragon.js | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/openseadragon.js b/src/openseadragon.js index 2eba0da9..4f0e5bce 100644 --- a/src/openseadragon.js +++ b/src/openseadragon.js @@ -1829,8 +1829,6 @@ window.OpenSeadragon = window.OpenSeadragon || function( options ){ * @deprecated */ function processDZI( imageNode, tilesUrl ) { - /* global imageFormatSupported:true */ - var fileFormat = imageNode.getAttribute( "Format" ), sizeNode = imageNode.getElementsByTagName( "Size" )[ 0 ], dispRectNodes = imageNode.getElementsByTagName( "DisplayRect" ), @@ -1843,7 +1841,7 @@ window.OpenSeadragon = window.OpenSeadragon || function( options ){ rectNode, i; - if ( !imageFormatSupported( fileFormat ) ) { + if ( !$.imageFormatSupported( fileFormat ) ) { throw new Error( $.getString( "Errors.ImageFormat", fileFormat.toUpperCase() ) ); @@ -1882,8 +1880,6 @@ window.OpenSeadragon = window.OpenSeadragon || function( options ){ * @deprecated */ function processDZIJSON( imageData, tilesUrl ) { - /* global imageFormatSupported:true */ - var fileFormat = imageData.Format, sizeData = imageData.Size, dispRectData = imageData.DisplayRect || [], @@ -1895,7 +1891,7 @@ window.OpenSeadragon = window.OpenSeadragon || function( options ){ rectData, i; - if ( !imageFormatSupported( fileFormat ) ) { + if ( !$.imageFormatSupported( fileFormat ) ) { throw new Error( $.getString( "Errors.ImageFormat", fileFormat.toUpperCase() ) ); From adc41473048434de5dc437f34ff3921d140103b6 Mon Sep 17 00:00:00 2001 From: Chris Adams Date: Wed, 19 Jun 2013 15:37:57 -0400 Subject: [PATCH 13/18] Expose semi-private processDZIError for use by DziTileSource This previously wasn't in scope outside of the main OpenSeadragon closure. Now it's exposed with an underscore prefix to encourage people not to think of it as a public interface. --- src/dzitilesource.js | 3 +-- src/openseadragon.js | 2 ++ 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/dzitilesource.js b/src/dzitilesource.js index 9410ee68..1bdfa9cf 100644 --- a/src/dzitilesource.js +++ b/src/dzitilesource.js @@ -31,7 +31,6 @@ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -/* global processDZIError:true */ (function( $ ){ @@ -284,7 +283,7 @@ function configureFromXML( tileSource, xmlDoc ){ } else if ( rootName == "Collection" ) { throw new Error( $.getString( "Errors.Dzc" ) ); } else if ( rootName == "Error" ) { - return processDZIError( root ); + return $._processDZIError( root ); } throw new Error( $.getString( "Errors.Dzi" ) ); diff --git a/src/openseadragon.js b/src/openseadragon.js index 4f0e5bce..0bd32ba5 100644 --- a/src/openseadragon.js +++ b/src/openseadragon.js @@ -1934,5 +1934,7 @@ window.OpenSeadragon = window.OpenSeadragon || function( options ){ throw new Error(message); } + // Add an alias so this is in-scope for dzitilesource but obviously not a blessed public method: + $._processDZIError = processDZIError; }( OpenSeadragon )); From 72f0f05d2f9114637e9008396c7f37dc7501ad39 Mon Sep 17 00:00:00 2001 From: Chris Adams Date: Wed, 19 Jun 2013 17:35:19 -0400 Subject: [PATCH 14/18] JSHint: disable unused variable check This is nice but until jshint/jshint#1146 is fixed there's no way to selectively disable W098 for unused function arguments which we wish to include for documentary purposes. With this change there are only three remaining warnings, all of which are actionable. --- .jshintrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.jshintrc b/.jshintrc index ef54d227..2c3f7d32 100644 --- a/.jshintrc +++ b/.jshintrc @@ -6,7 +6,7 @@ "noarg": true, "trailing": true, "undef": true, - "unused": true, + "unused": false, "globals": { "OpenSeadragon": true From de29a34890fd71643bcfc598c96904796da44a6d Mon Sep 17 00:00:00 2001 From: Chris Adams Date: Thu, 20 Jun 2013 15:07:09 -0400 Subject: [PATCH 15/18] viewer.js: remove dead code --- src/viewer.js | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/viewer.js b/src/viewer.js index 7c0183f2..05054eff 100644 --- a/src/viewer.js +++ b/src/viewer.js @@ -597,11 +597,6 @@ $.extend( $.Viewer.prototype, $.EventHandler.prototype, $.ControlDock.prototype, bodyStyle.width = "100%"; bodyStyle.height = "100%"; - //canvasStyle.backgroundColor = "black"; - //canvasStyle.color = "white"; - - //containerStyle.position = "fixed"; - //when entering full screen on the ipad it wasnt sufficient to leave //the body intact as only only the top half of the screen would //respond to touch events on the canvas, while the bottom half treated @@ -693,9 +688,6 @@ $.extend( $.Viewer.prototype, $.EventHandler.prototype, $.ControlDock.prototype, canvasStyle.backgroundColor = ""; canvasStyle.color = ""; - //containerStyle.position = "relative"; - //containerStyle.zIndex = ""; - body.removeChild( this.element ); nodes = this.previousBody.length; for ( i = 0; i < nodes; i++ ){ From 9ef6e085c8d864e13882dd5f94051317e7ad9078 Mon Sep 17 00:00:00 2001 From: Chris Adams Date: Thu, 20 Jun 2013 15:17:44 -0400 Subject: [PATCH 16/18] viewer.js: update onfullscreenchange handler comment --- src/viewer.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/viewer.js b/src/viewer.js index 05054eff..8232b9fa 100644 --- a/src/viewer.js +++ b/src/viewer.js @@ -631,9 +631,12 @@ $.extend( $.Viewer.prototype, $.EventHandler.prototype, $.ControlDock.prototype, if( $.supportsFullScreen ){ THIS[ this.hash ].onfullscreenchange = function() { - // The event object doesn't carry information about the - // fullscreen state of the browser, but it is possible to - // retrieve it through the fullscreen API + /* + fullscreenchange events don't include the new fullscreen status so we need to + retrieve the current status from the fullscreen API. See: + https://developer.mozilla.org/en-US/docs/Web/Reference/Events/fullscreenchange + */ + if( $.isFullScreen() ){ _this.setFullPage( true ); } else { From c2107fcb224ccc8650eae441f00b882853a8fdbd Mon Sep 17 00:00:00 2001 From: Chris Adams Date: Fri, 21 Jun 2013 16:37:31 -0400 Subject: [PATCH 17/18] Declare _processDZIError directly on OpenSeadragon --- src/openseadragon.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/openseadragon.js b/src/openseadragon.js index 0bd32ba5..ca9f741f 100644 --- a/src/openseadragon.js +++ b/src/openseadragon.js @@ -1814,7 +1814,7 @@ window.OpenSeadragon = window.OpenSeadragon || function( options ){ } else if ( rootName == "Collection" ) { throw new Error( $.getString( "Errors.Dzc" ) ); } else if ( rootName == "Error" ) { - return processDZIError( root ); + return $._processDZIError( root ); } throw new Error( $.getString( "Errors.Dzi" ) ); @@ -1928,13 +1928,11 @@ window.OpenSeadragon = window.OpenSeadragon || function( options ){ * @throws {Error} * @deprecated */ - function processDZIError( errorNode ) { + $._processDZIError = function ( errorNode ) { var messageNode = errorNode.getElementsByTagName( "Message" )[ 0 ], message = messageNode.firstChild.nodeValue; throw new Error(message); - } - // Add an alias so this is in-scope for dzitilesource but obviously not a blessed public method: - $._processDZIError = processDZIError; + }; }( OpenSeadragon )); From c648c1df8a41220809e9b9c86935421ce621bec4 Mon Sep 17 00:00:00 2001 From: Chris Adams Date: Tue, 25 Jun 2013 14:26:09 -0400 Subject: [PATCH 18/18] drawer: don't leak drawLevel into global namespace This code is still under-tested and documented but no longer relies on `drawLevel` being leaked into the global namespace where `updateLevel` to find it. See #145 --- src/drawer.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/drawer.js b/src/drawer.js index 86c1db90..cd110561 100644 --- a/src/drawer.js +++ b/src/drawer.js @@ -527,7 +527,9 @@ function updateViewport( drawer ) { lowestLevel = Math.min( lowestLevel, highestLevel ); //TODO + var drawLevel; // FIXME: drawLevel should have a more explanatory name for ( level = highestLevel; level >= lowestLevel; level-- ) { + drawLevel = false; //Avoid calculations for draw if we have already drawn this renderPixelRatioC = drawer.viewport.deltaPixelsFromPoints( @@ -572,6 +574,7 @@ function updateViewport( drawer ) { best = updateLevel( drawer, haveDrawn, + drawLevel, level, levelOpacity, levelVisibility, @@ -601,7 +604,7 @@ function updateViewport( drawer ) { } -function updateLevel( drawer, haveDrawn, level, levelOpacity, levelVisibility, viewportTL, viewportBR, currentTime, best ){ +function updateLevel( drawer, haveDrawn, drawLevel, level, levelOpacity, levelVisibility, viewportTL, viewportBR, currentTime, best ){ var x, y, tileTL,