Skip to content

Commit

Permalink
Merge pull request Modernizr#921 from SlexAxton/master
Browse files Browse the repository at this point in the history
Add Async Event Support
  • Loading branch information
SlexAxton committed May 14, 2013
2 parents 0f8d27f + 8ef2bca commit e2cc7f3
Show file tree
Hide file tree
Showing 17 changed files with 269 additions and 33 deletions.
18 changes: 14 additions & 4 deletions feature-detects/css/resize.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
/*!
{
"name": "CSS UI Resize",
"property": "cssresize",
"tags": ["css"],
"notes": [{
"name": "W3C Specification",
"href": "http://www.w3.org/TR/css3-ui/#resize"
},{
"name": "MDN Docs",
"href": "https://developer.mozilla.org/en/CSS/resize"
}]
}
!*/
define(['Modernizr', 'testAllProps'], function( Modernizr, testAllProps ) {
// Test for CSS 3 UI "resize" property
// http://www.w3.org/TR/css3-ui/#resize
// https://developer.mozilla.org/en/CSS/resize

Modernizr.addTest('cssresize', testAllProps('resize'));
});
13 changes: 11 additions & 2 deletions feature-detects/css/rgba.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
/*!
{
"name": "CSS rgba",
"property": "rgba",
"tags": ["css"],
"notes": [{
"name": "CSSTricks Tutorial",
"href": "http://css-tricks.com/rgba-browser-support/"
}]
}
!*/
define(['Modernizr', 'createElement'], function( Modernizr, createElement ) {
// css-tricks.com/rgba-browser-support/

Modernizr.addTest('rgba', function() {
var elem = createElement('div');
var style = elem.style;
Expand Down
21 changes: 18 additions & 3 deletions feature-detects/css/subpixelfont.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,24 @@
/*!
{
"name": "CSS Subpixel Fonts",
"property": "subpixelfont",
"tags": ["css"],
"authors": [
"@derSchepp",
"@gerritvanaaken",
"@rodneyrehm",
"@yatil",
"@ryanseddon"
],
"notes": [{
"name": "Origin Test",
"href": "https://github.com/gerritvanaaken/subpixeldetect"
}]
}
!*/
define(['Modernizr', 'testStyles'], function( Modernizr, testStyles ) {
/*
* Test for SubPixel Font Rendering
* (to infer if GDI or DirectWrite is used on Windows)
* Authors: @derSchepp, @gerritvanaaken, @rodneyrehm, @yatil, @ryanseddon
* Web: https://github.com/gerritvanaaken/subpixeldetect
*/
testStyles(
'#modernizr{position: absolute; top: -10em; visibility:hidden; font: normal 10px arial;}#subpixel{float: left; font-size: 33.3333%;}',
Expand Down
22 changes: 18 additions & 4 deletions feature-detects/css/supports.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,22 @@
/*!
{
"name": "CSS Supports",
"property": "supports",
"tags": ["css"],
"notes": [{
"name": "W3 Spec",
"href": "http://dev.w3.org/csswg/css3-conditional/#at-supports"
},{
"name": "Related Github Issue",
"href": "github.com/Modernizr/Modernizr/issues/648"
},{
"name": "W3 Info",
"href": "http://dev.w3.org/csswg/css3-conditional/#the-csssupportsrule-interface"
}]
}
!*/
define(['Modernizr'], function( Modernizr ) {
// http://dev.w3.org/csswg/css3-conditional/#at-supports
// github.com/Modernizr/Modernizr/issues/648
// Relies on the fact that a browser vendor should expose the CSSSupportsRule interface
// http://dev.w3.org/csswg/css3-conditional/#the-csssupportsrule-interface

Modernizr.addTest('supports','CSSSupportsRule' in window);
Modernizr.addTest('supports', 'CSSSupportsRule' in window);
});
9 changes: 8 additions & 1 deletion feature-detects/css/textshadow.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
/*!
{
"name": "CSS textshadow",
"property": "textshadow",
"tags": ["css"],
"knownBugs": ["FF3.0 will false positive on this test"]
}
!*/
define(['Modernizr', 'createElement'], function( Modernizr, createElement ) {
// FF3.0 will false positive on this test
Modernizr.addTest('textshadow', createElement('div').style.textShadow === '');
});
7 changes: 7 additions & 0 deletions feature-detects/css/transforms.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
/*!
{
"name": "CSS Transforms",
"property": "csstransforms",
"tags": ["css"]
}
!*/
define(['Modernizr', 'testAllProps'], function( Modernizr, testAllProps ) {
Modernizr.addTest('csstransforms', !!testAllProps('transform'));
});
8 changes: 8 additions & 0 deletions feature-detects/css/transforms3d.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
/*!
{
"name": "CSS Transforms 3D",
"property": "csstransforms3d",
"tags": ["css"]
}
!*/
define(['Modernizr', 'testAllProps', 'testStyles', 'docElement'], function( Modernizr, testAllProps, testStyles, docElement ) {
Modernizr.addTest('csstransforms3d', function() {
var ret = !!testAllProps('perspective');
Expand All @@ -15,6 +22,7 @@ define(['Modernizr', 'testAllProps', 'testStyles', 'docElement'], function( Mode
ret = node.offsetLeft === 9 && node.offsetHeight === 5;
});
}

return ret;
});
});
7 changes: 7 additions & 0 deletions feature-detects/css/transitions.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
/*!
{
"name": "CSS Transitions",
"property": "csstransitions",
"tags": ["css"]
}
!*/
define(['Modernizr', 'testAllProps'], function( Modernizr, testAllProps ) {
Modernizr.addTest('csstransitions', testAllProps('transition'));
});
16 changes: 12 additions & 4 deletions feature-detects/css/userselect.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
/*!
{
"name": "CSS user-select",
"property": "userselect",
"authors": ["ryan seddon"],
"tags": ["css"],
"notes": [{
"name": "Related Modernizr Issue",
"href": "https://github.com/Modernizr/Modernizr/issues/250"
}]
}
!*/
define(['Modernizr', 'testAllProps'], function( Modernizr, testAllProps ) {
// -moz-user-select:none test.
// by ryan seddon
//https://github.com/Modernizr/Modernizr/issues/250

Modernizr.addTest('userselect', testAllProps('userSelect'));
});
16 changes: 14 additions & 2 deletions feature-detects/css/vhunit.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
/*!
{
"name": "CSS vh unit",
"property": "cssvhunit",
"tags": ["css"],
"notes": [{
"name": "Related Modernizr Issue",
"href": "https://github.com/Modernizr/Modernizr/issues/572"
},{
"name": "Similar JSFiddle",
"href": "http://jsfiddle.net/FWeinb/etnYC/"
}]
}
!*/
define(['Modernizr', 'testStyles'], function( Modernizr, testStyles ) {
// https://github.com/Modernizr/Modernizr/issues/572
// Similar to http://jsfiddle.net/FWeinb/etnYC/
testStyles('#modernizr { height: 50vh; }', function( elem, rule ) {
var height = parseInt(window.innerHeight/2,10);
var compStyle = parseInt((window.getComputedStyle ?
Expand Down
16 changes: 14 additions & 2 deletions feature-detects/css/vmaxunit.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
/*!
{
"name": "CSS vmax unit",
"property": "cssvmaxunit",
"tags": ["css"],
"notes": [{
"name": "Related Modernizr Issue",
"href": "https://github.com/Modernizr/Modernizr/issues/572"
},{
"name": "JSFiddle Example",
"href": "http://jsfiddle.net/glsee/JDsWQ/4/"
}]
}
!*/
define(['Modernizr', 'testStyles'], function( Modernizr, testStyles ) {
// https://github.com/Modernizr/Modernizr/issues/572
// http://jsfiddle.net/glsee/JDsWQ/4/
testStyles('#modernizr { width: 50vmax; }', function( elem, rule ) {
var one_vw = window.innerWidth/100;
var one_vh = window.innerHeight/100;
Expand Down
16 changes: 14 additions & 2 deletions feature-detects/css/vminunit.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
/*!
{
"name": "CSS vmin unit",
"property": "cssvminunit",
"tags": ["css"],
"notes": [{
"name": "Related Modernizr Issue",
"href": "https://github.com/Modernizr/Modernizr/issues/572"
},{
"name": "JSFiddle Example",
"href": "http://jsfiddle.net/glsee/JRmdq/8/"
}]
}
!*/
define(['Modernizr', 'testStyles'], function( Modernizr, testStyles ) {
// https://github.com/Modernizr/Modernizr/issues/572
// http://jsfiddle.net/glsee/JRmdq/8/
testStyles('#modernizr { width: 50vmin; }', function( elem, rule ) {
var one_vw = window.innerWidth/100;
var one_vh = window.innerHeight/100;
Expand Down
16 changes: 14 additions & 2 deletions feature-detects/css/vwunit.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
/*!
{
"name": "CSS vw unit",
"property": "cssvwunit",
"tags": ["css"],
"notes": [{
"name": "Related Modernizr Issue",
"href": "https://github.com/Modernizr/Modernizr/issues/572"
},{
"name": "JSFiddle Example",
"href": "http://jsfiddle.net/FWeinb/etnYC/"
}]
}
!*/
define(['Modernizr', 'testStyles'], function( Modernizr, testStyles ) {
// https://github.com/Modernizr/Modernizr/issues/572
// http://jsfiddle.net/FWeinb/etnYC/
testStyles('#modernizr { width: 50vw; }', function( elem, rule ) {
var width = parseInt(window.innerWidth/2,10);
var compStyle = parseInt((window.getComputedStyle ?
Expand Down
16 changes: 14 additions & 2 deletions feature-detects/css/wrapflow.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
/*!
{
"name": "CSS wrap-flow",
"property": "wrapflow",
"tags": ["css"],
"notes": [{
"name": "W3C Exclusions Spec",
"href": "http://www.w3.org/TR/css3-exclusions"
},{
"name": "Example by Adobe",
"href": "http://html.adobe.com/webstandards/cssexclusions"
}]
}
!*/
define(['Modernizr', 'prefixed', 'docElement', 'createElement'], function( Modernizr, prefixed, docElement, createElement ) {
// http://www.w3.org/TR/css3-exclusions
// Examples: http://html.adobe.com/webstandards/cssexclusions
// Separate test for `wrap-flow` property as IE10 has just implemented this alone
Modernizr.addTest('wrapflow', function () {
var prefixedProperty = prefixed('wrapFlow');
Expand Down
23 changes: 23 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,29 @@ Modernizr tests which native CSS3 and HTML5 features are available in the curren

Modernizr has an optional (*not included*) conditional resource loader called `Modernizr.load()`, based on [Yepnope.js](http://yepnopejs.com). You can get a build that includes `Modernizr.load()`, as well as choosing which feature tests to include on the [Download page](http://www.modernizr.com/download/).

## New Asynchronous Event Listeners

Often times people want to know when an asynchronous test is done so they can allow their application to react to it.
In the past, you've had to rely on watching properties or `<html>` classes. Only events on **asynchronous** tests are
supported. Synchronous tests should be handled synchronously for speed and consistency reasons.

The new api looks like this:

```javascript
// Listen to a test, give it a callback
Modernizr.on('testname', function( result ) {
if (result) {
console.log('The test passed!');
}
else {
console.log('The test failed!');
}
});
```

We guarantee that we'll only invoke your function once (per time that you call `on`). We are currently not exposing
a method for exposing the `trigger` functionality. Instead, if you'd like to have control over async tests, use the
`src/addTest` feature, and any test that you set will automatically expose and trigger the `on` functionality.

## Test suite

Expand Down
25 changes: 20 additions & 5 deletions src/ModernizrProto.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,37 @@
define(['tests'], function ( tests ) {
var ModernizrProto = {
// The current version, dummy
_version : 'v3.0.0pre',
_version: 'v3.0.0pre',

// Any settings that don't work as separate modules
// can go in here as configuration.
_config : {
_config: {
classPrefix : '',
enableClasses : true
},

_q : [],
// Queue of tests
_q: [],

addTest : function( name, fn, options ) {
// Stub these for people who are listening
on: function( test, cb ) {
// I don't really think people should do this, but we can
// safe guard it a bit.
// -- NOTE:: this gets WAY overridden in src/addTest for
// actual async tests. This is in case people listen to
// synchronous tests. I would leave it out, but the code
// to *disallow* sync tests in the real version of this
// function is actually larger than this.
setTimeout(function() {
cb(this[test]);
}, 0);
},

addTest: function( name, fn, options ) {
tests.push({name : name, fn : fn, options : options });
},

addAsyncTest : function (fn) {
addAsyncTest: function (fn) {
tests.push({name : null, fn : fn});
}
};
Expand Down
Loading

0 comments on commit e2cc7f3

Please sign in to comment.