diff --git a/Gruntfile.js b/Gruntfile.js index c5bcd022eb..49f119c406 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -205,7 +205,7 @@ module.exports = function( grunt ) { // Remove `define("modernizr-init" ...)` and `define("modernizr-build" ...)` var mod = grunt.file.read(filepath).replace(/define\("modernizr-(init|build)", function\(\)\{\}\);/g, ''); - // Hack the prefix into place. Anything is way to big for something so small. + // Hack the prefix into place. Anything is way too big for something so small. if ( modConfig && modConfig.classPrefix ) { mod = mod.replace("classPrefix : '',", "classPrefix : '" + modConfig.classPrefix.replace(/"/g, '\\"') + "',"); } diff --git a/feature-detects/network/eventsource.js b/feature-detects/network/eventsource.js index 5b25361602..152be06f0e 100644 --- a/feature-detects/network/eventsource.js +++ b/feature-detects/network/eventsource.js @@ -12,6 +12,7 @@ /* DOC Tests for server sent events aka eventsource. + */ define(['Modernizr'], function( Modernizr ) { Modernizr.addTest('eventsource', !!window.EventSource); diff --git a/feature-detects/network/xhr-responsetype-arraybuffer.js b/feature-detects/network/xhr-responsetype-arraybuffer.js new file mode 100644 index 0000000000..1aa13aef24 --- /dev/null +++ b/feature-detects/network/xhr-responsetype-arraybuffer.js @@ -0,0 +1,19 @@ +/*! +{ + "name": "XMLHttpRequest xhr.responseType='arraybuffer'", + "property": "xhrresponsetypearraybuffer", + "tags": ["network"], + "notes": [{ + "name": "XMLHttpRequest Living Standard", + "href": "http://xhr.spec.whatwg.org/#the-responsetype-attribute" + }] +} +!*/ +/* DOC + +Tests for XMLHttpRequest xhr.responseType='arraybuffer'. + +*/ +define(['Modernizr', 'testXhrType'], function( Modernizr, testXhrType ) { + Modernizr.addTest('xhrresponsetypearraybuffer', testXhrType('arraybuffer')); +}); diff --git a/feature-detects/network/xhr-responsetype-blob.js b/feature-detects/network/xhr-responsetype-blob.js new file mode 100644 index 0000000000..cba530e07d --- /dev/null +++ b/feature-detects/network/xhr-responsetype-blob.js @@ -0,0 +1,19 @@ +/*! +{ + "name": "XMLHttpRequest xhr.responseType='blob'", + "property": "xhrresponsetypeblob", + "tags": ["network"], + "notes": [{ + "name": "XMLHttpRequest Living Standard", + "href": "http://xhr.spec.whatwg.org/#the-responsetype-attribute" + }] +} +!*/ +/* DOC + +Tests for XMLHttpRequest xhr.responseType='blob'. + +*/ +define(['Modernizr', 'testXhrType'], function( Modernizr, testXhrType ) { + Modernizr.addTest('xhrresponsetypeblob', testXhrType('blob')); +}); diff --git a/feature-detects/network/xhr-responsetype-document.js b/feature-detects/network/xhr-responsetype-document.js new file mode 100644 index 0000000000..5502183963 --- /dev/null +++ b/feature-detects/network/xhr-responsetype-document.js @@ -0,0 +1,19 @@ +/*! +{ + "name": "XMLHttpRequest xhr.responseType='document'", + "property": "xhrresponsetypedocument", + "tags": ["network"], + "notes": [{ + "name": "XMLHttpRequest Living Standard", + "href": "http://xhr.spec.whatwg.org/#the-responsetype-attribute" + }] +} +!*/ +/* DOC + +Tests for XMLHttpRequest xhr.responseType='document'. + +*/ +define(['Modernizr', 'testXhrType'], function( Modernizr, testXhrType ) { + Modernizr.addTest('xhrresponsetypedocument', testXhrType('document')); +}); diff --git a/feature-detects/network/xhr-responsetype-json.js b/feature-detects/network/xhr-responsetype-json.js new file mode 100644 index 0000000000..aaa206ab24 --- /dev/null +++ b/feature-detects/network/xhr-responsetype-json.js @@ -0,0 +1,22 @@ +/*! +{ + "name": "XMLHttpRequest xhr.responseType='json'", + "property": "xhrresponsetypejson", + "tags": ["network"], + "notes": [{ + "name": "XMLHttpRequest Living Standard", + "href": "http://xhr.spec.whatwg.org/#the-responsetype-attribute" + },{ + "name": "Explanation of xhr.responseType='json'", + "href": "http://mathiasbynens.be/notes/xhr-responsetype-json" + }] +} +!*/ +/* DOC + +Tests for XMLHttpRequest xhr.responseType='json'. + +*/ +define(['Modernizr', 'testXhrType'], function( Modernizr, testXhrType ) { + Modernizr.addTest('xhrresponsetypejson', testXhrType('json')); +}); diff --git a/feature-detects/network/xhr-responsetype-text.js b/feature-detects/network/xhr-responsetype-text.js new file mode 100644 index 0000000000..f8fa6f665d --- /dev/null +++ b/feature-detects/network/xhr-responsetype-text.js @@ -0,0 +1,19 @@ +/*! +{ + "name": "XMLHttpRequest xhr.responseType='text'", + "property": "xhrresponsetypetext", + "tags": ["network"], + "notes": [{ + "name": "XMLHttpRequest Living Standard", + "href": "http://xhr.spec.whatwg.org/#the-responsetype-attribute" + }] +} +!*/ +/* DOC + +Tests for XMLHttpRequest xhr.responseType='text'. + +*/ +define(['Modernizr', 'testXhrType'], function( Modernizr, testXhrType ) { + Modernizr.addTest('xhrresponsetypetext', testXhrType('text')); +}); diff --git a/feature-detects/network/xhr-responsetype.js b/feature-detects/network/xhr-responsetype.js new file mode 100644 index 0000000000..18c05215c5 --- /dev/null +++ b/feature-detects/network/xhr-responsetype.js @@ -0,0 +1,26 @@ +/*! +{ + "name": "XMLHttpRequest xhr.responseType", + "property": "xhrresponsetype", + "tags": ["network"], + "notes": [{ + "name": "XMLHttpRequest Living Standard", + "href": "http://xhr.spec.whatwg.org/#the-responsetype-attribute" + }] +} +!*/ +/* DOC + +Tests for XMLHttpRequest xhr.responseType. + +*/ +define(['Modernizr'], function( Modernizr ) { + Modernizr.addTest('xhrresponsetype', (function() { + if (typeof XMLHttpRequest == 'undefined') { + return false; + } + var xhr = new XMLHttpRequest(); + xhr.open('get', '/', true); + return 'response' in xhr; + }())); +}); diff --git a/lib/config-all.json b/lib/config-all.json index ec4df21cd9..6277503aaf 100644 --- a/lib/config-all.json +++ b/lib/config-all.json @@ -130,6 +130,12 @@ "test/network/connection", "test/network/eventsource", "test/network/xhr2", + "test/network/xhr-responsetype-arraybuffer", + "test/network/xhr-responsetype-blob", + "test/network/xhr-responsetype-document", + "test/network/xhr-responsetype-json", + "test/network/xhr-responsetype-text", + "test/network/xhr-responsetype", "test/notification", "test/pagevisibility-api", "test/performance", diff --git a/src/testXhrType.js b/src/testXhrType.js new file mode 100644 index 0000000000..6fce2fee7a --- /dev/null +++ b/src/testXhrType.js @@ -0,0 +1,18 @@ +define(function() { + // http://mathiasbynens.be/notes/xhr-responsetype-json#comment-4 + var testXhrType = function(type) { + if (typeof XMLHttpRequest == 'undefined') { + return false; + } + var xhr = new XMLHttpRequest(); + xhr.open('get', '/', true); + try { + xhr.responseType = type; + } catch(error) { + return false; + } + return 'response' in xhr && xhr.responseType == type; + }; + + return testXhrType; +});