mirror of
https://github.com/openseadragon/openseadragon.git
synced 2024-11-22 05:06:09 +03:00
Fix ajax call for file: and ftp: #73
This commit is contained in:
parent
c298b89b64
commit
47ae094675
@ -1725,6 +1725,21 @@ window.OpenSeadragon = window.OpenSeadragon || function( options ){
|
||||
return value ? value : null;
|
||||
},
|
||||
|
||||
/**
|
||||
* Retrieves the protocol used by the url. The url can either be absolute
|
||||
* or relative.
|
||||
* @function
|
||||
* @param {String} url The url to retrieve the protocol from.
|
||||
* @return {String} The protocol (http:, https:, file:, ftp: ...)
|
||||
*/
|
||||
getUrlProtocol: function( url ) {
|
||||
var match = url.match(/^([a-z]+:)\/\//i);
|
||||
if ( match === null ) {
|
||||
// Relative URL, retrive the protocol from window.location
|
||||
return window.location.protocol;
|
||||
}
|
||||
return match[1].toLowerCase();
|
||||
},
|
||||
|
||||
createAjaxRequest: function(){
|
||||
var request;
|
||||
@ -1778,10 +1793,13 @@ window.OpenSeadragon = window.OpenSeadragon || function( options ){
|
||||
if ( request.readyState == 4 ) {
|
||||
request.onreadystatechange = function(){};
|
||||
|
||||
if ( request.status == 200 ) {
|
||||
var protocol = $.getUrlProtocol( url );
|
||||
var successStatus =
|
||||
protocol === "http:" || protocol === "https:" ? 200 : 0;
|
||||
if ( request.status === successStatus ) {
|
||||
onSuccess( request );
|
||||
} else {
|
||||
$.console.log( "AJAX request returned %s: %s", request.status, url );
|
||||
$.console.log( "AJAX request returned %d: %s", request.status, url );
|
||||
|
||||
if ( $.isFunction( onError ) ) {
|
||||
onError( request );
|
||||
|
@ -56,7 +56,7 @@
|
||||
|
||||
equal($(".openseadragon-message").length, 1, "Open failures should display a message");
|
||||
|
||||
ok(testLog.log.contains('["AJAX request returned %s: %s",404,"/test/data/not-a-real-file"]'),
|
||||
ok(testLog.log.contains('["AJAX request returned %d: %s",404,"/test/data/not-a-real-file"]'),
|
||||
"AJAX failures should be logged to the console");
|
||||
|
||||
start();
|
||||
|
@ -87,6 +87,30 @@
|
||||
);
|
||||
});
|
||||
|
||||
test("getUrlProtocol", function() {
|
||||
|
||||
equal(OpenSeadragon.getUrlProtocol("test"), window.location.protocol,
|
||||
"'test' url protocol should be window.location.protocol");
|
||||
|
||||
equal(OpenSeadragon.getUrlProtocol("/test"), window.location.protocol,
|
||||
"'/test' url protocol should be window.location.protocol");
|
||||
|
||||
equal(OpenSeadragon.getUrlProtocol("//test"), window.location.protocol,
|
||||
"'//test' url protocol should be window.location.protocol");
|
||||
|
||||
equal(OpenSeadragon.getUrlProtocol("http://test"), "http:",
|
||||
"'http://test' url protocol should be http:");
|
||||
|
||||
equal(OpenSeadragon.getUrlProtocol("https://test"), "https:",
|
||||
"'https://test' url protocol should be https:");
|
||||
|
||||
equal(OpenSeadragon.getUrlProtocol("file://test"), "file:",
|
||||
"'file://test' url protocol should be file:");
|
||||
|
||||
equal(OpenSeadragon.getUrlProtocol("FTP://test"), "ftp:",
|
||||
"'FTP://test' url protocol should be ftp:");
|
||||
});
|
||||
|
||||
// ----------
|
||||
asyncTest("requestAnimationFrame", function() {
|
||||
var timeWatcher = Util.timeWatcher();
|
||||
|
Loading…
Reference in New Issue
Block a user