~bjornt/lazr-js/prefetch-yui-3.5

« back to all changes in this revision

Viewing changes to src-js/lazrjs/yui/io/io.js

  • Committer: Launchpad Patch Queue Manager
  • Date: 2011-01-14 23:32:29 UTC
  • mfrom: (197.1.7 yui-3.3.0)
  • Revision ID: launchpad@pqm.canonical.com-20110114233229-r6i4cazdiiw18o7p
Upgrade to YUI 3.3.0 [r=mars]

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
Copyright (c) 2010, Yahoo! Inc. All rights reserved.
3
3
Code licensed under the BSD License:
4
4
http://developer.yahoo.com/yui/license.html
5
 
version: 3.2.0
6
 
build: 2676
 
5
version: 3.3.0
 
6
build: 3167
7
7
*/
8
8
YUI.add('io-base', function(Y) {
9
9
 
173
173
        }
174
174
        else {
175
175
            o.c = {};
 
176
                        o.t = 'io:iframe';
176
177
        }
177
178
 
178
179
        return o;
180
181
 
181
182
 
182
183
    function _destroy(o) {
183
 
        // IE, when using XMLHttpRequest as an ActiveX Object, will throw
184
 
        // a "Type Mismatch" error if the event handler is set to "null".
185
 
        if (w && w.XMLHttpRequest) {
186
 
            if (o.c) {
 
184
        if (w) {
 
185
            if (o.c && w.XMLHttpRequest) {
187
186
                o.c.onreadystatechange = null;
188
187
            }
 
188
                        else if (Y.UA.ie === 6 && !o.t) {
 
189
                                // IE, when using XMLHttpRequest as an ActiveX Object, will throw
 
190
                                // a "Type Mismatch" error if the event handler is set to "null".
 
191
                                o.c.abort();
 
192
                        }
189
193
        }
190
194
 
191
195
        o.c = null;
444
448
 
445
449
        for (p in _headers) {
446
450
            if (_headers.hasOwnProperty(p)) {
 
451
                                /*
447
452
                if (h[p]) {
448
 
                    // Configuration headers will supersede io preset headers,
 
453
                    // Configuration headers will supersede preset io headers,
449
454
                    // if headers match.
450
455
                    continue;
451
456
                }
452
457
                else {
453
458
                    h[p] = _headers[p];
454
459
                }
 
460
                                */
 
461
                                if (!h[p]) {
 
462
                                        h[p] = _headers[p];
 
463
                                }
455
464
            }
456
465
        }
457
466
 
458
467
        for (p in h) {
459
468
            if (h.hasOwnProperty(p)) {
460
 
                o.setRequestHeader(p, h[p]);
461
 
            }
 
469
                                if (h[p] !== 'disable') {
 
470
                        o.setRequestHeader(p, h[p]);
 
471
                                }
 
472
                        }
462
473
        }
463
474
    }
464
475
 
526
537
        var status;
527
538
 
528
539
        try {
529
 
            if (o.c.status && o.c.status !== 0) {
530
 
                status = o.c.status;
531
 
            }
532
 
            else {
533
 
                status = 0;
534
 
            }
 
540
                        status = (o.c.status && o.c.status !== 0) ? o.c.status : 0;
535
541
        }
536
542
        catch(e) {
537
543
            status = 0;
813
819
 
814
820
 
815
821
 
816
 
}, '3.2.0' ,{optional:['querystring-stringify-simple'], requires:['event-custom-base']});
 
822
}, '3.3.0' ,{requires:['event-custom-base', 'querystring-stringify-simple']});
817
823
 
818
824
YUI.add('io-form', function(Y) {
819
825
 
909
915
 
910
916
 
911
917
 
912
 
}, '3.2.0' ,{requires:['io-base','node-base']});
 
918
}, '3.3.0' ,{requires:['io-base','node-base']});
913
919
 
914
920
YUI.add('io-xdr', function(Y) {
915
921
 
950
956
    */
951
957
    _rS = {},
952
958
 
953
 
    ie = w && w.XDomainRequest,
954
 
 
955
959
    // Document reference
956
960
    d = Y.config.doc,
957
961
    // Window reference
958
 
    w = Y.config.win;
 
962
    w = Y.config.win,
 
963
        // IE8 cross-origin request detection
 
964
    ie = w && w.XDomainRequest;
959
965
 
960
966
   /**
961
967
    * @description Method that creates the Flash transport swf.
1032
1038
            return { id: o.id, c: { responseText: s, responseXML: x } };
1033
1039
        }
1034
1040
        else {
1035
 
            return { id: o.id, status: o.e };
 
1041
            return { id: o.id, e: o.e };
1036
1042
        }
1037
1043
 
1038
1044
    }
1087
1093
        * @param {object} c - configuration object for the transaction.
1088
1094
        */
1089
1095
        xdr: function(uri, o, c) {
1090
 
            if (c.on && c.xdr.use === 'flash') {
1091
 
                _cB[o.id] = {
1092
 
                    on: c.on,
1093
 
                    context: c.context,
1094
 
                    arguments: c.arguments
1095
 
                };
1096
 
                // These properties cannot be serialized across Flash's
1097
 
                // ExternalInterface.  Doing so will result in exceptions.
1098
 
                c.context = null;
1099
 
                c.form = null;
1100
 
                o.c.send(uri, c, o.id);
1101
 
            }
1102
 
            else if (ie) {
1103
 
                _evt(o, c);
1104
 
                o.c.open(c.method || 'GET', uri);
1105
 
                o.c.send(c.data);
1106
 
            }
1107
 
            else {
1108
 
                o.c.send(uri, o, c);
1109
 
            }
1110
 
 
1111
 
            return {
1112
 
                id: o.id,
1113
 
                abort: function() {
1114
 
                    return o.c ? _abort(o, c) : false;
1115
 
                },
1116
 
                isInProgress: function() {
1117
 
                    return o.c ? _isInProgress(o.id) : false;
1118
 
                }
1119
 
            };
 
1096
                        if (c.xdr.use === 'flash') {
 
1097
                                _cB[o.id] = {
 
1098
                                        on: c.on,
 
1099
                                        context: c.context,
 
1100
                                        arguments: c.arguments
 
1101
                                };
 
1102
                                // These properties cannot be serialized across Flash's
 
1103
                                // ExternalInterface.  Doing so will result in exceptions.
 
1104
                                c.context = null;
 
1105
                                c.form = null;
 
1106
 
 
1107
                                w.setTimeout(function() {
 
1108
                                        if (o.c && o.c.send) {
 
1109
                                                o.c.send(uri, c, o.id);
 
1110
                                        }
 
1111
                                        else {
 
1112
                                                Y.io.xdrResponse(o, c, 'transport error');
 
1113
                                        }
 
1114
                                }, Y.io.xdr.delay);
 
1115
                        }
 
1116
                        else if (ie) {
 
1117
                                _evt(o, c);
 
1118
                                o.c.open(c.method || 'GET', uri);
 
1119
                                o.c.send(c.data);
 
1120
                        }
 
1121
                        else {
 
1122
                                o.c.send(uri, o, c);
 
1123
                        }
 
1124
 
 
1125
                        return {
 
1126
                                id: o.id,
 
1127
                                abort: function() {
 
1128
                                        return o.c ? _abort(o, c) : false;
 
1129
                                },
 
1130
                                isInProgress: function() {
 
1131
                                        return o.c ? _isInProgress(o.id) : false;
 
1132
                                }
 
1133
                        };
1120
1134
        },
1121
1135
 
1122
1136
       /**
1147
1161
                }
1148
1162
            }
1149
1163
 
1150
 
            switch (e.toLowerCase()) {
 
1164
            switch (e) {
1151
1165
                case 'start':
1152
1166
                    Y.io.start(o.id, c);
1153
1167
                    break;
1155
1169
                    Y.io.complete(o, c);
1156
1170
                    break;
1157
1171
                case 'success':
1158
 
                    Y.io.success(t || f ?  _data(o, f, t) : o, c);
 
1172
                    Y.io.success(t || f ? _data(o, f, t) : o, c);
1159
1173
                    delete m[o.id];
1160
1174
                    break;
1161
1175
                case 'timeout':
1162
1176
                case 'abort':
 
1177
                                case 'transport error':
 
1178
                                        o.e = e;
1163
1179
                case 'failure':
1164
 
                    if (e === ('abort' || 'timeout')) {
1165
 
                        o.e = e;
1166
 
                    }
1167
 
 
1168
1180
                    Y.io.failure(t || f ? _data(o, f, t) : o, c);
1169
1181
                    delete m[o.id];
1170
1182
                    break;
1183
1195
        * @return void
1184
1196
        */
1185
1197
        xdrReady: function(id) {
 
1198
                        Y.io.xdr.delay = 0;
1186
1199
            Y.fire(E_XDR_READY, id);
1187
1200
        },
1188
1201
 
1196
1209
        * @return void
1197
1210
        */
1198
1211
        transport: function(o) {
1199
 
            var id = o.yid ? o.yid : Y.id;
1200
 
                o.id = o.id || 'flash';
1201
 
 
1202
 
            if (o.id === 'native' || o.id === 'flash') {
1203
 
                _swf(o.src, id);
 
1212
            var yid = o.yid || Y.id,
 
1213
                                oid = o.id || 'flash',
 
1214
                                src = Y.UA.ie ? o.src + '?d=' + new Date().valueOf().toString() : o.src;
 
1215
 
 
1216
            if (oid === 'native' || oid === 'flash') {
 
1217
 
 
1218
                                _swf(src, yid);
1204
1219
                this._transport.flash = d.getElementById('yuiIoSwf');
1205
1220
            }
1206
 
            else {
 
1221
            else if (oid) {
1207
1222
                this._transport[o.id] = o.src;
1208
1223
            }
1209
1224
        }
1210
1225
    });
1211
1226
 
1212
 
 
1213
 
 
1214
 
}, '3.2.0' ,{requires:['io-base','datatype-xml']});
 
1227
   /**
 
1228
        * @description Delay value to calling the Flash transport, in the
 
1229
        * event io.swf has not finished loading.  Once the E_XDR_READY
 
1230
    * event is fired, this value will be set to 0.
 
1231
        *
 
1232
        * @property delay
 
1233
        * @public
 
1234
        * @static
 
1235
        * @type number
 
1236
        */
 
1237
        Y.io.xdr.delay = 50;
 
1238
 
 
1239
 
 
1240
 
 
1241
}, '3.3.0' ,{requires:['io-base','datatype-xml']});
1215
1242
 
1216
1243
YUI.add('io-upload-iframe', function(Y) {
1217
1244
 
1224
1251
 
1225
1252
    var w = Y.config.win,
1226
1253
        d = Y.config.doc,
1227
 
        str = (d.documentMode && d.documentMode === 8);
 
1254
        _std = (d.documentMode && d.documentMode >= 8),
 
1255
                _d = decodeURIComponent;
1228
1256
   /**
1229
1257
    * @description Parses the POST data object and creates hidden form elements
1230
1258
    * for each key-value, and appends them to the HTML form object.
1243
1271
        for (i = 0, l = m.length - 1; i < l; i++) {
1244
1272
            o[i] = d.createElement('input');
1245
1273
            o[i].type = 'hidden';
1246
 
            o[i].name = m[i].substring(m[i].lastIndexOf('&') + 1);
1247
 
            o[i].value = (i + 1 === l) ? m[i + 1] : m[i + 1].substring(0, (m[i + 1].lastIndexOf('&')));
 
1274
            o[i].name = _d(m[i].substring(m[i].lastIndexOf('&') + 1));
 
1275
            o[i].value = (i + 1 === l) ? _d(m[i + 1]) : _d(m[i + 1].substring(0, (m[i + 1].lastIndexOf('&'))));
1248
1276
            f.appendChild(o[i]);
1249
1277
        }
1250
1278
 
1264
1292
    function _removeData(f, o) {
1265
1293
        var i, l;
1266
1294
 
1267
 
        for(i = 0, l = o.length; i < l; i++){
 
1295
        for (i = 0, l = o.length; i < l; i++) {
1268
1296
            f.removeChild(o[i]);
1269
1297
        }
1270
1298
    }
1284
1312
        f.setAttribute('action', uri);
1285
1313
        f.setAttribute('method', 'POST');
1286
1314
        f.setAttribute('target', 'ioupload' + id );
1287
 
        f.setAttribute(Y.UA.ie && !str ? 'encoding' : 'enctype', 'multipart/form-data');
 
1315
        f.setAttribute(Y.UA.ie && !_std ? 'encoding' : 'enctype', 'multipart/form-data');
1288
1316
    }
1289
1317
 
1290
1318
   /**
1291
 
    * @description Sets the appropriate attributes and values to the HTML
1292
 
    * form, in preparation of a file upload transaction.
 
1319
    * @description Reset the HTML form attributes to their original values.
1293
1320
    * @method _resetAttrs
1294
1321
    * @private
1295
1322
    * @static
1301
1328
        var p;
1302
1329
 
1303
1330
        for (p in a) {
1304
 
            if (a.hasOwnProperty(a, p)) {
 
1331
            if (a.hasOwnProperty(p)) {
1305
1332
                if (a[p]) {
1306
1333
                    f.setAttribute(p, f[p]);
1307
1334
                }
1383
1410
        if (b) {
1384
1411
            // When a response Content-Type of "text/plain" is used, Firefox and Safari
1385
1412
            // will wrap the response string with <pre></pre>.
1386
 
            p = b.query('pre:first-child');
 
1413
            p = b.one('pre:first-child');
1387
1414
            o.c.responseText = p ? p.get('text') : b.get('text');
1388
1415
        }
1389
1416
        else {
1491
1518
 
1492
1519
 
1493
1520
 
1494
 
}, '3.2.0' ,{requires:['io-base','node-base']});
 
1521
}, '3.3.0' ,{requires:['io-base','node-base']});
1495
1522
 
1496
1523
YUI.add('io-queue', function(Y) {
1497
1524
 
1697
1724
 
1698
1725
 
1699
1726
 
1700
 
}, '3.2.0' ,{requires:['io-base','queue-promote']});
1701
 
 
1702
 
 
1703
 
 
1704
 
YUI.add('io', function(Y){}, '3.2.0' ,{use:['io-base', 'io-form', 'io-xdr', 'io-upload-iframe', 'io-queue']});
 
1727
}, '3.3.0' ,{requires:['io-base','queue-promote']});
 
1728
 
 
1729
 
 
1730
 
 
1731
YUI.add('io', function(Y){}, '3.3.0' ,{use:['io-base', 'io-form', 'io-xdr', 'io-upload-iframe', 'io-queue']});
1705
1732