patch for recursive function call causing ie8 errors - oops. Also completed support for jsonp dzi format/protocol which is useful for running openseadragon from the filesystem as well, see main gh-pages index.html for example

This commit is contained in:
thatcher 2012-04-12 13:20:24 -04:00
parent e595ad2381
commit 107a5efabf
2 changed files with 150 additions and 14 deletions

View File

@ -773,6 +773,10 @@ OpenSeadragon = window.OpenSeadragon || function( options ){
document.documentElement.scrollTop document.documentElement.scrollTop
); );
}; };
} else {
$.getPageScroll = function(){
return new $.Point(0,0);
};
} }
return $.getPageScroll(); return $.getPageScroll();
@ -1283,7 +1287,11 @@ OpenSeadragon = window.OpenSeadragon || function( options ){
// Install callback // Install callback
window[ jsonpCallback ] = function( response ) { window[ jsonpCallback ] = function( response ) {
if ( !previous ){ if ( !previous ){
try{
delete window[ jsonpCallback ]; delete window[ jsonpCallback ];
}catch(e){
//swallow
}
} else { } else {
window[ jsonpCallback ] = previous; window[ jsonpCallback ] = previous;
} }
@ -1343,7 +1351,8 @@ OpenSeadragon = window.OpenSeadragon || function( options ){
urlParts, urlParts,
filename, filename,
lastDot, lastDot,
tilesUrl; tilesUrl,
callbackName;
if( tileHost ){ if( tileHost ){
@ -1383,6 +1392,17 @@ OpenSeadragon = window.OpenSeadragon || function( options ){
// call after finish sets error // call after finish sets error
callback( source, error ); callback( source, error );
}, 1); }, 1);
} else {
if( xmlUrl.match(/\.js$/) ){
callbackName = xmlUrl.split( '/' ).pop().replace('.js','_dzi');
$.jsonp({
url: xmlUrl,
callbackName: callbackName,
callback: function( imageData ){
var source = finish( processDZIJSON, imageData.Image );
callback( source );
}
});
} else { } else {
$.makeAjaxRequest( xmlUrl, function( xhr ) { $.makeAjaxRequest( xmlUrl, function( xhr ) {
var source = finish( processDZIResponse, xhr ); var source = finish( processDZIResponse, xhr );
@ -1390,6 +1410,7 @@ OpenSeadragon = window.OpenSeadragon || function( options ){
callback( source, error ); callback( source, error );
}); });
} }
}
return null; return null;
} }
@ -1674,6 +1695,53 @@ OpenSeadragon = window.OpenSeadragon || function( options ){
); );
}; };
/**
* @private
* @inner
* @function
* @param {Element} imageNode
* @param {String} tilesUrl
*/
function processDZIJSON( imageData, tilesUrl ) {
var fileFormat = imageData.Format,
sizeData = imageData.Size,
dispRectData = imageData.DisplayRect || [],
width = parseInt( sizeData.Width ),
height = parseInt( sizeData.Height ),
tileSize = parseInt( imageData.TileSize ),
tileOverlap = parseInt( imageData.Overlap ),
dispRects = [],
rectData,
i;
if ( !imageFormatSupported( fileFormat ) ) {
throw new Error(
$.getString( "Errors.ImageFormat", fileFormat.toUpperCase() )
);
}
for ( i = 0; i < dispRectData.length; i++ ) {
rectData = dispRectData[ i ].Rect;
dispRects.push( new $.DisplayRect(
parseInt( rectData.X ),
parseInt( rectData.Y ),
parseInt( rectData.Width ),
parseInt( rectData.Height ),
0, // ignore MinLevel attribute, bug in Deep Zoom Composer
parseInt( rectData.MaxLevel )
));
}
return new $.DziTileSource(
width,
height,
tileSize,
tileOverlap,
tilesUrl,
fileFormat,
dispRects
);
};
/** /**
* @private * @private
* @inner * @inner

View File

@ -773,6 +773,10 @@ OpenSeadragon = window.OpenSeadragon || function( options ){
document.documentElement.scrollTop document.documentElement.scrollTop
); );
}; };
} else {
$.getPageScroll = function(){
return new $.Point(0,0);
};
} }
return $.getPageScroll(); return $.getPageScroll();
@ -1283,7 +1287,11 @@ OpenSeadragon = window.OpenSeadragon || function( options ){
// Install callback // Install callback
window[ jsonpCallback ] = function( response ) { window[ jsonpCallback ] = function( response ) {
if ( !previous ){ if ( !previous ){
try{
delete window[ jsonpCallback ]; delete window[ jsonpCallback ];
}catch(e){
//swallow
}
} else { } else {
window[ jsonpCallback ] = previous; window[ jsonpCallback ] = previous;
} }
@ -1343,7 +1351,8 @@ OpenSeadragon = window.OpenSeadragon || function( options ){
urlParts, urlParts,
filename, filename,
lastDot, lastDot,
tilesUrl; tilesUrl,
callbackName;
if( tileHost ){ if( tileHost ){
@ -1383,6 +1392,17 @@ OpenSeadragon = window.OpenSeadragon || function( options ){
// call after finish sets error // call after finish sets error
callback( source, error ); callback( source, error );
}, 1); }, 1);
} else {
if( xmlUrl.match(/\.js$/) ){
callbackName = xmlUrl.split( '/' ).pop().replace('.js','_dzi');
$.jsonp({
url: xmlUrl,
callbackName: callbackName,
callback: function( imageData ){
var source = finish( processDZIJSON, imageData.Image );
callback( source );
}
});
} else { } else {
$.makeAjaxRequest( xmlUrl, function( xhr ) { $.makeAjaxRequest( xmlUrl, function( xhr ) {
var source = finish( processDZIResponse, xhr ); var source = finish( processDZIResponse, xhr );
@ -1390,6 +1410,7 @@ OpenSeadragon = window.OpenSeadragon || function( options ){
callback( source, error ); callback( source, error );
}); });
} }
}
return null; return null;
} }
@ -1674,6 +1695,53 @@ OpenSeadragon = window.OpenSeadragon || function( options ){
); );
}; };
/**
* @private
* @inner
* @function
* @param {Element} imageNode
* @param {String} tilesUrl
*/
function processDZIJSON( imageData, tilesUrl ) {
var fileFormat = imageData.Format,
sizeData = imageData.Size,
dispRectData = imageData.DisplayRect || [],
width = parseInt( sizeData.Width ),
height = parseInt( sizeData.Height ),
tileSize = parseInt( imageData.TileSize ),
tileOverlap = parseInt( imageData.Overlap ),
dispRects = [],
rectData,
i;
if ( !imageFormatSupported( fileFormat ) ) {
throw new Error(
$.getString( "Errors.ImageFormat", fileFormat.toUpperCase() )
);
}
for ( i = 0; i < dispRectData.length; i++ ) {
rectData = dispRectData[ i ].Rect;
dispRects.push( new $.DisplayRect(
parseInt( rectData.X ),
parseInt( rectData.Y ),
parseInt( rectData.Width ),
parseInt( rectData.Height ),
0, // ignore MinLevel attribute, bug in Deep Zoom Composer
parseInt( rectData.MaxLevel )
));
}
return new $.DziTileSource(
width,
height,
tileSize,
tileOverlap,
tilesUrl,
fileFormat,
dispRects
);
};
/** /**
* @private * @private
* @inner * @inner