mirror of
https://github.com/openseadragon/openseadragon.git
synced 2024-11-24 22:26:10 +03:00
Merge pull request #981 from LarissaSmith/master
Added an option to addTiledImage to change the crossOriginPolicy.
This commit is contained in:
commit
469341094d
@ -1229,6 +1229,8 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype,
|
||||
* browsers that support the HTML5 canvas.
|
||||
* @param {Number} [options.opacity] Opacity the tiled image should be drawn at by default.
|
||||
* @param {String} [options.compositeOperation] How the image is composited onto other images.
|
||||
* @param {String} [options.crossOriginPolicy] The crossOriginPolicy for this specific image,
|
||||
* overriding viewer.crossOriginPolicy.
|
||||
* @param {Function} [options.success] A function that gets called when the image is
|
||||
* successfully added. It's passed the event object which contains a single property:
|
||||
* "item", the resulting TiledImage.
|
||||
@ -1264,6 +1266,9 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype,
|
||||
if (options.compositeOperation === undefined) {
|
||||
options.compositeOperation = this.compositeOperation;
|
||||
}
|
||||
if (options.crossOriginPolicy === undefined) {
|
||||
options.crossOriginPolicy = options.tileSource.crossOriginPolicy !== undefined ? options.tileSource.crossOriginPolicy : this.crossOriginPolicy;
|
||||
}
|
||||
|
||||
var myQueueItem = {
|
||||
options: options
|
||||
@ -1326,7 +1331,7 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype,
|
||||
|
||||
this._loadQueue.push(myQueueItem);
|
||||
|
||||
getTileSourceImplementation( this, options.tileSource, function( tileSource ) {
|
||||
getTileSourceImplementation( this, options.tileSource, options, function( tileSource ) {
|
||||
|
||||
myQueueItem.tileSource = tileSource;
|
||||
|
||||
@ -1376,7 +1381,7 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype,
|
||||
minPixelRatio: _this.minPixelRatio,
|
||||
smoothTileEdgesMinZoom: _this.smoothTileEdgesMinZoom,
|
||||
iOSDevice: _this.iOSDevice,
|
||||
crossOriginPolicy: _this.crossOriginPolicy,
|
||||
crossOriginPolicy: queueItem.options.crossOriginPolicy,
|
||||
debugMode: _this.debugMode
|
||||
});
|
||||
|
||||
@ -2110,7 +2115,7 @@ function _getSafeElemSize (oElement) {
|
||||
* @function
|
||||
* @private
|
||||
*/
|
||||
function getTileSourceImplementation( viewer, tileSource, successCallback,
|
||||
function getTileSourceImplementation( viewer, tileSource, imgOptions, successCallback,
|
||||
failCallback ) {
|
||||
var _this = viewer;
|
||||
|
||||
@ -2144,7 +2149,8 @@ function getTileSourceImplementation( viewer, tileSource, successCallback,
|
||||
//If its still a string it means it must be a url at this point
|
||||
tileSource = new $.TileSource({
|
||||
url: tileSource,
|
||||
crossOriginPolicy: viewer.crossOriginPolicy,
|
||||
crossOriginPolicy: imgOptions.crossOriginPolicy !== undefined ?
|
||||
imgOptions.crossOriginPolicy : viewer.crossOriginPolicy,
|
||||
ajaxWithCredentials: viewer.ajaxWithCredentials,
|
||||
useCanvas: viewer.useCanvas,
|
||||
success: function( event ) {
|
||||
@ -2156,8 +2162,10 @@ function getTileSourceImplementation( viewer, tileSource, successCallback,
|
||||
} );
|
||||
|
||||
} else if ($.isPlainObject(tileSource) || tileSource.nodeType) {
|
||||
if (!tileSource.crossOriginPolicy && viewer.crossOriginPolicy) {
|
||||
tileSource.crossOriginPolicy = viewer.crossOriginPolicy;
|
||||
if (tileSource.crossOriginPolicy === undefined &&
|
||||
(imgOptions.crossOriginPolicy !== undefined || viewer.crossOriginPolicy !== undefined)) {
|
||||
tileSource.crossOriginPolicy = imgOptions.crossOriginPolicy !== undefined ?
|
||||
imgOptions.crossOriginPolicy : viewer.crossOriginPolicy;
|
||||
}
|
||||
if (tileSource.ajaxWithCredentials === undefined) {
|
||||
tileSource.ajaxWithCredentials = viewer.ajaxWithCredentials;
|
||||
|
@ -365,4 +365,62 @@
|
||||
|
||||
} );
|
||||
|
||||
asyncTest( 'CrossOriginPolicyOption', function () {
|
||||
|
||||
browserSupportsImgCrossOrigin(function(supported) {
|
||||
if (!supported) {
|
||||
expect(0);
|
||||
start();
|
||||
} else {
|
||||
viewer.crossOriginPolicy = "Anonymous";
|
||||
viewer.smoothTileEdgesMinZoom = Infinity;
|
||||
viewer.addTiledImage( {
|
||||
tileSource: {
|
||||
type: 'legacy-image-pyramid',
|
||||
levels: [ {
|
||||
url: corsImg,
|
||||
width: 135,
|
||||
height: 155
|
||||
} ]
|
||||
},
|
||||
crossOriginPolicy : false
|
||||
} );
|
||||
viewer.addHandler('tile-drawn', function() {
|
||||
ok(OpenSeadragon.isCanvasTainted(viewer.drawer.context.canvas),
|
||||
"Canvas should be tainted.");
|
||||
start();
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
} );
|
||||
asyncTest( 'CrossOriginPolicyTileSource', function () {
|
||||
|
||||
browserSupportsImgCrossOrigin(function(supported) {
|
||||
if (!supported) {
|
||||
expect(0);
|
||||
start();
|
||||
} else {
|
||||
viewer.crossOriginPolicy = false;
|
||||
viewer.smoothTileEdgesMinZoom = Infinity;
|
||||
viewer.addTiledImage( {
|
||||
tileSource: {
|
||||
type: 'legacy-image-pyramid',
|
||||
levels: [ {
|
||||
url: corsImg,
|
||||
width: 135,
|
||||
height: 155
|
||||
} ],
|
||||
crossOriginPolicy : "Anonymous"
|
||||
}
|
||||
} );
|
||||
viewer.addHandler('tile-drawn', function() {
|
||||
ok(!OpenSeadragon.isCanvasTainted(viewer.drawer.context.canvas),
|
||||
"Canvas should not be tainted.");
|
||||
start();
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
} );
|
||||
})();
|
||||
|
Loading…
Reference in New Issue
Block a user