mirror of
https://github.com/openseadragon/openseadragon.git
synced 2024-11-22 13:16:10 +03:00
Refine setAjaxHeaders
- Allow null to clear headers (same as empty object) - Add TiledImage._updateAjaxHeaders - Add error message in case of invalid headers
This commit is contained in:
parent
182c11481e
commit
e51aa4a9c5
@ -1012,23 +1012,30 @@ $.extend($.TiledImage.prototype, $.EventSource.prototype, /** @lends OpenSeadrag
|
|||||||
/**
|
/**
|
||||||
* TODO
|
* TODO
|
||||||
*/
|
*/
|
||||||
setAjaxHeaders: function(ajaxHeaders, propagate){
|
setAjaxHeaders: function(ajaxHeaders, propagate) {
|
||||||
|
if (ajaxHeaders === null) {
|
||||||
|
ajaxHeaders = {};
|
||||||
|
}
|
||||||
|
if (!$.isPlainObject(ajaxHeaders)) {
|
||||||
|
console.error('[TiledImage.setAjaxHeaders] Ignoring invalid headers, must be a plain object');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this._ownAjaxHeaders = ajaxHeaders;
|
||||||
|
this._updateAjaxHeaders(propagate);
|
||||||
|
},
|
||||||
|
|
||||||
|
// private
|
||||||
|
_updateAjaxHeaders: function(propagate) {
|
||||||
if (propagate === undefined) {
|
if (propagate === undefined) {
|
||||||
propagate = true;
|
propagate = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// use same headers if provided 'ajaxHeaders' is invalid (useful for propagation)
|
|
||||||
if ($.isPlainObject(ajaxHeaders)) {
|
|
||||||
this._ownAjaxHeaders = ajaxHeaders;
|
|
||||||
} else {
|
|
||||||
ajaxHeaders = this._ownAjaxHeaders;
|
|
||||||
}
|
|
||||||
|
|
||||||
// merge with viewer's headers
|
// merge with viewer's headers
|
||||||
if ($.isPlainObject(this.viewer.ajaxHeaders)) {
|
if ($.isPlainObject(this.viewer.ajaxHeaders)) {
|
||||||
this.ajaxHeaders = $.extend({}, this.viewer.ajaxHeaders, ajaxHeaders);
|
this.ajaxHeaders = $.extend({}, this.viewer.ajaxHeaders, this._ownAjaxHeaders);
|
||||||
} else {
|
} else {
|
||||||
this.ajaxHeaders = ajaxHeaders;
|
this.ajaxHeaders = this._ownAjaxHeaders;
|
||||||
}
|
}
|
||||||
|
|
||||||
// propagate header updates to all tiles and queued imageloader jobs
|
// propagate header updates to all tiles and queued imageloader jobs
|
||||||
|
@ -981,18 +981,23 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype,
|
|||||||
/**
|
/**
|
||||||
* TODO
|
* TODO
|
||||||
*/
|
*/
|
||||||
setAjaxHeaders: function(ajaxHeaders, propagate){
|
setAjaxHeaders: function(ajaxHeaders, propagate) {
|
||||||
|
if (ajaxHeaders === null) {
|
||||||
|
ajaxHeaders = {};
|
||||||
|
}
|
||||||
|
if (!$.isPlainObject(ajaxHeaders)) {
|
||||||
|
console.error('[Viewer.setAjaxHeaders] Ignoring invalid headers, must be a plain object');
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (propagate === undefined) {
|
if (propagate === undefined) {
|
||||||
propagate = true;
|
propagate = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($.isPlainObject(ajaxHeaders)) {
|
|
||||||
this.ajaxHeaders = ajaxHeaders;
|
this.ajaxHeaders = ajaxHeaders;
|
||||||
}
|
|
||||||
|
|
||||||
if (propagate) {
|
if (propagate) {
|
||||||
for (var i = 0; i < this.world.getItemCount(); i++) {
|
for (var i = 0; i < this.world.getItemCount(); i++) {
|
||||||
this.world.getItemAt(i).setAjaxHeaders(null, true);
|
this.world.getItemAt(i)._updateAjaxHeaders(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.referenceStrip && this.referenceStrip.miniViewers) {
|
if (this.referenceStrip && this.referenceStrip.miniViewers) {
|
||||||
|
@ -346,7 +346,7 @@
|
|||||||
assert.deepEqual(evt.tiledImage.ajaxHeaders, OpenSeadragon.extend({}, viewer.ajaxHeaders, newHeaders2));
|
assert.deepEqual(evt.tiledImage.ajaxHeaders, OpenSeadragon.extend({}, viewer.ajaxHeaders, newHeaders2));
|
||||||
assert.deepEqual(evt.tile.ajaxHeaders, OpenSeadragon.extend({}, viewer.ajaxHeaders, newHeaders2, tileSourceHeaders));
|
assert.deepEqual(evt.tile.ajaxHeaders, OpenSeadragon.extend({}, viewer.ajaxHeaders, newHeaders2, tileSourceHeaders));
|
||||||
// set new TiledImage headers but do not propagate to Tile
|
// set new TiledImage headers but do not propagate to Tile
|
||||||
evt.tiledImage.setAjaxHeaders({}, false);
|
evt.tiledImage.setAjaxHeaders(null, false);
|
||||||
viewer.addHandler('tile-loaded', tileLoaded4);
|
viewer.addHandler('tile-loaded', tileLoaded4);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user