Last active
December 12, 2015 04:28
-
-
Save klarstil/4714128 to your computer and use it in GitHub Desktop.
Simple feature detection
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
/** | |
* 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