mirror of
https://github.com/openseadragon/openseadragon.git
synced 2024-11-25 22:56:11 +03:00
mostly superficial formating. removing $.Strings and putting it directly in $. more clean up of the Drawer update related functions
This commit is contained in:
parent
bc50a7df04
commit
a8730a9f00
@ -6,7 +6,7 @@
|
||||
PROJECT: openseadragon
|
||||
BUILD_MAJOR: 0
|
||||
BUILD_MINOR: 8
|
||||
BUILD_ID: 20
|
||||
BUILD_ID: 22
|
||||
BUILD: ${PROJECT}.${BUILD_MAJOR}.${BUILD_MINOR}.${BUILD_ID}
|
||||
VERSION: ${BUILD_MAJOR}.${BUILD_MINOR}.${BUILD_ID}
|
||||
|
||||
|
475
openseadragon.js
475
openseadragon.js
@ -3,7 +3,7 @@
|
||||
* (c) 2010 OpenSeadragon
|
||||
* (c) 2010 CodePlex Foundation
|
||||
*
|
||||
* OpenSeadragon 0.8.20
|
||||
* OpenSeadragon 0.8.22
|
||||
* ----------------------------------------------------------------------------
|
||||
*
|
||||
* License: New BSD License (BSD)
|
||||
@ -711,7 +711,11 @@ OpenSeadragon = window.OpenSeadragon || (function(){
|
||||
request.open( "GET", url, async );
|
||||
request.send( null );
|
||||
} catch (e) {
|
||||
$.Debug.log(e.name + " while making AJAX request: " + e.message);
|
||||
$.Debug.log(
|
||||
"%s while making AJAX request: %s",
|
||||
e.name,
|
||||
e.message
|
||||
);
|
||||
|
||||
request.onreadystatechange = null;
|
||||
request = null;
|
||||
@ -791,8 +795,8 @@ OpenSeadragon = window.OpenSeadragon || (function(){
|
||||
Array.apply( null, events );
|
||||
return function( source, args ) {
|
||||
var i,
|
||||
l = events.length;
|
||||
for ( i = 0; i < l; i++ ) {
|
||||
length = events.length;
|
||||
for ( i = 0; i < length; i++ ) {
|
||||
events[ i ]( source, args );
|
||||
}
|
||||
};
|
||||
@ -1297,23 +1301,32 @@ $.Control = function (elmt, anchor, container) {
|
||||
|
||||
if ( this.anchor == $.ControlAnchor.TOP_RIGHT ||
|
||||
this.anchor == $.ControlAnchor.BOTTOM_RIGHT ) {
|
||||
this.container.insertBefore(this.wrapper, this.container.firstChild);
|
||||
this.container.insertBefore(
|
||||
this.wrapper,
|
||||
this.container.firstChild
|
||||
);
|
||||
} else {
|
||||
this.container.appendChild( this.wrapper );
|
||||
}
|
||||
};
|
||||
|
||||
$.Control.prototype = {
|
||||
|
||||
destroy: function() {
|
||||
this.wrapper.removeChild( this.elmt );
|
||||
this.container.removeChild( this.wrapper );
|
||||
},
|
||||
|
||||
isVisible: function() {
|
||||
return this.wrapper.style.display != "none";
|
||||
},
|
||||
|
||||
setVisible: function( visible ) {
|
||||
this.wrapper.style.display = visible ? "inline-block" : "none";
|
||||
this.wrapper.style.display = visible ?
|
||||
"inline-block" :
|
||||
"none";
|
||||
},
|
||||
|
||||
setOpacity: function( opacity ) {
|
||||
if ( this.elmt[ $.SIGNAL ] && $.Browser.vendor == $.BROWSERS.IE ) {
|
||||
$.setElementOpacity( this.elmt, opacity, true );
|
||||
@ -1525,25 +1538,27 @@ $.Viewer = function( options ) {
|
||||
// Navigation Controls
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
this._group = null;
|
||||
this._zooming = false; // whether we should be continuously zooming
|
||||
this._zoomFactor = null; // how much we should be continuously zooming by
|
||||
// whether we should be continuously zooming
|
||||
this._zooming = false;
|
||||
// how much we should be continuously zooming by
|
||||
this._zoomFactor = null;
|
||||
this._lastZoomTime = null;
|
||||
|
||||
this.elmt = null;
|
||||
|
||||
var beginZoomingInHandler = $.delegate(this, beginZoomingIn);
|
||||
var endZoomingHandler = $.delegate(this, endZooming);
|
||||
var doSingleZoomInHandler = $.delegate(this, doSingleZoomIn);
|
||||
var beginZoomingOutHandler = $.delegate(this, beginZoomingOut);
|
||||
var doSingleZoomOutHandler = $.delegate(this, doSingleZoomOut);
|
||||
var onHomeHandler = $.delegate(this, onHome);
|
||||
var onFullPageHandler = $.delegate(this, onFullPage);
|
||||
var beginZoomingInHandler = $.delegate(this, beginZoomingIn),
|
||||
endZoomingHandler = $.delegate(this, endZooming),
|
||||
doSingleZoomInHandler = $.delegate(this, doSingleZoomIn),
|
||||
beginZoomingOutHandler = $.delegate(this, beginZoomingOut),
|
||||
doSingleZoomOutHandler = $.delegate(this, doSingleZoomOut),
|
||||
onHomeHandler = $.delegate(this, onHome),
|
||||
onFullPageHandler = $.delegate(this, onFullPage);
|
||||
|
||||
var navImages = this.config.navImages;
|
||||
|
||||
var zoomIn = new $.Button({
|
||||
config: this.config,
|
||||
tooltip: $.Strings.getString("Tooltips.ZoomIn"),
|
||||
tooltip: $.getString("Tooltips.ZoomIn"),
|
||||
srcRest: resolveUrl(this.urlPrefix, navImages.zoomIn.REST),
|
||||
srcGroup: resolveUrl(this.urlPrefix, navImages.zoomIn.GROUP),
|
||||
srcHover: resolveUrl(this.urlPrefix, navImages.zoomIn.HOVER),
|
||||
@ -1557,7 +1572,7 @@ $.Viewer = function( options ) {
|
||||
|
||||
var zoomOut = new $.Button({
|
||||
config: this.config,
|
||||
tooltip: $.Strings.getString("Tooltips.ZoomOut"),
|
||||
tooltip: $.getString("Tooltips.ZoomOut"),
|
||||
srcRest: resolveUrl(this.urlPrefix, navImages.zoomOut.REST),
|
||||
srcGroup: resolveUrl(this.urlPrefix, navImages.zoomOut.GROUP),
|
||||
srcHover: resolveUrl(this.urlPrefix, navImages.zoomOut.HOVER),
|
||||
@ -1570,7 +1585,7 @@ $.Viewer = function( options ) {
|
||||
});
|
||||
var goHome = new $.Button({
|
||||
config: this.config,
|
||||
tooltip: $.Strings.getString("Tooltips.Home"),
|
||||
tooltip: $.getString("Tooltips.Home"),
|
||||
srcRest: resolveUrl(this.urlPrefix, navImages.home.REST),
|
||||
srcGroup: resolveUrl(this.urlPrefix, navImages.home.GROUP),
|
||||
srcHover: resolveUrl(this.urlPrefix, navImages.home.HOVER),
|
||||
@ -1579,7 +1594,7 @@ $.Viewer = function( options ) {
|
||||
});
|
||||
var fullPage = new $.Button({
|
||||
config: this.config,
|
||||
tooltip: $.Strings.getString("Tooltips.FullPage"),
|
||||
tooltip: $.getString("Tooltips.FullPage"),
|
||||
srcRest: resolveUrl(this.urlPrefix, navImages.fullpage.REST),
|
||||
srcGroup: resolveUrl(this.urlPrefix, navImages.fullpage.GROUP),
|
||||
srcHover: resolveUrl(this.urlPrefix, navImages.fullpage.HOVER),
|
||||
@ -1698,7 +1713,7 @@ $.extend($.Viewer.prototype, $.EventHandler.prototype, {
|
||||
|
||||
window.setTimeout( function () {
|
||||
if ( _this._lastOpenStartTime > _this._lastOpenEndTime ) {
|
||||
_this._setMessage( $.Strings.getString( "Messages.Loading" ) );
|
||||
_this._setMessage( $.getString( "Messages.Loading" ) );
|
||||
}
|
||||
}, 2000);
|
||||
|
||||
@ -2210,9 +2225,7 @@ function onFullPage() {
|
||||
//TODO: I guess this is where the i18n needs to be reimplemented. I'll look
|
||||
// into existing patterns for i18n in javascript but i think that mimicking
|
||||
// pythons gettext might be a reasonable approach.
|
||||
|
||||
$.Strings = {
|
||||
|
||||
var I18N = {
|
||||
Errors: {
|
||||
Failure: "Sorry, but Seadragon Ajax can't run on your browser!\n" +
|
||||
"Please try using IE 7 or Firefox 3.\n",
|
||||
@ -2236,12 +2249,15 @@ $.Strings = {
|
||||
Home: "Go home",
|
||||
ZoomIn: "Zoom in",
|
||||
ZoomOut: "Zoom out"
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
$.extend( $, {
|
||||
|
||||
getString: function( prop ) {
|
||||
|
||||
var props = prop.split('.'),
|
||||
string = $.Strings,
|
||||
string = I18N,
|
||||
args = arguments,
|
||||
i;
|
||||
|
||||
@ -2277,7 +2293,7 @@ $.Strings = {
|
||||
container[ props[ i ] ] = value;
|
||||
}
|
||||
|
||||
};
|
||||
});
|
||||
|
||||
}( OpenSeadragon ));
|
||||
|
||||
@ -2334,9 +2350,13 @@ $.Point.prototype = {
|
||||
},
|
||||
|
||||
equals: function( point ) {
|
||||
return ( point instanceof $.Point ) &&
|
||||
( this.x === point.x ) &&
|
||||
( this.y === point.y );
|
||||
return (
|
||||
point instanceof $.Point
|
||||
) && (
|
||||
this.x === point.x
|
||||
) && (
|
||||
this.y === point.y
|
||||
);
|
||||
},
|
||||
|
||||
toString: function() {
|
||||
@ -2436,59 +2456,57 @@ $.Profiler.prototype = {
|
||||
$.TileSource = function( width, height, tileSize, tileOverlap, minLevel, maxLevel ) {
|
||||
this.aspectRatio = width / height;
|
||||
this.dimensions = new $.Point( width, height );
|
||||
this.tileSize = tileSize ? tileSize : 0;
|
||||
this.tileOverlap = tileOverlap ? tileOverlap : 0;
|
||||
this.minLevel = minLevel ? minLevel : 0;
|
||||
this.maxLevel = maxLevel ? maxLevel :
|
||||
Math.ceil(
|
||||
Math.log( Math.max( width, height ) ) /
|
||||
Math.log( 2 )
|
||||
);
|
||||
this.tileSize = tileSize ? tileSize : 0;
|
||||
this.tileOverlap = tileOverlap ? tileOverlap : 0;
|
||||
};
|
||||
|
||||
$.TileSource.prototype = {
|
||||
|
||||
getLevelScale: function( level ) {
|
||||
return 1 / ( 1 << ( this.maxLevel - level ) );
|
||||
},
|
||||
|
||||
getNumTiles: function( level ) {
|
||||
var scale = this.getLevelScale(level);
|
||||
var x = Math.ceil(scale * this.dimensions.x / this.tileSize);
|
||||
var y = Math.ceil(scale * this.dimensions.y / this.tileSize);
|
||||
var scale = this.getLevelScale( level ),
|
||||
x = Math.ceil( scale * this.dimensions.x / this.tileSize ),
|
||||
y = Math.ceil( scale * this.dimensions.y / this.tileSize );
|
||||
|
||||
return new $.Point( x, y );
|
||||
},
|
||||
|
||||
getPixelRatio: function( level ) {
|
||||
var imageSizeScaled = this.dimensions.times(this.getLevelScale(level));
|
||||
var rx = 1.0 / imageSizeScaled.x;
|
||||
var ry = 1.0 / imageSizeScaled.y;
|
||||
var imageSizeScaled = this.dimensions.times( this.getLevelScale( level ) ),
|
||||
rx = 1.0 / imageSizeScaled.x,
|
||||
ry = 1.0 / imageSizeScaled.y;
|
||||
|
||||
return new $.Point(rx, ry);
|
||||
},
|
||||
|
||||
getTileAtPoint: function( level, point ) {
|
||||
var pixel = point.times(this.dimensions.x).times(this.getLevelScale(level));
|
||||
|
||||
var tx = Math.floor(pixel.x / this.tileSize);
|
||||
var ty = Math.floor(pixel.y / this.tileSize);
|
||||
var pixel = point.times( this.dimensions.x ).times( this.getLevelScale(level ) ),
|
||||
tx = Math.floor( pixel.x / this.tileSize ),
|
||||
ty = Math.floor( pixel.y / this.tileSize );
|
||||
|
||||
return new $.Point( tx, ty );
|
||||
},
|
||||
|
||||
getTileBounds: function( level, x, y ) {
|
||||
var dimensionsScaled = this.dimensions.times(this.getLevelScale(level));
|
||||
|
||||
var px = (x === 0) ? 0 : this.tileSize * x - this.tileOverlap;
|
||||
var py = (y === 0) ? 0 : this.tileSize * y - this.tileOverlap;
|
||||
|
||||
var sx = this.tileSize + (x === 0 ? 1 : 2) * this.tileOverlap;
|
||||
var sy = this.tileSize + (y === 0 ? 1 : 2) * this.tileOverlap;
|
||||
var dimensionsScaled = this.dimensions.times( this.getLevelScale( level ) ),
|
||||
px = ( x === 0 ) ? 0 : this.tileSize * x - this.tileOverlap,
|
||||
py = ( y === 0 ) ? 0 : this.tileSize * y - this.tileOverlap,
|
||||
sx = this.tileSize + ( x === 0 ? 1 : 2 ) * this.tileOverlap,
|
||||
sy = this.tileSize + ( y === 0 ? 1 : 2 ) * this.tileOverlap,
|
||||
scale = 1.0 / dimensionsScaled.x;
|
||||
|
||||
sx = Math.min( sx, dimensionsScaled.x - px );
|
||||
sy = Math.min( sy, dimensionsScaled.y - py );
|
||||
|
||||
var scale = 1.0 / dimensionsScaled.x;
|
||||
return new $.Rect( px * scale, py * scale, sx * scale, sy * scale );
|
||||
},
|
||||
|
||||
@ -2513,18 +2531,21 @@ $.TileSource.prototype = {
|
||||
|
||||
|
||||
$.DziTileSource = function( width, height, tileSize, tileOverlap, tilesUrl, fileFormat, displayRects ) {
|
||||
var i,
|
||||
rect,
|
||||
level;
|
||||
|
||||
$.TileSource.call( this, width, height, tileSize, tileOverlap, null, null );
|
||||
|
||||
this._levelRects = {};
|
||||
this.tilesUrl = tilesUrl;
|
||||
|
||||
this.fileFormat = fileFormat;
|
||||
this.displayRects = displayRects;
|
||||
|
||||
if ( this.displayRects ) {
|
||||
for (var i = this.displayRects.length - 1; i >= 0; i--) {
|
||||
var rect = this.displayRects[i];
|
||||
for (var level = rect.minLevel; level <= rect.maxLevel; level++) {
|
||||
for ( i = this.displayRects.length - 1; i >= 0; i-- ) {
|
||||
rect = this.displayRects[ i ];
|
||||
for ( level = rect.minLevel; level <= rect.maxLevel; level++ ) {
|
||||
if ( !this._levelRects[ level ] ) {
|
||||
this._levelRects[ level ] = [];
|
||||
}
|
||||
@ -2542,24 +2563,31 @@ $.extend( $.DziTileSource.prototype, $.TileSource.prototype, {
|
||||
},
|
||||
|
||||
tileExists: function( level, x, y ) {
|
||||
var rects = this._levelRects[level];
|
||||
var rects = this._levelRects[ level ],
|
||||
rect,
|
||||
scale,
|
||||
xMin,
|
||||
yMin,
|
||||
xMax,
|
||||
yMax,
|
||||
i;
|
||||
|
||||
if ( !rects || !rects.length ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
for (var i = rects.length - 1; i >= 0; i--) {
|
||||
var rect = rects[i];
|
||||
for ( i = rects.length - 1; i >= 0; i-- ) {
|
||||
rect = rects[ i ];
|
||||
|
||||
if ( level < rect.minLevel || level > rect.maxLevel ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
var scale = this.getLevelScale(level);
|
||||
var xMin = rect.x * scale;
|
||||
var yMin = rect.y * scale;
|
||||
var xMax = xMin + rect.width * scale;
|
||||
var yMax = yMin + rect.height * scale;
|
||||
scale = this.getLevelScale( level );
|
||||
xMin = rect.x * scale;
|
||||
yMin = rect.y * scale;
|
||||
xMax = xMin + rect.width * scale;
|
||||
yMax = yMin + rect.height * scale;
|
||||
|
||||
xMin = Math.floor( xMin / this.tileSize );
|
||||
yMin = Math.floor( yMin / this.tileSize );
|
||||
@ -2576,12 +2604,18 @@ $.extend( $.DziTileSource.prototype, $.TileSource.prototype, {
|
||||
});
|
||||
|
||||
$.DziTileSourceHelper = {
|
||||
|
||||
createFromXml: function( xmlUrl, xmlString, callback ) {
|
||||
var async = typeof (callback) == "function";
|
||||
var error = null;
|
||||
var async = typeof (callback) == "function",
|
||||
error = null,
|
||||
urlParts,
|
||||
filename,
|
||||
lastDot,
|
||||
tilesUrl,
|
||||
handler;
|
||||
|
||||
if ( !xmlUrl ) {
|
||||
this.error = $.Strings.getString("Errors.Empty");
|
||||
this.error = $.getString( "Errors.Empty" );
|
||||
if ( async ) {
|
||||
window.setTimeout( function() {
|
||||
callback( null, error );
|
||||
@ -2591,15 +2625,16 @@ $.DziTileSourceHelper = {
|
||||
throw new Error( error );
|
||||
}
|
||||
|
||||
var urlParts = xmlUrl.split('/');
|
||||
var filename = urlParts[urlParts.length - 1];
|
||||
var lastDot = filename.lastIndexOf('.');
|
||||
urlParts = xmlUrl.split( '/' );
|
||||
filename = urlParts[ urlParts.length - 1 ];
|
||||
lastDot = filename.lastIndexOf( '.' );
|
||||
|
||||
if ( lastDot > -1 ) {
|
||||
urlParts[ urlParts.length - 1 ] = filename.slice( 0, lastDot );
|
||||
}
|
||||
|
||||
var tilesUrl = urlParts.join('/') + "_files/";
|
||||
tilesUrl = urlParts.join( '/' ) + "_files/";
|
||||
|
||||
function finish( func, obj ) {
|
||||
try {
|
||||
return func( obj, tilesUrl );
|
||||
@ -2611,18 +2646,21 @@ $.DziTileSourceHelper = {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( async ) {
|
||||
if ( xmlString ) {
|
||||
var handler = $.delegate(this, this.processXml);
|
||||
handler = $.delegate( this, this.processXml );
|
||||
window.setTimeout( function() {
|
||||
var source = finish( handler, $.parseXml( xmlString ) );
|
||||
callback(source, error); // call after finish sets error
|
||||
// call after finish sets error
|
||||
callback( source, error );
|
||||
}, 1);
|
||||
} else {
|
||||
var handler = $.delegate(this, this.processResponse);
|
||||
handler = $.delegate( this, this.processResponse );
|
||||
$.makeAjaxRequest( xmlUrl, function( xhr ) {
|
||||
var source = finish( handler, xhr );
|
||||
callback(source, error); // call after finish sets error
|
||||
// call after finish sets error
|
||||
callback( source, error );
|
||||
});
|
||||
}
|
||||
|
||||
@ -2630,21 +2668,31 @@ $.DziTileSourceHelper = {
|
||||
}
|
||||
|
||||
if ( xmlString ) {
|
||||
return finish($.delegate(this, this.processXml), $.parseXml(xmlString));
|
||||
return finish(
|
||||
$.delegate( this, this.processXml ),
|
||||
$.parseXml( xmlString )
|
||||
);
|
||||
} else {
|
||||
return finish($.delegate(this, this.processResponse), $.makeAjaxRequest(xmlUrl));
|
||||
return finish(
|
||||
$.delegate( this, this.processResponse ),
|
||||
$.makeAjaxRequest( xmlUrl )
|
||||
);
|
||||
}
|
||||
},
|
||||
processResponse: function( xhr, tilesUrl ) {
|
||||
if (!xhr) {
|
||||
throw new Error($.Strings.getString("Errors.Security"));
|
||||
} else if (xhr.status !== 200 && xhr.status !== 0) {
|
||||
var status = xhr.status;
|
||||
var statusText = (status == 404) ? "Not Found" : xhr.statusText;
|
||||
throw new Error($.Strings.getString("Errors.Status", status, statusText));
|
||||
}
|
||||
var status,
|
||||
statusText,
|
||||
doc = null;
|
||||
|
||||
var doc = null;
|
||||
if ( !xhr ) {
|
||||
throw new Error( $.getString( "Errors.Security" ) );
|
||||
} else if ( xhr.status !== 200 && xhr.status !== 0 ) {
|
||||
status = xhr.status;
|
||||
statusText = ( status == 404 ) ?
|
||||
"Not Found" :
|
||||
xhr.statusText;
|
||||
throw new Error( $.getString( "Errors.Status", status, statusText ) );
|
||||
}
|
||||
|
||||
if ( xhr.responseXML && xhr.responseXML.documentElement ) {
|
||||
doc = xhr.responseXML;
|
||||
@ -2656,66 +2704,77 @@ $.DziTileSourceHelper = {
|
||||
},
|
||||
|
||||
processXml: function( xmlDoc, tilesUrl ) {
|
||||
|
||||
if ( !xmlDoc || !xmlDoc.documentElement ) {
|
||||
throw new Error($.Strings.getString("Errors.Xml"));
|
||||
throw new Error( $.getString( "Errors.Xml" ) );
|
||||
}
|
||||
|
||||
var root = xmlDoc.documentElement;
|
||||
var rootName = root.tagName;
|
||||
var root = xmlDoc.documentElement,
|
||||
rootName = root.tagName;
|
||||
|
||||
if ( rootName == "Image" ) {
|
||||
try {
|
||||
return this.processDzi( root, tilesUrl );
|
||||
} catch ( e ) {
|
||||
var defMsg = $.Strings.getString("Errors.Dzi");
|
||||
throw (e instanceof Error) ? e : new Error(defMsg);
|
||||
throw (e instanceof Error) ?
|
||||
e :
|
||||
new Error( $.getString("Errors.Dzi") );
|
||||
}
|
||||
} else if ( rootName == "Collection" ) {
|
||||
throw new Error($.Strings.getString("Errors.Dzc"));
|
||||
throw new Error( $.getString( "Errors.Dzc" ) );
|
||||
} else if ( rootName == "Error" ) {
|
||||
return this.processError( root );
|
||||
}
|
||||
|
||||
throw new Error($.Strings.getString("Errors.Dzi"));
|
||||
throw new Error( $.getString( "Errors.Dzi" ) );
|
||||
},
|
||||
|
||||
processDzi: function( imageNode, tilesUrl ) {
|
||||
var fileFormat = imageNode.getAttribute("Format");
|
||||
var fileFormat = imageNode.getAttribute( "Format" ),
|
||||
sizeNode = imageNode.getElementsByTagName( "Size" )[ 0 ],
|
||||
dispRectNodes = imageNode.getElementsByTagName( "DisplayRect" ),
|
||||
width = parseInt( sizeNode.getAttribute( "Width" ) ),
|
||||
height = parseInt( sizeNode.getAttribute( "Height" ) ),
|
||||
tileSize = parseInt( imageNode.getAttribute( "TileSize" ) ),
|
||||
tileOverlap = parseInt( imageNode.getAttribute( "Overlap" ) ),
|
||||
dispRects = [],
|
||||
dispRectNode,
|
||||
rectNode,
|
||||
i;
|
||||
|
||||
if ( !$.imageFormatSupported( fileFormat ) ) {
|
||||
throw new Error($.Strings.getString("Errors.ImageFormat",
|
||||
fileFormat.toUpperCase()));
|
||||
throw new Error(
|
||||
$.getString( "Errors.ImageFormat", fileFormat.toUpperCase() )
|
||||
);
|
||||
}
|
||||
|
||||
var sizeNode = imageNode.getElementsByTagName("Size")[0];
|
||||
var dispRectNodes = imageNode.getElementsByTagName("DisplayRect");
|
||||
|
||||
var width = parseInt(sizeNode.getAttribute("Width"), 10);
|
||||
var height = parseInt(sizeNode.getAttribute("Height"), 10);
|
||||
var tileSize = parseInt(imageNode.getAttribute("TileSize"));
|
||||
var tileOverlap = parseInt(imageNode.getAttribute("Overlap"));
|
||||
var dispRects = [];
|
||||
|
||||
for (var i = 0; i < dispRectNodes.length; i++) {
|
||||
var dispRectNode = dispRectNodes[i];
|
||||
var rectNode = dispRectNode.getElementsByTagName("Rect")[0];
|
||||
for ( i = 0; i < dispRectNodes.length; i++ ) {
|
||||
dispRectNode = dispRectNodes[ i ];
|
||||
rectNode = dispRectNode.getElementsByTagName( "Rect" )[ 0 ];
|
||||
|
||||
dispRects.push( new $.DisplayRect(
|
||||
parseInt(rectNode.getAttribute("X"), 10),
|
||||
parseInt(rectNode.getAttribute("Y"), 10),
|
||||
parseInt(rectNode.getAttribute("Width"), 10),
|
||||
parseInt(rectNode.getAttribute("Height"), 10),
|
||||
parseInt( rectNode.getAttribute( "X" ) ),
|
||||
parseInt( rectNode.getAttribute( "Y" ) ),
|
||||
parseInt( rectNode.getAttribute( "Width" ) ),
|
||||
parseInt( rectNode.getAttribute( "Height" ) ),
|
||||
0, // ignore MinLevel attribute, bug in Deep Zoom Composer
|
||||
parseInt(dispRectNode.getAttribute("MaxLevel"), 10)
|
||||
parseInt( dispRectNode.getAttribute( "MaxLevel" ) )
|
||||
));
|
||||
}
|
||||
return new $.DziTileSource(width, height, tileSize, tileOverlap,
|
||||
tilesUrl, fileFormat, dispRects);
|
||||
return new $.DziTileSource(
|
||||
width,
|
||||
height,
|
||||
tileSize,
|
||||
tileOverlap,
|
||||
tilesUrl,
|
||||
fileFormat,
|
||||
dispRects
|
||||
);
|
||||
},
|
||||
|
||||
processError: function( errorNode ) {
|
||||
var messageNode = errorNode.getElementsByTagName("Message")[0];
|
||||
var message = messageNode.firstChild.nodeValue;
|
||||
var messageNode = errorNode.getElementsByTagName( "Message" )[ 0 ],
|
||||
message = messageNode.firstChild.nodeValue;
|
||||
|
||||
throw new Error(message);
|
||||
}
|
||||
@ -2747,22 +2806,23 @@ $.Button = function( options ) {
|
||||
//TODO: make button elements accessible by making them a-tags
|
||||
// maybe even consider basing them on the element and adding
|
||||
// methods jquery-style.
|
||||
this.element = options.element || $.makeNeutralElement("span");
|
||||
this.element = options.element || $.makeNeutralElement( "a" );
|
||||
this.element.href = '#';
|
||||
this.config = options.config;
|
||||
|
||||
if ( options.onPress != undefined ){
|
||||
if ( options.onPress ){
|
||||
this.addHandler( "onPress", options.onPress );
|
||||
}
|
||||
if ( options.onRelease != undefined ){
|
||||
if ( options.onRelease ){
|
||||
this.addHandler( "onRelease", options.onRelease );
|
||||
}
|
||||
if ( options.onClick != undefined ){
|
||||
if ( options.onClick ){
|
||||
this.addHandler( "onClick", options.onClick );
|
||||
}
|
||||
if ( options.onEnter != undefined ){
|
||||
if ( options.onEnter ){
|
||||
this.addHandler( "onEnter", options.onEnter );
|
||||
}
|
||||
if ( options.onExit != undefined ){
|
||||
if ( options.onExit ){
|
||||
this.addHandler( "onExit", options.onExit );
|
||||
}
|
||||
|
||||
@ -2791,10 +2851,10 @@ $.Button = function( options ) {
|
||||
this.element.appendChild( this.imgHover );
|
||||
this.element.appendChild( this.imgDown );
|
||||
|
||||
var styleRest = this.imgRest.style;
|
||||
var styleGroup = this.imgGroup.style;
|
||||
var styleHover = this.imgHover.style;
|
||||
var styleDown = this.imgDown.style;
|
||||
var styleRest = this.imgRest.style,
|
||||
styleGroup = this.imgGroup.style,
|
||||
styleHover = this.imgHover.style,
|
||||
styleDown = this.imgDown.style;
|
||||
|
||||
styleGroup.position =
|
||||
styleHover.position =
|
||||
@ -2865,12 +2925,15 @@ $.Button = function( options ) {
|
||||
};
|
||||
|
||||
$.extend( $.Button.prototype, $.EventHandler.prototype, {
|
||||
|
||||
notifyGroupEnter: function() {
|
||||
inTo( this, $.ButtonState.GROUP );
|
||||
},
|
||||
|
||||
notifyGroupExit: function() {
|
||||
outTo( this, $.ButtonState.REST );
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
|
||||
@ -2914,17 +2977,20 @@ function stopFading( button ) {
|
||||
};
|
||||
|
||||
function inTo( button, newState ) {
|
||||
if ( newState >= $.ButtonState.GROUP && button.currentState == $.ButtonState.REST ) {
|
||||
if ( newState >= $.ButtonState.GROUP &&
|
||||
button.currentState == $.ButtonState.REST ) {
|
||||
stopFading( button );
|
||||
button.currentState = $.ButtonState.GROUP;
|
||||
}
|
||||
|
||||
if ( newState >= $.ButtonState.HOVER && button.currentState == $.ButtonState.GROUP ) {
|
||||
if ( newState >= $.ButtonState.HOVER &&
|
||||
button.currentState == $.ButtonState.GROUP ) {
|
||||
button.imgHover.style.visibility = "";
|
||||
button.currentState = $.ButtonState.HOVER;
|
||||
}
|
||||
|
||||
if ( newState >= $.ButtonState.DOWN && button.currentState == $.ButtonState.HOVER ) {
|
||||
if ( newState >= $.ButtonState.DOWN &&
|
||||
button.currentState == $.ButtonState.HOVER ) {
|
||||
button.imgDown.style.visibility = "";
|
||||
button.currentState = $.ButtonState.DOWN;
|
||||
}
|
||||
@ -2932,17 +2998,20 @@ function inTo( button, newState ) {
|
||||
|
||||
|
||||
function outTo( button, newState ) {
|
||||
if ( newState <= $.ButtonState.HOVER && button.currentState == $.ButtonState.DOWN ) {
|
||||
if ( newState <= $.ButtonState.HOVER &&
|
||||
button.currentState == $.ButtonState.DOWN ) {
|
||||
button.imgDown.style.visibility = "hidden";
|
||||
button.currentState = $.ButtonState.HOVER;
|
||||
}
|
||||
|
||||
if ( newState <= $.ButtonState.GROUP && button.currentState == $.ButtonState.HOVER ) {
|
||||
if ( newState <= $.ButtonState.GROUP &&
|
||||
button.currentState == $.ButtonState.HOVER ) {
|
||||
button.imgHover.style.visibility = "hidden";
|
||||
button.currentState = $.ButtonState.GROUP;
|
||||
}
|
||||
|
||||
if ( button.newState <= $.ButtonState.REST && button.currentState == $.ButtonState.GROUP ) {
|
||||
if ( button.newState <= $.ButtonState.REST &&
|
||||
button.currentState == $.ButtonState.GROUP ) {
|
||||
button.beginFading();
|
||||
button.currentState = $.ButtonState.REST;
|
||||
}
|
||||
@ -3098,8 +3167,8 @@ $.DisplayRect = function( x, y, width, height, minLevel, maxLevel ) {
|
||||
this.minLevel = minLevel;
|
||||
this.maxLevel = maxLevel;
|
||||
}
|
||||
$.DisplayRect.prototype = new $.Rect();
|
||||
$.DisplayRect.prototype.constructor = $.DisplayRect;
|
||||
|
||||
$.extend( $.DisplayRect.prototype, $.Rect.prototype );
|
||||
|
||||
}( OpenSeadragon ));
|
||||
|
||||
@ -3223,11 +3292,13 @@ $.Tile.prototype = {
|
||||
|
||||
drawHTML: function( container ) {
|
||||
|
||||
var position = this.position.apply( Math.floor ),
|
||||
size = this.size.apply( Math.ceil );
|
||||
|
||||
if ( !this.loaded ) {
|
||||
$.Debug.error(
|
||||
"Attempting to draw tile " +
|
||||
this.toString() +
|
||||
" when it's not yet loaded."
|
||||
$.Debug.warn(
|
||||
"Attempting to draw tile %s when it's not yet loaded.",
|
||||
this.toString()
|
||||
);
|
||||
return;
|
||||
}
|
||||
@ -3241,9 +3312,6 @@ $.Tile.prototype = {
|
||||
this.style.msInterpolationMode = "nearest-neighbor";
|
||||
}
|
||||
|
||||
var position = this.position.apply( Math.floor );
|
||||
var size = this.size.apply( Math.ceil );
|
||||
|
||||
|
||||
if ( this.elmt.parentNode != container ) {
|
||||
container.appendChild( this.elmt );
|
||||
@ -3259,18 +3327,18 @@ $.Tile.prototype = {
|
||||
},
|
||||
|
||||
drawCanvas: function(context) {
|
||||
if (!this.loaded) {
|
||||
$.Debug.error(
|
||||
"Attempting to draw tile " +
|
||||
this.toString() +
|
||||
" when it's not yet loaded."
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
var position = this.position,
|
||||
size = this.size;
|
||||
|
||||
if (!this.loaded) {
|
||||
$.Debug.warn(
|
||||
"Attempting to draw tile %s when it's not yet loaded.",
|
||||
this.toString()
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
context.globalAlpha = this.opacity;
|
||||
context.drawImage(this.image, position.x, position.y, size.x, size.y);
|
||||
},
|
||||
@ -3310,8 +3378,8 @@ $.Tile.prototype = {
|
||||
location.x,
|
||||
location.y,
|
||||
location.width,
|
||||
location.height)
|
||||
;
|
||||
location.height
|
||||
);
|
||||
this.position = new $.Point(
|
||||
location.x,
|
||||
location.y
|
||||
@ -3364,12 +3432,13 @@ $.Tile.prototype = {
|
||||
break;
|
||||
}
|
||||
},
|
||||
destroy: function() {
|
||||
var elmt = this.elmt;
|
||||
var style = this.style;
|
||||
|
||||
if (elmt.parentNode) {
|
||||
elmt.parentNode.removeChild(elmt);
|
||||
destroy: function() {
|
||||
var element = this.elmt,
|
||||
style = this.style;
|
||||
|
||||
if ( element.parentNode ) {
|
||||
element.parentNode.removeChild( element );
|
||||
}
|
||||
|
||||
style.top = "";
|
||||
@ -3381,19 +3450,20 @@ $.Tile.prototype = {
|
||||
style.height = "";
|
||||
}
|
||||
},
|
||||
|
||||
drawHTML: function( container ) {
|
||||
var elmt = this.elmt,
|
||||
var element = this.elmt,
|
||||
style = this.style,
|
||||
scales = this.scales,
|
||||
position,
|
||||
size;
|
||||
|
||||
if ( elmt.parentNode != container ) {
|
||||
container.appendChild( elmt );
|
||||
if ( element.parentNode != container ) {
|
||||
container.appendChild( element );
|
||||
}
|
||||
|
||||
if ( !scales ) {
|
||||
this.size = $.getElementSize( elmt );
|
||||
this.size = $.getElementSize( element );
|
||||
}
|
||||
|
||||
position = this.position;
|
||||
@ -3413,11 +3483,17 @@ $.Tile.prototype = {
|
||||
style.height = size.y + "px";
|
||||
}
|
||||
},
|
||||
update: function( loc, placement ) {
|
||||
this.scales = ( loc instanceof $.Rect );
|
||||
this.bounds = new $.Rect(loc.x, loc.y, loc.width, loc.height);
|
||||
|
||||
update: function( location, placement ) {
|
||||
this.scales = location instanceof $.Rect;
|
||||
this.bounds = new $.Rect(
|
||||
location.x,
|
||||
location.y,
|
||||
location.width,
|
||||
location.height
|
||||
);
|
||||
// rects are always top-left
|
||||
this.placement = loc instanceof $.Point ?
|
||||
this.placement = location instanceof $.Point ?
|
||||
placement :
|
||||
$.OverlayPlacement.TOP_LEFT;
|
||||
}
|
||||
@ -3461,7 +3537,7 @@ $.Drawer = function(source, viewport, elmt) {
|
||||
this.downloading = 0;
|
||||
this.imageLoaderLimit = this.config.imageLoaderLimit;
|
||||
|
||||
this.profiler = new $.Profiler();
|
||||
//this.profiler = new $.Profiler();
|
||||
|
||||
this.minLevel = source.minLevel;
|
||||
this.maxLevel = source.maxLevel;
|
||||
@ -3578,14 +3654,14 @@ $.Drawer.prototype = {
|
||||
tile.loading = false;
|
||||
|
||||
if ( this.midUpdate ) {
|
||||
$.Debug.error( "Tile load callback in middle of drawing routine." );
|
||||
$.Debug.warn( "Tile load callback in middle of drawing routine." );
|
||||
return;
|
||||
} else if ( !image ) {
|
||||
$.Debug.log( "Tile " + tile + " failed to load: " + tile.url );
|
||||
$.Debug.log( "Tile %s failed to load: %s", tile, tile.url );
|
||||
tile.exists = false;
|
||||
return;
|
||||
} else if ( time < this.lastResetTime ) {
|
||||
$.Debug.log( "Ignoring tile " + tile + " loaded before reset: " + tile.url );
|
||||
$.Debug.log( "Ignoring tile %s loaded before reset: %s", tile, tile.url );
|
||||
return;
|
||||
}
|
||||
|
||||
@ -3704,8 +3780,9 @@ $.Drawer.prototype = {
|
||||
*/
|
||||
_setCoverage: function( level, x, y, covers ) {
|
||||
if ( !this.coverage[ level ] ) {
|
||||
$.Debug.error(
|
||||
"Setting coverage for a tile before its level's coverage has been reset: " + level
|
||||
$.Debug.warn(
|
||||
"Setting coverage for a tile before its level's coverage has been reset: %s",
|
||||
level
|
||||
);
|
||||
return;
|
||||
}
|
||||
@ -3830,7 +3907,14 @@ $.Drawer.prototype = {
|
||||
for ( level = highestLevel; level >= lowestLevel; level-- ) {
|
||||
|
||||
//TODO
|
||||
best = this._drawLevel( level, lowestLevel, viewportTL, viewportBR, currentTime, best );
|
||||
best = this._drawLevel(
|
||||
level,
|
||||
lowestLevel,
|
||||
viewportTL,
|
||||
viewportBR,
|
||||
currentTime,
|
||||
best
|
||||
);
|
||||
|
||||
//TODO
|
||||
if ( this._providesCoverage( level ) ) {
|
||||
@ -3918,7 +4002,7 @@ $.Drawer.prototype = {
|
||||
|
||||
for ( x = tileTL.x; x <= tileBR.x; x++ ) {
|
||||
for ( y = tileTL.y; y <= tileBR.y; y++ ) {
|
||||
drawTile = drawLevel;
|
||||
|
||||
tile = this._getTile(
|
||||
level,
|
||||
x, y,
|
||||
@ -3933,6 +4017,7 @@ $.Drawer.prototype = {
|
||||
continue;
|
||||
}
|
||||
|
||||
drawTile = drawLevel;
|
||||
if ( haveDrawn && !drawTile ) {
|
||||
if ( this._isCovered( level, x, y ) ) {
|
||||
this._setCoverage( level, x, y, true );
|
||||
@ -4149,7 +4234,10 @@ $.Drawer.prototype = {
|
||||
callback( image );
|
||||
} catch ( e ) {
|
||||
$.Debug.error(
|
||||
e.name + " while executing " + src +" callback: " + e.message,
|
||||
"%s while executing %s callback: %s",
|
||||
e.name,
|
||||
src,
|
||||
e.message,
|
||||
e
|
||||
);
|
||||
}
|
||||
@ -4204,35 +4292,48 @@ function numberOfTiles( drawer, level ){
|
||||
|
||||
(function( $ ){
|
||||
|
||||
$.Viewport = function(containerSize, contentSize, config) {
|
||||
$.Viewport = function( options ) {
|
||||
|
||||
var options;
|
||||
|
||||
if( arguments.length && arguments[ 0 ] instanceof $.Point ){
|
||||
options = {
|
||||
containerSize: arguments[ 0 ],
|
||||
contentSize: arguments[ 1 ],
|
||||
config: arguments[ 2 ]
|
||||
};
|
||||
} else {
|
||||
options = arguments[ 0 ];
|
||||
}
|
||||
|
||||
//TODO: this.config is something that should go away but currently the
|
||||
// Drawer references the viewport.config
|
||||
this.config = config;
|
||||
this.config = options.config;
|
||||
this.zoomPoint = null;
|
||||
this.containerSize = containerSize;
|
||||
this.contentSize = contentSize;
|
||||
this.contentAspect = contentSize.x / contentSize.y;
|
||||
this.contentHeight = contentSize.y / contentSize.x;
|
||||
this.containerSize = options.containerSize;
|
||||
this.contentSize = options.contentSize;
|
||||
this.contentAspect = this.contentSize.x / this.contentSize.y;
|
||||
this.contentHeight = this.contentSize.y / this.contentSize.x;
|
||||
this.centerSpringX = new $.Spring({
|
||||
initial: 0,
|
||||
springStiffness: config.springStiffness,
|
||||
animationTime: config.animationTime
|
||||
springStiffness: this.config.springStiffness,
|
||||
animationTime: this.config.animationTime
|
||||
});
|
||||
this.centerSpringY = new $.Spring({
|
||||
initial: 0,
|
||||
springStiffness: config.springStiffness,
|
||||
animationTime: config.animationTime
|
||||
springStiffness: this.config.springStiffness,
|
||||
animationTime: this.config.animationTime
|
||||
});
|
||||
this.zoomSpring = new $.Spring({
|
||||
initial: 1,
|
||||
springStiffness: config.springStiffness,
|
||||
animationTime: config.animationTime
|
||||
springStiffness: this.config.springStiffness,
|
||||
animationTime: this.config.animationTime
|
||||
});
|
||||
this.minZoomImageRatio = config.minZoomImageRatio;
|
||||
this.maxZoomPixelRatio = config.maxZoomPixelRatio;
|
||||
this.visibilityRatio = config.visibilityRatio;
|
||||
this.wrapHorizontal = config.wrapHorizontal;
|
||||
this.wrapVertical = config.wrapVertical;
|
||||
this.minZoomImageRatio = this.config.minZoomImageRatio;
|
||||
this.maxZoomPixelRatio = this.config.maxZoomPixelRatio;
|
||||
this.visibilityRatio = this.config.visibilityRatio;
|
||||
this.wrapHorizontal = this.config.wrapHorizontal;
|
||||
this.wrapVertical = this.config.wrapVertical;
|
||||
this.homeBounds = new $.Rect( 0, 0, 1, this.contentHeight );
|
||||
this.goHome( true );
|
||||
this.update();
|
||||
|
@ -22,22 +22,23 @@ $.Button = function( options ) {
|
||||
//TODO: make button elements accessible by making them a-tags
|
||||
// maybe even consider basing them on the element and adding
|
||||
// methods jquery-style.
|
||||
this.element = options.element || $.makeNeutralElement("span");
|
||||
this.element = options.element || $.makeNeutralElement( "a" );
|
||||
this.element.href = '#';
|
||||
this.config = options.config;
|
||||
|
||||
if ( options.onPress != undefined ){
|
||||
if ( options.onPress ){
|
||||
this.addHandler( "onPress", options.onPress );
|
||||
}
|
||||
if ( options.onRelease != undefined ){
|
||||
if ( options.onRelease ){
|
||||
this.addHandler( "onRelease", options.onRelease );
|
||||
}
|
||||
if ( options.onClick != undefined ){
|
||||
if ( options.onClick ){
|
||||
this.addHandler( "onClick", options.onClick );
|
||||
}
|
||||
if ( options.onEnter != undefined ){
|
||||
if ( options.onEnter ){
|
||||
this.addHandler( "onEnter", options.onEnter );
|
||||
}
|
||||
if ( options.onExit != undefined ){
|
||||
if ( options.onExit ){
|
||||
this.addHandler( "onExit", options.onExit );
|
||||
}
|
||||
|
||||
@ -66,10 +67,10 @@ $.Button = function( options ) {
|
||||
this.element.appendChild( this.imgHover );
|
||||
this.element.appendChild( this.imgDown );
|
||||
|
||||
var styleRest = this.imgRest.style;
|
||||
var styleGroup = this.imgGroup.style;
|
||||
var styleHover = this.imgHover.style;
|
||||
var styleDown = this.imgDown.style;
|
||||
var styleRest = this.imgRest.style,
|
||||
styleGroup = this.imgGroup.style,
|
||||
styleHover = this.imgHover.style,
|
||||
styleDown = this.imgDown.style;
|
||||
|
||||
styleGroup.position =
|
||||
styleHover.position =
|
||||
@ -140,12 +141,15 @@ $.Button = function( options ) {
|
||||
};
|
||||
|
||||
$.extend( $.Button.prototype, $.EventHandler.prototype, {
|
||||
|
||||
notifyGroupEnter: function() {
|
||||
inTo( this, $.ButtonState.GROUP );
|
||||
},
|
||||
|
||||
notifyGroupExit: function() {
|
||||
outTo( this, $.ButtonState.REST );
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
|
||||
@ -189,17 +193,20 @@ function stopFading( button ) {
|
||||
};
|
||||
|
||||
function inTo( button, newState ) {
|
||||
if ( newState >= $.ButtonState.GROUP && button.currentState == $.ButtonState.REST ) {
|
||||
if ( newState >= $.ButtonState.GROUP &&
|
||||
button.currentState == $.ButtonState.REST ) {
|
||||
stopFading( button );
|
||||
button.currentState = $.ButtonState.GROUP;
|
||||
}
|
||||
|
||||
if ( newState >= $.ButtonState.HOVER && button.currentState == $.ButtonState.GROUP ) {
|
||||
if ( newState >= $.ButtonState.HOVER &&
|
||||
button.currentState == $.ButtonState.GROUP ) {
|
||||
button.imgHover.style.visibility = "";
|
||||
button.currentState = $.ButtonState.HOVER;
|
||||
}
|
||||
|
||||
if ( newState >= $.ButtonState.DOWN && button.currentState == $.ButtonState.HOVER ) {
|
||||
if ( newState >= $.ButtonState.DOWN &&
|
||||
button.currentState == $.ButtonState.HOVER ) {
|
||||
button.imgDown.style.visibility = "";
|
||||
button.currentState = $.ButtonState.DOWN;
|
||||
}
|
||||
@ -207,17 +214,20 @@ function inTo( button, newState ) {
|
||||
|
||||
|
||||
function outTo( button, newState ) {
|
||||
if ( newState <= $.ButtonState.HOVER && button.currentState == $.ButtonState.DOWN ) {
|
||||
if ( newState <= $.ButtonState.HOVER &&
|
||||
button.currentState == $.ButtonState.DOWN ) {
|
||||
button.imgDown.style.visibility = "hidden";
|
||||
button.currentState = $.ButtonState.HOVER;
|
||||
}
|
||||
|
||||
if ( newState <= $.ButtonState.GROUP && button.currentState == $.ButtonState.HOVER ) {
|
||||
if ( newState <= $.ButtonState.GROUP &&
|
||||
button.currentState == $.ButtonState.HOVER ) {
|
||||
button.imgHover.style.visibility = "hidden";
|
||||
button.currentState = $.ButtonState.GROUP;
|
||||
}
|
||||
|
||||
if ( button.newState <= $.ButtonState.REST && button.currentState == $.ButtonState.GROUP ) {
|
||||
if ( button.newState <= $.ButtonState.REST &&
|
||||
button.currentState == $.ButtonState.GROUP ) {
|
||||
button.beginFading();
|
||||
button.currentState = $.ButtonState.REST;
|
||||
}
|
||||
|
@ -25,23 +25,32 @@ $.Control = function (elmt, anchor, container) {
|
||||
|
||||
if ( this.anchor == $.ControlAnchor.TOP_RIGHT ||
|
||||
this.anchor == $.ControlAnchor.BOTTOM_RIGHT ) {
|
||||
this.container.insertBefore(this.wrapper, this.container.firstChild);
|
||||
this.container.insertBefore(
|
||||
this.wrapper,
|
||||
this.container.firstChild
|
||||
);
|
||||
} else {
|
||||
this.container.appendChild( this.wrapper );
|
||||
}
|
||||
};
|
||||
|
||||
$.Control.prototype = {
|
||||
|
||||
destroy: function() {
|
||||
this.wrapper.removeChild( this.elmt );
|
||||
this.container.removeChild( this.wrapper );
|
||||
},
|
||||
|
||||
isVisible: function() {
|
||||
return this.wrapper.style.display != "none";
|
||||
},
|
||||
|
||||
setVisible: function( visible ) {
|
||||
this.wrapper.style.display = visible ? "inline-block" : "none";
|
||||
this.wrapper.style.display = visible ?
|
||||
"inline-block" :
|
||||
"none";
|
||||
},
|
||||
|
||||
setOpacity: function( opacity ) {
|
||||
if ( this.elmt[ $.SIGNAL ] && $.Browser.vendor == $.BROWSERS.IE ) {
|
||||
$.setElementOpacity( this.elmt, opacity, true );
|
||||
|
@ -7,7 +7,7 @@ $.DisplayRect = function( x, y, width, height, minLevel, maxLevel ) {
|
||||
this.minLevel = minLevel;
|
||||
this.maxLevel = maxLevel;
|
||||
}
|
||||
$.DisplayRect.prototype = new $.Rect();
|
||||
$.DisplayRect.prototype.constructor = $.DisplayRect;
|
||||
|
||||
$.extend( $.DisplayRect.prototype, $.Rect.prototype );
|
||||
|
||||
}( OpenSeadragon ));
|
||||
|
@ -34,7 +34,7 @@ $.Drawer = function(source, viewport, elmt) {
|
||||
this.downloading = 0;
|
||||
this.imageLoaderLimit = this.config.imageLoaderLimit;
|
||||
|
||||
this.profiler = new $.Profiler();
|
||||
//this.profiler = new $.Profiler();
|
||||
|
||||
this.minLevel = source.minLevel;
|
||||
this.maxLevel = source.maxLevel;
|
||||
@ -151,14 +151,14 @@ $.Drawer.prototype = {
|
||||
tile.loading = false;
|
||||
|
||||
if ( this.midUpdate ) {
|
||||
$.Debug.error( "Tile load callback in middle of drawing routine." );
|
||||
$.Debug.warn( "Tile load callback in middle of drawing routine." );
|
||||
return;
|
||||
} else if ( !image ) {
|
||||
$.Debug.log( "Tile " + tile + " failed to load: " + tile.url );
|
||||
$.Debug.log( "Tile %s failed to load: %s", tile, tile.url );
|
||||
tile.exists = false;
|
||||
return;
|
||||
} else if ( time < this.lastResetTime ) {
|
||||
$.Debug.log( "Ignoring tile " + tile + " loaded before reset: " + tile.url );
|
||||
$.Debug.log( "Ignoring tile %s loaded before reset: %s", tile, tile.url );
|
||||
return;
|
||||
}
|
||||
|
||||
@ -277,8 +277,9 @@ $.Drawer.prototype = {
|
||||
*/
|
||||
_setCoverage: function( level, x, y, covers ) {
|
||||
if ( !this.coverage[ level ] ) {
|
||||
$.Debug.error(
|
||||
"Setting coverage for a tile before its level's coverage has been reset: " + level
|
||||
$.Debug.warn(
|
||||
"Setting coverage for a tile before its level's coverage has been reset: %s",
|
||||
level
|
||||
);
|
||||
return;
|
||||
}
|
||||
@ -403,7 +404,14 @@ $.Drawer.prototype = {
|
||||
for ( level = highestLevel; level >= lowestLevel; level-- ) {
|
||||
|
||||
//TODO
|
||||
best = this._drawLevel( level, lowestLevel, viewportTL, viewportBR, currentTime, best );
|
||||
best = this._drawLevel(
|
||||
level,
|
||||
lowestLevel,
|
||||
viewportTL,
|
||||
viewportBR,
|
||||
currentTime,
|
||||
best
|
||||
);
|
||||
|
||||
//TODO
|
||||
if ( this._providesCoverage( level ) ) {
|
||||
@ -491,7 +499,7 @@ $.Drawer.prototype = {
|
||||
|
||||
for ( x = tileTL.x; x <= tileBR.x; x++ ) {
|
||||
for ( y = tileTL.y; y <= tileBR.y; y++ ) {
|
||||
drawTile = drawLevel;
|
||||
|
||||
tile = this._getTile(
|
||||
level,
|
||||
x, y,
|
||||
@ -506,6 +514,7 @@ $.Drawer.prototype = {
|
||||
continue;
|
||||
}
|
||||
|
||||
drawTile = drawLevel;
|
||||
if ( haveDrawn && !drawTile ) {
|
||||
if ( this._isCovered( level, x, y ) ) {
|
||||
this._setCoverage( level, x, y, true );
|
||||
@ -722,7 +731,10 @@ $.Drawer.prototype = {
|
||||
callback( image );
|
||||
} catch ( e ) {
|
||||
$.Debug.error(
|
||||
e.name + " while executing " + src +" callback: " + e.message,
|
||||
"%s while executing %s callback: %s",
|
||||
e.name,
|
||||
src,
|
||||
e.message,
|
||||
e
|
||||
);
|
||||
}
|
||||
|
@ -3,18 +3,21 @@
|
||||
|
||||
|
||||
$.DziTileSource = function( width, height, tileSize, tileOverlap, tilesUrl, fileFormat, displayRects ) {
|
||||
var i,
|
||||
rect,
|
||||
level;
|
||||
|
||||
$.TileSource.call( this, width, height, tileSize, tileOverlap, null, null );
|
||||
|
||||
this._levelRects = {};
|
||||
this.tilesUrl = tilesUrl;
|
||||
|
||||
this.fileFormat = fileFormat;
|
||||
this.displayRects = displayRects;
|
||||
|
||||
if ( this.displayRects ) {
|
||||
for (var i = this.displayRects.length - 1; i >= 0; i--) {
|
||||
var rect = this.displayRects[i];
|
||||
for (var level = rect.minLevel; level <= rect.maxLevel; level++) {
|
||||
for ( i = this.displayRects.length - 1; i >= 0; i-- ) {
|
||||
rect = this.displayRects[ i ];
|
||||
for ( level = rect.minLevel; level <= rect.maxLevel; level++ ) {
|
||||
if ( !this._levelRects[ level ] ) {
|
||||
this._levelRects[ level ] = [];
|
||||
}
|
||||
@ -32,24 +35,31 @@ $.extend( $.DziTileSource.prototype, $.TileSource.prototype, {
|
||||
},
|
||||
|
||||
tileExists: function( level, x, y ) {
|
||||
var rects = this._levelRects[level];
|
||||
var rects = this._levelRects[ level ],
|
||||
rect,
|
||||
scale,
|
||||
xMin,
|
||||
yMin,
|
||||
xMax,
|
||||
yMax,
|
||||
i;
|
||||
|
||||
if ( !rects || !rects.length ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
for (var i = rects.length - 1; i >= 0; i--) {
|
||||
var rect = rects[i];
|
||||
for ( i = rects.length - 1; i >= 0; i-- ) {
|
||||
rect = rects[ i ];
|
||||
|
||||
if ( level < rect.minLevel || level > rect.maxLevel ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
var scale = this.getLevelScale(level);
|
||||
var xMin = rect.x * scale;
|
||||
var yMin = rect.y * scale;
|
||||
var xMax = xMin + rect.width * scale;
|
||||
var yMax = yMin + rect.height * scale;
|
||||
scale = this.getLevelScale( level );
|
||||
xMin = rect.x * scale;
|
||||
yMin = rect.y * scale;
|
||||
xMax = xMin + rect.width * scale;
|
||||
yMax = yMin + rect.height * scale;
|
||||
|
||||
xMin = Math.floor( xMin / this.tileSize );
|
||||
yMin = Math.floor( yMin / this.tileSize );
|
||||
@ -66,12 +76,18 @@ $.extend( $.DziTileSource.prototype, $.TileSource.prototype, {
|
||||
});
|
||||
|
||||
$.DziTileSourceHelper = {
|
||||
|
||||
createFromXml: function( xmlUrl, xmlString, callback ) {
|
||||
var async = typeof (callback) == "function";
|
||||
var error = null;
|
||||
var async = typeof (callback) == "function",
|
||||
error = null,
|
||||
urlParts,
|
||||
filename,
|
||||
lastDot,
|
||||
tilesUrl,
|
||||
handler;
|
||||
|
||||
if ( !xmlUrl ) {
|
||||
this.error = $.Strings.getString("Errors.Empty");
|
||||
this.error = $.getString( "Errors.Empty" );
|
||||
if ( async ) {
|
||||
window.setTimeout( function() {
|
||||
callback( null, error );
|
||||
@ -81,15 +97,16 @@ $.DziTileSourceHelper = {
|
||||
throw new Error( error );
|
||||
}
|
||||
|
||||
var urlParts = xmlUrl.split('/');
|
||||
var filename = urlParts[urlParts.length - 1];
|
||||
var lastDot = filename.lastIndexOf('.');
|
||||
urlParts = xmlUrl.split( '/' );
|
||||
filename = urlParts[ urlParts.length - 1 ];
|
||||
lastDot = filename.lastIndexOf( '.' );
|
||||
|
||||
if ( lastDot > -1 ) {
|
||||
urlParts[ urlParts.length - 1 ] = filename.slice( 0, lastDot );
|
||||
}
|
||||
|
||||
var tilesUrl = urlParts.join('/') + "_files/";
|
||||
tilesUrl = urlParts.join( '/' ) + "_files/";
|
||||
|
||||
function finish( func, obj ) {
|
||||
try {
|
||||
return func( obj, tilesUrl );
|
||||
@ -101,18 +118,21 @@ $.DziTileSourceHelper = {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( async ) {
|
||||
if ( xmlString ) {
|
||||
var handler = $.delegate(this, this.processXml);
|
||||
handler = $.delegate( this, this.processXml );
|
||||
window.setTimeout( function() {
|
||||
var source = finish( handler, $.parseXml( xmlString ) );
|
||||
callback(source, error); // call after finish sets error
|
||||
// call after finish sets error
|
||||
callback( source, error );
|
||||
}, 1);
|
||||
} else {
|
||||
var handler = $.delegate(this, this.processResponse);
|
||||
handler = $.delegate( this, this.processResponse );
|
||||
$.makeAjaxRequest( xmlUrl, function( xhr ) {
|
||||
var source = finish( handler, xhr );
|
||||
callback(source, error); // call after finish sets error
|
||||
// call after finish sets error
|
||||
callback( source, error );
|
||||
});
|
||||
}
|
||||
|
||||
@ -120,21 +140,31 @@ $.DziTileSourceHelper = {
|
||||
}
|
||||
|
||||
if ( xmlString ) {
|
||||
return finish($.delegate(this, this.processXml), $.parseXml(xmlString));
|
||||
return finish(
|
||||
$.delegate( this, this.processXml ),
|
||||
$.parseXml( xmlString )
|
||||
);
|
||||
} else {
|
||||
return finish($.delegate(this, this.processResponse), $.makeAjaxRequest(xmlUrl));
|
||||
return finish(
|
||||
$.delegate( this, this.processResponse ),
|
||||
$.makeAjaxRequest( xmlUrl )
|
||||
);
|
||||
}
|
||||
},
|
||||
processResponse: function( xhr, tilesUrl ) {
|
||||
if (!xhr) {
|
||||
throw new Error($.Strings.getString("Errors.Security"));
|
||||
} else if (xhr.status !== 200 && xhr.status !== 0) {
|
||||
var status = xhr.status;
|
||||
var statusText = (status == 404) ? "Not Found" : xhr.statusText;
|
||||
throw new Error($.Strings.getString("Errors.Status", status, statusText));
|
||||
}
|
||||
var status,
|
||||
statusText,
|
||||
doc = null;
|
||||
|
||||
var doc = null;
|
||||
if ( !xhr ) {
|
||||
throw new Error( $.getString( "Errors.Security" ) );
|
||||
} else if ( xhr.status !== 200 && xhr.status !== 0 ) {
|
||||
status = xhr.status;
|
||||
statusText = ( status == 404 ) ?
|
||||
"Not Found" :
|
||||
xhr.statusText;
|
||||
throw new Error( $.getString( "Errors.Status", status, statusText ) );
|
||||
}
|
||||
|
||||
if ( xhr.responseXML && xhr.responseXML.documentElement ) {
|
||||
doc = xhr.responseXML;
|
||||
@ -146,66 +176,77 @@ $.DziTileSourceHelper = {
|
||||
},
|
||||
|
||||
processXml: function( xmlDoc, tilesUrl ) {
|
||||
|
||||
if ( !xmlDoc || !xmlDoc.documentElement ) {
|
||||
throw new Error($.Strings.getString("Errors.Xml"));
|
||||
throw new Error( $.getString( "Errors.Xml" ) );
|
||||
}
|
||||
|
||||
var root = xmlDoc.documentElement;
|
||||
var rootName = root.tagName;
|
||||
var root = xmlDoc.documentElement,
|
||||
rootName = root.tagName;
|
||||
|
||||
if ( rootName == "Image" ) {
|
||||
try {
|
||||
return this.processDzi( root, tilesUrl );
|
||||
} catch ( e ) {
|
||||
var defMsg = $.Strings.getString("Errors.Dzi");
|
||||
throw (e instanceof Error) ? e : new Error(defMsg);
|
||||
throw (e instanceof Error) ?
|
||||
e :
|
||||
new Error( $.getString("Errors.Dzi") );
|
||||
}
|
||||
} else if ( rootName == "Collection" ) {
|
||||
throw new Error($.Strings.getString("Errors.Dzc"));
|
||||
throw new Error( $.getString( "Errors.Dzc" ) );
|
||||
} else if ( rootName == "Error" ) {
|
||||
return this.processError( root );
|
||||
}
|
||||
|
||||
throw new Error($.Strings.getString("Errors.Dzi"));
|
||||
throw new Error( $.getString( "Errors.Dzi" ) );
|
||||
},
|
||||
|
||||
processDzi: function( imageNode, tilesUrl ) {
|
||||
var fileFormat = imageNode.getAttribute("Format");
|
||||
var fileFormat = imageNode.getAttribute( "Format" ),
|
||||
sizeNode = imageNode.getElementsByTagName( "Size" )[ 0 ],
|
||||
dispRectNodes = imageNode.getElementsByTagName( "DisplayRect" ),
|
||||
width = parseInt( sizeNode.getAttribute( "Width" ) ),
|
||||
height = parseInt( sizeNode.getAttribute( "Height" ) ),
|
||||
tileSize = parseInt( imageNode.getAttribute( "TileSize" ) ),
|
||||
tileOverlap = parseInt( imageNode.getAttribute( "Overlap" ) ),
|
||||
dispRects = [],
|
||||
dispRectNode,
|
||||
rectNode,
|
||||
i;
|
||||
|
||||
if ( !$.imageFormatSupported( fileFormat ) ) {
|
||||
throw new Error($.Strings.getString("Errors.ImageFormat",
|
||||
fileFormat.toUpperCase()));
|
||||
throw new Error(
|
||||
$.getString( "Errors.ImageFormat", fileFormat.toUpperCase() )
|
||||
);
|
||||
}
|
||||
|
||||
var sizeNode = imageNode.getElementsByTagName("Size")[0];
|
||||
var dispRectNodes = imageNode.getElementsByTagName("DisplayRect");
|
||||
|
||||
var width = parseInt(sizeNode.getAttribute("Width"), 10);
|
||||
var height = parseInt(sizeNode.getAttribute("Height"), 10);
|
||||
var tileSize = parseInt(imageNode.getAttribute("TileSize"));
|
||||
var tileOverlap = parseInt(imageNode.getAttribute("Overlap"));
|
||||
var dispRects = [];
|
||||
|
||||
for (var i = 0; i < dispRectNodes.length; i++) {
|
||||
var dispRectNode = dispRectNodes[i];
|
||||
var rectNode = dispRectNode.getElementsByTagName("Rect")[0];
|
||||
for ( i = 0; i < dispRectNodes.length; i++ ) {
|
||||
dispRectNode = dispRectNodes[ i ];
|
||||
rectNode = dispRectNode.getElementsByTagName( "Rect" )[ 0 ];
|
||||
|
||||
dispRects.push( new $.DisplayRect(
|
||||
parseInt(rectNode.getAttribute("X"), 10),
|
||||
parseInt(rectNode.getAttribute("Y"), 10),
|
||||
parseInt(rectNode.getAttribute("Width"), 10),
|
||||
parseInt(rectNode.getAttribute("Height"), 10),
|
||||
parseInt( rectNode.getAttribute( "X" ) ),
|
||||
parseInt( rectNode.getAttribute( "Y" ) ),
|
||||
parseInt( rectNode.getAttribute( "Width" ) ),
|
||||
parseInt( rectNode.getAttribute( "Height" ) ),
|
||||
0, // ignore MinLevel attribute, bug in Deep Zoom Composer
|
||||
parseInt(dispRectNode.getAttribute("MaxLevel"), 10)
|
||||
parseInt( dispRectNode.getAttribute( "MaxLevel" ) )
|
||||
));
|
||||
}
|
||||
return new $.DziTileSource(width, height, tileSize, tileOverlap,
|
||||
tilesUrl, fileFormat, dispRects);
|
||||
return new $.DziTileSource(
|
||||
width,
|
||||
height,
|
||||
tileSize,
|
||||
tileOverlap,
|
||||
tilesUrl,
|
||||
fileFormat,
|
||||
dispRects
|
||||
);
|
||||
},
|
||||
|
||||
processError: function( errorNode ) {
|
||||
var messageNode = errorNode.getElementsByTagName("Message")[0];
|
||||
var message = messageNode.firstChild.nodeValue;
|
||||
var messageNode = errorNode.getElementsByTagName( "Message" )[ 0 ],
|
||||
message = messageNode.firstChild.nodeValue;
|
||||
|
||||
throw new Error(message);
|
||||
}
|
||||
|
@ -37,8 +37,8 @@
|
||||
Array.apply( null, events );
|
||||
return function( source, args ) {
|
||||
var i,
|
||||
l = events.length;
|
||||
for ( i = 0; i < l; i++ ) {
|
||||
length = events.length;
|
||||
for ( i = 0; i < length; i++ ) {
|
||||
events[ i ]( source, args );
|
||||
}
|
||||
};
|
||||
|
@ -711,7 +711,11 @@ OpenSeadragon = window.OpenSeadragon || (function(){
|
||||
request.open( "GET", url, async );
|
||||
request.send( null );
|
||||
} catch (e) {
|
||||
$.Debug.log(e.name + " while making AJAX request: " + e.message);
|
||||
$.Debug.log(
|
||||
"%s while making AJAX request: %s",
|
||||
e.name,
|
||||
e.message
|
||||
);
|
||||
|
||||
request.onreadystatechange = null;
|
||||
request = null;
|
||||
|
@ -20,8 +20,8 @@
|
||||
location.x,
|
||||
location.y,
|
||||
location.width,
|
||||
location.height)
|
||||
;
|
||||
location.height
|
||||
);
|
||||
this.position = new $.Point(
|
||||
location.x,
|
||||
location.y
|
||||
@ -74,12 +74,13 @@
|
||||
break;
|
||||
}
|
||||
},
|
||||
destroy: function() {
|
||||
var elmt = this.elmt;
|
||||
var style = this.style;
|
||||
|
||||
if (elmt.parentNode) {
|
||||
elmt.parentNode.removeChild(elmt);
|
||||
destroy: function() {
|
||||
var element = this.elmt,
|
||||
style = this.style;
|
||||
|
||||
if ( element.parentNode ) {
|
||||
element.parentNode.removeChild( element );
|
||||
}
|
||||
|
||||
style.top = "";
|
||||
@ -91,19 +92,20 @@
|
||||
style.height = "";
|
||||
}
|
||||
},
|
||||
|
||||
drawHTML: function( container ) {
|
||||
var elmt = this.elmt,
|
||||
var element = this.elmt,
|
||||
style = this.style,
|
||||
scales = this.scales,
|
||||
position,
|
||||
size;
|
||||
|
||||
if ( elmt.parentNode != container ) {
|
||||
container.appendChild( elmt );
|
||||
if ( element.parentNode != container ) {
|
||||
container.appendChild( element );
|
||||
}
|
||||
|
||||
if ( !scales ) {
|
||||
this.size = $.getElementSize( elmt );
|
||||
this.size = $.getElementSize( element );
|
||||
}
|
||||
|
||||
position = this.position;
|
||||
@ -123,11 +125,17 @@
|
||||
style.height = size.y + "px";
|
||||
}
|
||||
},
|
||||
update: function( loc, placement ) {
|
||||
this.scales = ( loc instanceof $.Rect );
|
||||
this.bounds = new $.Rect(loc.x, loc.y, loc.width, loc.height);
|
||||
|
||||
update: function( location, placement ) {
|
||||
this.scales = location instanceof $.Rect;
|
||||
this.bounds = new $.Rect(
|
||||
location.x,
|
||||
location.y,
|
||||
location.width,
|
||||
location.height
|
||||
);
|
||||
// rects are always top-left
|
||||
this.placement = loc instanceof $.Point ?
|
||||
this.placement = location instanceof $.Point ?
|
||||
placement :
|
||||
$.OverlayPlacement.TOP_LEFT;
|
||||
}
|
||||
|
10
src/point.js
10
src/point.js
@ -52,9 +52,13 @@ $.Point.prototype = {
|
||||
},
|
||||
|
||||
equals: function( point ) {
|
||||
return ( point instanceof $.Point ) &&
|
||||
( this.x === point.x ) &&
|
||||
( this.y === point.y );
|
||||
return (
|
||||
point instanceof $.Point
|
||||
) && (
|
||||
this.x === point.x
|
||||
) && (
|
||||
this.y === point.y
|
||||
);
|
||||
},
|
||||
|
||||
toString: function() {
|
||||
|
@ -4,9 +4,7 @@
|
||||
//TODO: I guess this is where the i18n needs to be reimplemented. I'll look
|
||||
// into existing patterns for i18n in javascript but i think that mimicking
|
||||
// pythons gettext might be a reasonable approach.
|
||||
|
||||
$.Strings = {
|
||||
|
||||
var I18N = {
|
||||
Errors: {
|
||||
Failure: "Sorry, but Seadragon Ajax can't run on your browser!\n" +
|
||||
"Please try using IE 7 or Firefox 3.\n",
|
||||
@ -30,12 +28,15 @@ $.Strings = {
|
||||
Home: "Go home",
|
||||
ZoomIn: "Zoom in",
|
||||
ZoomOut: "Zoom out"
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
$.extend( $, {
|
||||
|
||||
getString: function( prop ) {
|
||||
|
||||
var props = prop.split('.'),
|
||||
string = $.Strings,
|
||||
string = I18N,
|
||||
args = arguments,
|
||||
i;
|
||||
|
||||
@ -71,6 +72,6 @@ $.Strings = {
|
||||
container[ props[ i ] ] = value;
|
||||
}
|
||||
|
||||
};
|
||||
});
|
||||
|
||||
}( OpenSeadragon ));
|
||||
|
29
src/tile.js
29
src/tile.js
@ -34,11 +34,13 @@ $.Tile.prototype = {
|
||||
|
||||
drawHTML: function( container ) {
|
||||
|
||||
var position = this.position.apply( Math.floor ),
|
||||
size = this.size.apply( Math.ceil );
|
||||
|
||||
if ( !this.loaded ) {
|
||||
$.Debug.error(
|
||||
"Attempting to draw tile " +
|
||||
this.toString() +
|
||||
" when it's not yet loaded."
|
||||
$.Debug.warn(
|
||||
"Attempting to draw tile %s when it's not yet loaded.",
|
||||
this.toString()
|
||||
);
|
||||
return;
|
||||
}
|
||||
@ -52,9 +54,6 @@ $.Tile.prototype = {
|
||||
this.style.msInterpolationMode = "nearest-neighbor";
|
||||
}
|
||||
|
||||
var position = this.position.apply( Math.floor );
|
||||
var size = this.size.apply( Math.ceil );
|
||||
|
||||
|
||||
if ( this.elmt.parentNode != container ) {
|
||||
container.appendChild( this.elmt );
|
||||
@ -70,18 +69,18 @@ $.Tile.prototype = {
|
||||
},
|
||||
|
||||
drawCanvas: function(context) {
|
||||
if (!this.loaded) {
|
||||
$.Debug.error(
|
||||
"Attempting to draw tile " +
|
||||
this.toString() +
|
||||
" when it's not yet loaded."
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
var position = this.position,
|
||||
size = this.size;
|
||||
|
||||
if (!this.loaded) {
|
||||
$.Debug.warn(
|
||||
"Attempting to draw tile %s when it's not yet loaded.",
|
||||
this.toString()
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
context.globalAlpha = this.opacity;
|
||||
context.drawImage(this.image, position.x, position.y, size.x, size.y);
|
||||
},
|
||||
|
@ -4,59 +4,57 @@
|
||||
$.TileSource = function( width, height, tileSize, tileOverlap, minLevel, maxLevel ) {
|
||||
this.aspectRatio = width / height;
|
||||
this.dimensions = new $.Point( width, height );
|
||||
this.tileSize = tileSize ? tileSize : 0;
|
||||
this.tileOverlap = tileOverlap ? tileOverlap : 0;
|
||||
this.minLevel = minLevel ? minLevel : 0;
|
||||
this.maxLevel = maxLevel ? maxLevel :
|
||||
Math.ceil(
|
||||
Math.log( Math.max( width, height ) ) /
|
||||
Math.log( 2 )
|
||||
);
|
||||
this.tileSize = tileSize ? tileSize : 0;
|
||||
this.tileOverlap = tileOverlap ? tileOverlap : 0;
|
||||
};
|
||||
|
||||
$.TileSource.prototype = {
|
||||
|
||||
getLevelScale: function( level ) {
|
||||
return 1 / ( 1 << ( this.maxLevel - level ) );
|
||||
},
|
||||
|
||||
getNumTiles: function( level ) {
|
||||
var scale = this.getLevelScale(level);
|
||||
var x = Math.ceil(scale * this.dimensions.x / this.tileSize);
|
||||
var y = Math.ceil(scale * this.dimensions.y / this.tileSize);
|
||||
var scale = this.getLevelScale( level ),
|
||||
x = Math.ceil( scale * this.dimensions.x / this.tileSize ),
|
||||
y = Math.ceil( scale * this.dimensions.y / this.tileSize );
|
||||
|
||||
return new $.Point( x, y );
|
||||
},
|
||||
|
||||
getPixelRatio: function( level ) {
|
||||
var imageSizeScaled = this.dimensions.times(this.getLevelScale(level));
|
||||
var rx = 1.0 / imageSizeScaled.x;
|
||||
var ry = 1.0 / imageSizeScaled.y;
|
||||
var imageSizeScaled = this.dimensions.times( this.getLevelScale( level ) ),
|
||||
rx = 1.0 / imageSizeScaled.x,
|
||||
ry = 1.0 / imageSizeScaled.y;
|
||||
|
||||
return new $.Point(rx, ry);
|
||||
},
|
||||
|
||||
getTileAtPoint: function( level, point ) {
|
||||
var pixel = point.times(this.dimensions.x).times(this.getLevelScale(level));
|
||||
|
||||
var tx = Math.floor(pixel.x / this.tileSize);
|
||||
var ty = Math.floor(pixel.y / this.tileSize);
|
||||
var pixel = point.times( this.dimensions.x ).times( this.getLevelScale(level ) ),
|
||||
tx = Math.floor( pixel.x / this.tileSize ),
|
||||
ty = Math.floor( pixel.y / this.tileSize );
|
||||
|
||||
return new $.Point( tx, ty );
|
||||
},
|
||||
|
||||
getTileBounds: function( level, x, y ) {
|
||||
var dimensionsScaled = this.dimensions.times(this.getLevelScale(level));
|
||||
|
||||
var px = (x === 0) ? 0 : this.tileSize * x - this.tileOverlap;
|
||||
var py = (y === 0) ? 0 : this.tileSize * y - this.tileOverlap;
|
||||
|
||||
var sx = this.tileSize + (x === 0 ? 1 : 2) * this.tileOverlap;
|
||||
var sy = this.tileSize + (y === 0 ? 1 : 2) * this.tileOverlap;
|
||||
var dimensionsScaled = this.dimensions.times( this.getLevelScale( level ) ),
|
||||
px = ( x === 0 ) ? 0 : this.tileSize * x - this.tileOverlap,
|
||||
py = ( y === 0 ) ? 0 : this.tileSize * y - this.tileOverlap,
|
||||
sx = this.tileSize + ( x === 0 ? 1 : 2 ) * this.tileOverlap,
|
||||
sy = this.tileSize + ( y === 0 ? 1 : 2 ) * this.tileOverlap,
|
||||
scale = 1.0 / dimensionsScaled.x;
|
||||
|
||||
sx = Math.min( sx, dimensionsScaled.x - px );
|
||||
sy = Math.min( sy, dimensionsScaled.y - py );
|
||||
|
||||
var scale = 1.0 / dimensionsScaled.x;
|
||||
return new $.Rect( px * scale, py * scale, sx * scale, sy * scale );
|
||||
},
|
||||
|
||||
|
@ -199,25 +199,27 @@ $.Viewer = function( options ) {
|
||||
// Navigation Controls
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
this._group = null;
|
||||
this._zooming = false; // whether we should be continuously zooming
|
||||
this._zoomFactor = null; // how much we should be continuously zooming by
|
||||
// whether we should be continuously zooming
|
||||
this._zooming = false;
|
||||
// how much we should be continuously zooming by
|
||||
this._zoomFactor = null;
|
||||
this._lastZoomTime = null;
|
||||
|
||||
this.elmt = null;
|
||||
|
||||
var beginZoomingInHandler = $.delegate(this, beginZoomingIn);
|
||||
var endZoomingHandler = $.delegate(this, endZooming);
|
||||
var doSingleZoomInHandler = $.delegate(this, doSingleZoomIn);
|
||||
var beginZoomingOutHandler = $.delegate(this, beginZoomingOut);
|
||||
var doSingleZoomOutHandler = $.delegate(this, doSingleZoomOut);
|
||||
var onHomeHandler = $.delegate(this, onHome);
|
||||
var onFullPageHandler = $.delegate(this, onFullPage);
|
||||
var beginZoomingInHandler = $.delegate(this, beginZoomingIn),
|
||||
endZoomingHandler = $.delegate(this, endZooming),
|
||||
doSingleZoomInHandler = $.delegate(this, doSingleZoomIn),
|
||||
beginZoomingOutHandler = $.delegate(this, beginZoomingOut),
|
||||
doSingleZoomOutHandler = $.delegate(this, doSingleZoomOut),
|
||||
onHomeHandler = $.delegate(this, onHome),
|
||||
onFullPageHandler = $.delegate(this, onFullPage);
|
||||
|
||||
var navImages = this.config.navImages;
|
||||
|
||||
var zoomIn = new $.Button({
|
||||
config: this.config,
|
||||
tooltip: $.Strings.getString("Tooltips.ZoomIn"),
|
||||
tooltip: $.getString("Tooltips.ZoomIn"),
|
||||
srcRest: resolveUrl(this.urlPrefix, navImages.zoomIn.REST),
|
||||
srcGroup: resolveUrl(this.urlPrefix, navImages.zoomIn.GROUP),
|
||||
srcHover: resolveUrl(this.urlPrefix, navImages.zoomIn.HOVER),
|
||||
@ -231,7 +233,7 @@ $.Viewer = function( options ) {
|
||||
|
||||
var zoomOut = new $.Button({
|
||||
config: this.config,
|
||||
tooltip: $.Strings.getString("Tooltips.ZoomOut"),
|
||||
tooltip: $.getString("Tooltips.ZoomOut"),
|
||||
srcRest: resolveUrl(this.urlPrefix, navImages.zoomOut.REST),
|
||||
srcGroup: resolveUrl(this.urlPrefix, navImages.zoomOut.GROUP),
|
||||
srcHover: resolveUrl(this.urlPrefix, navImages.zoomOut.HOVER),
|
||||
@ -244,7 +246,7 @@ $.Viewer = function( options ) {
|
||||
});
|
||||
var goHome = new $.Button({
|
||||
config: this.config,
|
||||
tooltip: $.Strings.getString("Tooltips.Home"),
|
||||
tooltip: $.getString("Tooltips.Home"),
|
||||
srcRest: resolveUrl(this.urlPrefix, navImages.home.REST),
|
||||
srcGroup: resolveUrl(this.urlPrefix, navImages.home.GROUP),
|
||||
srcHover: resolveUrl(this.urlPrefix, navImages.home.HOVER),
|
||||
@ -253,7 +255,7 @@ $.Viewer = function( options ) {
|
||||
});
|
||||
var fullPage = new $.Button({
|
||||
config: this.config,
|
||||
tooltip: $.Strings.getString("Tooltips.FullPage"),
|
||||
tooltip: $.getString("Tooltips.FullPage"),
|
||||
srcRest: resolveUrl(this.urlPrefix, navImages.fullpage.REST),
|
||||
srcGroup: resolveUrl(this.urlPrefix, navImages.fullpage.GROUP),
|
||||
srcHover: resolveUrl(this.urlPrefix, navImages.fullpage.HOVER),
|
||||
@ -372,7 +374,7 @@ $.extend($.Viewer.prototype, $.EventHandler.prototype, {
|
||||
|
||||
window.setTimeout( function () {
|
||||
if ( _this._lastOpenStartTime > _this._lastOpenEndTime ) {
|
||||
_this._setMessage( $.Strings.getString( "Messages.Loading" ) );
|
||||
_this._setMessage( $.getString( "Messages.Loading" ) );
|
||||
}
|
||||
}, 2000);
|
||||
|
||||
|
@ -1,35 +1,48 @@
|
||||
|
||||
(function( $ ){
|
||||
|
||||
$.Viewport = function(containerSize, contentSize, config) {
|
||||
$.Viewport = function( options ) {
|
||||
|
||||
var options;
|
||||
|
||||
if( arguments.length && arguments[ 0 ] instanceof $.Point ){
|
||||
options = {
|
||||
containerSize: arguments[ 0 ],
|
||||
contentSize: arguments[ 1 ],
|
||||
config: arguments[ 2 ]
|
||||
};
|
||||
} else {
|
||||
options = arguments[ 0 ];
|
||||
}
|
||||
|
||||
//TODO: this.config is something that should go away but currently the
|
||||
// Drawer references the viewport.config
|
||||
this.config = config;
|
||||
this.config = options.config;
|
||||
this.zoomPoint = null;
|
||||
this.containerSize = containerSize;
|
||||
this.contentSize = contentSize;
|
||||
this.contentAspect = contentSize.x / contentSize.y;
|
||||
this.contentHeight = contentSize.y / contentSize.x;
|
||||
this.containerSize = options.containerSize;
|
||||
this.contentSize = options.contentSize;
|
||||
this.contentAspect = this.contentSize.x / this.contentSize.y;
|
||||
this.contentHeight = this.contentSize.y / this.contentSize.x;
|
||||
this.centerSpringX = new $.Spring({
|
||||
initial: 0,
|
||||
springStiffness: config.springStiffness,
|
||||
animationTime: config.animationTime
|
||||
springStiffness: this.config.springStiffness,
|
||||
animationTime: this.config.animationTime
|
||||
});
|
||||
this.centerSpringY = new $.Spring({
|
||||
initial: 0,
|
||||
springStiffness: config.springStiffness,
|
||||
animationTime: config.animationTime
|
||||
springStiffness: this.config.springStiffness,
|
||||
animationTime: this.config.animationTime
|
||||
});
|
||||
this.zoomSpring = new $.Spring({
|
||||
initial: 1,
|
||||
springStiffness: config.springStiffness,
|
||||
animationTime: config.animationTime
|
||||
springStiffness: this.config.springStiffness,
|
||||
animationTime: this.config.animationTime
|
||||
});
|
||||
this.minZoomImageRatio = config.minZoomImageRatio;
|
||||
this.maxZoomPixelRatio = config.maxZoomPixelRatio;
|
||||
this.visibilityRatio = config.visibilityRatio;
|
||||
this.wrapHorizontal = config.wrapHorizontal;
|
||||
this.wrapVertical = config.wrapVertical;
|
||||
this.minZoomImageRatio = this.config.minZoomImageRatio;
|
||||
this.maxZoomPixelRatio = this.config.maxZoomPixelRatio;
|
||||
this.visibilityRatio = this.config.visibilityRatio;
|
||||
this.wrapHorizontal = this.config.wrapHorizontal;
|
||||
this.wrapVertical = this.config.wrapVertical;
|
||||
this.homeBounds = new $.Rect( 0, 0, 1, this.contentHeight );
|
||||
this.goHome( true );
|
||||
this.update();
|
||||
|
Loading…
Reference in New Issue
Block a user