Last active
August 31, 2018 03:20
-
-
Save peduarte/68153970739a753a5dbc to your computer and use it in GitHub Desktop.
Modernizr CSS3 Sizing Values check (min-content, max-content, fill-content, fill-available)
This file contains 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(Modernizr) { | |
'use strict'; | |
/** | |
* Modernizr test to check if CSS3 Sizing values are supported | |
* W3: http://www.w3.org/TR/css3-sizing/ | |
* CanIUse: http://caniuse.com/#feat=intrinsic-width | |
* | |
* Values to check: | |
* min-content | |
* max-content | |
* fill-content | |
* fill-available | |
* | |
* Extra check if all of the above are supported: | |
* sizingvalues | |
* | |
*/ | |
var test = function (prop, val) { | |
var element, property, value; | |
property = prop + ':'; | |
value = val + ';'; | |
element = document.createElement('div'); | |
element.style.cssText = property + Modernizr._prefixes.join(value + property); | |
testCount++; | |
return !!element.style.length; | |
}; | |
var supportsAll = function (array) { | |
for (var i = 1; i < array.length; i++) { | |
if (array[i] !== array[0] || array[i] === false) { | |
return false; | |
} | |
} | |
return true; | |
}; | |
var results = []; | |
var testCount = -1; | |
Modernizr.addTest('mincontent', function() { | |
results.push(test('width', 'min-content')); | |
return results[testCount]; | |
}); | |
Modernizr.addTest('maxcontent', function() { | |
results.push(test('width', 'max-content')); | |
return results[testCount]; | |
}); | |
Modernizr.addTest('fillcontent', function() { | |
results.push(test('width', 'fill-content')); | |
return results[testCount]; | |
}); | |
Modernizr.addTest('fillavailable', function() { | |
results.push(test('width', 'fill-available')); | |
return results[testCount]; | |
}); | |
Modernizr.addTest('sizingvalues', function() { | |
return supportsAll(results); | |
}); | |
})(Modernizr); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks!
Might be worth adding this to the comment: