Skip to content

Commit

Permalink
Merge pull request #16 from aldendaniels/master
Browse files Browse the repository at this point in the history
Update modernizr
  • Loading branch information
jnordberg committed Sep 11, 2015
2 parents 7099120 + 551e6f1 commit e8079d5
Show file tree
Hide file tree
Showing 270 changed files with 3,562 additions and 4,205 deletions.
11 changes: 7 additions & 4 deletions lib/ModernizrProto.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ var tests = require('./tests');

var ModernizrProto = {
// The current version, dummy
_version: 'v3.0.0pre',
_version: '__VERSION__',

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

// Queue of tests
Expand All @@ -24,8 +26,9 @@ var tests = require('./tests');
// 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.
var self = this;
setTimeout(function() {
cb(this[test]);
cb(self[test]);
}, 0);
},

Expand Down
27 changes: 17 additions & 10 deletions lib/addTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,12 @@ var setClasses = require('./setClasses');
} else {

feature = feature.toLowerCase();
var featureSplit = feature.split('.');
var last = Modernizr[featureSplit[0]];
var featureNameSplit = feature.split('.');
var last = Modernizr[featureNameSplit[0]];

// Again, we don't check for parent test existence. Get that right, though.
if (featureSplit.length == 2) {
last = last[featureSplit[1]];
if (featureNameSplit.length == 2) {
last = last[featureNameSplit[1]];
}

if ( typeof last != 'undefined' ) {
Expand All @@ -89,15 +89,22 @@ var setClasses = require('./setClasses');
test = typeof test == 'function' ? test() : test;

// Set the value (this is the magic, right here).
if (featureSplit.length == 1) {
Modernizr[featureSplit[0]] = test;
}
else if (featureSplit.length == 2) {
Modernizr[featureSplit[0]][featureSplit[1]] = test;
if (featureNameSplit.length == 1) {
Modernizr[featureNameSplit[0]] = test;
} else {
// cast to a Boolean, if not one already
/* jshint -W053 */
if (Modernizr[featureNameSplit[0]] && !(Modernizr[featureNameSplit[0]] instanceof Boolean)) {
Modernizr[featureNameSplit[0]] = new Boolean(Modernizr[featureNameSplit[0]]);
}

Modernizr[featureNameSplit[0]][featureNameSplit[1]] = test;
}

// Set a single class (either `feature` or `no-feature`)
setClasses([(test ? '' : 'no-') + featureSplit.join('-')]);
/* jshint -W041 */
setClasses([(!!test && test != false ? '' : 'no-') + featureNameSplit.join('-')]);
/* jshint +W041 */

// Trigger the event
Modernizr._trigger(feature, test);
Expand Down
50 changes: 50 additions & 0 deletions lib/atRule.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
var ModernizrProto = require('./ModernizrProto');
var prefixes = require('./cssomPrefixes');


/**
* atRule returns a given CSS property at-rule (eg @keyframes), possibly in
* some prefixed form, or false, in the case of an unsupported rule
*
* @param prop - String naming the property to test
*/

var atRule = function(prop) {
var length = prefixes.length;
var cssrule = window.CSSRule;
var rule;

if (typeof cssrule === 'undefined') {
return undefined;
}

if (!prop) {
return false;
}

// remove literal @ from beginning of provided property
prop = prop.replace(/^@/,'');

// CSSRules use underscores instead of dashes
rule = prop.replace(/-/g,'_').toUpperCase() + '_RULE';

if (rule in cssrule) {
return '@' + prop;
}

for ( var i = 0; i < length; i++ ) {
// prefixes gives us something like -o-, and we want O_
var prefix = prefixes[i];
var thisRule = prefix.toUpperCase() + '_' + rule;

if (thisRule in cssrule) {
return '@-' + prefix.toLowerCase() + '-' + prop;
}
}

return false;
};



module.exports = atRule;
18 changes: 15 additions & 3 deletions lib/createElement.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
var isSVG = require('./isSVG');


function createElement() {
if (typeof document.createElement !== 'function') {
// This is the case in IE7, where the type of createElement is "object".
// For this reason, we cannot call apply() as Object is not a Function.
return document.createElement(arguments[0]);
} else if (isSVG) {
return document.createElementNS.call(document, 'http://www.w3.org/2000/svg', arguments[0]);
} else {
return document.createElement.apply(document, arguments);
}
}

var createElement = function() {
return document.createElement.apply(document, arguments);
};


module.exports = createElement;
10 changes: 10 additions & 0 deletions lib/cssToDOM.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

// Helper function for converting kebab-case to camelCase,
// e.g. box-sizing -> boxSizing
function cssToDOM( name ) {
return name.replace(/([a-z])-([a-z])/g, function(str, m1, m2) {
return m1 + m2.toUpperCase();
}).replace(/^-/, '');
}

module.exports = cssToDOM;
2 changes: 1 addition & 1 deletion lib/cssomPrefixes.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ var ModernizrProto = require('./ModernizrProto');
var omPrefixes = require('./omPrefixes');


var cssomPrefixes = omPrefixes.split(' ');
var cssomPrefixes = (ModernizrProto._config.usePrefixes ? omPrefixes.split(' ') : []);
ModernizrProto._cssomPrefixes = cssomPrefixes;


Expand Down
2 changes: 1 addition & 1 deletion lib/domPrefixes.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ var ModernizrProto = require('./ModernizrProto');
var omPrefixes = require('./omPrefixes');


var domPrefixes = omPrefixes.toLowerCase().split(' ');
var domPrefixes = (ModernizrProto._config.usePrefixes ? omPrefixes.toLowerCase().split(' ') : []);
ModernizrProto._domPrefixes = domPrefixes;


Expand Down
10 changes: 10 additions & 0 deletions lib/domToCSS.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

// Helper function for converting camelCase to kebab-case,
// e.g. boxSizing -> box-sizing
function domToCSS( name ) {
return name.replace(/([A-Z])/g, function(str, m1) {
return '-' + m1.toLowerCase();
}).replace(/^ms-/, '-ms-');
}

module.exports = domToCSS;
9 changes: 0 additions & 9 deletions lib/domToHyphenated.js

This file was deleted.

51 changes: 5 additions & 46 deletions lib/fnBind.js
Original file line number Diff line number Diff line change
@@ -1,51 +1,10 @@
var slice = require('./slice');


// Adapted from ES5-shim https://github.com/kriskowal/es5-shim/blob/master/es5-shim.js
// es5.github.com/#x15.3.4.5

if (!Function.prototype.bind) {
Function.prototype.bind = function bind(that) {

var target = this;

if (typeof target != "function") {
throw new TypeError();
}

var args = slice.call(arguments, 1);
var bound = function() {

if (this instanceof bound) {

var F = function(){};
F.prototype = target.prototype;
var self = new F();

var result = target.apply(
self,
args.concat(slice.call(arguments))
);
if (Object(result) === result) {
return result;
}
return self;

} else {

return target.apply(
that,
args.concat(slice.call(arguments))
);

}

};

return bound;
// Change the function's scope.
function fnBind(fn, that) {
return function() {
return fn.apply(that, arguments);
};
}



module.exports = Function.prototype.bind;
module.exports = fnBind;
18 changes: 12 additions & 6 deletions lib/generate.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var _ = require('./underscore');
var _ = require('./lodash');


return function( config ) {
Expand All @@ -7,13 +7,13 @@ var _ = require('./underscore');
config = {};
}
config.options = config.options || [];
config["feature-detects"] = config["feature-detects"] || [];
config['feature-detects'] = config['feature-detects'] || [];

// Some special cases
var setClasses = _(config.options).contains('setClasses');
var setClasses = _.contains(config.options, 'setClasses');

// Remove the special cases
config.options = _(config.options).without('setClasses');
config.options = _.without(config.options, 'setClasses');

var output = 'require(["ModernizrProto", "Modernizr", "testRunner"';

Expand All @@ -22,13 +22,19 @@ var _ = require('./underscore');
output += ', "setClasses", "classes"';
}

// Only allow one shiv at a time
if (_.includes(config.options, 'html5printshiv')) {
config.options = _.without(config.options, 'html5shiv');
}

// Load in the rest of the options (they dont return values, so they aren't declared
_(config.options).forEach(function (option) {
_.forEach(config.options, function (option) {
output += ', "' + option + '"';
});

// Load in all the detects
_(config["feature-detects"]).forEach(function (detect) {
_.forEach(config['feature-detects'], function (detect) {
detect = detect.indexOf('test/') === 0 ? detect : 'test/' + detect;
output += ', "' + detect + '"';
});

Expand Down
3 changes: 2 additions & 1 deletion lib/getBody.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var createElement = require('./createElement');
var isSVG = require('./isSVG');


function getBody() {
Expand All @@ -7,7 +8,7 @@ var createElement = require('./createElement');

if(!body) {
// Can't use the real body create a fake one.
body = createElement('body');
body = createElement(isSVG ? 'svg' : 'body');
body.fake = true;
}

Expand Down
3 changes: 3 additions & 0 deletions lib/hasOwnProp.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ var is = require('./is');

(function() {
var _hasOwnProperty = ({}).hasOwnProperty;
/* istanbul ignore else */
/* we have no way of testing IE 5.5 or safari 2,
* so just assume the else gets hit */
if ( !is(_hasOwnProperty, 'undefined') && !is(_hasOwnProperty.call, 'undefined') ) {
hasOwnProp = function (object, property) {
return _hasOwnProperty.call(object, property);
Expand Down
Loading

0 comments on commit e8079d5

Please sign in to comment.