Skip to content

Instantly share code, notes, and snippets.

@termi
Last active December 17, 2015 11:39
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 termi/5603873 to your computer and use it in GitHub Desktop.
Save termi/5603873 to your computer and use it in GitHub Desktop.
CSS.supports
/** github.com/termi/CSS.supports */
if( !global.CSS || !global.CSS.supports ) {
if( !global.CSS ) {
/**
* @expose
*/
global.CSS = {};
}
if( !global.CSS.supports && global["supportsCSS"] ) {// Opera 12.10 impl
global.CSS.supports = global["supportsCSS"].bind(global);
}
else {
var _CSS_supports_cache = {};
/**
* @expose
*/
global.CSS.supports = function(msie, testElement, ToCamel_replacer, propertyName, propertyValue) {
var name_and_value = propertyName + "\\/" + propertyValue;
if( name_and_value in _CSS_supports_cache ) {
return _CSS_supports_cache[name_and_value];
}
/* TODO:: for IE < 9:
_ = document.documentElement.appendChild(document.createElement("_"))
_.currentStyle[propertyName] == propertyValue
*/
if(arguments.length < 5) {
throw new Error("WRONG_ARGUMENTS_ERR");//TODO:: DOMException ?
}
var __bind__RE_FIRST_LETTER = this
, propertyName_CC = (propertyName + "").replace(__bind__RE_FIRST_LETTER, ToCamel_replacer)
;
var result = propertyName && propertyValue && (propertyName_CC in testElement.style);
if( result ) {
if( msie ) {
if( /\(|\s/.test(propertyValue) ) {
try {
testElement.style[propertyName_CC] = propertyValue;// IE throw here, if unsupported this syntax. Exception: clip:rect(1px,1px,1px,1px)
result = !!testElement.style[propertyName_CC];
}
catch(e) {
result = false;
}
}
else {
testElement.style.cssText = "display:none;height:0;width:0;visibility:hidden;position:absolute;position:fixed;" + propertyName + ":" + propertyValue;
document.documentElement.appendChild(testElement);
result = testElement.currentStyle[propertyName_CC] == propertyValue;
document.documentElement.removeChild(testElement);
}
}
else {
testElement.style.cssText = propertyName + ":" + propertyValue;
result = testElement.style[propertyName_CC] == propertyValue;
}
}
testElement.style.cssText = "";
_CSS_supports_cache[name_and_value] = result;
return result;
}.bind(
/(-)([a-z])/g // __bind__RE_FIRST_LETTER
, "runtimeStyle" in document.documentElement
, global["document"].createElement("_")
, function(a, b, c) { // __bind__fromCSSPropToCamel_replacer
return c.toUpperCase()
}
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment