-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathindex.js
58 lines (47 loc) · 918 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/**
* Module Dependencies
*/
var debug = require('debug')('css');
var set = require('./lib/style');
var get = require('./lib/css');
/**
* Expose `css`
*/
module.exports = css;
/**
* Get and set css values
*
* @param {Element} el
* @param {String|Object} prop
* @param {Mixed} val
* @return {Element} el
* @api public
*/
function css(el, prop, val) {
if (!el) return;
if (undefined !== val) {
var obj = {};
obj[prop] = val;
debug('setting styles %j', obj);
return setStyles(el, obj);
}
if ('object' == typeof prop) {
debug('setting styles %j', prop);
return setStyles(el, prop);
}
debug('getting %s', prop);
return get(el, prop);
}
/**
* Set the styles on an element
*
* @param {Element} el
* @param {Object} props
* @return {Element} el
*/
function setStyles(el, props) {
for (var prop in props) {
set(el, prop, props[prop]);
}
return el;
}