Last active
November 21, 2022 22:08
-
-
Save oslego/4475244 to your computer and use it in GitHub Desktop.
Basic feature detection with prefix support.
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
var Supports = (function(){ | |
// all spaces are important! | |
var prefixes = ' -webkit- -moz- -o- -ms- '; | |
function getPrefixedProperties(property, prefixes) { | |
var properties = prefixes.join(property + " ").split(' '); | |
// ignore the last string which is empty. | |
return properties.slice(0, properties.length-1); | |
} | |
return{ | |
cssProperty: function(property, host) { | |
var host = host || document.body; | |
var cssPrefixes = prefixes.split(' '); | |
// build an array of prefixed properties. | |
var properties = getPrefixedProperties(property, cssPrefixes); | |
for (var i = 0, len = properties.length; i < len; i++){ | |
if (host.style[properties[i]] !== undefined){ | |
return true | |
} | |
} | |
return false | |
}, | |
omProperty: function(property, host) { | |
var host = host || document.body; | |
var omPrefixes = prefixes.replace(/-/g, '').split(' '); | |
// drop the first element, which is empty | |
omPrefixes = omPrefixes.slice(1, omPrefixes.length); | |
// uppercase the property to attach prefixes | |
var ucProperty = property.charAt(0).toUpperCase() + property.slice(1) | |
// build an array of prefixed properties. | |
var properties = getPrefixedProperties(ucProperty, omPrefixes); | |
// ignore the last string which is empty. | |
properties = properties.slice(0, properties.length-1); | |
// add the unprefixed property | |
properties.unshift(property) | |
for (var i = 0, len = properties.length; i < len; i++){ | |
if (properties[i] in host){ | |
return true | |
} | |
} | |
return false | |
} | |
} | |
})() |
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
// true if CSS Regions is supported | |
Supports.cssProperty('flow-into'); | |
// true if CSS Regions Object Model is supported | |
Supports.omProperty('getNamedFlows'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment