Skip to content

Commit

Permalink
update quota mgmt test to req the actual object. cc @addyosmani. ref #…
Browse files Browse the repository at this point in the history
  • Loading branch information
paulirish committed Jan 17, 2012
2 parents 74df0b0 + a56f0ca commit 7273d5d
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 38 deletions.
10 changes: 10 additions & 0 deletions feature-detects/a-download.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

// a[download] attribute
// When used on an <a>, this attribute signifies that the resource it
// points to should be downloaded by the browser rather than navigating to it.
// http://developers.whatwg.org/links.html#downloading-resources
// By Addy Osmani

Modernizr.addTest('adownload',
!!('download' in document.createElement('a'))
);
41 changes: 21 additions & 20 deletions feature-detects/mathml.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@

// MathML omg!
// http://www.w3.org/Math/

// this tests MathML in HTML, not MathML as XML.
// test by Niels Leenheer

// demo:
// http://www1.chapman.edu/~jipsen/mathml/mathhtmltest.htm
// MathML
// http://www.w3.org/Math/
// By Addy Osmani
// Based on work by Davide (@dpvc) and David (@davidcarlisle)
// in https://github.com/mathjax/MathJax/issues/182

Modernizr.addTest('mathml', function(){

var e = document.createElement('div');
e.innerHTML = '<math></math>';

var bool = e.firstChild
&& "namespaceURI" in e.firstChild
&& e.firstChild.namespaceURI == 'http://www.w3.org/1998/Math/MathML';

return bool;

});
var hasMathML = false;
if ( document.createElementNS ) {
var ns = "http://www.w3.org/1998/Math/MathML",
div = document.createElement("div");
div.style.position = "absolute";
var mfrac = div.appendChild(document.createElementNS(ns,"math"))
.appendChild(document.createElementNS(ns,"mfrac"));
mfrac.appendChild(document.createElementNS(ns,"mi"))
.appendChild(document.createTextNode("xx"));
mfrac.appendChild(document.createElementNS(ns,"mi"))
.appendChild(document.createTextNode("yy"));
document.body.appendChild(div);
hasMathML = div.offsetHeight > div.offsetWidth;
}
return hasMathML;
});
12 changes: 12 additions & 0 deletions feature-detects/quota-management-api.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

// Quota storage management API
// This API can be used to check how much quota an origin is using and request more

// Currently only implemented in WebKit
// https://groups.google.com/a/chromium.org/group/chromium-html5/msg/5261d24266ba4366
// By Addy Osmani

Modernizr.addTest('quotamanagement', function(){
var storage = window[ Modernizr.prefixed('StorageInfo', window) ];
return !!('TEMPORARY' in storage && 'PERSISTENT' in storage);
});
7 changes: 7 additions & 0 deletions feature-detects/requestanimationframe.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

// requestAnimationFrame
// Offload animation repainting to browser for optimized performance.
// http://dvcs.w3.org/hg/webperf/raw-file/tip/specs/RequestAnimationFrame/Overview.html
// By Addy Osmani

Modernizr.addTest('raf', !!Modernizr.prefixed('requestAnimationFrame', window));
44 changes: 33 additions & 11 deletions modernizr.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,11 @@ window.Modernizr = (function( window, document, undefined ) {
// erik.eae.net/archives/2008/03/10/21.48.10/

// More here: github.com/Modernizr/Modernizr/issues/issue/21
cssomPrefixes = 'Webkit Moz O ms Khtml'.split(' '),
omPrefixes = 'Webkit Moz O ms Khtml',

cssomPrefixes = omPrefixes.split(' '),

domPrefixes = omPrefixes.toLowerCase().split(' '),

ns = {'svg': 'http://www.w3.org/2000/svg'},

Expand Down Expand Up @@ -238,6 +242,19 @@ window.Modernizr = (function( window, document, undefined ) {
return false;
}

/**
* testDOMProps is a generic DOM property test; if a browser supports
* a certain property, it won't return undefined for it.
*/
function testDOMProps( props, obj ) {
for ( var i in props ) {
if ( obj[ props[i] ] !== undefined) {
return props[i];
}
}
return false;
}

/**
* testPropsAll tests a list of DOM properties we want to check against.
* We specify literally ALL possible (known and/or likely) properties on
Expand All @@ -249,7 +266,12 @@ window.Modernizr = (function( window, document, undefined ) {
var ucProp = prop.charAt(0).toUpperCase() + prop.substr(1),
props = (prop + ' ' + cssomPrefixes.join(ucProp + ' ') + ucProp).split(' ');

return testProps(props, prefixed);
if(!is(prefixed, "object")) {
return testProps(props, prefixed);
} else {
props = (prop + ' ' + (domPrefixes).join(ucProp + ' ') + ucProp).split(' ');
return testDOMProps(props, prefixed);
}
}

/**
Expand Down Expand Up @@ -399,12 +421,7 @@ window.Modernizr = (function( window, document, undefined ) {
// - Firefox shipped moz_indexedDB before FF4b9, but since then has been mozIndexedDB
// For speed, we don't test the legacy (and beta-only) indexedDB
tests['indexedDB'] = function() {
for ( var i = -1, len = cssomPrefixes.length; ++i < len; ){
if ( window[cssomPrefixes[i].toLowerCase() + 'IndexedDB'] ){
return true;
}
}
return !!window.indexedDB;
return !!testPropsAll("indexedDB",window);
};

// documentMode logic from YUI to filter out IE8 Compat Mode
Expand Down Expand Up @@ -1101,13 +1118,18 @@ window.Modernizr = (function( window, document, undefined ) {
// 'WebkitTransition' : 'webkitTransitionEnd',
// 'MozTransition' : 'transitionend',
// 'OTransition' : 'oTransitionEnd',
// 'msTransition' : 'MSTransitionEnd',
// 'msTransition' : 'MsTransitionEnd',
// 'transition' : 'transitionend'
// },
// transEndEventName = transEndEventNames[ Modernizr.prefixed('transition') ];

Modernizr.prefixed = function(prop){
return testPropsAll(prop, 'pfx');
Modernizr.prefixed = function(prop, obj){
if(!obj) {
return testPropsAll(prop, 'pfx');
} else {
// Testing DOM property e.g. Modernizr.prefixed('requestAnimationFrame', window) // 'mozRequestAnimationFrame'
return testPropsAll(prop, obj);
}
};


Expand Down
34 changes: 27 additions & 7 deletions test/js/unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -436,17 +436,28 @@ test('Modernizr.testAllProps()',function(){
test('Modernizr.prefixed()', function(){
// https://gist.github.com/523692

function gimmePrefix(prop){
function gimmePrefix(prop, obj){
var prefixes = ['Moz','Khtml','Webkit','O','ms'],
domPrefixes = ['moz','khtml','webkit','o','ms'],
elem = document.createElement('div'),
upper = prop.charAt(0).toUpperCase() + prop.slice(1);

if (prop in elem.style)
return prop;
if(!obj) {
if (prop in elem.style)
return prop;

for (var len = prefixes.length; len--; ){
if ((prefixes[len] + upper) in elem.style)
return (prefixes[len] + upper);
for (var len = prefixes.length; len--; ){
if ((prefixes[len] + upper) in elem.style)
return (prefixes[len] + upper);
}
} else {
if (prop in obj)
return prop;

for (var len = domPrefixes.length; len--; ){
if ((domPrefixes[len] + upper) in obj)
return (domPrefixes[len] + upper);
}
}


Expand All @@ -456,11 +467,20 @@ test('Modernizr.prefixed()', function(){
var propArr = ['transition', 'backgroundSize', 'boxSizing', 'borderImage',
'borderRadius', 'boxShadow', 'columnCount'];


var domPropArr = [{ 'prop': 'requestAnimationFrame', 'obj': window },
{ 'prop': 'querySelectorAll', 'obj': document },
{ 'prop': 'matchesSelector', 'obj': document.createElement('div') }];

for (var i = -1, len = propArr.length; ++i < len; ){
var prop = propArr[i];
equals( Modernizr.prefixed(prop), gimmePrefix(prop), 'results for ' + prop + ' match the homebaked prefix finder');
}

for (var i = -1, len = domPropArr.length; ++i < len; ){
var prop = domPropArr[i];
equals( Modernizr.prefixed(prop.prop, prop.obj), gimmePrefix(prop.prop, prop.obj), 'results for ' + prop.prop + ' match the homebaked prefix finder');
}




Expand Down

1 comment on commit 7273d5d

@addyosmani
Copy link
Contributor

Choose a reason for hiding this comment

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

Thx for the head's up!

Please sign in to comment.