Created
September 3, 2013 05:19
-
-
Save mateuszkocz/6419945 to your computer and use it in GitHub Desktop.
Supports for CSS properties in JavaScript. Source: http://ryanmorr.com/detecting-css-style-support
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
(function(win){ | |
"use strict"; | |
var el = win.document.createElement('div'), | |
camelRe = /-([a-z]|[0-9])/ig, | |
cache = {}, | |
support, | |
camel, | |
key; | |
win.isStyleSupported = function(style, value){ | |
value = arguments.length === 2 ? value : 'inherit'; | |
if('CSS' in win && 'supports' in win.CSS){ | |
return win.CSS.supports(style, value); | |
} | |
if('supportsCSS' in win){ | |
return win.supportsCSS(style, value); | |
} | |
key = style + ':' + value; | |
if(key in cache){ | |
return cache[key]; | |
} | |
support = false; | |
camel = style.replace(camelRe, function(all, letter){ | |
return (letter + '').toUpperCase(); | |
}); | |
support = (typeof el.style[camel] === 'string'); | |
el.style.cssText = style+':'+value; | |
support = support && (el.style[camel] !== ''); | |
return cache[key] = support; | |
}; | |
})(this); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment