-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathjquery.easyXDM.provider.js
More file actions
90 lines (89 loc) · 3.33 KB
/
jquery.easyXDM.provider.js
File metadata and controls
90 lines (89 loc) · 3.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/*
* https://github.com/GyldendalDigital/jQuery-easyXDM
*
* This is a CORS (Cross-Origin Resource Sharing) and AJAX enabled endpoint
* for jQuery-easyXDM plugin.
* It proxys jquery.easyXDM requests with an easyXDM provider.
*
*/
(function ($) {
var jquery_easyXDM = {};
var global = this;
// Load correct version of easyXDM
var easyXDM_debug = false;
if (/jquery\.easyXDM\.debug=true/.test(String(window.location))) {
easyXDM_debug = true;
}
var easyXDM_url = "/easyXDM/easyXDM.min.js";
if (easyXDM_debug) {
easyXDM_url = "/easyXDM/easyXDM.debug.js"
}
function continue_after_easyXDM_load() {
// Use the scoped easyXDM available as a unique global name in the "parent",
// and must match the noConflict name in parent.
var scoped_easyXDM = easyXDM.noConflict("jquery_easyXDM");
jquery_easyXDM.easyXDM = scoped_easyXDM;
// instantiate a new easyXDM object which will handle the request
var remote = new scoped_easyXDM.Rpc(
{
local:"/easyXDM/name.html",
swf:"/easyXDM/easyxdm.swf"
// The provider is "passive", so no need to define an onReady handler
}, {
local:{
// define the exposed method
jquery_proxy:function (config, continuation_proxy) {
// By definition easyXDM is used when crossDomain is not supported,
// and easyXDM transforms the crossDomain request into a regular request
// inside an embedded iframe.
// This request is now inside the embedded iframe, and is therefore
// by definition no longer a crossDomain request.
config.crossDomain = false;
if (typeof(config.xhrFields) === "object") {
// The withCredentials attribute is not supported in IE <= 7
// (causes a native xhr exception if set), and it's not needed for
// this non-crossDomain request anyway.
delete config.xhrFields.withCredentials;
}
$.ajax(config).done(function (data, textStatus, jqXHR) {
var result = {
status :jqXHR.status,
statusText:jqXHR.statusText,
responses :{},
headers :jqXHR.getAllResponseHeaders()
};
if (jqXHR.responseText) {
result.responses.text = jqXHR.responseText;
}
if (jqXHR.responseXml) {
result.responses.xml = jqXHR.responseXml;
}
continuation_proxy(result);
}).fail(function(jqXHR, textStatus, errorMessage) {
var result = {
status :jqXHR.status,
statusText:jqXHR.statusText,
responses :{},
headers :jqXHR.getAllResponseHeaders()
};
if (jqXHR.responseText) {
result.responses.text = jqXHR.responseText;
}
if (jqXHR.responseXml) {
result.responses.xml = jqXHR.responseXml;
}
continuation_proxy(result);
});
}
}
});
}
$.getScript(easyXDM_url,function () {
if (!(typeof(window["JSON"]) == 'object' && window["JSON"])) {
$.getScript("/easyXDM/json2.js", continue_after_easyXDM_load);
} else {
continue_after_easyXDM_load();
}
});
global.jquery_easyXDM = jquery_easyXDM;
})(jQuery);