mostly superficial formating. removing $.Strings and putting it directly in $. more clean up of the Drawer update related functions

This commit is contained in:
thatcher 2012-01-23 22:48:45 -05:00
parent bc50a7df04
commit a8730a9f00
17 changed files with 826 additions and 624 deletions

View File

@ -6,7 +6,7 @@
PROJECT: openseadragon PROJECT: openseadragon
BUILD_MAJOR: 0 BUILD_MAJOR: 0
BUILD_MINOR: 8 BUILD_MINOR: 8
BUILD_ID: 20 BUILD_ID: 22
BUILD: ${PROJECT}.${BUILD_MAJOR}.${BUILD_MINOR}.${BUILD_ID} BUILD: ${PROJECT}.${BUILD_MAJOR}.${BUILD_MINOR}.${BUILD_ID}
VERSION: ${BUILD_MAJOR}.${BUILD_MINOR}.${BUILD_ID} VERSION: ${BUILD_MAJOR}.${BUILD_MINOR}.${BUILD_ID}

View File

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

View File

@ -22,22 +22,23 @@ $.Button = function( options ) {
//TODO: make button elements accessible by making them a-tags //TODO: make button elements accessible by making them a-tags
// maybe even consider basing them on the element and adding // maybe even consider basing them on the element and adding
// methods jquery-style. // methods jquery-style.
this.element = options.element || $.makeNeutralElement("span"); this.element = options.element || $.makeNeutralElement( "a" );
this.element.href = '#';
this.config = options.config; this.config = options.config;
if ( options.onPress != undefined ){ if ( options.onPress ){
this.addHandler( "onPress", options.onPress ); this.addHandler( "onPress", options.onPress );
} }
if ( options.onRelease != undefined ){ if ( options.onRelease ){
this.addHandler( "onRelease", options.onRelease ); this.addHandler( "onRelease", options.onRelease );
} }
if ( options.onClick != undefined ){ if ( options.onClick ){
this.addHandler( "onClick", options.onClick ); this.addHandler( "onClick", options.onClick );
} }
if ( options.onEnter != undefined ){ if ( options.onEnter ){
this.addHandler( "onEnter", options.onEnter ); this.addHandler( "onEnter", options.onEnter );
} }
if ( options.onExit != undefined ){ if ( options.onExit ){
this.addHandler( "onExit", options.onExit ); this.addHandler( "onExit", options.onExit );
} }
@ -66,10 +67,10 @@ $.Button = function( options ) {
this.element.appendChild( this.imgHover ); this.element.appendChild( this.imgHover );
this.element.appendChild( this.imgDown ); this.element.appendChild( this.imgDown );
var styleRest = this.imgRest.style; var styleRest = this.imgRest.style,
var styleGroup = this.imgGroup.style; styleGroup = this.imgGroup.style,
var styleHover = this.imgHover.style; styleHover = this.imgHover.style,
var styleDown = this.imgDown.style; styleDown = this.imgDown.style;
styleGroup.position = styleGroup.position =
styleHover.position = styleHover.position =
@ -140,12 +141,15 @@ $.Button = function( options ) {
}; };
$.extend( $.Button.prototype, $.EventHandler.prototype, { $.extend( $.Button.prototype, $.EventHandler.prototype, {
notifyGroupEnter: function() { notifyGroupEnter: function() {
inTo( this, $.ButtonState.GROUP ); inTo( this, $.ButtonState.GROUP );
}, },
notifyGroupExit: function() { notifyGroupExit: function() {
outTo( this, $.ButtonState.REST ); outTo( this, $.ButtonState.REST );
} }
}); });
@ -189,17 +193,20 @@ function stopFading( button ) {
}; };
function inTo( button, newState ) { function inTo( button, newState ) {
if ( newState >= $.ButtonState.GROUP && button.currentState == $.ButtonState.REST ) { if ( newState >= $.ButtonState.GROUP &&
button.currentState == $.ButtonState.REST ) {
stopFading( button ); stopFading( button );
button.currentState = $.ButtonState.GROUP; 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.imgHover.style.visibility = "";
button.currentState = $.ButtonState.HOVER; 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.imgDown.style.visibility = "";
button.currentState = $.ButtonState.DOWN; button.currentState = $.ButtonState.DOWN;
} }
@ -207,17 +214,20 @@ function inTo( button, newState ) {
function outTo( 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.imgDown.style.visibility = "hidden";
button.currentState = $.ButtonState.HOVER; 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.imgHover.style.visibility = "hidden";
button.currentState = $.ButtonState.GROUP; 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.beginFading();
button.currentState = $.ButtonState.REST; button.currentState = $.ButtonState.REST;
} }

View File

@ -25,23 +25,32 @@ $.Control = function (elmt, anchor, container) {
if ( this.anchor == $.ControlAnchor.TOP_RIGHT || if ( this.anchor == $.ControlAnchor.TOP_RIGHT ||
this.anchor == $.ControlAnchor.BOTTOM_RIGHT ) { this.anchor == $.ControlAnchor.BOTTOM_RIGHT ) {
this.container.insertBefore(this.wrapper, this.container.firstChild); this.container.insertBefore(
this.wrapper,
this.container.firstChild
);
} else { } else {
this.container.appendChild( this.wrapper ); this.container.appendChild( this.wrapper );
} }
}; };
$.Control.prototype = { $.Control.prototype = {
destroy: function() { destroy: function() {
this.wrapper.removeChild( this.elmt ); this.wrapper.removeChild( this.elmt );
this.container.removeChild( this.wrapper ); this.container.removeChild( this.wrapper );
}, },
isVisible: function() { isVisible: function() {
return this.wrapper.style.display != "none"; return this.wrapper.style.display != "none";
}, },
setVisible: function( visible ) { setVisible: function( visible ) {
this.wrapper.style.display = visible ? "inline-block" : "none"; this.wrapper.style.display = visible ?
"inline-block" :
"none";
}, },
setOpacity: function( opacity ) { setOpacity: function( opacity ) {
if ( this.elmt[ $.SIGNAL ] && $.Browser.vendor == $.BROWSERS.IE ) { if ( this.elmt[ $.SIGNAL ] && $.Browser.vendor == $.BROWSERS.IE ) {
$.setElementOpacity( this.elmt, opacity, true ); $.setElementOpacity( this.elmt, opacity, true );

View File

@ -7,7 +7,7 @@ $.DisplayRect = function( x, y, width, height, minLevel, maxLevel ) {
this.minLevel = minLevel; this.minLevel = minLevel;
this.maxLevel = maxLevel; this.maxLevel = maxLevel;
} }
$.DisplayRect.prototype = new $.Rect();
$.DisplayRect.prototype.constructor = $.DisplayRect; $.extend( $.DisplayRect.prototype, $.Rect.prototype );
}( OpenSeadragon )); }( OpenSeadragon ));

View File

@ -34,7 +34,7 @@ $.Drawer = function(source, viewport, elmt) {
this.downloading = 0; this.downloading = 0;
this.imageLoaderLimit = this.config.imageLoaderLimit; this.imageLoaderLimit = this.config.imageLoaderLimit;
this.profiler = new $.Profiler(); //this.profiler = new $.Profiler();
this.minLevel = source.minLevel; this.minLevel = source.minLevel;
this.maxLevel = source.maxLevel; this.maxLevel = source.maxLevel;
@ -151,14 +151,14 @@ $.Drawer.prototype = {
tile.loading = false; tile.loading = false;
if ( this.midUpdate ) { if ( this.midUpdate ) {
$.Debug.error( "Tile load callback in middle of drawing routine." ); $.Debug.warn( "Tile load callback in middle of drawing routine." );
return; return;
} else if ( !image ) { } 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; tile.exists = false;
return; return;
} else if ( time < this.lastResetTime ) { } 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; return;
} }
@ -277,8 +277,9 @@ $.Drawer.prototype = {
*/ */
_setCoverage: function( level, x, y, covers ) { _setCoverage: function( level, x, y, covers ) {
if ( !this.coverage[ level ] ) { if ( !this.coverage[ level ] ) {
$.Debug.error( $.Debug.warn(
"Setting coverage for a tile before its level's coverage has been reset: " + level "Setting coverage for a tile before its level's coverage has been reset: %s",
level
); );
return; return;
} }
@ -403,7 +404,14 @@ $.Drawer.prototype = {
for ( level = highestLevel; level >= lowestLevel; level-- ) { for ( level = highestLevel; level >= lowestLevel; level-- ) {
//TODO //TODO
best = this._drawLevel( level, lowestLevel, viewportTL, viewportBR, currentTime, best ); best = this._drawLevel(
level,
lowestLevel,
viewportTL,
viewportBR,
currentTime,
best
);
//TODO //TODO
if ( this._providesCoverage( level ) ) { if ( this._providesCoverage( level ) ) {
@ -491,7 +499,7 @@ $.Drawer.prototype = {
for ( x = tileTL.x; x <= tileBR.x; x++ ) { for ( x = tileTL.x; x <= tileBR.x; x++ ) {
for ( y = tileTL.y; y <= tileBR.y; y++ ) { for ( y = tileTL.y; y <= tileBR.y; y++ ) {
drawTile = drawLevel;
tile = this._getTile( tile = this._getTile(
level, level,
x, y, x, y,
@ -506,6 +514,7 @@ $.Drawer.prototype = {
continue; continue;
} }
drawTile = drawLevel;
if ( haveDrawn && !drawTile ) { if ( haveDrawn && !drawTile ) {
if ( this._isCovered( level, x, y ) ) { if ( this._isCovered( level, x, y ) ) {
this._setCoverage( level, x, y, true ); this._setCoverage( level, x, y, true );
@ -722,7 +731,10 @@ $.Drawer.prototype = {
callback( image ); callback( image );
} catch ( e ) { } catch ( e ) {
$.Debug.error( $.Debug.error(
e.name + " while executing " + src +" callback: " + e.message, "%s while executing %s callback: %s",
e.name,
src,
e.message,
e e
); );
} }

View File

@ -3,18 +3,21 @@
$.DziTileSource = function( width, height, tileSize, tileOverlap, tilesUrl, fileFormat, displayRects ) { $.DziTileSource = function( width, height, tileSize, tileOverlap, tilesUrl, fileFormat, displayRects ) {
var i,
rect,
level;
$.TileSource.call( this, width, height, tileSize, tileOverlap, null, null ); $.TileSource.call( this, width, height, tileSize, tileOverlap, null, null );
this._levelRects = {}; this._levelRects = {};
this.tilesUrl = tilesUrl; this.tilesUrl = tilesUrl;
this.fileFormat = fileFormat; this.fileFormat = fileFormat;
this.displayRects = displayRects; this.displayRects = displayRects;
if ( this.displayRects ) { if ( this.displayRects ) {
for (var i = this.displayRects.length - 1; i >= 0; i--) { for ( i = this.displayRects.length - 1; i >= 0; i-- ) {
var rect = this.displayRects[i]; rect = this.displayRects[ i ];
for (var level = rect.minLevel; level <= rect.maxLevel; level++) { for ( level = rect.minLevel; level <= rect.maxLevel; level++ ) {
if ( !this._levelRects[ level ] ) { if ( !this._levelRects[ level ] ) {
this._levelRects[ level ] = []; this._levelRects[ level ] = [];
} }
@ -32,24 +35,31 @@ $.extend( $.DziTileSource.prototype, $.TileSource.prototype, {
}, },
tileExists: function( level, x, y ) { 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 ) { if ( !rects || !rects.length ) {
return true; return true;
} }
for (var i = rects.length - 1; i >= 0; i--) { for ( i = rects.length - 1; i >= 0; i-- ) {
var rect = rects[i]; rect = rects[ i ];
if ( level < rect.minLevel || level > rect.maxLevel ) { if ( level < rect.minLevel || level > rect.maxLevel ) {
continue; continue;
} }
var scale = this.getLevelScale(level); scale = this.getLevelScale( level );
var xMin = rect.x * scale; xMin = rect.x * scale;
var yMin = rect.y * scale; yMin = rect.y * scale;
var xMax = xMin + rect.width * scale; xMax = xMin + rect.width * scale;
var yMax = yMin + rect.height * scale; yMax = yMin + rect.height * scale;
xMin = Math.floor( xMin / this.tileSize ); xMin = Math.floor( xMin / this.tileSize );
yMin = Math.floor( yMin / this.tileSize ); yMin = Math.floor( yMin / this.tileSize );
@ -66,12 +76,18 @@ $.extend( $.DziTileSource.prototype, $.TileSource.prototype, {
}); });
$.DziTileSourceHelper = { $.DziTileSourceHelper = {
createFromXml: function( xmlUrl, xmlString, callback ) { createFromXml: function( xmlUrl, xmlString, callback ) {
var async = typeof (callback) == "function"; var async = typeof (callback) == "function",
var error = null; error = null,
urlParts,
filename,
lastDot,
tilesUrl,
handler;
if ( !xmlUrl ) { if ( !xmlUrl ) {
this.error = $.Strings.getString("Errors.Empty"); this.error = $.getString( "Errors.Empty" );
if ( async ) { if ( async ) {
window.setTimeout( function() { window.setTimeout( function() {
callback( null, error ); callback( null, error );
@ -81,15 +97,16 @@ $.DziTileSourceHelper = {
throw new Error( error ); throw new Error( error );
} }
var urlParts = xmlUrl.split('/'); urlParts = xmlUrl.split( '/' );
var filename = urlParts[urlParts.length - 1]; filename = urlParts[ urlParts.length - 1 ];
var lastDot = filename.lastIndexOf('.'); lastDot = filename.lastIndexOf( '.' );
if ( lastDot > -1 ) { if ( lastDot > -1 ) {
urlParts[ urlParts.length - 1 ] = filename.slice( 0, lastDot ); urlParts[ urlParts.length - 1 ] = filename.slice( 0, lastDot );
} }
var tilesUrl = urlParts.join('/') + "_files/"; tilesUrl = urlParts.join( '/' ) + "_files/";
function finish( func, obj ) { function finish( func, obj ) {
try { try {
return func( obj, tilesUrl ); return func( obj, tilesUrl );
@ -101,18 +118,21 @@ $.DziTileSourceHelper = {
} }
} }
} }
if ( async ) { if ( async ) {
if ( xmlString ) { if ( xmlString ) {
var handler = $.delegate(this, this.processXml); handler = $.delegate( this, this.processXml );
window.setTimeout( function() { window.setTimeout( function() {
var source = finish( handler, $.parseXml( xmlString ) ); var source = finish( handler, $.parseXml( xmlString ) );
callback(source, error); // call after finish sets error // call after finish sets error
callback( source, error );
}, 1); }, 1);
} else { } else {
var handler = $.delegate(this, this.processResponse); handler = $.delegate( this, this.processResponse );
$.makeAjaxRequest( xmlUrl, function( xhr ) { $.makeAjaxRequest( xmlUrl, function( xhr ) {
var source = finish( handler, 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 ) { if ( xmlString ) {
return finish($.delegate(this, this.processXml), $.parseXml(xmlString)); return finish(
$.delegate( this, this.processXml ),
$.parseXml( xmlString )
);
} else { } else {
return finish($.delegate(this, this.processResponse), $.makeAjaxRequest(xmlUrl)); return finish(
$.delegate( this, this.processResponse ),
$.makeAjaxRequest( xmlUrl )
);
} }
}, },
processResponse: function( xhr, tilesUrl ) { processResponse: function( xhr, tilesUrl ) {
if (!xhr) { var status,
throw new Error($.Strings.getString("Errors.Security")); statusText,
} else if (xhr.status !== 200 && xhr.status !== 0) { doc = null;
var status = xhr.status;
var statusText = (status == 404) ? "Not Found" : xhr.statusText;
throw new Error($.Strings.getString("Errors.Status", status, statusText));
}
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 ) { if ( xhr.responseXML && xhr.responseXML.documentElement ) {
doc = xhr.responseXML; doc = xhr.responseXML;
@ -146,66 +176,77 @@ $.DziTileSourceHelper = {
}, },
processXml: function( xmlDoc, tilesUrl ) { processXml: function( xmlDoc, tilesUrl ) {
if ( !xmlDoc || !xmlDoc.documentElement ) { if ( !xmlDoc || !xmlDoc.documentElement ) {
throw new Error($.Strings.getString("Errors.Xml")); throw new Error( $.getString( "Errors.Xml" ) );
} }
var root = xmlDoc.documentElement; var root = xmlDoc.documentElement,
var rootName = root.tagName; rootName = root.tagName;
if ( rootName == "Image" ) { if ( rootName == "Image" ) {
try { try {
return this.processDzi( root, tilesUrl ); return this.processDzi( root, tilesUrl );
} catch ( e ) { } catch ( e ) {
var defMsg = $.Strings.getString("Errors.Dzi"); throw (e instanceof Error) ?
throw (e instanceof Error) ? e : new Error(defMsg); e :
new Error( $.getString("Errors.Dzi") );
} }
} else if ( rootName == "Collection" ) { } else if ( rootName == "Collection" ) {
throw new Error($.Strings.getString("Errors.Dzc")); throw new Error( $.getString( "Errors.Dzc" ) );
} else if ( rootName == "Error" ) { } else if ( rootName == "Error" ) {
return this.processError( root ); return this.processError( root );
} }
throw new Error($.Strings.getString("Errors.Dzi")); throw new Error( $.getString( "Errors.Dzi" ) );
}, },
processDzi: function( imageNode, tilesUrl ) { 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 ) ) { if ( !$.imageFormatSupported( fileFormat ) ) {
throw new Error($.Strings.getString("Errors.ImageFormat", throw new Error(
fileFormat.toUpperCase())); $.getString( "Errors.ImageFormat", fileFormat.toUpperCase() )
);
} }
var sizeNode = imageNode.getElementsByTagName("Size")[0]; for ( i = 0; i < dispRectNodes.length; i++ ) {
var dispRectNodes = imageNode.getElementsByTagName("DisplayRect"); dispRectNode = dispRectNodes[ i ];
rectNode = dispRectNode.getElementsByTagName( "Rect" )[ 0 ];
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];
dispRects.push( new $.DisplayRect( dispRects.push( new $.DisplayRect(
parseInt(rectNode.getAttribute("X"), 10), parseInt( rectNode.getAttribute( "X" ) ),
parseInt(rectNode.getAttribute("Y"), 10), parseInt( rectNode.getAttribute( "Y" ) ),
parseInt(rectNode.getAttribute("Width"), 10), parseInt( rectNode.getAttribute( "Width" ) ),
parseInt(rectNode.getAttribute("Height"), 10), parseInt( rectNode.getAttribute( "Height" ) ),
0, // ignore MinLevel attribute, bug in Deep Zoom Composer 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, return new $.DziTileSource(
tilesUrl, fileFormat, dispRects); width,
height,
tileSize,
tileOverlap,
tilesUrl,
fileFormat,
dispRects
);
}, },
processError: function( errorNode ) { processError: function( errorNode ) {
var messageNode = errorNode.getElementsByTagName("Message")[0]; var messageNode = errorNode.getElementsByTagName( "Message" )[ 0 ],
var message = messageNode.firstChild.nodeValue; message = messageNode.firstChild.nodeValue;
throw new Error(message); throw new Error(message);
} }

View File

@ -37,8 +37,8 @@
Array.apply( null, events ); Array.apply( null, events );
return function( source, args ) { return function( source, args ) {
var i, var i,
l = events.length; length = events.length;
for ( i = 0; i < l; i++ ) { for ( i = 0; i < length; i++ ) {
events[ i ]( source, args ); events[ i ]( source, args );
} }
}; };

View File

@ -711,7 +711,11 @@ OpenSeadragon = window.OpenSeadragon || (function(){
request.open( "GET", url, async ); request.open( "GET", url, async );
request.send( null ); request.send( null );
} catch (e) { } 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.onreadystatechange = null;
request = null; request = null;

View File

@ -20,8 +20,8 @@
location.x, location.x,
location.y, location.y,
location.width, location.width,
location.height) location.height
; );
this.position = new $.Point( this.position = new $.Point(
location.x, location.x,
location.y location.y
@ -74,12 +74,13 @@
break; break;
} }
}, },
destroy: function() {
var elmt = this.elmt;
var style = this.style;
if (elmt.parentNode) { destroy: function() {
elmt.parentNode.removeChild(elmt); var element = this.elmt,
style = this.style;
if ( element.parentNode ) {
element.parentNode.removeChild( element );
} }
style.top = ""; style.top = "";
@ -91,19 +92,20 @@
style.height = ""; style.height = "";
} }
}, },
drawHTML: function( container ) { drawHTML: function( container ) {
var elmt = this.elmt, var element = this.elmt,
style = this.style, style = this.style,
scales = this.scales, scales = this.scales,
position, position,
size; size;
if ( elmt.parentNode != container ) { if ( element.parentNode != container ) {
container.appendChild( elmt ); container.appendChild( element );
} }
if ( !scales ) { if ( !scales ) {
this.size = $.getElementSize( elmt ); this.size = $.getElementSize( element );
} }
position = this.position; position = this.position;
@ -123,11 +125,17 @@
style.height = size.y + "px"; style.height = size.y + "px";
} }
}, },
update: function( loc, placement ) {
this.scales = ( loc instanceof $.Rect ); update: function( location, placement ) {
this.bounds = new $.Rect(loc.x, loc.y, loc.width, loc.height); this.scales = location instanceof $.Rect;
this.bounds = new $.Rect(
location.x,
location.y,
location.width,
location.height
);
// rects are always top-left // rects are always top-left
this.placement = loc instanceof $.Point ? this.placement = location instanceof $.Point ?
placement : placement :
$.OverlayPlacement.TOP_LEFT; $.OverlayPlacement.TOP_LEFT;
} }

View File

@ -52,9 +52,13 @@ $.Point.prototype = {
}, },
equals: function( point ) { equals: function( point ) {
return ( point instanceof $.Point ) && return (
( this.x === point.x ) && point instanceof $.Point
( this.y === point.y ); ) && (
this.x === point.x
) && (
this.y === point.y
);
}, },
toString: function() { toString: function() {

View File

@ -4,9 +4,7 @@
//TODO: I guess this is where the i18n needs to be reimplemented. I'll look //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 // into existing patterns for i18n in javascript but i think that mimicking
// pythons gettext might be a reasonable approach. // pythons gettext might be a reasonable approach.
var I18N = {
$.Strings = {
Errors: { Errors: {
Failure: "Sorry, but Seadragon Ajax can't run on your browser!\n" + Failure: "Sorry, but Seadragon Ajax can't run on your browser!\n" +
"Please try using IE 7 or Firefox 3.\n", "Please try using IE 7 or Firefox 3.\n",
@ -30,12 +28,15 @@ $.Strings = {
Home: "Go home", Home: "Go home",
ZoomIn: "Zoom in", ZoomIn: "Zoom in",
ZoomOut: "Zoom out" ZoomOut: "Zoom out"
}, }
};
$.extend( $, {
getString: function( prop ) { getString: function( prop ) {
var props = prop.split('.'), var props = prop.split('.'),
string = $.Strings, string = I18N,
args = arguments, args = arguments,
i; i;
@ -71,6 +72,6 @@ $.Strings = {
container[ props[ i ] ] = value; container[ props[ i ] ] = value;
} }
}; });
}( OpenSeadragon )); }( OpenSeadragon ));

View File

@ -34,11 +34,13 @@ $.Tile.prototype = {
drawHTML: function( container ) { drawHTML: function( container ) {
var position = this.position.apply( Math.floor ),
size = this.size.apply( Math.ceil );
if ( !this.loaded ) { if ( !this.loaded ) {
$.Debug.error( $.Debug.warn(
"Attempting to draw tile " + "Attempting to draw tile %s when it's not yet loaded.",
this.toString() + this.toString()
" when it's not yet loaded."
); );
return; return;
} }
@ -52,9 +54,6 @@ $.Tile.prototype = {
this.style.msInterpolationMode = "nearest-neighbor"; this.style.msInterpolationMode = "nearest-neighbor";
} }
var position = this.position.apply( Math.floor );
var size = this.size.apply( Math.ceil );
if ( this.elmt.parentNode != container ) { if ( this.elmt.parentNode != container ) {
container.appendChild( this.elmt ); container.appendChild( this.elmt );
@ -70,18 +69,18 @@ $.Tile.prototype = {
}, },
drawCanvas: function(context) { 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, var position = this.position,
size = this.size; 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.globalAlpha = this.opacity;
context.drawImage(this.image, position.x, position.y, size.x, size.y); context.drawImage(this.image, position.x, position.y, size.x, size.y);
}, },

View File

@ -4,59 +4,57 @@
$.TileSource = function( width, height, tileSize, tileOverlap, minLevel, maxLevel ) { $.TileSource = function( width, height, tileSize, tileOverlap, minLevel, maxLevel ) {
this.aspectRatio = width / height; this.aspectRatio = width / height;
this.dimensions = new $.Point( width, height ); this.dimensions = new $.Point( width, height );
this.tileSize = tileSize ? tileSize : 0;
this.tileOverlap = tileOverlap ? tileOverlap : 0;
this.minLevel = minLevel ? minLevel : 0; this.minLevel = minLevel ? minLevel : 0;
this.maxLevel = maxLevel ? maxLevel : this.maxLevel = maxLevel ? maxLevel :
Math.ceil( Math.ceil(
Math.log( Math.max( width, height ) ) / Math.log( Math.max( width, height ) ) /
Math.log( 2 ) Math.log( 2 )
); );
this.tileSize = tileSize ? tileSize : 0;
this.tileOverlap = tileOverlap ? tileOverlap : 0;
}; };
$.TileSource.prototype = { $.TileSource.prototype = {
getLevelScale: function( level ) { getLevelScale: function( level ) {
return 1 / ( 1 << ( this.maxLevel - level ) ); return 1 / ( 1 << ( this.maxLevel - level ) );
}, },
getNumTiles: function( level ) { getNumTiles: function( level ) {
var scale = this.getLevelScale(level); var scale = this.getLevelScale( level ),
var x = Math.ceil(scale * this.dimensions.x / this.tileSize); x = Math.ceil( scale * this.dimensions.x / this.tileSize ),
var y = Math.ceil(scale * this.dimensions.y / this.tileSize); y = Math.ceil( scale * this.dimensions.y / this.tileSize );
return new $.Point( x, y ); return new $.Point( x, y );
}, },
getPixelRatio: function( level ) { getPixelRatio: function( level ) {
var imageSizeScaled = this.dimensions.times(this.getLevelScale(level)); var imageSizeScaled = this.dimensions.times( this.getLevelScale( level ) ),
var rx = 1.0 / imageSizeScaled.x; rx = 1.0 / imageSizeScaled.x,
var ry = 1.0 / imageSizeScaled.y; ry = 1.0 / imageSizeScaled.y;
return new $.Point(rx, ry); return new $.Point(rx, ry);
}, },
getTileAtPoint: function( level, point ) { getTileAtPoint: function( level, point ) {
var pixel = point.times(this.dimensions.x).times(this.getLevelScale(level)); var pixel = point.times( this.dimensions.x ).times( this.getLevelScale(level ) ),
tx = Math.floor( pixel.x / this.tileSize ),
var tx = Math.floor(pixel.x / this.tileSize); ty = Math.floor( pixel.y / this.tileSize );
var ty = Math.floor(pixel.y / this.tileSize);
return new $.Point( tx, ty ); return new $.Point( tx, ty );
}, },
getTileBounds: function( level, x, y ) { getTileBounds: function( level, x, y ) {
var dimensionsScaled = this.dimensions.times(this.getLevelScale(level)); var dimensionsScaled = this.dimensions.times( this.getLevelScale( level ) ),
px = ( x === 0 ) ? 0 : this.tileSize * x - this.tileOverlap,
var px = (x === 0) ? 0 : this.tileSize * x - this.tileOverlap; py = ( y === 0 ) ? 0 : this.tileSize * y - this.tileOverlap,
var 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,
var sx = this.tileSize + (x === 0 ? 1 : 2) * this.tileOverlap; scale = 1.0 / dimensionsScaled.x;
var sy = this.tileSize + (y === 0 ? 1 : 2) * this.tileOverlap;
sx = Math.min( sx, dimensionsScaled.x - px ); sx = Math.min( sx, dimensionsScaled.x - px );
sy = Math.min( sy, dimensionsScaled.y - py ); sy = Math.min( sy, dimensionsScaled.y - py );
var scale = 1.0 / dimensionsScaled.x;
return new $.Rect( px * scale, py * scale, sx * scale, sy * scale ); return new $.Rect( px * scale, py * scale, sx * scale, sy * scale );
}, },

View File

@ -199,25 +199,27 @@ $.Viewer = function( options ) {
// Navigation Controls // Navigation Controls
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
this._group = null; this._group = null;
this._zooming = false; // whether we should be continuously zooming // whether we should be continuously zooming
this._zoomFactor = null; // how much we should be continuously zooming by this._zooming = false;
// how much we should be continuously zooming by
this._zoomFactor = null;
this._lastZoomTime = null; this._lastZoomTime = null;
this.elmt = null; this.elmt = null;
var beginZoomingInHandler = $.delegate(this, beginZoomingIn); var beginZoomingInHandler = $.delegate(this, beginZoomingIn),
var endZoomingHandler = $.delegate(this, endZooming); endZoomingHandler = $.delegate(this, endZooming),
var doSingleZoomInHandler = $.delegate(this, doSingleZoomIn); doSingleZoomInHandler = $.delegate(this, doSingleZoomIn),
var beginZoomingOutHandler = $.delegate(this, beginZoomingOut); beginZoomingOutHandler = $.delegate(this, beginZoomingOut),
var doSingleZoomOutHandler = $.delegate(this, doSingleZoomOut); doSingleZoomOutHandler = $.delegate(this, doSingleZoomOut),
var onHomeHandler = $.delegate(this, onHome); onHomeHandler = $.delegate(this, onHome),
var onFullPageHandler = $.delegate(this, onFullPage); onFullPageHandler = $.delegate(this, onFullPage);
var navImages = this.config.navImages; var navImages = this.config.navImages;
var zoomIn = new $.Button({ var zoomIn = new $.Button({
config: this.config, config: this.config,
tooltip: $.Strings.getString("Tooltips.ZoomIn"), tooltip: $.getString("Tooltips.ZoomIn"),
srcRest: resolveUrl(this.urlPrefix, navImages.zoomIn.REST), srcRest: resolveUrl(this.urlPrefix, navImages.zoomIn.REST),
srcGroup: resolveUrl(this.urlPrefix, navImages.zoomIn.GROUP), srcGroup: resolveUrl(this.urlPrefix, navImages.zoomIn.GROUP),
srcHover: resolveUrl(this.urlPrefix, navImages.zoomIn.HOVER), srcHover: resolveUrl(this.urlPrefix, navImages.zoomIn.HOVER),
@ -231,7 +233,7 @@ $.Viewer = function( options ) {
var zoomOut = new $.Button({ var zoomOut = new $.Button({
config: this.config, config: this.config,
tooltip: $.Strings.getString("Tooltips.ZoomOut"), tooltip: $.getString("Tooltips.ZoomOut"),
srcRest: resolveUrl(this.urlPrefix, navImages.zoomOut.REST), srcRest: resolveUrl(this.urlPrefix, navImages.zoomOut.REST),
srcGroup: resolveUrl(this.urlPrefix, navImages.zoomOut.GROUP), srcGroup: resolveUrl(this.urlPrefix, navImages.zoomOut.GROUP),
srcHover: resolveUrl(this.urlPrefix, navImages.zoomOut.HOVER), srcHover: resolveUrl(this.urlPrefix, navImages.zoomOut.HOVER),
@ -244,7 +246,7 @@ $.Viewer = function( options ) {
}); });
var goHome = new $.Button({ var goHome = new $.Button({
config: this.config, config: this.config,
tooltip: $.Strings.getString("Tooltips.Home"), tooltip: $.getString("Tooltips.Home"),
srcRest: resolveUrl(this.urlPrefix, navImages.home.REST), srcRest: resolveUrl(this.urlPrefix, navImages.home.REST),
srcGroup: resolveUrl(this.urlPrefix, navImages.home.GROUP), srcGroup: resolveUrl(this.urlPrefix, navImages.home.GROUP),
srcHover: resolveUrl(this.urlPrefix, navImages.home.HOVER), srcHover: resolveUrl(this.urlPrefix, navImages.home.HOVER),
@ -253,7 +255,7 @@ $.Viewer = function( options ) {
}); });
var fullPage = new $.Button({ var fullPage = new $.Button({
config: this.config, config: this.config,
tooltip: $.Strings.getString("Tooltips.FullPage"), tooltip: $.getString("Tooltips.FullPage"),
srcRest: resolveUrl(this.urlPrefix, navImages.fullpage.REST), srcRest: resolveUrl(this.urlPrefix, navImages.fullpage.REST),
srcGroup: resolveUrl(this.urlPrefix, navImages.fullpage.GROUP), srcGroup: resolveUrl(this.urlPrefix, navImages.fullpage.GROUP),
srcHover: resolveUrl(this.urlPrefix, navImages.fullpage.HOVER), srcHover: resolveUrl(this.urlPrefix, navImages.fullpage.HOVER),
@ -372,7 +374,7 @@ $.extend($.Viewer.prototype, $.EventHandler.prototype, {
window.setTimeout( function () { window.setTimeout( function () {
if ( _this._lastOpenStartTime > _this._lastOpenEndTime ) { if ( _this._lastOpenStartTime > _this._lastOpenEndTime ) {
_this._setMessage( $.Strings.getString( "Messages.Loading" ) ); _this._setMessage( $.getString( "Messages.Loading" ) );
} }
}, 2000); }, 2000);

View File

@ -1,35 +1,48 @@
(function( $ ){ (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 //TODO: this.config is something that should go away but currently the
// Drawer references the viewport.config // Drawer references the viewport.config
this.config = config; this.config = options.config;
this.zoomPoint = null; this.zoomPoint = null;
this.containerSize = containerSize; this.containerSize = options.containerSize;
this.contentSize = contentSize; this.contentSize = options.contentSize;
this.contentAspect = contentSize.x / contentSize.y; this.contentAspect = this.contentSize.x / this.contentSize.y;
this.contentHeight = contentSize.y / contentSize.x; this.contentHeight = this.contentSize.y / this.contentSize.x;
this.centerSpringX = new $.Spring({ this.centerSpringX = new $.Spring({
initial: 0, initial: 0,
springStiffness: config.springStiffness, springStiffness: this.config.springStiffness,
animationTime: config.animationTime animationTime: this.config.animationTime
}); });
this.centerSpringY = new $.Spring({ this.centerSpringY = new $.Spring({
initial: 0, initial: 0,
springStiffness: config.springStiffness, springStiffness: this.config.springStiffness,
animationTime: config.animationTime animationTime: this.config.animationTime
}); });
this.zoomSpring = new $.Spring({ this.zoomSpring = new $.Spring({
initial: 1, initial: 1,
springStiffness: config.springStiffness, springStiffness: this.config.springStiffness,
animationTime: config.animationTime animationTime: this.config.animationTime
}); });
this.minZoomImageRatio = config.minZoomImageRatio; this.minZoomImageRatio = this.config.minZoomImageRatio;
this.maxZoomPixelRatio = config.maxZoomPixelRatio; this.maxZoomPixelRatio = this.config.maxZoomPixelRatio;
this.visibilityRatio = config.visibilityRatio; this.visibilityRatio = this.config.visibilityRatio;
this.wrapHorizontal = config.wrapHorizontal; this.wrapHorizontal = this.config.wrapHorizontal;
this.wrapVertical = config.wrapVertical; this.wrapVertical = this.config.wrapVertical;
this.homeBounds = new $.Rect( 0, 0, 1, this.contentHeight ); this.homeBounds = new $.Rect( 0, 0, 1, this.contentHeight );
this.goHome( true ); this.goHome( true );
this.update(); this.update();