Skip to content

Commit

Permalink
Use jquery with native transport support
Browse files Browse the repository at this point in the history
The jquery mainline is lagging on support for responseType:
'arraybuffer', an XHRHTTPRequest Level 2 feature (whatever that means).
We use this responseType to transfer attachments.

I rebased jquery/jquery#1525 on the 2.1.1
release and cut 2.1.1-ajax-nativetransport in my own fork.
  • Loading branch information
liliakai committed Oct 30, 2014
1 parent 800e5ab commit e156c2c
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 33 deletions.
32 changes: 23 additions & 9 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,30 @@
"backbone": "~1.1.2",
"underscore": "~1.7.0",
"protobuf": "~3.8.0",
"jquery": "~2.1.1",
"bootstrap": "~3.3.0"
"bootstrap": "~3.3.0",
"jquery": "liliakai/jquery#2.1.1-ajax-nativetransport"
},
"preen": {
"jquery": ["dist/jquery.js"],
"long": ["dist/Long.js"],
"bytebuffer": ["dist/ByteBufferAB.js"],
"protobuf": ["dist/ProtoBuf.js"],
"underscore": ["underscore.js"],
"backbone": ["backbone.js"],
"bootstrap": ["dist/css/bootstrap.css"]
"jquery": [
"dist/jquery.js"
],
"long": [
"dist/Long.js"
],
"bytebuffer": [
"dist/ByteBufferAB.js"
],
"protobuf": [
"dist/ProtoBuf.js"
],
"underscore": [
"underscore.js"
],
"backbone": [
"backbone.js"
],
"bootstrap": [
"dist/css/bootstrap.css"
]
}
}
39 changes: 27 additions & 12 deletions bower_components/jquery/dist/jquery.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* jQuery JavaScript Library v2.1.1
* jQuery JavaScript Library v2.1.1-pre
* http://jquery.com/
*
* Includes Sizzle.js
Expand All @@ -9,7 +9,7 @@
* Released under the MIT license
* http://jquery.org/license
*
* Date: 2014-05-01T17:11Z
* Date: 2014-10-30T07:56Z
*/

(function( global, factory ) {
Expand Down Expand Up @@ -67,7 +67,7 @@ var
// Use the correct document accordingly with window argument (sandbox)
document = window.document,

version = "2.1.1",
version = "2.1.1-pre",

// Define a local copy of jQuery
jQuery = function( selector, context ) {
Expand Down Expand Up @@ -7842,7 +7842,8 @@ jQuery.extend({
responseFields: {
xml: "responseXML",
text: "responseText",
json: "responseJSON"
json: "responseJSON",
native: "responseNative"
},

// Data converters
Expand All @@ -7859,7 +7860,10 @@ jQuery.extend({
"text json": jQuery.parseJSON,

// Parse text as xml
"text xml": jQuery.parseXML
"text xml": jQuery.parseXML,

// Don't convert a native response
"* native": true
},

// For options that shouldn't be deep extended:
Expand Down Expand Up @@ -8549,7 +8553,8 @@ jQuery.ajaxTransport(function( options ) {
send: function( headers, complete ) {
var i,
xhr = options.xhr(),
id = ++xhrId;
id = ++xhrId,
responses = {};

xhr.open( options.type, options.url, options.async, options.username, options.password );

Expand Down Expand Up @@ -8595,15 +8600,25 @@ jQuery.ajaxTransport(function( options ) {
xhr.statusText
);
} else {
// Verify the responseType attribute to avoid InvalidStateError Exception (XHR2 Spec)
// Support: IE9
// Accessing binary-data responseText throws an exception
// (#11426)
if ( (!xhr.responseType || xhr.responseType === "text") &&
typeof xhr.responseText === "string" ) {
responses.text = xhr.responseText;
}

// The native response associated with the responseType
// Stored in the xhr.response attribute (XHR2 Spec)
if ( xhr.response ) {
responses.native = xhr.response;
}

complete(
xhrSuccessStatus[ xhr.status ] || xhr.status,
xhr.statusText,
// Support: IE9
// Accessing binary-data responseText throws an exception
// (#11426)
typeof xhr.responseText === "string" ? {
text: xhr.responseText
} : undefined,
responses,
xhr.getAllResponseHeaders()
);
}
Expand Down
39 changes: 27 additions & 12 deletions js-deps/bower_components.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* jQuery JavaScript Library v2.1.1
* jQuery JavaScript Library v2.1.1-pre
* http://jquery.com/
*
* Includes Sizzle.js
Expand All @@ -9,7 +9,7 @@
* Released under the MIT license
* http://jquery.org/license
*
* Date: 2014-05-01T17:11Z
* Date: 2014-10-30T07:56Z
*/

(function( global, factory ) {
Expand Down Expand Up @@ -67,7 +67,7 @@ var
// Use the correct document accordingly with window argument (sandbox)
document = window.document,

version = "2.1.1",
version = "2.1.1-pre",

// Define a local copy of jQuery
jQuery = function( selector, context ) {
Expand Down Expand Up @@ -7842,7 +7842,8 @@ jQuery.extend({
responseFields: {
xml: "responseXML",
text: "responseText",
json: "responseJSON"
json: "responseJSON",
native: "responseNative"
},

// Data converters
Expand All @@ -7859,7 +7860,10 @@ jQuery.extend({
"text json": jQuery.parseJSON,

// Parse text as xml
"text xml": jQuery.parseXML
"text xml": jQuery.parseXML,

// Don't convert a native response
"* native": true
},

// For options that shouldn't be deep extended:
Expand Down Expand Up @@ -8549,7 +8553,8 @@ jQuery.ajaxTransport(function( options ) {
send: function( headers, complete ) {
var i,
xhr = options.xhr(),
id = ++xhrId;
id = ++xhrId,
responses = {};

xhr.open( options.type, options.url, options.async, options.username, options.password );

Expand Down Expand Up @@ -8595,15 +8600,25 @@ jQuery.ajaxTransport(function( options ) {
xhr.statusText
);
} else {
// Verify the responseType attribute to avoid InvalidStateError Exception (XHR2 Spec)
// Support: IE9
// Accessing binary-data responseText throws an exception
// (#11426)
if ( (!xhr.responseType || xhr.responseType === "text") &&
typeof xhr.responseText === "string" ) {
responses.text = xhr.responseText;
}

// The native response associated with the responseType
// Stored in the xhr.response attribute (XHR2 Spec)
if ( xhr.response ) {
responses.native = xhr.response;
}

complete(
xhrSuccessStatus[ xhr.status ] || xhr.status,
xhr.statusText,
// Support: IE9
// Accessing binary-data responseText throws an exception
// (#11426)
typeof xhr.responseText === "string" ? {
text: xhr.responseText
} : undefined,
responses,
xhr.getAllResponseHeaders()
);
}
Expand Down

1 comment on commit e156c2c

@tarikbenmerar
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@liliakai the feature has just been cancelled, as I wished it could have passed :(.

Please sign in to comment.