Merge pull request #136 from acdha/jshint-cleanup

JSHint tidying
This commit is contained in:
iangilman 2013-06-26 09:37:08 -07:00
commit 8fe0ce26b8
15 changed files with 74 additions and 108 deletions

14
.jshintrc Normal file
View File

@ -0,0 +1,14 @@
{
"browser": true,
"curly": true,
"eqeqeq": false,
"loopfunc": false,
"noarg": true,
"trailing": true,
"undef": true,
"unused": false,
"globals": {
"OpenSeadragon": true
}
}

View File

@ -147,13 +147,7 @@ module.exports = function(grunt) {
}, },
jshint: { jshint: {
options: { options: {
browser: true, jshintrc: '.jshintrc'
eqeqeq: false,
loopfunc: false,
trailing: true,
globals: {
OpenSeadragon: true
}
}, },
beforeconcat: sources, beforeconcat: sources,
afterconcat: [ distribution ] afterconcat: [ distribution ]

View File

@ -6,7 +6,7 @@
"grunt": "~0.4.0", "grunt": "~0.4.0",
"grunt-contrib-compress": "~0.5.0", "grunt-contrib-compress": "~0.5.0",
"grunt-contrib-concat": "~0.1.2", "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-uglify": "~0.2.2",
"grunt-contrib-qunit": "~0.2.0", "grunt-contrib-qunit": "~0.2.0",
"grunt-contrib-connect": "~0.1.2", "grunt-contrib-connect": "~0.1.2",

View File

@ -33,10 +33,6 @@
*/ */
(function( $ ){ (function( $ ){
//id hash for private properties;
var THIS = {};
/** /**
* @class * @class
*/ */

View File

@ -527,7 +527,9 @@ function updateViewport( drawer ) {
lowestLevel = Math.min( lowestLevel, highestLevel ); lowestLevel = Math.min( lowestLevel, highestLevel );
//TODO //TODO
var drawLevel; // FIXME: drawLevel should have a more explanatory name
for ( level = highestLevel; level >= lowestLevel; level-- ) { for ( level = highestLevel; level >= lowestLevel; level-- ) {
drawLevel = false;
//Avoid calculations for draw if we have already drawn this //Avoid calculations for draw if we have already drawn this
renderPixelRatioC = drawer.viewport.deltaPixelsFromPoints( renderPixelRatioC = drawer.viewport.deltaPixelsFromPoints(
@ -572,6 +574,7 @@ function updateViewport( drawer ) {
best = updateLevel( best = updateLevel(
drawer, drawer,
haveDrawn, haveDrawn,
drawLevel,
level, level,
levelOpacity, levelOpacity,
levelVisibility, 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, var x, y,
tileTL, tileTL,
@ -672,8 +675,7 @@ function updateTile( drawer, drawLevel, haveDrawn, x, y, level, levelOpacity, le
numberOfTiles, numberOfTiles,
drawer.normHeight drawer.normHeight
), ),
drawTile = drawLevel, drawTile = drawLevel;
newbest;
if( drawer.viewer ){ if( drawer.viewer ){
drawer.viewer.raiseEvent( 'update-tile', { drawer.viewer.raiseEvent( 'update-tile', {
@ -1113,11 +1115,13 @@ function drawTiles( drawer, lastDrawn ){
position = collectionTileSource.layout == 'horizontal' ? position = collectionTileSource.layout == 'horizontal' ?
tile.y + ( tile.x * collectionTileSource.rows ) : tile.y + ( tile.x * collectionTileSource.rows ) :
tile.x + ( tile.y * collectionTileSource.rows ), tile.x + ( tile.y * collectionTileSource.rows );
tileSource = position < collectionTileSource.tileSources.length ? if (position < collectionTileSource.tileSources.length) {
collectionTileSource.tileSources[ position ] : tileSource = collectionTileSource.tileSources[ position ];
null; } else {
tileSource = null;
}
//$.console.log("Rendering collection tile %s | %s | %s", tile.y, tile.y, position); //$.console.log("Rendering collection tile %s | %s | %s", tile.y, tile.y, position);
if( tileSource ){ if( tileSource ){

View File

@ -126,11 +126,7 @@ $.extend( $.DziTileSource.prototype, $.TileSource.prototype, {
*/ */
configure: function( data, url ){ configure: function( data, url ){
var dziPath, var options;
dziName,
tilesUrl,
options,
host;
if( !$.isPlainObject(data) ){ if( !$.isPlainObject(data) ){
@ -287,7 +283,7 @@ function configureFromXML( tileSource, xmlDoc ){
} else if ( rootName == "Collection" ) { } else if ( rootName == "Collection" ) {
throw new Error( $.getString( "Errors.Dzc" ) ); throw new Error( $.getString( "Errors.Dzc" ) );
} else if ( rootName == "Error" ) { } else if ( rootName == "Error" ) {
return processDZIError( root ); return $._processDZIError( root );
} }
throw new Error( $.getString( "Errors.Dzi" ) ); throw new Error( $.getString( "Errors.Dzi" ) );

View File

@ -112,7 +112,7 @@
element[this.prefix + 'RequestFullScreen'](); element[this.prefix + 'RequestFullScreen']();
}; };
fullScreenApi.cancelFullScreen = function( element ) { fullScreenApi.cancelFullScreen = function() {
return (this.prefix === '') ? return (this.prefix === '') ?
document.cancelFullScreen() : document.cancelFullScreen() :
document[this.prefix + 'CancelFullScreen'](); document[this.prefix + 'CancelFullScreen']();
@ -121,6 +121,7 @@
// Older IE. Support based on: // Older IE. Support based on:
// http://stackoverflow.com/questions/1125084/how-to-make-in-javascript-full-screen-windows-stretching-all-over-the-screen/7525760 // http://stackoverflow.com/questions/1125084/how-to-make-in-javascript-full-screen-windows-stretching-all-over-the-screen/7525760
fullScreenApi.requestFullScreen = function(){ fullScreenApi.requestFullScreen = function(){
/* global ActiveXObject:true */
var wscript = new ActiveXObject("WScript.Shell"); var wscript = new ActiveXObject("WScript.Shell");
if ( wscript !== null ) { if ( wscript !== null ) {
wscript.SendKeys("{F11}"); wscript.SendKeys("{F11}");
@ -130,7 +131,6 @@
fullScreenApi.cancelFullScreen = fullScreenApi.requestFullScreen; fullScreenApi.cancelFullScreen = fullScreenApi.requestFullScreen;
} }
// export api // export api
$.extend( $, fullScreenApi ); $.extend( $, fullScreenApi );

View File

@ -111,7 +111,6 @@ $.extend( $.IIIFTileSource.prototype, $.TileSource.prototype, {
*/ */
configure: function( data, url ){ configure: function( data, url ){
var service, var service,
identifier,
options, options,
host; host;
@ -236,11 +235,7 @@ function configureFromXml( tileSource, xmlDoc ){
var root = xmlDoc.documentElement, var root = xmlDoc.documentElement,
rootName = root.tagName, rootName = root.tagName,
configuration = null, configuration = null;
scale_factors,
formats,
qualities,
i;
if ( rootName == "info" ) { if ( rootName == "info" ) {

View File

@ -49,8 +49,7 @@
*/ */
$.Navigator = function( options ){ $.Navigator = function( options ){
var _this = this, var viewer = options.viewer,
viewer = options.viewer,
viewerSize = $.getElementSize( viewer.element), viewerSize = $.getElementSize( viewer.element),
unneededElement; unneededElement;
@ -199,7 +198,7 @@ $.extend( $.Navigator.prototype, $.EventHandler.prototype, $.Viewer.prototype, {
bottomright = this.viewport.pixelFromPoint( bounds.getBottomRight()).minus(this.totalBorderWidths); bottomright = this.viewport.pixelFromPoint( bounds.getBottomRight()).minus(this.totalBorderWidths);
//update style for navigator-box //update style for navigator-box
(function(style, borderWidth){ (function(style) {
style.top = topleft.y + 'px'; style.top = topleft.y + 'px';
style.left = topleft.x + 'px'; style.left = topleft.x + 'px';
@ -210,7 +209,7 @@ $.extend( $.Navigator.prototype, $.EventHandler.prototype, $.Viewer.prototype, {
style.width = Math.max( width, 0 ) + 'px'; style.width = Math.max( width, 0 ) + 'px';
style.height = Math.max( height, 0 ) + 'px'; style.height = Math.max( height, 0 ) + 'px';
}( this.displayRegion.style, this.borderWidth)); }( this.displayRegion.style ));
} }
}, },

View File

@ -291,11 +291,7 @@ window.OpenSeadragon = window.OpenSeadragon || function( options ){
}, },
// Save a reference to some core methods // Save a reference to some core methods
toString = Object.prototype.toString, toString = Object.prototype.toString,
hasOwn = Object.prototype.hasOwnProperty, hasOwn = Object.prototype.hasOwnProperty;
push = Array.prototype.push,
slice = Array.prototype.slice,
trim = String.prototype.trim,
indexOf = Array.prototype.indexOf;
/** /**
@ -747,11 +743,11 @@ window.OpenSeadragon = window.OpenSeadragon || function( options ){
*/ */
getEvent: function( event ) { getEvent: function( event ) {
if( event ){ if( event ){
$.getEvent = function( event ){ $.getEvent = function( event ) {
return event; return event;
}; };
} else { } else {
$.getEvent = function( event ){ $.getEvent = function() {
return window.event; return window.event;
}; };
} }
@ -1283,7 +1279,8 @@ window.OpenSeadragon = window.OpenSeadragon || function( options ){
request = new XMLHttpRequest(); request = new XMLHttpRequest();
} else if ( window.ActiveXObject ) { } else if ( window.ActiveXObject ) {
/*jshint loopfunc:true*/ /*jshint loopfunc:true*/
for ( i = 0; i < ACTIVEX.length; i++ ) { /* global ActiveXObject:true */
for ( var i = 0; i < ACTIVEX.length; i++ ) {
try { try {
request = new ActiveXObject( ACTIVEX[ i ] ); request = new ActiveXObject( ACTIVEX[ i ] );
$.createAjaxRequest = function( ){ $.createAjaxRequest = function( ){
@ -1316,9 +1313,7 @@ window.OpenSeadragon = window.OpenSeadragon || function( options ){
var async = true, var async = true,
request = $.createAjaxRequest(), request = $.createAjaxRequest(),
actual, options;
options,
i;
if( $.isPlainObject( url ) ){ if( $.isPlainObject( url ) ){
@ -1454,12 +1449,9 @@ window.OpenSeadragon = window.OpenSeadragon || function( options ){
* Fully deprecated. Will throw an error. * Fully deprecated. Will throw an error.
* @function * @function
* @name OpenSeadragon.createFromDZI * @name OpenSeadragon.createFromDZI
* @param {String} xmlUrl
* @param {String} xmlString
* @param {Function} callback
* @deprecated - use OpenSeadragon.Viewer.prototype.open * @deprecated - use OpenSeadragon.Viewer.prototype.open
*/ */
createFromDZI: function( dzi, callback, tileHost ) { createFromDZI: function() {
throw "OpenSeadragon.createFromDZI is deprecated, use Viewer.open."; throw "OpenSeadragon.createFromDZI is deprecated, use Viewer.open.";
}, },
@ -1477,8 +1469,7 @@ window.OpenSeadragon = window.OpenSeadragon || function( options ){
if ( window.ActiveXObject ) { if ( window.ActiveXObject ) {
$.parseXml = function( string ){ $.parseXml = function( string ){
var xmlDoc = null, var xmlDoc = null;
parser;
xmlDoc = new ActiveXObject( "Microsoft.XMLDOM" ); xmlDoc = new ActiveXObject( "Microsoft.XMLDOM" );
xmlDoc.async = false; xmlDoc.async = false;
@ -1824,7 +1815,7 @@ window.OpenSeadragon = window.OpenSeadragon || function( options ){
} else if ( rootName == "Collection" ) { } else if ( rootName == "Collection" ) {
throw new Error( $.getString( "Errors.Dzc" ) ); throw new Error( $.getString( "Errors.Dzc" ) );
} else if ( rootName == "Error" ) { } else if ( rootName == "Error" ) {
return processDZIError( root ); return $._processDZIError( root );
} }
throw new Error( $.getString( "Errors.Dzi" ) ); throw new Error( $.getString( "Errors.Dzi" ) );
@ -1851,7 +1842,7 @@ window.OpenSeadragon = window.OpenSeadragon || function( options ){
rectNode, rectNode,
i; i;
if ( !imageFormatSupported( fileFormat ) ) { if ( !$.imageFormatSupported( fileFormat ) ) {
throw new Error( throw new Error(
$.getString( "Errors.ImageFormat", fileFormat.toUpperCase() ) $.getString( "Errors.ImageFormat", fileFormat.toUpperCase() )
); );
@ -1901,7 +1892,7 @@ window.OpenSeadragon = window.OpenSeadragon || function( options ){
rectData, rectData,
i; i;
if ( !imageFormatSupported( fileFormat ) ) { if ( !$.imageFormatSupported( fileFormat ) ) {
throw new Error( throw new Error(
$.getString( "Errors.ImageFormat", fileFormat.toUpperCase() ) $.getString( "Errors.ImageFormat", fileFormat.toUpperCase() )
); );
@ -1938,11 +1929,11 @@ window.OpenSeadragon = window.OpenSeadragon || function( options ){
* @throws {Error} * @throws {Error}
* @deprecated * @deprecated
*/ */
function processDZIError( errorNode ) { $._processDZIError = function ( errorNode ) {
var messageNode = errorNode.getElementsByTagName( "Message" )[ 0 ], var messageNode = errorNode.getElementsByTagName( "Message" )[ 0 ],
message = messageNode.firstChild.nodeValue; message = messageNode.firstChild.nodeValue;
throw new Error(message); throw new Error(message);
} };
}( OpenSeadragon )); }( OpenSeadragon ));

View File

@ -61,8 +61,6 @@ $.ReferenceStrip = function( options ){
var _this = this, var _this = this,
viewer = options.viewer, viewer = options.viewer,
viewerSize = $.getElementSize( viewer.element ), viewerSize = $.getElementSize( viewer.element ),
miniViewer,
minPixelRatio,
element, element,
style, style,
i; i;
@ -273,14 +271,12 @@ $.extend( $.ReferenceStrip.prototype, $.EventHandler.prototype, $.Viewer.prototy
* @function * @function
* @name OpenSeadragon.ReferenceStrip.prototype.update * @name OpenSeadragon.ReferenceStrip.prototype.update
*/ */
update: function( viewport ){ update: function() {
if ( THIS[ this.id ].animating ) {
if( THIS[ this.id ].animating ){
$.console.log('image reference strip update'); $.console.log('image reference strip update');
return true; return true;
} }
return false; return false;
} }
}); });
@ -391,7 +387,8 @@ function loadPanels(strip, viewerSize, scroll){
activePanelsEnd, activePanelsEnd,
miniViewer, miniViewer,
style, style,
i; i,
element;
if( 'horizontal' == strip.scroll ){ if( 'horizontal' == strip.scroll ){
panelSize = strip.panelWidth; panelSize = strip.panelWidth;
}else{ }else{
@ -484,15 +481,7 @@ function onStripEnter( tracker ) {
* @function * @function
*/ */
function onStripExit( tracker ) { function onStripExit( tracker ) {
if ( 'horizontal' == this.scroll ) {
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 ){
//tracker.element.style.paddingTop = "10px"; //tracker.element.style.paddingTop = "10px";
tracker.element.style.marginBottom = "-" + ( $.getElementSize( tracker.element ).y / 2 ) + "px"; tracker.element.style.marginBottom = "-" + ( $.getElementSize( tracker.element ).y / 2 ) + "px";

View File

@ -84,9 +84,7 @@
* The maximum pyramid level this tile source supports or should attempt to load. * The maximum pyramid level this tile source supports or should attempt to load.
*/ */
$.TileSource = function( width, height, tileSize, tileOverlap, minLevel, maxLevel ) { $.TileSource = function( width, height, tileSize, tileOverlap, minLevel, maxLevel ) {
var _this = this, var callback = null,
callback = null,
readyHandler = null,
args = arguments, args = arguments,
options, options,
i; i;
@ -274,16 +272,14 @@ $.TileSource.prototype = {
* @throws {Error} * @throws {Error}
*/ */
getImageInfo: function( url ) { getImageInfo: function( url ) {
var _this = this, var _this = this,
error,
callbackName, callbackName,
callback, callback,
readySource, readySource,
options, options,
urlParts, urlParts,
filename, filename,
lastDot, lastDot;
tilesUrl;
if( url ) { if( url ) {

View File

@ -39,7 +39,7 @@
* @extends OpenSeadragon.TileSource * @extends OpenSeadragon.TileSource
*/ */
$.TileSourceCollection = function( tileSize, tileSources, rows, layout ) { $.TileSourceCollection = function( tileSize, tileSources, rows, layout ) {
var options;
if( $.isPlainObject( tileSize ) ){ if( $.isPlainObject( tileSize ) ){
options = tileSize; options = tileSize;

View File

@ -174,8 +174,7 @@ $.Viewer = function( options ) {
$.ControlDock.call( this, options ); $.ControlDock.call( this, options );
//Deal with tile sources //Deal with tile sources
var initialTileSource, var initialTileSource;
customTileSource;
if ( this.xmlPath ){ if ( this.xmlPath ){
//Deprecated option. Now it is preferred to use the tileSources option //Deprecated option. Now it is preferred to use the tileSources option
@ -277,19 +276,21 @@ $.Viewer = function( options ) {
case 119://w case 119://w
case 87://W case 87://W
case 38://up arrow case 38://up arrow
if (shiftKey) if (shiftKey) {
_this.viewport.zoomBy(1.1); _this.viewport.zoomBy(1.1);
else } else {
_this.viewport.panBy(new $.Point(0, -0.05)); _this.viewport.panBy(new $.Point(0, -0.05));
}
_this.viewport.applyConstraints(); _this.viewport.applyConstraints();
return false; return false;
case 115://s case 115://s
case 83://S case 83://S
case 40://down arrow case 40://down arrow
if (shiftKey) if (shiftKey) {
_this.viewport.zoomBy(0.9); _this.viewport.zoomBy(0.9);
else } else {
_this.viewport.panBy(new $.Point(0, 0.05)); _this.viewport.panBy(new $.Point(0, 0.05));
}
_this.viewport.applyConstraints(); _this.viewport.applyConstraints();
return false; return false;
case 97://a case 97://a
@ -569,7 +570,6 @@ $.extend( $.Viewer.prototype, $.EventHandler.prototype, $.ControlDock.prototype,
var body = document.body, var body = document.body,
bodyStyle = body.style, bodyStyle = body.style,
docStyle = document.documentElement.style, docStyle = document.documentElement.style,
containerStyle = this.element.style,
canvasStyle = this.canvas.style, canvasStyle = this.canvas.style,
_this = this, _this = this,
oldBounds, oldBounds,
@ -597,11 +597,6 @@ $.extend( $.Viewer.prototype, $.EventHandler.prototype, $.ControlDock.prototype,
bodyStyle.width = "100%"; bodyStyle.width = "100%";
bodyStyle.height = "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 //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 //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 //respond to touch events on the canvas, while the bottom half treated
@ -635,10 +630,13 @@ $.extend( $.Viewer.prototype, $.EventHandler.prototype, $.ControlDock.prototype,
body.appendChild( this.element ); body.appendChild( this.element );
if( $.supportsFullScreen ){ 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 fullscreenchange events don't include the new fullscreen status so we need to
// retrieve it through the fullscreen API retrieve the current status from the fullscreen API. See:
https://developer.mozilla.org/en-US/docs/Web/Reference/Events/fullscreenchange
*/
if( $.isFullScreen() ){ if( $.isFullScreen() ){
_this.setFullPage( true ); _this.setFullPage( true );
} else { } else {
@ -693,9 +691,6 @@ $.extend( $.Viewer.prototype, $.EventHandler.prototype, $.ControlDock.prototype,
canvasStyle.backgroundColor = ""; canvasStyle.backgroundColor = "";
canvasStyle.color = ""; canvasStyle.color = "";
//containerStyle.position = "relative";
//containerStyle.zIndex = "";
body.removeChild( this.element ); body.removeChild( this.element );
nodes = this.previousBody.length; nodes = this.previousBody.length;
for ( i = 0; i < nodes; i++ ){ for ( i = 0; i < nodes; i++ ){
@ -817,7 +812,6 @@ $.extend( $.Viewer.prototype, $.EventHandler.prototype, $.ControlDock.prototype,
onNextHandler = $.delegate( this, onNext ), onNextHandler = $.delegate( this, onNext ),
onPreviousHandler = $.delegate( this, onPrevious ), onPreviousHandler = $.delegate( this, onPrevious ),
navImages = this.navImages, navImages = this.navImages,
buttons = [],
useGroup = true ; useGroup = true ;
if( this.showSequenceControl && THIS[ this.hash ].sequenced ){ if( this.showSequenceControl && THIS[ this.hash ].sequenced ){
@ -1324,7 +1318,7 @@ function onBlur(){
} }
function onCanvasClick( tracker, position, quick, shift ) { function onCanvasClick( tracker, position, quick, shift ) {
var zoomPreClick, var zoomPerClick,
factor; factor;
if ( this.viewport && quick ) { // ignore clicks where mouse moved if ( this.viewport && quick ) { // ignore clicks where mouse moved
zoomPerClick = this.zoomPerClick; zoomPerClick = this.zoomPerClick;
@ -1556,7 +1550,7 @@ function scheduleZoom( viewer ) {
function doZoom() { function doZoom() {
var currentTime, var currentTime,
deltaTime, deltaTime,
adjustFactor; adjustedFactor;
if ( THIS[ this.hash ].zooming && this.viewport) { if ( THIS[ this.hash ].zooming && this.viewport) {
currentTime = $.now(); currentTime = $.now();

View File

@ -309,10 +309,8 @@ $.Viewport.prototype = {
right, right,
top, top,
bottom, bottom,
center,
dx = 0, dx = 0,
dy = 0, dy = 0;
dx1 = 0, dx2 = 0, dy1 = 0, dy2 = 0;
if ( actualZoom != constrainedZoom ) { if ( actualZoom != constrainedZoom ) {
this.zoomTo( constrainedZoom, this.zoomPoint, immediately ); this.zoomTo( constrainedZoom, this.zoomPoint, immediately );