Skip to content

Instantly share code, notes, and snippets.

@klarstil
Last active December 12, 2015 04:28
Show Gist options
  • Save klarstil/4714128 to your computer and use it in GitHub Desktop.
Save klarstil/4714128 to your computer and use it in GitHub Desktop.
Simple feature detection
/**
* Tests if a property has a vendor prefix and returns the properly
* property.
*
* @param {string} prop - Property to test
* @param {string} propGroup - Group where the test property is located
* @returns {*} If the property was found, it will be returned. Otherwise false
* @private
*/
var _getVendorPrefix = function(prop, propGroup) {
var testEl = document.createElement('fakeElement'),
prefixes = ['', 'webkit', 'moz', 'ms', 'o'],
i, prefix, testProp;
// Modify the testEl
propGroup = propGroup || '';
if(propGroup.length) {
testEl = testEl[propGroup];
}
// Loop through the vendor prefixes
for(i in prefixes) {
prefix = prefixes[i];
// Vendor prefix property
if(prefix.length) {
prop = prop.charAt(0).toUpperCase() + prop.slice(1);
}
testProp = prefix + prop;
if(testEl[testProp] !== undefined) {
return testProp;
}
}
return false;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment