diff --git a/src/strings.js b/src/strings.js index fba93de0..9616850a 100644 --- a/src/strings.js +++ b/src/strings.js @@ -45,7 +45,8 @@ var I18N = { ImageFormat: "Sorry, we don't support {0}-based Deep Zoom Images.", Security: "It looks like a security restriction stopped us from " + "loading this Deep Zoom Image.", - Status: "This space unintentionally left blank ({0} {1})." + Status: "This space unintentionally left blank ({0} {1}).", + "Open-Failed": "Unable to open {0}: {1}" }, Tooltips: { diff --git a/src/tilesource.js b/src/tilesource.js index 3168606e..fb22b21c 100644 --- a/src/tilesource.js +++ b/src/tilesource.js @@ -293,6 +293,11 @@ $.TileSource.prototype = { callback = function( data ){ var $TileSource = $.TileSource.determineType( _this, data, url ); + if ( !$TileSource ) { + _this.raiseEvent( 'open-failed', { message: "Unable to load TileSource", source: url } ); + return; + } + options = $TileSource.prototype.configure.apply( _this, [ data, url ]); readySource = new $TileSource( options ); _this.ready = true; @@ -315,6 +320,11 @@ $.TileSource.prototype = { $.makeAjaxRequest( url, function( xhr ) { var data = processResponse( xhr ); callback( data ); + }, function ( xhr ) { + _this.raiseEvent( 'open-failed', { + message: "HTTP " + xhr.status + " attempting to load TileSource", + source: url + }); }); } @@ -458,6 +468,8 @@ $.TileSource.determineType = function( tileSource, data, url ){ return OpenSeadragon[ property ]; } } + + $.console.error( "No TileSource was able to open %s %s", url, data ); }; diff --git a/src/viewer.js b/src/viewer.js index cf5c9aa1..532f5078 100644 --- a/src/viewer.js +++ b/src/viewer.js @@ -171,6 +171,12 @@ $.Viewer = function( options ) { //Inherit some behaviors and properties $.EventHandler.call( this ); + + this.addHandler( 'open-failed', function (source, args) { + var msg = $.getString( "Errors.Open-Failed", args.source, args.message); + window.alert( msg ); + }); + $.ControlDock.call( this, options ); //Deal with tile sources @@ -433,6 +439,9 @@ $.extend( $.Viewer.prototype, $.EventHandler.prototype, $.ControlDock.prototype, tileSource = new $.TileSource( tileSource, function( readySource ){ openTileSource( _this, readySource ); }); + tileSource.addHandler( 'open-failed', function ( name, args ) { + _this.raiseEvent( 'open-failed', args ); + }); } else if ( $.isPlainObject( tileSource ) || tileSource.nodeType ){ if( $.isFunction( tileSource.getTileUrl ) ){ @@ -443,6 +452,13 @@ $.extend( $.Viewer.prototype, $.EventHandler.prototype, $.ControlDock.prototype, } else { //inline configuration $TileSource = $.TileSource.determineType( _this, tileSource ); + if ( !$TileSource ) { + _this.raiseEvent( 'open-failed', { + message: "Unable to load TileSource", + source: tileSource + }); + return; + } options = $TileSource.prototype.configure.apply( _this, [ tileSource ]); readySource = new $TileSource( options ); openTileSource( _this, readySource );