Skip to content

Instantly share code, notes, and snippets.

@oslego
Last active November 21, 2022 22:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oslego/4475244 to your computer and use it in GitHub Desktop.
Save oslego/4475244 to your computer and use it in GitHub Desktop.
Basic feature detection with prefix support.
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
}
}
})()
// 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