css(document.body, {
fontSize: 72,
opacity: '0.5',
background: 'red'
});
-
-
Save yckart/6440596 to your computer and use it in GitHub Desktop.
CSS
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
function ( | |
a, // a single dom-node | |
b, // an object containing your properties and values | |
c // value-placholder | |
) { | |
for (var d in b) // iterate over the css-object | |
a.style[d] = // add the property | |
(c = b[d]) + // assign the value | |
// if the property is none of this: | |
// columnCount|fillOpacity|fontWeight|lineHeight|opacity|order|orphans|widows|zIndex|zoom/ | |
(!/columnC|fillOpac|fontW|lineH|opac|order|orph|wido|zI|zo/i.test(d) | |
&& // and | |
+c === c // it is a number | |
? 'px' // append `'px'` as default unit | |
: '' // otherwise append nothing | |
); | |
} |
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
function(a,b,c){for(var d in b)a.style[d]=(c=b[d])+(!/columnC|fillOpac|fontW|lineH|opac|order|orph|wido|zI|zo/i.test(d)&&+c===c?'px':'');} |
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
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE | |
Version 2, December 2004 | |
Copyright (C) 2013 Yannick Albert <http://yckart.com> | |
Everyone is permitted to copy and distribute verbatim or modified | |
copies of this license document, and changing it is allowed as long | |
as the name is changed. | |
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE | |
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION | |
0. You just DO WHAT THE FUCK YOU WANT TO. |
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
{ | |
"name": "CSS", | |
"description": "Set one or more CSS properties for every matched element.", | |
"keywords": [ | |
"style", | |
"css", | |
"object", | |
"dom", | |
"node" | |
] | |
} |
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
<!DOCTYPE html> | |
<title>Foo</title> | |
<div>Expected value: <b style="font-size: 72px; opacity: 0.5; background: red">140byt.es</b></div> | |
<div>Actual value: <b id="ret">140byt.es</b></div> | |
<script> | |
var css = function(a,b,c){for(var d in b)a.style[d]=(c=b[d])+(!/columnC|fillOpac|fontW|lineH|opac|order|orph|wido|zI|zo/i.test(d)&&+c===c?'px':'');}; | |
css(document.getElementById('ret'), { | |
fontSize: 72, | |
opacity: '0.5', | |
background: 'red' | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment