easyxdm-rails 0.0.7 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/easyxdm-rails/version.rb +1 -1
- data/vendor/assets/javascripts/cors/index.html +214 -214
- data/vendor/assets/javascripts/easyXDM.Widgets.debug.js +23 -23
- data/vendor/assets/javascripts/easyXDM.Widgets.js +23 -23
- data/vendor/assets/javascripts/easyXDM.Widgets.min.js +23 -23
- data/vendor/assets/javascripts/easyXDM.debug.js +28 -25
- data/vendor/assets/javascripts/easyXDM.js +28 -25
- data/vendor/assets/javascripts/easyXDM.min.js +24 -24
- data/vendor/assets/javascripts/json2.js +482 -482
- data/vendor/assets/javascripts/name.html +3 -0
- metadata +35 -17
- checksums.yaml +0 -7
@@ -1,214 +1,214 @@
|
|
1
|
-
<!doctype html>
|
2
|
-
<html>
|
3
|
-
<head>
|
4
|
-
<title>easyXDM cross-domain XHMLHttpRequest provider</title>
|
5
|
-
<script type="text/javascript" src="../easyXDM.debug.js">
|
6
|
-
// This should be changed so that it points to the minified version before use in production.
|
7
|
-
</script>
|
8
|
-
<script type="text/javascript">
|
9
|
-
// Update to point to your copy
|
10
|
-
easyXDM.DomHelper.requiresJSON("../json2.js");
|
11
|
-
</script>
|
12
|
-
<script type="text/javascript">
|
13
|
-
|
14
|
-
/*
|
15
|
-
* This is a CORS (Cross-Origin Resource Sharing) and AJAX enabled endpoint for easyXDM.
|
16
|
-
* The ACL code is adapted from pmxdr (http://github.com/eligrey/pmxdr/) by Eli Grey (http://eligrey.com/)
|
17
|
-
*
|
18
|
-
*/
|
19
|
-
// From http://peter.michaux.ca/articles/feature-detection-state-of-the-art-browser-scripting
|
20
|
-
function isHostMethod(object, property){
|
21
|
-
var t = typeof object[property];
|
22
|
-
return t == 'function' ||
|
23
|
-
(!!(t == 'object' && object[property])) ||
|
24
|
-
t == 'unknown';
|
25
|
-
}
|
26
|
-
|
27
|
-
/**
|
28
|
-
* Creates a cross-browser XMLHttpRequest object
|
29
|
-
* @return {XMLHttpRequest} A XMLHttpRequest object.
|
30
|
-
*/
|
31
|
-
var getXhr = (function(){
|
32
|
-
if (isHostMethod(window, "XMLHttpRequest")) {
|
33
|
-
return function(){
|
34
|
-
return new XMLHttpRequest();
|
35
|
-
};
|
36
|
-
}
|
37
|
-
else {
|
38
|
-
var item = (function(){
|
39
|
-
var list = ["Microsoft", "Msxml2", "Msxml3"], i = list.length;
|
40
|
-
while (i--) {
|
41
|
-
try {
|
42
|
-
item = list[i] + ".XMLHTTP";
|
43
|
-
var obj = new ActiveXObject(item);
|
44
|
-
return item;
|
45
|
-
}
|
46
|
-
catch (e) {
|
47
|
-
}
|
48
|
-
}
|
49
|
-
}());
|
50
|
-
return function(){
|
51
|
-
return new ActiveXObject(item);
|
52
|
-
};
|
53
|
-
}
|
54
|
-
}());
|
55
|
-
|
56
|
-
// this file is by default set up to use Access Control - this means that it will use the headers set by the server to decide whether or not to allow the call to return
|
57
|
-
var useAccessControl = true;
|
58
|
-
// always trusted origins, can be exact strings or regular expressions
|
59
|
-
var alwaysTrustedOrigins = [(/\.?easyxdm\.net/), (/xdm1/)];
|
60
|
-
|
61
|
-
// instantiate a new easyXDM object which will handle the request
|
62
|
-
var remote = new easyXDM.Rpc({
|
63
|
-
local: "../name.html",
|
64
|
-
swf: "../easyxdm.swf"
|
65
|
-
}, {
|
66
|
-
local: {
|
67
|
-
// define the exposed method
|
68
|
-
request: function(config, success, error){
|
69
|
-
|
70
|
-
// apply default values if not set
|
71
|
-
easyXDM.apply(config, {
|
72
|
-
method: "POST",
|
73
|
-
headers: {
|
74
|
-
"Content-Type": "application/x-www-form-urlencoded",
|
75
|
-
"X-Requested-With": "XMLHttpRequest"
|
76
|
-
},
|
77
|
-
success: Function.prototype,
|
78
|
-
error: function(msg){
|
79
|
-
throw new Error(msg);
|
80
|
-
},
|
81
|
-
data: {},
|
82
|
-
timeout: 10 * 1000
|
83
|
-
}, true);
|
84
|
-
|
85
|
-
// set the CORS request header
|
86
|
-
// only if there is no XHR2 features
|
87
|
-
if (!window.XMLHttpRequest || !('withCredentials' in (new XMLHttpRequest))) {
|
88
|
-
config.headers.Origin = remote.origin;
|
89
|
-
}
|
90
|
-
|
91
|
-
var isPOST = config.method == "POST";
|
92
|
-
|
93
|
-
// convert the data into a format we can send to the server
|
94
|
-
var pairs = [];
|
95
|
-
for (var key in config.data) {
|
96
|
-
if (config.data.hasOwnProperty(key)) {
|
97
|
-
pairs.push(encodeURIComponent(key) + "=" + encodeURIComponent(config.data[key]));
|
98
|
-
}
|
99
|
-
}
|
100
|
-
var data = pairs.join("&");
|
101
|
-
|
102
|
-
// create the XMLHttpRequest object
|
103
|
-
var req = getXhr();
|
104
|
-
var url = !isPOST && data
|
105
|
-
? config.url + (~config.url.indexOf('?') ? '&' : '?') + data
|
106
|
-
: config.url;
|
107
|
-
req.open(config.method, url, true);
|
108
|
-
|
109
|
-
// apply the request headers
|
110
|
-
for (var prop in config.headers) {
|
111
|
-
if (config.headers.hasOwnProperty(prop) && config.headers[prop]) {
|
112
|
-
req.setRequestHeader(prop, config.headers[prop]);
|
113
|
-
}
|
114
|
-
}
|
115
|
-
|
116
|
-
// set a timeout
|
117
|
-
var timeout;
|
118
|
-
timeout = setTimeout(function(){
|
119
|
-
// reset the handler
|
120
|
-
req.onreadystatechange = Function.prototype;
|
121
|
-
req.abort();
|
122
|
-
req = null;
|
123
|
-
error({
|
124
|
-
message: "timeout after " + config.timeout + " second",
|
125
|
-
status: 0,
|
126
|
-
data: null,
|
127
|
-
toString: function(){
|
128
|
-
return this.message + " Status: " + this.status;
|
129
|
-
}
|
130
|
-
}, null);
|
131
|
-
}, config.timeout);
|
132
|
-
|
133
|
-
// check if this origin should always be trusted
|
134
|
-
var alwaysTrusted = false, i = alwaysTrustedOrigins.length;
|
135
|
-
while (i-- && !alwaysTrusted) {
|
136
|
-
if (alwaysTrustedOrigins[i] instanceof RegExp) {
|
137
|
-
alwaysTrusted = alwaysTrustedOrigins[i].test(remote.origin);
|
138
|
-
}
|
139
|
-
else if (typeof alwaysTrustedOrigins[i] == "string") {
|
140
|
-
alwaysTrusted = (remote.origin === alwaysTrustedOrigins[i]);
|
141
|
-
}
|
142
|
-
}
|
143
|
-
|
144
|
-
|
145
|
-
// define the onreadystate handler
|
146
|
-
req.onreadystatechange = function(){
|
147
|
-
if (req.readyState == 4) {
|
148
|
-
clearTimeout(timeout);
|
149
|
-
|
150
|
-
// parse the response headers
|
151
|
-
var rawHeaders = req.getAllResponseHeaders(), headers = {}, headers_lowercase = {}, reHeader = /([\w-_]+):\s+(.*)$/gm, m;
|
152
|
-
while ((m = reHeader.exec(rawHeaders))) {
|
153
|
-
headers_lowercase[m[1].toLowerCase()] = headers[m[1]] = m[2];
|
154
|
-
}
|
155
|
-
|
156
|
-
if (req.status < 200 || req.status >= 300) {
|
157
|
-
if (useAccessControl) {
|
158
|
-
error("INVALID_STATUS_CODE");
|
159
|
-
}
|
160
|
-
else {
|
161
|
-
error("INVALID_STATUS_CODE", {
|
162
|
-
status: req.status,
|
163
|
-
data: req.responseText
|
164
|
-
});
|
165
|
-
}
|
166
|
-
}
|
167
|
-
else {
|
168
|
-
|
169
|
-
var errorMessage;
|
170
|
-
if (useAccessControl) {
|
171
|
-
// normalize the valuse access controls
|
172
|
-
var aclAllowedOrigin = (headers_lowercase["access-control-allow-origin"] || "").replace(/\s/g, "");
|
173
|
-
var aclAllowedMethods = (headers_lowercase["access-control-allow-methods"] || "").replace(/\s/g, "");
|
174
|
-
|
175
|
-
// determine if origin is trusted
|
176
|
-
if (alwaysTrusted || aclAllowedOrigin == "*" || aclAllowedOrigin.indexOf(remote.origin) != -1) {
|
177
|
-
// determine if the request method was allowed
|
178
|
-
if (aclAllowedMethods && aclAllowedMethods != "*" && aclAllowedMethods.indexOf(config.method) == -1) {
|
179
|
-
errorMessage = "DISALLOWED_REQUEST_METHOD";
|
180
|
-
}
|
181
|
-
}
|
182
|
-
else {
|
183
|
-
errorMessage = "DISALLOWED_ORIGIN";
|
184
|
-
}
|
185
|
-
|
186
|
-
}
|
187
|
-
|
188
|
-
if (errorMessage) {
|
189
|
-
error(errorMessage);
|
190
|
-
}
|
191
|
-
else {
|
192
|
-
success({
|
193
|
-
data: req.responseText,
|
194
|
-
status: req.status,
|
195
|
-
headers: headers
|
196
|
-
});
|
197
|
-
}
|
198
|
-
}
|
199
|
-
// reset the handler
|
200
|
-
req.onreadystatechange = Function.prototype;
|
201
|
-
req = null;
|
202
|
-
}
|
203
|
-
};
|
204
|
-
|
205
|
-
// issue the request
|
206
|
-
req.send(isPOST ? data : "");
|
207
|
-
}
|
208
|
-
}
|
209
|
-
});
|
210
|
-
</script>
|
211
|
-
</head>
|
212
|
-
<body>
|
213
|
-
</body>
|
214
|
-
</html>
|
1
|
+
<!doctype html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>easyXDM cross-domain XHMLHttpRequest provider</title>
|
5
|
+
<script type="text/javascript" src="../easyXDM.debug.js">
|
6
|
+
// This should be changed so that it points to the minified version before use in production.
|
7
|
+
</script>
|
8
|
+
<script type="text/javascript">
|
9
|
+
// Update to point to your copy
|
10
|
+
easyXDM.DomHelper.requiresJSON("../json2.js");
|
11
|
+
</script>
|
12
|
+
<script type="text/javascript">
|
13
|
+
|
14
|
+
/*
|
15
|
+
* This is a CORS (Cross-Origin Resource Sharing) and AJAX enabled endpoint for easyXDM.
|
16
|
+
* The ACL code is adapted from pmxdr (http://github.com/eligrey/pmxdr/) by Eli Grey (http://eligrey.com/)
|
17
|
+
*
|
18
|
+
*/
|
19
|
+
// From http://peter.michaux.ca/articles/feature-detection-state-of-the-art-browser-scripting
|
20
|
+
function isHostMethod(object, property){
|
21
|
+
var t = typeof object[property];
|
22
|
+
return t == 'function' ||
|
23
|
+
(!!(t == 'object' && object[property])) ||
|
24
|
+
t == 'unknown';
|
25
|
+
}
|
26
|
+
|
27
|
+
/**
|
28
|
+
* Creates a cross-browser XMLHttpRequest object
|
29
|
+
* @return {XMLHttpRequest} A XMLHttpRequest object.
|
30
|
+
*/
|
31
|
+
var getXhr = (function(){
|
32
|
+
if (isHostMethod(window, "XMLHttpRequest")) {
|
33
|
+
return function(){
|
34
|
+
return new XMLHttpRequest();
|
35
|
+
};
|
36
|
+
}
|
37
|
+
else {
|
38
|
+
var item = (function(){
|
39
|
+
var list = ["Microsoft", "Msxml2", "Msxml3"], i = list.length;
|
40
|
+
while (i--) {
|
41
|
+
try {
|
42
|
+
item = list[i] + ".XMLHTTP";
|
43
|
+
var obj = new ActiveXObject(item);
|
44
|
+
return item;
|
45
|
+
}
|
46
|
+
catch (e) {
|
47
|
+
}
|
48
|
+
}
|
49
|
+
}());
|
50
|
+
return function(){
|
51
|
+
return new ActiveXObject(item);
|
52
|
+
};
|
53
|
+
}
|
54
|
+
}());
|
55
|
+
|
56
|
+
// this file is by default set up to use Access Control - this means that it will use the headers set by the server to decide whether or not to allow the call to return
|
57
|
+
var useAccessControl = true;
|
58
|
+
// always trusted origins, can be exact strings or regular expressions
|
59
|
+
var alwaysTrustedOrigins = [(/\.?easyxdm\.net/), (/xdm1/)];
|
60
|
+
|
61
|
+
// instantiate a new easyXDM object which will handle the request
|
62
|
+
var remote = new easyXDM.Rpc({
|
63
|
+
local: "../name.html",
|
64
|
+
swf: "../easyxdm.swf"
|
65
|
+
}, {
|
66
|
+
local: {
|
67
|
+
// define the exposed method
|
68
|
+
request: function(config, success, error){
|
69
|
+
|
70
|
+
// apply default values if not set
|
71
|
+
easyXDM.apply(config, {
|
72
|
+
method: "POST",
|
73
|
+
headers: {
|
74
|
+
"Content-Type": "application/x-www-form-urlencoded",
|
75
|
+
"X-Requested-With": "XMLHttpRequest"
|
76
|
+
},
|
77
|
+
success: Function.prototype,
|
78
|
+
error: function(msg){
|
79
|
+
throw new Error(msg);
|
80
|
+
},
|
81
|
+
data: {},
|
82
|
+
timeout: 10 * 1000
|
83
|
+
}, true);
|
84
|
+
|
85
|
+
// set the CORS request header
|
86
|
+
// only if there is no XHR2 features
|
87
|
+
if (!window.XMLHttpRequest || !('withCredentials' in (new XMLHttpRequest))) {
|
88
|
+
config.headers.Origin = remote.origin;
|
89
|
+
}
|
90
|
+
|
91
|
+
var isPOST = config.method == "POST";
|
92
|
+
|
93
|
+
// convert the data into a format we can send to the server
|
94
|
+
var pairs = [];
|
95
|
+
for (var key in config.data) {
|
96
|
+
if (config.data.hasOwnProperty(key)) {
|
97
|
+
pairs.push(encodeURIComponent(key) + "=" + encodeURIComponent(config.data[key]));
|
98
|
+
}
|
99
|
+
}
|
100
|
+
var data = pairs.join("&");
|
101
|
+
|
102
|
+
// create the XMLHttpRequest object
|
103
|
+
var req = getXhr();
|
104
|
+
var url = !isPOST && data
|
105
|
+
? config.url + (~config.url.indexOf('?') ? '&' : '?') + data
|
106
|
+
: config.url;
|
107
|
+
req.open(config.method, url, true);
|
108
|
+
|
109
|
+
// apply the request headers
|
110
|
+
for (var prop in config.headers) {
|
111
|
+
if (config.headers.hasOwnProperty(prop) && config.headers[prop]) {
|
112
|
+
req.setRequestHeader(prop, config.headers[prop]);
|
113
|
+
}
|
114
|
+
}
|
115
|
+
|
116
|
+
// set a timeout
|
117
|
+
var timeout;
|
118
|
+
timeout = setTimeout(function(){
|
119
|
+
// reset the handler
|
120
|
+
req.onreadystatechange = Function.prototype;
|
121
|
+
req.abort();
|
122
|
+
req = null;
|
123
|
+
error({
|
124
|
+
message: "timeout after " + config.timeout + " second",
|
125
|
+
status: 0,
|
126
|
+
data: null,
|
127
|
+
toString: function(){
|
128
|
+
return this.message + " Status: " + this.status;
|
129
|
+
}
|
130
|
+
}, null);
|
131
|
+
}, config.timeout);
|
132
|
+
|
133
|
+
// check if this origin should always be trusted
|
134
|
+
var alwaysTrusted = false, i = alwaysTrustedOrigins.length;
|
135
|
+
while (i-- && !alwaysTrusted) {
|
136
|
+
if (alwaysTrustedOrigins[i] instanceof RegExp) {
|
137
|
+
alwaysTrusted = alwaysTrustedOrigins[i].test(remote.origin);
|
138
|
+
}
|
139
|
+
else if (typeof alwaysTrustedOrigins[i] == "string") {
|
140
|
+
alwaysTrusted = (remote.origin === alwaysTrustedOrigins[i]);
|
141
|
+
}
|
142
|
+
}
|
143
|
+
|
144
|
+
|
145
|
+
// define the onreadystate handler
|
146
|
+
req.onreadystatechange = function(){
|
147
|
+
if (req.readyState == 4) {
|
148
|
+
clearTimeout(timeout);
|
149
|
+
|
150
|
+
// parse the response headers
|
151
|
+
var rawHeaders = req.getAllResponseHeaders(), headers = {}, headers_lowercase = {}, reHeader = /([\w-_]+):\s+(.*)$/gm, m;
|
152
|
+
while ((m = reHeader.exec(rawHeaders))) {
|
153
|
+
headers_lowercase[m[1].toLowerCase()] = headers[m[1]] = m[2];
|
154
|
+
}
|
155
|
+
|
156
|
+
if (req.status < 200 || req.status >= 300) {
|
157
|
+
if (useAccessControl) {
|
158
|
+
error("INVALID_STATUS_CODE");
|
159
|
+
}
|
160
|
+
else {
|
161
|
+
error("INVALID_STATUS_CODE", {
|
162
|
+
status: req.status,
|
163
|
+
data: req.responseText
|
164
|
+
});
|
165
|
+
}
|
166
|
+
}
|
167
|
+
else {
|
168
|
+
|
169
|
+
var errorMessage;
|
170
|
+
if (useAccessControl) {
|
171
|
+
// normalize the valuse access controls
|
172
|
+
var aclAllowedOrigin = (headers_lowercase["access-control-allow-origin"] || "").replace(/\s/g, "");
|
173
|
+
var aclAllowedMethods = (headers_lowercase["access-control-allow-methods"] || "").replace(/\s/g, "");
|
174
|
+
|
175
|
+
// determine if origin is trusted
|
176
|
+
if (alwaysTrusted || aclAllowedOrigin == "*" || aclAllowedOrigin.indexOf(remote.origin) != -1) {
|
177
|
+
// determine if the request method was allowed
|
178
|
+
if (aclAllowedMethods && aclAllowedMethods != "*" && aclAllowedMethods.indexOf(config.method) == -1) {
|
179
|
+
errorMessage = "DISALLOWED_REQUEST_METHOD";
|
180
|
+
}
|
181
|
+
}
|
182
|
+
else {
|
183
|
+
errorMessage = "DISALLOWED_ORIGIN";
|
184
|
+
}
|
185
|
+
|
186
|
+
}
|
187
|
+
|
188
|
+
if (errorMessage) {
|
189
|
+
error(errorMessage);
|
190
|
+
}
|
191
|
+
else {
|
192
|
+
success({
|
193
|
+
data: req.responseText,
|
194
|
+
status: req.status,
|
195
|
+
headers: headers
|
196
|
+
});
|
197
|
+
}
|
198
|
+
}
|
199
|
+
// reset the handler
|
200
|
+
req.onreadystatechange = Function.prototype;
|
201
|
+
req = null;
|
202
|
+
}
|
203
|
+
};
|
204
|
+
|
205
|
+
// issue the request
|
206
|
+
req.send(isPOST ? data : "");
|
207
|
+
}
|
208
|
+
}
|
209
|
+
});
|
210
|
+
</script>
|
211
|
+
</head>
|
212
|
+
<body>
|
213
|
+
</body>
|
214
|
+
</html>
|
@@ -1,26 +1,26 @@
|
|
1
|
-
/**
|
2
|
-
* easyXDM
|
3
|
-
* http://easyxdm.net/
|
4
|
-
* Copyright(c) 2009-2011, Øyvind Sean Kinsey, oyvind@kinsey.no.
|
5
|
-
*
|
6
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
7
|
-
* of this software and associated documentation files (the "Software"), to deal
|
8
|
-
* in the Software without restriction, including without limitation the rights
|
9
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10
|
-
* copies of the Software, and to permit persons to whom the Software is
|
11
|
-
* furnished to do so, subject to the following conditions:
|
12
|
-
*
|
13
|
-
* The above copyright notice and this permission notice shall be included in
|
14
|
-
* all copies or substantial portions of the Software.
|
15
|
-
*
|
16
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
19
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
22
|
-
* THE SOFTWARE.
|
23
|
-
*/
|
1
|
+
/**
|
2
|
+
* easyXDM
|
3
|
+
* http://easyxdm.net/
|
4
|
+
* Copyright(c) 2009-2011, Øyvind Sean Kinsey, oyvind@kinsey.no.
|
5
|
+
*
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
7
|
+
* of this software and associated documentation files (the "Software"), to deal
|
8
|
+
* in the Software without restriction, including without limitation the rights
|
9
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10
|
+
* copies of the Software, and to permit persons to whom the Software is
|
11
|
+
* furnished to do so, subject to the following conditions:
|
12
|
+
*
|
13
|
+
* The above copyright notice and this permission notice shall be included in
|
14
|
+
* all copies or substantial portions of the Software.
|
15
|
+
*
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
19
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
22
|
+
* THE SOFTWARE.
|
23
|
+
*/
|
24
24
|
/*jslint browser: true, immed: true, passfail: true, undef: true, newcap: true*/
|
25
25
|
/*global easyXDM, window */
|
26
26
|
/**
|