Created
August 29, 2011 14:21
-
-
Save kswedberg/1178490 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function( jQuery ) { | |
jQuery.ajaxPrefilter( "img", function( settings ) { | |
if ( settings.cache == null ) { | |
settings.cache = false; | |
} | |
settings.type = "GET"; | |
settings.async = true; | |
}); | |
jQuery.ajaxTransport( "img", function( settings ) { | |
var callback, $img, img, prop; | |
var xport = { | |
send: function( _, complete ) { | |
callback = function( success ) { | |
if ( success ) { | |
complete( 200, "OK", { img: img } ); | |
} else { | |
$img.remove(); | |
if ( success === false ) { | |
complete( 404, "Not Found" ); | |
} | |
} | |
}; | |
$img = $( "<img>", { | |
src: settings.url | |
}); | |
img = $img[0]; | |
prop = typeof img.naturalWidth === "undefined" ? "width" : "naturalWidth"; | |
if ( img.complete ) { | |
callback( !!img[ prop ] ); | |
} else { | |
$img.bind( "load error", function( event ) { | |
callback( event.type == "load" ); | |
}); | |
} | |
}, | |
abort: function() { | |
if ( callback ) { | |
callback(); | |
} | |
} | |
}; | |
return xport; | |
}); | |
})( jQuery ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment