Created
January 24, 2018 09:13
-
-
Save jcubic/9ef9fa2561de8430e953e2fe62011c20 to your computer and use it in GitHub Desktop.
Monkey patch for jQuery css to handle custom properties aka css variables
This file contains 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
$.fn.css = (function(css) { | |
return function fn(key, value) { | |
var self = this; | |
if (arguments.length == 1 && $.isPlainObject(arguments[0])) { | |
var data = arguments[0]; | |
Object.keys(data).forEach(function(key) { | |
fn.call(self, key, data[key]); | |
}); | |
} else if (key.match(/^\s*--/)) { | |
if (typeof value === 'undefined') { | |
return self[0].style.getPropertyValue(key); | |
} else { | |
self[0].style.setProperty(key, value); | |
} | |
} else { | |
return css.apply(self, arguments); | |
} | |
return self; | |
}; | |
})($.fn.css); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment