Created
September 5, 2014 01:04
-
-
Save jehoshua02/d33892df58a95244cf5c to your computer and use it in GitHub Desktop.
Check if a style property is supported.
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
var styleSupported = (function () { | |
var supported = []; | |
var check = function (property) { | |
var body = document.body || document.documentElement; | |
var style = body.style; | |
// check for standard | |
if (typeof style[property] == 'string') { return true; } | |
// check for vendor specific | |
var vendors = ['Moz', 'webkit', 'Webkit', 'Khtml', 'O', 'ms']; | |
property = property.charAt(0).toUpperCase() + property.substr(1); | |
for (var i = 0; i < vendors.length; i++) { | |
var vendorProperty = vendors[i]; | |
if (typeof style[vendorProperty] == 'string') { return true; } | |
} | |
return false; | |
}; | |
return function (property) { | |
if (supported[property] === undefined) { | |
supported[property] = check(property); | |
} | |
return supported[property]; | |
}; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment