Add eslint and hound

This commit is contained in:
Antoine Vandecreme 2017-01-08 15:52:57 +01:00
parent 537c3d04c1
commit de25b68b43
24 changed files with 721 additions and 97 deletions

285
.eslintrc.hound.json Normal file
View File

@ -0,0 +1,285 @@
{
"env": {
"browser": true
},
"extends": "eslint:recommended",
"rules": {
"indent": [
"error",
4
],
"linebreak-style": [
"error",
"unix"
],
"quotes": [
"error",
"double"
],
"semi": [
"error",
"always"
],
"no-unused-vars": [
"error",
{
"args": "none"
}
],
"block-scoped-var": [
"error"
],
"consistent-return": [
"error"
],
"curly": [
"error",
"all"
],
"eqeqeq": [
"error"
],
"no-eval": [
"error"
],
"no-implicit-globals": [
"error"
],
"no-implied-eval": [
"error"
],
"no-invalid-this": [
"error"
],
"no-multi-spaces": [
"error",
{
"exceptions": {
"Property": true,
"VariableDeclarator": true,
"AssignmentExpression": true
}
}
],
"no-new-wrappers": [
"error"
],
"no-new": [
"error"
],
"no-return-assign": [
"error"
],
"no-self-compare": [
"error"
],
"no-unmodified-loop-condition": [
"error"
],
"no-unused-expressions": [
"error"
],
"no-useless-call": [
"error"
],
"no-useless-concat": [
"error"
],
"no-useless-escape": [
"error"
],
"no-useless-return": [
"error"
],
"no-with": [
"error"
],
"radix": [
"error"
],
"yoda": [
"error"
],
"no-undef-init": [
"error"
],
"no-use-before-define": [
"error",
{
"functions": false
}
],
"array-bracket-spacing": [
"error",
"never"
],
"block-spacing": [
"error"
],
"brace-style": [
"error"
],
"camelcase": [
"error"
],
"comma-spacing": [
"error"
],
"comma-style": [
"error"
],
"computed-property-spacing": [
"error"
],
"consistent-this": [
"error",
"self"
],
"eol-last": [
"error"
],
"func-call-spacing": [
"error"
],
"func-name-matching": [
"error"
],
"key-spacing": [
"error",
{
"mode": "minimum"
}
],
"keyword-spacing": [
"error"
],
"max-len": [
"error",
80
],
"max-statements-per-line": [
"error",
{
"max": 1
}
],
"new-cap": [
"error"
],
"new-parens": [
"error"
],
"no-array-constructor": [
"error"
],
"no-mixed-operators": [
"error",
{
"groups": [
[
"&",
"|",
"^",
"~",
"<<",
">>",
">>>"
],
[
"==",
"!=",
"===",
"!==",
">",
">=",
"<",
"<="
],
[
"&&",
"||"
],
[
"in",
"instanceof"
]
]
}
],
"no-new-object": [
"error"
],
"no-tabs": [
"error"
],
"no-trailing-spaces": [
"error"
],
"no-unneeded-ternary": [
"error"
],
"no-whitespace-before-property": [
"error"
],
"object-curly-spacing": [
"error",
"always"
],
"one-var-declaration-per-line": [
"error"
],
"one-var": [
"error",
"never"
],
"operator-assignment": [
"error"
],
"operator-linebreak": [
"error",
"after"
],
"quote-props": [
"error",
"as-needed"
],
"semi-spacing": [
"error"
],
"space-before-blocks": [
"error"
],
"space-before-function-paren": [
"error",
"never"
],
"space-in-parens": [
"error",
"never"
],
"space-infix-ops": [
"error"
],
"space-unary-ops": [
"error",
{
"words": false,
"nonwords": false
}
],
"unicode-bom": [
"error"
],
"no-caller": [
"error"
],
"no-loop-func": [
"error"
]
},
"globals": {
"OpenSeadragon": true,
"define": false,
"module": false
}
}

285
.eslintrc.json Normal file
View File

@ -0,0 +1,285 @@
{
"env": {
"browser": true
},
"extends": "eslint:recommended",
"rules": {
"indent": [
"off",
4
],
"linebreak-style": [
"error",
"unix"
],
"quotes": [
"off",
"double"
],
"semi": [
"error",
"always"
],
"no-unused-vars": [
"error",
{
"args": "none"
}
],
"block-scoped-var": [
"error"
],
"consistent-return": [
"off"
],
"curly": [
"error",
"all"
],
"eqeqeq": [
"off"
],
"no-eval": [
"error"
],
"no-implicit-globals": [
"error"
],
"no-implied-eval": [
"error"
],
"no-invalid-this": [
"error"
],
"no-multi-spaces": [
"error",
{
"exceptions": {
"Property": true,
"VariableDeclarator": true,
"AssignmentExpression": true
}
}
],
"no-new-wrappers": [
"error"
],
"no-new": [
"error"
],
"no-return-assign": [
"error"
],
"no-self-compare": [
"error"
],
"no-unmodified-loop-condition": [
"error"
],
"no-unused-expressions": [
"error"
],
"no-useless-call": [
"error"
],
"no-useless-concat": [
"error"
],
"no-useless-escape": [
"off"
],
"no-useless-return": [
"error"
],
"no-with": [
"error"
],
"radix": [
"error"
],
"yoda": [
"off"
],
"no-undef-init": [
"error"
],
"no-use-before-define": [
"error",
{
"functions": false
}
],
"array-bracket-spacing": [
"off",
"never"
],
"block-spacing": [
"off"
],
"brace-style": [
"off"
],
"camelcase": [
"error"
],
"comma-spacing": [
"error"
],
"comma-style": [
"error"
],
"computed-property-spacing": [
"off"
],
"consistent-this": [
"off",
"self"
],
"eol-last": [
"error"
],
"func-call-spacing": [
"error"
],
"func-name-matching": [
"error"
],
"key-spacing": [
"error",
{
"mode": "minimum"
}
],
"keyword-spacing": [
"off"
],
"max-len": [
"off",
80
],
"max-statements-per-line": [
"error",
{
"max": 1
}
],
"new-cap": [
"error"
],
"new-parens": [
"error"
],
"no-array-constructor": [
"error"
],
"no-mixed-operators": [
"error",
{
"groups": [
[
"&",
"|",
"^",
"~",
"<<",
">>",
">>>"
],
[
"==",
"!=",
"===",
"!==",
">",
">=",
"<",
"<="
],
[
"&&",
"||"
],
[
"in",
"instanceof"
]
]
}
],
"no-new-object": [
"error"
],
"no-tabs": [
"error"
],
"no-trailing-spaces": [
"error"
],
"no-unneeded-ternary": [
"error"
],
"no-whitespace-before-property": [
"error"
],
"object-curly-spacing": [
"off",
"always"
],
"one-var-declaration-per-line": [
"error"
],
"one-var": [
"off",
"never"
],
"operator-assignment": [
"error"
],
"operator-linebreak": [
"error",
"after"
],
"quote-props": [
"off",
"as-needed"
],
"semi-spacing": [
"error"
],
"space-before-blocks": [
"off"
],
"space-before-function-paren": [
"off",
"never"
],
"space-in-parens": [
"off",
"never"
],
"space-infix-ops": [
"error"
],
"space-unary-ops": [
"error",
{
"words": false,
"nonwords": false
}
],
"unicode-bom": [
"error"
],
"no-caller": [
"error"
],
"no-loop-func": [
"error"
]
},
"globals": {
"OpenSeadragon": true,
"define": false,
"module": false
}
}

6
.hound.yml Normal file
View File

@ -0,0 +1,6 @@
jshint:
config_file: .jshintrc
eslint:
enabled: true
config_file: .eslintrc.hound.json

View File

@ -11,6 +11,7 @@ module.exports = function(grunt) {
grunt.loadNpmTasks("grunt-contrib-connect"); grunt.loadNpmTasks("grunt-contrib-connect");
grunt.loadNpmTasks("grunt-contrib-watch"); grunt.loadNpmTasks("grunt-contrib-watch");
grunt.loadNpmTasks("grunt-contrib-clean"); grunt.loadNpmTasks("grunt-contrib-clean");
grunt.loadNpmTasks("grunt-eslint");
grunt.loadNpmTasks("grunt-git-describe"); grunt.loadNpmTasks("grunt-git-describe");
grunt.loadNpmTasks('grunt-text-replace'); grunt.loadNpmTasks('grunt-text-replace');
@ -194,6 +195,12 @@ module.exports = function(grunt) {
beforeconcat: sources, beforeconcat: sources,
afterconcat: [ distribution ] afterconcat: [ distribution ]
}, },
eslint: {
options: {
configFile: '.eslintrc.json'
},
target: sources
},
"git-describe": { "git-describe": {
build: {} build: {}
} }
@ -266,7 +273,7 @@ module.exports = function(grunt) {
// Cleans out the build folder and builds the code and images into it, checking lint. // Cleans out the build folder and builds the code and images into it, checking lint.
grunt.registerTask("build", [ grunt.registerTask("build", [
"clean:build", "jshint:beforeconcat", "git-describe", "concat", "jshint:afterconcat", "clean:build", "jshint:beforeconcat", "git-describe", "concat", "jshint:afterconcat",
"uglify", "replace:cleanPaths", "copy:build" "eslint", "uglify", "replace:cleanPaths", "copy:build"
]); ]);
// ---------- // ----------

View File

@ -24,6 +24,7 @@
"grunt-contrib-uglify": "^2.0.0", "grunt-contrib-uglify": "^2.0.0",
"grunt-contrib-watch": "^0.6.1", "grunt-contrib-watch": "^0.6.1",
"grunt-git-describe": "^2.3.2", "grunt-git-describe": "^2.3.2",
"grunt-eslint": "^19.0.0",
"grunt-qunit-istanbul": "^0.6.0", "grunt-qunit-istanbul": "^0.6.0",
"grunt-text-replace": "^0.4.0", "grunt-text-replace": "^0.4.0",
"qunitjs": "^1.20.0" "qunitjs": "^1.20.0"

View File

@ -120,7 +120,7 @@ $.Button = function( options ) {
* @member {Element} element * @member {Element} element
* @memberof OpenSeadragon.Button# * @memberof OpenSeadragon.Button#
*/ */
this.element = options.element || $.makeNeutralElement( "div" ); this.element = options.element || $.makeNeutralElement("div");
//if the user has specified the element to bind the control to explicitly //if the user has specified the element to bind the control to explicitly
//then do not add the default control images //then do not add the default control images
@ -158,7 +158,7 @@ $.Button = function( options ) {
this.imgDown.style.visibility = this.imgDown.style.visibility =
"hidden"; "hidden";
if ( $.Browser.vendor == $.BROWSERS.FIREFOX && $.Browser.version < 3 ){ if ($.Browser.vendor == $.BROWSERS.FIREFOX && $.Browser.version < 3) {
this.imgGroup.style.top = this.imgGroup.style.top =
this.imgHover.style.top = this.imgHover.style.top =
this.imgDown.style.top = this.imgDown.style.top =
@ -172,13 +172,13 @@ $.Button = function( options ) {
} }
this.addHandler( "press", this.onPress ); this.addHandler("press", this.onPress);
this.addHandler( "release", this.onRelease ); this.addHandler("release", this.onRelease);
this.addHandler( "click", this.onClick ); this.addHandler("click", this.onClick);
this.addHandler( "enter", this.onEnter ); this.addHandler("enter", this.onEnter);
this.addHandler( "exit", this.onExit ); this.addHandler("exit", this.onExit);
this.addHandler( "focus", this.onFocus ); this.addHandler("focus", this.onFocus);
this.addHandler( "blur", this.onBlur ); this.addHandler("blur", this.onBlur);
/** /**
* The button's current state. * The button's current state.

View File

@ -115,10 +115,10 @@ $.Control = function ( element, options, container ) {
if ( this.anchor == $.ControlAnchor.ABSOLUTE ) { if ( this.anchor == $.ControlAnchor.ABSOLUTE ) {
this.wrapper = $.makeNeutralElement( "div" ); this.wrapper = $.makeNeutralElement( "div" );
this.wrapper.style.position = "absolute"; this.wrapper.style.position = "absolute";
this.wrapper.style.top = typeof ( options.top ) == "number" ? ( options.top + 'px' ) : options.top; this.wrapper.style.top = typeof (options.top) == "number" ? (options.top + 'px') : options.top;
this.wrapper.style.left = typeof ( options.left ) == "number" ? (options.left + 'px' ) : options.left; this.wrapper.style.left = typeof (options.left) == "number" ? (options.left + 'px') : options.left;
this.wrapper.style.height = typeof ( options.height ) == "number" ? ( options.height + 'px' ) : options.height; this.wrapper.style.height = typeof (options.height) == "number" ? (options.height + 'px') : options.height;
this.wrapper.style.width = typeof ( options.width ) == "number" ? ( options.width + 'px' ) : options.width; this.wrapper.style.width = typeof (options.width) == "number" ? (options.width + 'px') : options.width;
this.wrapper.style.margin = "0px"; this.wrapper.style.margin = "0px";
this.wrapper.style.padding = "0px"; this.wrapper.style.padding = "0px";

View File

@ -45,7 +45,7 @@
i; i;
$.extend( true, this, { $.extend( true, this, {
id: 'controldock-'+$.now()+'-'+Math.floor(Math.random()*1000000), id: 'controldock-' + $.now() + '-' + Math.floor(Math.random() * 1000000),
container: $.makeNeutralElement( 'div' ), container: $.makeNeutralElement( 'div' ),
controls: [] controls: []
}, options ); }, options );

View File

@ -285,8 +285,8 @@ $.Drawer.prototype = {
return new $.Rect( return new $.Rect(
topLeft.x * $.pixelDensityRatio, topLeft.x * $.pixelDensityRatio,
topLeft.y * $.pixelDensityRatio, topLeft.y * $.pixelDensityRatio,
size.x * $.pixelDensityRatio, size.x * $.pixelDensityRatio,
size.y * $.pixelDensityRatio size.y * $.pixelDensityRatio
); );
}, },
@ -474,7 +474,7 @@ $.Drawer.prototype = {
position.x - widthExt * scale, position.x - widthExt * scale,
position.y - heightExt * scale, position.y - heightExt * scale,
(this.canvas.width + 2 * widthExt) * scale, (this.canvas.width + 2 * widthExt) * scale,
(this.canvas.height + 2 * heightExt) * scale, (this.canvas.height + 2 * heightExt) * scale,
-widthExt, -widthExt,
-heightExt, -heightExt,
this.canvas.width + 2 * widthExt, this.canvas.width + 2 * widthExt,

View File

@ -45,6 +45,7 @@
*/ */
$.IIIFTileSource = function( options ){ $.IIIFTileSource = function( options ){
/* eslint-disable camelcase */
$.extend( true, this, options ); $.extend( true, this, options );
@ -86,7 +87,7 @@ $.IIIFTileSource = function( options ){
} else if ( canBeTiled(options.profile) ) { } else if ( canBeTiled(options.profile) ) {
// use the largest of tileOptions that is smaller than the short dimension // use the largest of tileOptions that is smaller than the short dimension
var shortDim = Math.min( this.height, this.width ), var shortDim = Math.min( this.height, this.width ),
tileOptions = [256,512,1024], tileOptions = [256, 512, 1024],
smallerTiles = []; smallerTiles = [];
for ( var c = 0; c < tileOptions.length; c++ ) { for ( var c = 0; c < tileOptions.length; c++ ) {
@ -102,11 +103,11 @@ $.IIIFTileSource = function( options ){
options.tileSize = shortDim; options.tileSize = shortDim;
} }
} else if (this.sizes && this.sizes.length > 0) { } else if (this.sizes && this.sizes.length > 0) {
// This info.json can't be tiled, but we can still construct a legacy pyramid from the sizes array. // This info.json can't be tiled, but we can still construct a legacy pyramid from the sizes array.
// In this mode, IIIFTileSource will call functions from the abstract baseTileSource or the // In this mode, IIIFTileSource will call functions from the abstract baseTileSource or the
// LegacyTileSource instead of performing IIIF tiling. // LegacyTileSource instead of performing IIIF tiling.
this.emulateLegacyImagePyramid = true; this.emulateLegacyImagePyramid = true;
options.levels = constructLevels( this ); options.levels = constructLevels( this );
// use the largest available size to define tiles // use the largest available size to define tiles
$.extend( true, options, { $.extend( true, options, {
@ -141,7 +142,7 @@ $.extend( $.IIIFTileSource.prototype, $.TileSource.prototype, /** @lends OpenSea
* @param {Object|Array} data * @param {Object|Array} data
* @param {String} optional - url * @param {String} optional - url
*/ */
supports: function( data, url ) { supports: function( data, url ) {
// Version 2.0 and forwards // Version 2.0 and forwards
if (data.protocol && data.protocol == 'http://iiif.io/api/image') { if (data.protocol && data.protocol == 'http://iiif.io/api/image') {
@ -393,14 +394,16 @@ $.extend( $.IIIFTileSource.prototype, $.TileSource.prototype, /** @lends OpenSea
*/ */
function constructLevels(options) { function constructLevels(options) {
var levels = []; var levels = [];
for(var i=0; i<options.sizes.length; i++) { for(var i = 0; i < options.sizes.length; i++) {
levels.push({ levels.push({
url: options['@id'] + '/full/' + options.sizes[i].width + ',/0/default.jpg', url: options['@id'] + '/full/' + options.sizes[i].width + ',/0/default.jpg',
width: options.sizes[i].width, width: options.sizes[i].width,
height: options.sizes[i].height height: options.sizes[i].height
}); });
} }
return levels.sort(function(a,b){return a.width - b.width;}); return levels.sort(function(a, b) {
return a.width - b.width;
});
} }

View File

@ -217,7 +217,7 @@ function filterFiles( files ){
} }
} }
return filtered.sort(function(a,b){ return filtered.sort(function(a, b) {
return a.height - b.height; return a.height - b.height;
}); });
@ -253,7 +253,7 @@ function configureFromXML( tileSource, xmlDoc ){
for ( i = 0; i < levels.length; i++ ) { for ( i = 0; i < levels.length; i++ ) {
level = levels[ i ]; level = levels[ i ];
conf.levels .push({ conf.levels.push({
url: level.getAttribute( "url" ), url: level.getAttribute( "url" ),
width: parseInt( level.getAttribute( "width" ), 10 ), width: parseInt( level.getAttribute( "width" ), 10 ),
height: parseInt( level.getAttribute( "height" ), 10 ) height: parseInt( level.getAttribute( "height" ), 10 )

View File

@ -160,6 +160,7 @@
* @memberof OpenSeadragon.MouseTracker# * @memberof OpenSeadragon.MouseTracker#
*/ */
this.dblClickDistThreshold = options.dblClickDistThreshold || $.DEFAULT_SETTINGS.dblClickDistThreshold; this.dblClickDistThreshold = options.dblClickDistThreshold || $.DEFAULT_SETTINGS.dblClickDistThreshold;
/*eslint-disable no-multi-spaces*/
this.userData = options.userData || null; this.userData = options.userData || null;
this.stopDelay = options.stopDelay || 50; this.stopDelay = options.stopDelay || 50;
@ -182,6 +183,7 @@
this.keyHandler = options.keyHandler || null; this.keyHandler = options.keyHandler || null;
this.focusHandler = options.focusHandler || null; this.focusHandler = options.focusHandler || null;
this.blurHandler = options.blurHandler || null; this.blurHandler = options.blurHandler || null;
/*eslint-enable no-multi-spaces*/
//Store private properties in a scope sealed hash map //Store private properties in a scope sealed hash map
var _this = this; var _this = this;
@ -1370,6 +1372,7 @@
eventParams = getCaptureEventParams( tracker, $.MouseTracker.havePointerEvents ? 'pointerevent' : pointerType ); eventParams = getCaptureEventParams( tracker, $.MouseTracker.havePointerEvents ? 'pointerevent' : pointerType );
// We emulate mouse capture by hanging listeners on the document object. // We emulate mouse capture by hanging listeners on the document object.
// (Note we listen on the capture phase so the captured handlers will get called first) // (Note we listen on the capture phase so the captured handlers will get called first)
// eslint-disable-next-line no-use-before-define
if (isInIframe && canAccessEvents(window.top)) { if (isInIframe && canAccessEvents(window.top)) {
$.addEvent( $.addEvent(
window.top, window.top,
@ -1413,6 +1416,7 @@
eventParams = getCaptureEventParams( tracker, $.MouseTracker.havePointerEvents ? 'pointerevent' : pointerType ); eventParams = getCaptureEventParams( tracker, $.MouseTracker.havePointerEvents ? 'pointerevent' : pointerType );
// We emulate mouse capture by hanging listeners on the document object. // We emulate mouse capture by hanging listeners on the document object.
// (Note we listen on the capture phase so the captured handlers will get called first) // (Note we listen on the capture phase so the captured handlers will get called first)
// eslint-disable-next-line no-use-before-define
if (isInIframe && canAccessEvents(window.top)) { if (isInIframe && canAccessEvents(window.top)) {
$.removeEvent( $.removeEvent(
window.top, window.top,
@ -1703,7 +1707,7 @@
// Calculate deltaY // Calculate deltaY
if ( $.MouseTracker.wheelEventName == "mousewheel" ) { if ( $.MouseTracker.wheelEventName == "mousewheel" ) {
simulatedEvent.deltaY = - 1 / $.DEFAULT_SETTINGS.pixelsPerWheelLine * event.wheelDelta; simulatedEvent.deltaY = -event.wheelDelta / $.DEFAULT_SETTINGS.pixelsPerWheelLine;
} else { } else {
simulatedEvent.deltaY = event.detail; simulatedEvent.deltaY = event.detail;
} }
@ -2207,11 +2211,8 @@
* @inner * @inner
*/ */
function onTouchCancel( tracker, event ) { function onTouchCancel( tracker, event ) {
var i, var pointsList = tracker.getActivePointersListByType('touch');
touchCount = event.changedTouches.length,
gPoints = [],
pointsList = tracker.getActivePointersListByType( 'touch' );
abortTouchContacts( tracker, event, pointsList ); abortTouchContacts( tracker, event, pointsList );
} }
@ -2565,8 +2566,7 @@
* Gesture points associated with the event. * Gesture points associated with the event.
*/ */
function updatePointersExit( tracker, event, gPoints ) { function updatePointersExit( tracker, event, gPoints ) {
var delegate = THIS[ tracker.hash ], var pointsList = tracker.getActivePointersListByType(gPoints[0].type),
pointsList = tracker.getActivePointersListByType( gPoints[ 0 ].type ),
i, i,
gPointCount = gPoints.length, gPointCount = gPoints.length,
curGPoint, curGPoint,
@ -2801,7 +2801,6 @@
var delegate = THIS[ tracker.hash ], var delegate = THIS[ tracker.hash ],
pointsList = tracker.getActivePointersListByType( gPoints[ 0 ].type ), pointsList = tracker.getActivePointersListByType( gPoints[ 0 ].type ),
propagate, propagate,
insideElementReleased,
releasePoint, releasePoint,
releaseTime, releaseTime,
i, i,
@ -2866,7 +2865,7 @@
{ {
eventSource: tracker, eventSource: tracker,
pointerType: gPoints[ 0 ].type, pointerType: gPoints[ 0 ].type,
position: getPointRelativeToAbsolute( gPoints[ 0 ].currentPos, tracker.element ), position: getPointRelativeToAbsolute(gPoints[0].currentPos, tracker.element),
button: buttonChanged, button: buttonChanged,
buttons: pointsList.buttons, buttons: pointsList.buttons,
isTouchEvent: gPoints[ 0 ].type === 'touch', isTouchEvent: gPoints[ 0 ].type === 'touch',
@ -3267,7 +3266,7 @@
} ); } );
} }
} }
// True if inside an iframe, otherwise false. // True if inside an iframe, otherwise false.
// @member {Boolean} isInIframe // @member {Boolean} isInIframe
// @private // @private
@ -3279,7 +3278,7 @@
return true; return true;
} }
})(); })();
// @function // @function
// @private // @private
// @inner // @inner
@ -3292,4 +3291,4 @@
} }
} }
} ( OpenSeadragon ) ); }(OpenSeadragon));

View File

@ -121,7 +121,7 @@ $.Navigator = function( options ){
//At some browser magnification levels the display regions lines up correctly, but at some there appears to //At some browser magnification levels the display regions lines up correctly, but at some there appears to
//be a one pixel gap. //be a one pixel gap.
this.fudge = new $.Point(1, 1); this.fudge = new $.Point(1, 1);
this.totalBorderWidths = new $.Point(this.borderWidth*2, this.borderWidth*2).minus(this.fudge); this.totalBorderWidths = new $.Point(this.borderWidth * 2, this.borderWidth * 2).minus(this.fudge);
if ( options.controlOptions.anchor != $.ControlAnchor.NONE ) { if ( options.controlOptions.anchor != $.ControlAnchor.NONE ) {
@ -180,8 +180,8 @@ $.Navigator = function( options ){
if ( this._resizeWithViewer ) { if ( this._resizeWithViewer ) {
if ( options.width && options.height ) { if ( options.width && options.height ) {
this.element.style.height = typeof ( options.height ) == "number" ? ( options.height + 'px' ) : options.height; this.element.style.height = typeof (options.height) == "number" ? (options.height + 'px') : options.height;
this.element.style.width = typeof ( options.width ) == "number" ? ( options.width + 'px' ) : options.width; this.element.style.width = typeof (options.width) == "number" ? (options.width + 'px') : options.width;
} else { } else {
viewerSize = $.getElementSize( viewer.element ); viewerSize = $.getElementSize( viewer.element );
this.element.style.height = Math.round( viewerSize.y * options.sizeRatio ) + 'px'; this.element.style.height = Math.round( viewerSize.y * options.sizeRatio ) + 'px';

View File

@ -859,7 +859,7 @@ function OpenSeadragon( options ){
try { try {
// We test if the canvas is tainted by retrieving data from it. // We test if the canvas is tainted by retrieving data from it.
// An exception will be raised if the canvas is tainted. // An exception will be raised if the canvas is tainted.
var data = canvas.getContext('2d').getImageData(0, 0, 1, 1); canvas.getContext('2d').getImageData(0, 0, 1, 1);
} catch (e) { } catch (e) {
isTainted = true; isTainted = true;
} }
@ -1026,10 +1026,46 @@ function OpenSeadragon( options ){
dblClickDistThreshold: 20, dblClickDistThreshold: 20,
springStiffness: 6.5, springStiffness: 6.5,
animationTime: 1.2, animationTime: 1.2,
gestureSettingsMouse: { scrollToZoom: true, clickToZoom: true, dblClickToZoom: false, pinchToZoom: false, flickEnabled: false, flickMinSpeed: 120, flickMomentum: 0.25, pinchRotate: false }, gestureSettingsMouse: {
gestureSettingsTouch: { scrollToZoom: false, clickToZoom: false, dblClickToZoom: true, pinchToZoom: true, flickEnabled: true, flickMinSpeed: 120, flickMomentum: 0.25, pinchRotate: false }, scrollToZoom: true,
gestureSettingsPen: { scrollToZoom: false, clickToZoom: true, dblClickToZoom: false, pinchToZoom: false, flickEnabled: false, flickMinSpeed: 120, flickMomentum: 0.25, pinchRotate: false }, clickToZoom: true,
gestureSettingsUnknown: { scrollToZoom: false, clickToZoom: false, dblClickToZoom: true, pinchToZoom: true, flickEnabled: true, flickMinSpeed: 120, flickMomentum: 0.25, pinchRotate: false }, dblClickToZoom: false,
pinchToZoom: false,
flickEnabled: false,
flickMinSpeed: 120,
flickMomentum: 0.25,
pinchRotate: false
},
gestureSettingsTouch: {
scrollToZoom: false,
clickToZoom: false,
dblClickToZoom: true,
pinchToZoom: true,
flickEnabled: true,
flickMinSpeed: 120,
flickMomentum: 0.25,
pinchRotate: false
},
gestureSettingsPen: {
scrollToZoom: false,
clickToZoom: true,
dblClickToZoom: false,
pinchToZoom: false,
flickEnabled: false,
flickMinSpeed: 120,
flickMomentum: 0.25,
pinchRotate: false
},
gestureSettingsUnknown: {
scrollToZoom: false,
clickToZoom: false,
dblClickToZoom: true,
pinchToZoom: true,
flickEnabled: true,
flickMinSpeed: 120,
flickMomentum: 0.25,
pinchRotate: false
},
zoomPerClick: 2, zoomPerClick: 2,
zoomPerScroll: 1.2, zoomPerScroll: 1.2,
zoomPerSecond: 1.0, zoomPerSecond: 1.0,
@ -1504,7 +1540,7 @@ function OpenSeadragon( options ){
}; };
} else { } else {
// We can't reassign the function yet, as there was no scroll. // We can't reassign the function yet, as there was no scroll.
return new $.Point(0,0); return new $.Point(0, 0);
} }
return $.getPageScroll(); return $.getPageScroll();
@ -1672,13 +1708,15 @@ function OpenSeadragon( options ){
* @function * @function
*/ */
now: function( ) { now: function( ) {
if (Date.now) { if (Date.now) {
$.now = Date.now; $.now = Date.now;
} else { } else {
$.now = function() { return new Date().getTime(); }; $.now = function() {
} return new Date().getTime();
};
}
return $.now(); return $.now();
}, },
@ -1788,7 +1826,7 @@ function OpenSeadragon( options ){
addClass: function( element, className ) { addClass: function( element, className ) {
element = $.getElement( element ); element = $.getElement( element );
if ( ! element.className ) { if (!element.className) {
element.className = className; element.className = className;
} else if ( ( ' ' + element.className + ' ' ). } else if ( ( ' ' + element.className + ' ' ).
indexOf( ' ' + className + ' ' ) === -1 ) { indexOf( ' ' + className + ' ' ) === -1 ) {
@ -2012,6 +2050,7 @@ function OpenSeadragon( options ){
* @returns {String} The value of the url parameter or null if no param matches. * @returns {String} The value of the url parameter or null if no param matches.
*/ */
getUrlParameter: function( key ) { getUrlParameter: function( key ) {
// eslint-disable-next-line no-use-before-define
var value = URLPARAMS[ key ]; var value = URLPARAMS[ key ];
return value ? value : null; return value ? value : null;
}, },
@ -2169,7 +2208,7 @@ function OpenSeadragon( options ){
} }
}; };
xdr.onerror = function (e) { xdr.onerror = function (e) {
if ( $.isFunction ( onError ) ) { if ($.isFunction(onError)) {
onError({ // Faking an xhr object onError({ // Faking an xhr object
responseText: xdr.responseText, responseText: xdr.responseText,
status: 444, // 444 No Response status: 444, // 444 No Response
@ -2332,6 +2371,7 @@ function OpenSeadragon( options ){
// Should only be used by IE8 in non standards mode // Should only be used by IE8 in non standards mode
$.parseJSON = function(string) { $.parseJSON = function(string) {
/*jshint evil:true*/ /*jshint evil:true*/
//eslint-disable-next-line no-eval
return eval('(' + string + ')'); return eval('(' + string + ')');
}; };
} }
@ -2347,6 +2387,7 @@ function OpenSeadragon( options ){
*/ */
imageFormatSupported: function( extension ) { imageFormatSupported: function( extension ) {
extension = extension ? extension : ""; extension = extension ? extension : "";
// eslint-disable-next-line no-use-before-define
return !!FILEFORMATS[ extension.toLowerCase() ]; return !!FILEFORMATS[ extension.toLowerCase() ];
} }
@ -2383,8 +2424,7 @@ function OpenSeadragon( options ){
(function() { (function() {
//A small auto-executing routine to determine the browser vendor, //A small auto-executing routine to determine the browser vendor,
//version and supporting feature sets. //version and supporting feature sets.
var app = navigator.appName, var ver = navigator.appVersion,
ver = navigator.appVersion,
ua = navigator.userAgent, ua = navigator.userAgent,
regex; regex;
@ -2406,7 +2446,7 @@ function OpenSeadragon( options ){
} }
break; break;
case "Netscape": case "Netscape":
if( !!window.addEventListener ){ if (window.addEventListener) {
if ( ua.indexOf( "Firefox" ) >= 0 ) { if ( ua.indexOf( "Firefox" ) >= 0 ) {
$.Browser.vendor = $.BROWSERS.FIREFOX; $.Browser.vendor = $.BROWSERS.FIREFOX;
$.Browser.version = parseFloat( $.Browser.version = parseFloat(

View File

@ -592,6 +592,4 @@ function onKeyPress( event ) {
} }
} }
}(OpenSeadragon));
} ( OpenSeadragon ) );

View File

@ -226,7 +226,7 @@ $.Spring.prototype = {
transform( transform(
this.springStiffness, this.springStiffness,
( this.current.time - this.start.time ) / ( this.current.time - this.start.time ) /
( this.target.time - this.start.time ) ( this.target.time - this.start.time )
); );
if (this._exponential) { if (this._exponential) {

View File

@ -75,7 +75,7 @@ $.extend( $, /** @lends OpenSeadragon */{
container = I18N, container = I18N,
i; i;
for ( i = 0; i < props.length-1; i++ ) { for (i = 0; i < props.length - 1; i++) {
// in case not a subproperty // in case not a subproperty
container = container[ props[ i ] ] || {}; container = container[ props[ i ] ] || {};
} }

View File

@ -577,7 +577,7 @@ $.extend($.TiledImage.prototype, $.EventSource.prototype, /** @lends OpenSeadrag
viewportToImageZoom: function( viewportZoom ) { viewportToImageZoom: function( viewportZoom ) {
var ratio = this._scaleSpring.current.value * var ratio = this._scaleSpring.current.value *
this.viewport._containerInnerSize.x / this.source.dimensions.x; this.viewport._containerInnerSize.x / this.source.dimensions.x;
return ratio * viewportZoom ; return ratio * viewportZoom;
}, },
/** /**

View File

@ -187,8 +187,8 @@ $.TileSource = function( width, height, tileSize, tileOverlap, minLevel, maxLeve
//explicit configuration via positional args in constructor //explicit configuration via positional args in constructor
//or the more idiomatic 'options' object //or the more idiomatic 'options' object
this.ready = true; this.ready = true;
this.aspectRatio = ( options.width && options.height ) ? this.aspectRatio = (options.width && options.height) ?
( options.width / options.height ) : 1; (options.width / options.height) : 1;
this.dimensions = new $.Point( options.width, options.height ); this.dimensions = new $.Point( options.width, options.height );
if ( this.tileSize ){ if ( this.tileSize ){
@ -454,7 +454,7 @@ $.TileSource.prototype = {
//TODO: Its not very flexible to require tile sources to end jsonp //TODO: Its not very flexible to require tile sources to end jsonp
// request for info with a url that ends with '.js' but for // request for info with a url that ends with '.js' but for
// now it's the only way I see to distinguish uniformly. // now it's the only way I see to distinguish uniformly.
callbackName = url.split( '/' ).pop().replace('.js',''); callbackName = url.split('/').pop().replace('.js', '');
$.jsonp({ $.jsonp({
url: url, url: url,
async: false, async: false,
@ -574,12 +574,12 @@ $.TileSource.prototype = {
*/ */
tileExists: function( level, x, y ) { tileExists: function( level, x, y ) {
var numTiles = this.getNumTiles( level ); var numTiles = this.getNumTiles( level );
return level >= this.minLevel && return level >= this.minLevel &&
level <= this.maxLevel && level <= this.maxLevel &&
x >= 0 && x >= 0 &&
y >= 0 && y >= 0 &&
x < numTiles.x && x < numTiles.x &&
y < numTiles.y; y < numTiles.y;
} }
}; };

View File

@ -32,11 +32,11 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
(function( $ ){ (function($) {
// deprecated // deprecated
$.TileSourceCollection = function( tileSize, tileSources, rows, layout ) { $.TileSourceCollection = function(tileSize, tileSources, rows, layout) {
$.console.error('TileSourceCollection is deprecated; use World instead'); $.console.error('TileSourceCollection is deprecated; use World instead');
}; };
}( OpenSeadragon )); }(OpenSeadragon));

View File

@ -83,7 +83,7 @@ $.TmsTileSource = function( width, height, tileSize, tileOverlap, tilesUrl ) {
} else { } else {
max = bufferedHeight / 256; max = bufferedHeight / 256;
} }
options.maxLevel = Math.ceil(Math.log(max)/Math.log(2)) - 1; options.maxLevel = Math.ceil(Math.log(max) / Math.log(2)) - 1;
options.tileSize = 256; options.tileSize = 256;
options.width = bufferedWidth; options.width = bufferedWidth;
options.height = bufferedHeight; options.height = bufferedHeight;
@ -129,7 +129,7 @@ $.extend( $.TmsTileSource.prototype, $.TileSource.prototype, /** @lends OpenSead
// Convert from Deep Zoom definition to TMS zoom definition // Convert from Deep Zoom definition to TMS zoom definition
var yTiles = this.getNumTiles( level ).y - 1; var yTiles = this.getNumTiles( level ).y - 1;
return this.tilesUrl + level + "/" + x + "/" + (yTiles - y) + ".png"; return this.tilesUrl + level + "/" + x + "/" + (yTiles - y) + ".png";
} }
}); });

View File

@ -221,7 +221,7 @@ $.Viewer = function( options ) {
$.ControlDock.call( this, options ); $.ControlDock.call( this, options );
//Deal with tile sources //Deal with tile sources
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
this.tileSources = [ this.xmlPath ]; this.tileSources = [ this.xmlPath ];
} }
@ -268,7 +268,7 @@ $.Viewer = function( options ) {
this.innerTracker = new $.MouseTracker({ this.innerTracker = new $.MouseTracker({
element: this.canvas, element: this.canvas,
startDisabled: this.mouseNavEnabled ? false : true, startDisabled: !this.mouseNavEnabled,
clickTimeThreshold: this.clickTimeThreshold, clickTimeThreshold: this.clickTimeThreshold,
clickDistThreshold: this.clickDistThreshold, clickDistThreshold: this.clickDistThreshold,
dblClickTimeThreshold: this.dblClickTimeThreshold, dblClickTimeThreshold: this.dblClickTimeThreshold,
@ -291,7 +291,7 @@ $.Viewer = function( options ) {
this.outerTracker = new $.MouseTracker({ this.outerTracker = new $.MouseTracker({
element: this.container, element: this.container,
startDisabled: this.mouseNavEnabled ? false : true, startDisabled: !this.mouseNavEnabled,
clickTimeThreshold: this.clickTimeThreshold, clickTimeThreshold: this.clickTimeThreshold,
clickDistThreshold: this.clickDistThreshold, clickDistThreshold: this.clickDistThreshold,
dblClickTimeThreshold: this.dblClickTimeThreshold, dblClickTimeThreshold: this.dblClickTimeThreshold,
@ -674,7 +674,7 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype,
this.navigator.close(); this.navigator.close();
} }
if( ! this.preserveOverlays) { if (!this.preserveOverlays) {
this.clearOverlays(); this.clearOverlays();
this.overlaysContainer.innerHTML = ""; this.overlaysContainer.innerHTML = "";
} }
@ -869,7 +869,6 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype,
bodyStyle = body.style, bodyStyle = body.style,
docStyle = document.documentElement.style, docStyle = document.documentElement.style,
_this = this, _this = this,
hash,
nodes, nodes,
i; i;
@ -1031,9 +1030,9 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype,
$.setPageScroll( _this.pageScroll ); $.setPageScroll( _this.pageScroll );
var pageScroll = $.getPageScroll(); var pageScroll = $.getPageScroll();
restoreScrollCounter++; restoreScrollCounter++;
if ( restoreScrollCounter < 10 && if (restoreScrollCounter < 10 &&
pageScroll.x !== _this.pageScroll.x || (pageScroll.x !== _this.pageScroll.x ||
pageScroll.y !== _this.pageScroll.y ) { pageScroll.y !== _this.pageScroll.y)) {
$.requestAnimationFrame( restoreScroll ); $.requestAnimationFrame( restoreScroll );
} }
}; };
@ -1526,7 +1525,7 @@ $.extend( $.Viewer.prototype, $.EventSource.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,
useGroup = true ; useGroup = true;
if( this.showSequenceControl ){ if( this.showSequenceControl ){
@ -1622,7 +1621,7 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype,
onBlurHandler = $.delegate( this, onBlur ), onBlurHandler = $.delegate( this, onBlur ),
navImages = this.navImages, navImages = this.navImages,
buttons = [], buttons = [],
useGroup = true ; useGroup = true;
if ( this.showNavigationControl ) { if ( this.showNavigationControl ) {
@ -1993,7 +1992,7 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype,
element = $.getElement( element ); element = $.getElement( element );
i = getOverlayIndex( this.currentOverlays, element ); i = getOverlayIndex( this.currentOverlays, element );
if (i>=0) { if (i >= 0) {
return this.currentOverlays[i]; return this.currentOverlays[i];
} else { } else {
return null; return null;

View File

@ -60,11 +60,11 @@ $.Viewport = function( options ) {
//backward compatibility for positional args while prefering more //backward compatibility for positional args while prefering more
//idiomatic javascript options object as the only argument //idiomatic javascript options object as the only argument
var args = arguments; var args = arguments;
if( args.length && args[ 0 ] instanceof $.Point ){ if (args.length && args[0] instanceof $.Point) {
options = { options = {
containerSize: args[ 0 ], containerSize: args[0],
contentSize: args[ 1 ], contentSize: args[1],
config: args[ 2 ] config: args[2]
}; };
} }

View File

@ -212,7 +212,8 @@ $.extend( $.World.prototype, $.EventSource.prototype, /** @lends OpenSeadragon.W
// We need to make sure any pending images are canceled so the world items don't get messed up // We need to make sure any pending images are canceled so the world items don't get messed up
this.viewer._cancelPendingImages(); this.viewer._cancelPendingImages();
var item; var item;
for (var i = 0; i < this._items.length; i++) { var i;
for (i = 0; i < this._items.length; i++) {
item = this._items[i]; item = this._items[i];
item.removeHandler('bounds-change', this._delegatedFigureSizes); item.removeHandler('bounds-change', this._delegatedFigureSizes);
item.removeHandler('clip-change', this._delegatedFigureSizes); item.removeHandler('clip-change', this._delegatedFigureSizes);