mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/MultimediaViewer
synced 2024-11-30 19:04:19 +00:00
Merge "Better way to detect CORS support"
This commit is contained in:
commit
de9d10ce06
|
@ -100,11 +100,18 @@
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks whether the current browser supports AJAX preloading of images.
|
* Checks whether the current browser supports AJAX preloading of images.
|
||||||
|
* This means that:
|
||||||
|
* - the browser supports CORS requests (large wiki farms usually host images on a
|
||||||
|
* separate domain) and
|
||||||
|
* - either AJAX and normal image loading uses the same cache (when an image is used by a CORS
|
||||||
|
* request, and then normally by setting img.src, it is only loaded once)
|
||||||
|
* - or (as is the case with Firefox) they are cached separately, but that can be changed by
|
||||||
|
* setting the crossOrigin attribute
|
||||||
* @return {boolean}
|
* @return {boolean}
|
||||||
*/
|
*/
|
||||||
Image.prototype.imagePreloadingSupported = function () {
|
Image.prototype.imagePreloadingSupported = function () {
|
||||||
// FIXME this is a *very* rough guess, but it'll work as the first estimation.
|
// This checks if the browser supports CORS requests in XHRs
|
||||||
return 'crossOrigin' in new Image();
|
return 'withCredentials' in new XMLHttpRequest();
|
||||||
};
|
};
|
||||||
|
|
||||||
mw.mmv.provider.Image = Image;
|
mw.mmv.provider.Image = Image;
|
||||||
|
|
|
@ -30,10 +30,8 @@
|
||||||
+ '8yw83NDDeNGe4Ug9C9zwz3gVLMDA/A6P9/AFGGFyjOXZtQAAAAAElFTkSuQmCC',
|
+ '8yw83NDDeNGe4Ug9C9zwz3gVLMDA/A6P9/AFGGFyjOXZtQAAAAAElFTkSuQmCC',
|
||||||
imageProvider = new mw.mmv.provider.Image();
|
imageProvider = new mw.mmv.provider.Image();
|
||||||
|
|
||||||
imageProvider.performance = {
|
imageProvider.imagePreloadingSupported = function () { return false; };
|
||||||
imagePreloadingSupported: function () { return false; },
|
imageProvider.performance.recordEntry = $.noop;
|
||||||
recordEntry: $.noop
|
|
||||||
};
|
|
||||||
|
|
||||||
QUnit.stop();
|
QUnit.stop();
|
||||||
imageProvider.get( url ).then( function( image ) {
|
imageProvider.get( url ).then( function( image ) {
|
||||||
|
@ -52,10 +50,8 @@
|
||||||
result,
|
result,
|
||||||
imageProvider = new mw.mmv.provider.Image();
|
imageProvider = new mw.mmv.provider.Image();
|
||||||
|
|
||||||
imageProvider.performance = {
|
imageProvider.imagePreloadingSupported = function () { return false; };
|
||||||
imagePreloadingSupported: function () { return false; },
|
imageProvider.performance.recordEntry = $.noop;
|
||||||
recordEntry: $.noop
|
|
||||||
};
|
|
||||||
|
|
||||||
QUnit.stop();
|
QUnit.stop();
|
||||||
imageProvider.get( url ).then( function( image ) {
|
imageProvider.get( url ).then( function( image ) {
|
||||||
|
@ -85,10 +81,8 @@
|
||||||
QUnit.asyncTest( 'Image load fail test', 1, function ( assert ) {
|
QUnit.asyncTest( 'Image load fail test', 1, function ( assert ) {
|
||||||
var imageProvider = new mw.mmv.provider.Image();
|
var imageProvider = new mw.mmv.provider.Image();
|
||||||
|
|
||||||
imageProvider.performance = {
|
imageProvider.imagePreloadingSupported = function () { return false; };
|
||||||
imagePreloadingSupported: function () { return false; },
|
imageProvider.performance.recordEntry = $.noop;
|
||||||
recordEntry: $.noop
|
|
||||||
};
|
|
||||||
|
|
||||||
imageProvider.get( 'doesntexist.png' ).fail( function() {
|
imageProvider.get( 'doesntexist.png' ).fail( function() {
|
||||||
assert.ok( true, 'fail handler was called' );
|
assert.ok( true, 'fail handler was called' );
|
||||||
|
|
Loading…
Reference in a new issue