Last active
August 24, 2017 16:26
-
-
Save imaustink/9e256d92935b315512b1000fcc51b7dd to your computer and use it in GitHub Desktop.
A build of Modernizr.flexbox that has been formatted by jsnice.org
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
!function(win, d, obj) { | |
/** | |
* @param {string} obj | |
* @param {string} type | |
* @return {?} | |
*/ | |
function is(obj, type) { | |
return typeof obj === type; | |
} | |
/** | |
* @return {undefined} | |
*/ | |
function testRunner() { | |
var codeSegments; | |
var feature; | |
var aliasIdx; | |
var result; | |
var i; | |
var part; | |
var featureNameSplit; | |
var p; | |
for (p in tests) { | |
if (tests.hasOwnProperty(p)) { | |
if (codeSegments = [], feature = tests[p], feature.name && (codeSegments.push(feature.name.toLowerCase()), feature.options && (feature.options.aliases && feature.options.aliases.length))) { | |
/** @type {number} */ | |
aliasIdx = 0; | |
for (;aliasIdx < feature.options.aliases.length;aliasIdx++) { | |
codeSegments.push(feature.options.aliases[aliasIdx].toLowerCase()); | |
} | |
} | |
result = is(feature.fn, "function") ? feature.fn() : feature.fn; | |
/** @type {number} */ | |
i = 0; | |
for (;i < codeSegments.length;i++) { | |
part = codeSegments[i]; | |
featureNameSplit = part.split("."); | |
if (1 === featureNameSplit.length) { | |
Modernizr[featureNameSplit[0]] = result; | |
} else { | |
if (!!Modernizr[featureNameSplit[0]]) { | |
if (!(Modernizr[featureNameSplit[0]] instanceof Boolean)) { | |
/** @type {Boolean} */ | |
Modernizr[featureNameSplit[0]] = new Boolean(Modernizr[featureNameSplit[0]]); | |
} | |
} | |
Modernizr[featureNameSplit[0]][featureNameSplit[1]] = result; | |
} | |
classes.push((result ? "" : "no-") + featureNameSplit.join("-")); | |
} | |
} | |
} | |
} | |
/** | |
* @param {Array} classes | |
* @return {undefined} | |
*/ | |
function setClasses(classes) { | |
/** @type {string} */ | |
var className = element.className; | |
var classPrefix = Modernizr._config.classPrefix || ""; | |
if (min && (className = className.baseVal), Modernizr._config.enableJSClass) { | |
/** @type {RegExp} */ | |
var rclass = new RegExp("(^|\\s)" + classPrefix + "no-js(\\s|$)"); | |
className = className.replace(rclass, "$1" + classPrefix + "js$2"); | |
} | |
if (Modernizr._config.enableClasses) { | |
className += " " + classPrefix + classes.join(" " + classPrefix); | |
if (min) { | |
element.className.baseVal = className; | |
} else { | |
element.className = className; | |
} | |
} | |
} | |
/** | |
* @param {string} str | |
* @param {string} substr | |
* @return {?} | |
*/ | |
function contains(str, substr) { | |
return!!~("" + str).indexOf(substr); | |
} | |
/** | |
* @param {string} str | |
* @return {?} | |
*/ | |
function camelize(str) { | |
return str.replace(/([a-z])-([a-z])/g, function(dataAndEvents, deepDataAndEvents, letter) { | |
return deepDataAndEvents + letter.toUpperCase(); | |
}).replace(/^-/, ""); | |
} | |
/** | |
* @return {?} | |
*/ | |
function createElement() { | |
return "function" != typeof d.createElement ? d.createElement(arguments[0]) : min ? d.createElementNS.call(d, "http://www.w3.org/2000/svg", arguments[0]) : d.createElement.apply(d, arguments); | |
} | |
/** | |
* @param {Function} fn | |
* @param {?} me | |
* @return {?} | |
*/ | |
function __bind(fn, me) { | |
return function() { | |
return fn.apply(me, arguments); | |
}; | |
} | |
/** | |
* @param {(Array|string)} props | |
* @param {Object} obj | |
* @param {boolean} elem | |
* @return {?} | |
*/ | |
function testDOMProps(props, obj, elem) { | |
var val; | |
var i; | |
for (i in props) { | |
if (props[i] in obj) { | |
return elem === false ? props[i] : (val = obj[props[i]], is(val, "function") ? __bind(val, elem || obj) : val); | |
} | |
} | |
return false; | |
} | |
/** | |
* @param {string} messageFormat | |
* @return {?} | |
*/ | |
function domToHyphenated(messageFormat) { | |
return messageFormat.replace(/([A-Z])/g, function(dataAndEvents, m3) { | |
return "-" + m3.toLowerCase(); | |
}).replace(/^ms-/, "-ms-"); | |
} | |
/** | |
* @param {Element} obj | |
* @param {Array} name | |
* @param {string} key | |
* @return {?} | |
*/ | |
function log(obj, name, key) { | |
var ret; | |
if ("getComputedStyle" in win) { | |
ret = getComputedStyle.call(win, obj, name); | |
/** @type {(Console|null)} */ | |
var c = win.console; | |
if (null !== ret) { | |
if (key) { | |
ret = ret.getPropertyValue(key); | |
} | |
} else { | |
if (c) { | |
/** @type {string} */ | |
var method = c.error ? "error" : "log"; | |
c[method].call(c, "getComputedStyle returning null, its possible modernizr test results are inaccurate"); | |
} | |
} | |
} else { | |
ret = !name && (obj.currentStyle && obj.currentStyle[key]); | |
} | |
return ret; | |
} | |
/** | |
* @return {?} | |
*/ | |
function getBody() { | |
/** @type {(HTMLElement|null)} */ | |
var body = d.body; | |
return body || (body = createElement(min ? "svg" : "body"), body.fake = true), body; | |
} | |
/** | |
* @param {string} value | |
* @param {Function} callback | |
* @param {number} nodes | |
* @param {Array} testnames | |
* @return {?} | |
*/ | |
function injectElementWithStyles(value, callback, nodes, testnames) { | |
var node; | |
var ret; | |
var img; | |
var docOverflow; | |
/** @type {string} */ | |
var mod = "modernizr"; | |
var div = createElement("div"); | |
var body = getBody(); | |
if (parseInt(nodes, 10)) { | |
for (;nodes--;) { | |
img = createElement("div"); | |
img.id = testnames ? testnames[nodes] : mod + (nodes + 1); | |
div.appendChild(img); | |
} | |
} | |
return node = createElement("style"), node.type = "text/css", node.id = "s" + mod, (body.fake ? body : div).appendChild(node), body.appendChild(div), node.styleSheet ? node.styleSheet.cssText = value : node.appendChild(d.createTextNode(value)), div.id = mod, body.fake && (body.style.background = "", body.style.overflow = "hidden", docOverflow = element.style.overflow, element.style.overflow = "hidden", element.appendChild(body)), ret = callback(div, value), body.fake ? (body.parentNode.removeChild(body), | |
element.style.overflow = docOverflow, element.offsetHeight) : div.parentNode.removeChild(div), !!ret; | |
} | |
/** | |
* @param {Array} props | |
* @param {string} value | |
* @return {?} | |
*/ | |
function nativeTestProps(props, value) { | |
var i = props.length; | |
if ("CSS" in win && "supports" in win.CSS) { | |
for (;i--;) { | |
if (win.CSS.supports(domToHyphenated(props[i]), value)) { | |
return true; | |
} | |
} | |
return false; | |
} | |
if ("CSSSupportsRule" in win) { | |
/** @type {Array} */ | |
var tagNameArr = []; | |
for (;i--;) { | |
tagNameArr.push("(" + domToHyphenated(props[i]) + ":" + value + ")"); | |
} | |
return tagNameArr = tagNameArr.join(" or "), injectElementWithStyles("@supports (" + tagNameArr + ") { #modernizr { position: absolute; } }", function(walkers) { | |
return "absolute" == log(walkers, null, "position"); | |
}); | |
} | |
return obj; | |
} | |
/** | |
* @param {Array} props | |
* @param {string} prefixed | |
* @param {string} value | |
* @param {boolean} skipValueTest | |
* @return {?} | |
*/ | |
function testProps(props, prefixed, value, skipValueTest) { | |
/** | |
* @return {undefined} | |
*/ | |
function cleanElems() { | |
if (c) { | |
delete mStyle.style; | |
delete mStyle.modElem; | |
} | |
} | |
if (skipValueTest = is(skipValueTest, "undefined") ? false : skipValueTest, !is(value, "undefined")) { | |
var result = nativeTestProps(props, value); | |
if (!is(result, "undefined")) { | |
return result; | |
} | |
} | |
var c; | |
var _i; | |
var _len2; | |
var prop; | |
var before; | |
/** @type {Array} */ | |
var pathConfig = ["modernizr", "tspan", "samp"]; | |
for (;!mStyle.style && pathConfig.length;) { | |
/** @type {boolean} */ | |
c = true; | |
mStyle.modElem = createElement(pathConfig.shift()); | |
mStyle.style = mStyle.modElem.style; | |
} | |
_len2 = props.length; | |
/** @type {number} */ | |
_i = 0; | |
for (;_len2 > _i;_i++) { | |
if (prop = props[_i], before = mStyle.style[prop], contains(prop, "-") && (prop = camelize(prop)), mStyle.style[prop] !== obj) { | |
if (skipValueTest || is(value, "undefined")) { | |
return cleanElems(), "pfx" == prefixed ? prop : true; | |
} | |
try { | |
/** @type {string} */ | |
mStyle.style[prop] = value; | |
} catch (h) { | |
} | |
if (mStyle.style[prop] != before) { | |
return cleanElems(), "pfx" == prefixed ? prop : true; | |
} | |
} | |
} | |
return cleanElems(), false; | |
} | |
/** | |
* @param {string} prop | |
* @param {string} prefixed | |
* @param {boolean} elem | |
* @param {string} value | |
* @param {boolean} deepDataAndEvents | |
* @return {?} | |
*/ | |
function testPropsAll(prop, prefixed, elem, value, deepDataAndEvents) { | |
var ucProp = prop.charAt(0).toUpperCase() + prop.slice(1); | |
/** @type {Array.<string>} */ | |
var props = (prop + " " + cssomPrefixes.join(ucProp + " ") + ucProp).split(" "); | |
return is(prefixed, "string") || is(prefixed, "undefined") ? testProps(props, prefixed, value, deepDataAndEvents) : (props = (prop + " " + domPrefixes.join(ucProp + " ") + ucProp).split(" "), testDOMProps(props, prefixed, elem)); | |
} | |
/** | |
* @param {string} prop | |
* @param {string} value | |
* @param {boolean} deepDataAndEvents | |
* @return {?} | |
*/ | |
function testAllProps(prop, value, deepDataAndEvents) { | |
return testPropsAll(prop, obj, obj, value, deepDataAndEvents); | |
} | |
/** @type {Array} */ | |
var classes = []; | |
/** @type {Array} */ | |
var tests = []; | |
var ModernizrProto = { | |
_version : "3.5.0", | |
_config : { | |
classPrefix : "", | |
enableClasses : true, | |
enableJSClass : true, | |
usePrefixes : true | |
}, | |
_q : [], | |
/** | |
* @param {?} id | |
* @param {?} fn | |
* @return {undefined} | |
*/ | |
on : function(id, fn) { | |
var elems = this; | |
setTimeout(function() { | |
fn(elems[id]); | |
}, 0); | |
}, | |
/** | |
* @param {string} b | |
* @param {Function} fn | |
* @param {Object} options | |
* @return {undefined} | |
*/ | |
addTest : function(b, fn, options) { | |
tests.push({ | |
name : b, | |
/** @type {Function} */ | |
fn : fn, | |
options : options | |
}); | |
}, | |
/** | |
* @param {Function} fn | |
* @return {undefined} | |
*/ | |
addAsyncTest : function(fn) { | |
tests.push({ | |
name : null, | |
/** @type {Function} */ | |
fn : fn | |
}); | |
} | |
}; | |
/** | |
* @return {undefined} | |
*/ | |
var Modernizr = function() { | |
}; | |
Modernizr.prototype = ModernizrProto; | |
Modernizr = new Modernizr; | |
/** @type {Element} */ | |
var element = d.documentElement; | |
/** @type {boolean} */ | |
var min = "svg" === element.nodeName.toLowerCase(); | |
/** @type {string} */ | |
var uHostName = "Moz O ms Webkit"; | |
/** @type {Array} */ | |
var cssomPrefixes = ModernizrProto._config.usePrefixes ? uHostName.split(" ") : []; | |
/** @type {Array} */ | |
ModernizrProto._cssomPrefixes = cssomPrefixes; | |
/** @type {Array} */ | |
var domPrefixes = ModernizrProto._config.usePrefixes ? uHostName.toLowerCase().split(" ") : []; | |
/** @type {Array} */ | |
ModernizrProto._domPrefixes = domPrefixes; | |
var modElem = { | |
elem : createElement("modernizr") | |
}; | |
Modernizr._q.push(function() { | |
delete modElem.elem; | |
}); | |
var mStyle = { | |
style : modElem.elem.style | |
}; | |
Modernizr._q.unshift(function() { | |
delete mStyle.style; | |
}); | |
/** @type {function (string, string, boolean, string, boolean): ?} */ | |
ModernizrProto.testAllProps = testPropsAll; | |
/** @type {function (string, string, boolean): ?} */ | |
ModernizrProto.testAllProps = testAllProps; | |
Modernizr.addTest("flexbox", testAllProps("flexBasis", "1px", true)); | |
testRunner(); | |
setClasses(classes); | |
delete ModernizrProto.addTest; | |
delete ModernizrProto.addAsyncTest; | |
/** @type {number} */ | |
var conditionIndex = 0; | |
for (;conditionIndex < Modernizr._q.length;conditionIndex++) { | |
Modernizr._q[conditionIndex](); | |
} | |
win.Modernizr = Modernizr; | |
}(window, document); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment