This commit is contained in:
Stu Cox
2013-08-01 07:08:26 +01:00
10 changed files with 150 additions and 1 deletions

View File

@@ -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, '\\"') + "',");
}

View File

@@ -12,6 +12,7 @@
/* DOC
Tests for server sent events aka eventsource.
*/
define(['Modernizr'], function( Modernizr ) {
Modernizr.addTest('eventsource', !!window.EventSource);

View File

@@ -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'));
});

View File

@@ -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'));
});

View File

@@ -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'));
});

View File

@@ -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'));
});

View File

@@ -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'));
});

View File

@@ -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;
}()));
});

View File

@@ -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",

18
src/testXhrType.js Normal file
View File

@@ -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;
});