/usr/share/javascript/yui3/io-xdr/io-xdr.js is in libjs-yui3-full 3.5.1-1ubuntu3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 | /*
YUI 3.5.1 (build 22)
Copyright 2012 Yahoo! Inc. All rights reserved.
Licensed under the BSD License.
http://yuilibrary.com/license/
*/
YUI.add('io-xdr', function(Y) {
/**
Extends IO to provide an alternate, Flash transport, for making
cross-domain requests.
@module io
@submodule io-xdr
@for IO
**/
/**
Fires when the XDR transport is ready for use.
@event io:xdrReady
**/
var E_XDR_READY = Y.publish('io:xdrReady', { fireOnce: true }),
/**
Map of stored configuration objects when using
Flash as the transport for cross-domain requests.
@property _cB
@private
@type {Object}
**/
_cB = {},
/**
Map of transaction simulated readyState values
when XDomainRequest is the transport.
@property _rS
@private
@type {Object}
**/
_rS = {},
// Document reference
d = Y.config.doc,
// Window reference
w = Y.config.win,
// XDomainRequest cross-origin request detection
xdr = w && w.XDomainRequest;
/**
Method that creates the Flash transport swf.
@method _swf
@private
@param {String} uri - location of io.swf.
@param {String} yid - YUI sandbox id.
@param {String} yid - IO instance id.
**/
function _swf(uri, yid, uid) {
var o = '<object id="io_swf" type="application/x-shockwave-flash" data="' +
uri + '" width="0" height="0">' +
'<param name="movie" value="' + uri + '">' +
'<param name="FlashVars" value="yid=' + yid + '&uid=' + uid + '">' +
'<param name="allowScriptAccess" value="always">' +
'</object>',
c = d.createElement('div');
d.body.appendChild(c);
c.innerHTML = o;
}
/**
Creates a response object for XDR transactions, for success
and failure cases.
@method _data
@private
@param {Object} o - Transaction object generated by _create() in io-base.
@param {Boolean} u - Configuration xdr.use.
@param {Boolean} d - Configuration xdr.dataType.
@return {Object}
**/
function _data(o, u, d) {
if (u === 'flash') {
o.c.responseText = decodeURI(o.c.responseText);
}
if (d === 'xml') {
o.c.responseXML = Y.DataType.XML.parse(o.c.responseText);
}
return o;
}
/**
Method for intiating an XDR transaction abort.
@method _abort
@private
@param {Object} o - Transaction object generated by _create() in io-base.
@param {Object} c - configuration object for the transaction.
**/
function _abort(o, c) {
return o.c.abort(o.id, c);
}
/**
Method for determining if an XDR transaction has completed
and all data are received.
@method _isInProgress
@private
@param {Object} o - Transaction object generated by _create() in io-base.
**/
function _isInProgress(o) {
return xdr ? _rS[o.id] !== 4 : o.c.isInProgress(o.id);
}
Y.mix(Y.IO.prototype, {
/**
Map of io transports.
@property _transport
@private
@type {Object}
**/
_transport: {},
/**
Sets event handlers for XDomainRequest transactions.
@method _ieEvt
@private
@static
@param {Object} o - Transaction object generated by _create() in io-base.
@param {Object} c - configuration object for the transaction.
**/
_ieEvt: function(o, c) {
var io = this,
i = o.id,
t = 'timeout';
o.c.onprogress = function() { _rS[i] = 3; };
o.c.onload = function() {
_rS[i] = 4;
io.xdrResponse('success', o, c);
};
o.c.onerror = function() {
_rS[i] = 4;
io.xdrResponse('failure', o, c);
};
if (c[t]) {
o.c.ontimeout = function() {
_rS[i] = 4;
io.xdrResponse(t, o, c);
};
o.c[t] = c[t];
}
},
/**
Method for accessing the transport's interface for making a
cross-domain transaction.
@method xdr
@param {String} uri - qualified path to transaction resource.
@param {Object} o - Transaction object generated by _create() in io-base.
@param {Object} c - configuration object for the transaction.
**/
xdr: function(uri, o, c) {
var io = this;
if (c.xdr.use === 'flash') {
// The configuration object cannot be serialized safely
// across Flash's ExternalInterface.
_cB[o.id] = c;
w.setTimeout(function() {
try {
o.c.send(uri, { id: o.id,
uid: o.uid,
method: c.method,
data: c.data,
headers: c.headers });
}
catch(e) {
io.xdrResponse('transport error', o, c);
delete _cB[o.id];
}
}, Y.io.xdr.delay);
}
else if (xdr) {
io._ieEvt(o, c);
o.c.open(c.method || 'GET', uri);
o.c.send(c.data);
}
else {
o.c.send(uri, o, c);
}
return {
id: o.id,
abort: function() {
return o.c ? _abort(o, c) : false;
},
isInProgress: function() {
return o.c ? _isInProgress(o.id) : false;
},
io: io
};
},
/**
Response controller for cross-domain requests when using the
Flash transport or IE8's XDomainRequest object.
@method xdrResponse
@param {String} e Event name
@param {Object} o Transaction object generated by _create() in io-base.
@param {Object} c Configuration object for the transaction.
@return {Object}
**/
xdrResponse: function(e, o, c) {
c = _cB[o.id] ? _cB[o.id] : c;
var io = this,
m = xdr ? _rS : _cB,
u = c.xdr.use,
d = c.xdr.dataType;
switch (e) {
case 'start':
io.start(o, c);
break;
//case 'complete':
//This case is not used by Flash or XDomainRequest.
//io.complete(o, c);
//break;
case 'success':
io.success(_data(o, u, d), c);
delete m[o.id];
break;
case 'timeout':
case 'abort':
case 'transport error':
o.c = { status: 0, statusText: e };
case 'failure':
io.failure(_data(o, u, d), c);
delete m[o.id];
break;
}
},
/**
Fires event "io:xdrReady"
@method _xdrReady
@private
@param {Number} yid - YUI sandbox id.
@param {Number} uid - IO instance id.
**/
_xdrReady: function(yid, uid) {
Y.fire(E_XDR_READY, yid, uid);
},
/**
Initializes the desired transport.
@method transport
@param {Object} o - object of transport configurations.
**/
transport: function(c) {
if (c.id === 'flash') {
_swf(Y.UA.ie ? c.src + '?d=' + new Date().valueOf().toString() : c.src, Y.id, c.uid);
Y.IO.transports.flash = function() { return d.getElementById('io_swf'); };
}
}
});
/**
Fires event "io:xdrReady"
@method xdrReady
@protected
@static
@param {Number} yid - YUI sandbox id.
@param {Number} uid - IO instance id.
**/
Y.io.xdrReady = function(yid, uid){
var io = Y.io._map[uid];
Y.io.xdr.delay = 0;
io._xdrReady.apply(io, [yid, uid]);
};
Y.io.xdrResponse = function(e, o, c){
var io = Y.io._map[o.uid];
io.xdrResponse.apply(io, [e, o, c]);
};
Y.io.transport = function(c){
var io = Y.io._map['io:0'] || new Y.IO();
c.uid = io._uid;
io.transport.apply(io, [c]);
};
/**
Delay value to calling the Flash transport, in the
event io.swf has not finished loading. Once the E_XDR_READY
event is fired, this value will be set to 0.
@property delay
@static
@type {Number}
**/
Y.io.xdr = { delay : 100 };
}, '3.5.1' ,{requires:['io-base','datatype-xml-parse']});
|