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: {
options: {
browser: true,
eqeqeq: false,
loopfunc: false,
trailing: true,
globals: {
OpenSeadragon: true
}
jshintrc: '.jshintrc'
},
beforeconcat: sources,
afterconcat: [ distribution ]

View File

@ -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",

View File

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

View File

@ -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,
@ -672,8 +675,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', {
@ -1113,11 +1115,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 ){

View File

@ -126,11 +126,7 @@ $.extend( $.DziTileSource.prototype, $.TileSource.prototype, {
*/
configure: function( data, url ){
var dziPath,
dziName,
tilesUrl,
options,
host;
var options;
if( !$.isPlainObject(data) ){
@ -287,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" ) );

View File

@ -112,7 +112,7 @@
element[this.prefix + 'RequestFullScreen']();
};
fullScreenApi.cancelFullScreen = function( element ) {
fullScreenApi.cancelFullScreen = function() {
return (this.prefix === '') ?
document.cancelFullScreen() :
document[this.prefix + 'CancelFullScreen']();
@ -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}");
@ -130,7 +131,6 @@
fullScreenApi.cancelFullScreen = fullScreenApi.requestFullScreen;
}
// export api
$.extend( $, fullScreenApi );

View File

@ -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" ) {

View File

@ -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';
@ -210,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 ));
}
},

View File

@ -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;
/**
@ -751,7 +747,7 @@ window.OpenSeadragon = window.OpenSeadragon || function( options ){
return event;
};
} else {
$.getEvent = function( event ){
$.getEvent = function() {
return window.event;
};
}
@ -1283,7 +1279,8 @@ window.OpenSeadragon = window.OpenSeadragon || function( options ){
request = new XMLHttpRequest();
} else if ( window.ActiveXObject ) {
/*jshint loopfunc:true*/
for ( i = 0; i < ACTIVEX.length; i++ ) {
/* global ActiveXObject:true */
for ( var i = 0; i < ACTIVEX.length; i++ ) {
try {
request = new ActiveXObject( ACTIVEX[ i ] );
$.createAjaxRequest = function( ){
@ -1316,9 +1313,7 @@ window.OpenSeadragon = window.OpenSeadragon || function( options ){
var async = true,
request = $.createAjaxRequest(),
actual,
options,
i;
options;
if( $.isPlainObject( url ) ){
@ -1454,12 +1449,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.";
},
@ -1477,8 +1469,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;
@ -1824,7 +1815,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" ) );
@ -1851,7 +1842,7 @@ window.OpenSeadragon = window.OpenSeadragon || function( options ){
rectNode,
i;
if ( !imageFormatSupported( fileFormat ) ) {
if ( !$.imageFormatSupported( fileFormat ) ) {
throw new Error(
$.getString( "Errors.ImageFormat", fileFormat.toUpperCase() )
);
@ -1901,7 +1892,7 @@ window.OpenSeadragon = window.OpenSeadragon || function( options ){
rectData,
i;
if ( !imageFormatSupported( fileFormat ) ) {
if ( !$.imageFormatSupported( fileFormat ) ) {
throw new Error(
$.getString( "Errors.ImageFormat", fileFormat.toUpperCase() )
);
@ -1938,11 +1929,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);
}
};
}( OpenSeadragon ));

View File

@ -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 ){
update: function() {
if ( THIS[ this.id ].animating ) {
$.console.log('image reference strip update');
return true;
}
return false;
}
});
@ -391,7 +387,8 @@ function loadPanels(strip, viewerSize, scroll){
activePanelsEnd,
miniViewer,
style,
i;
i,
element;
if( 'horizontal' == strip.scroll ){
panelSize = strip.panelWidth;
}else{
@ -484,14 +481,6 @@ 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 ) {
//tracker.element.style.paddingTop = "10px";

View File

@ -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;
@ -275,15 +273,13 @@ $.TileSource.prototype = {
*/
getImageInfo: function( url ) {
var _this = this,
error,
callbackName,
callback,
readySource,
options,
urlParts,
filename,
lastDot,
tilesUrl;
lastDot;
if( url ) {

View File

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

View File

@ -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
@ -277,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
@ -569,7 +570,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,
@ -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
@ -635,10 +630,13 @@ $.extend( $.Viewer.prototype, $.EventHandler.prototype, $.ControlDock.prototype,
body.appendChild( this.element );
if( $.supportsFullScreen ){
THIS[ this.hash ].onfullscreenchange = function( event ) {
// 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
THIS[ this.hash ].onfullscreenchange = function() {
/*
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 {
@ -693,9 +691,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++ ){
@ -817,7 +812,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 ){
@ -1324,7 +1318,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;
@ -1556,7 +1550,7 @@ function scheduleZoom( viewer ) {
function doZoom() {
var currentTime,
deltaTime,
adjustFactor;
adjustedFactor;
if ( THIS[ this.hash ].zooming && this.viewport) {
currentTime = $.now();

View File

@ -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 );