This repository has been archived by the owner on Mar 8, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathindex.js
88 lines (70 loc) · 1.39 KB
/
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
var camel = require('to-camel-case')
, computed = require('computed-style')
, type = require('type');
/**
* Expose `css`.
*/
module.exports = css;
/**
* Don't append `px`.
*/
var ignore = {
columnCount: true,
fillOpacity: true,
fontWeight: true,
lineHeight: true,
opacity: true,
orphans: true,
widows: true,
zIndex: true,
zoom: true
};
/**
* Get or set CSS properties of an `el`.
*
* @param {Element} el
* @param {String|Object} prop
* @param {String} value (optional)
*/
function css (el, prop, value) {
if (1 == arguments.length) return wrapped(el);
if (type(prop) == 'object') {
for (var key in prop) set(el, key, prop[key]);
return;
}
return arguments.length == 3
? set(el, prop, value)
: get(el, prop);
}
/**
* Wrap the given `el`.
*
* @param {Element} el
*/
function wrapped (el) {
return function(){
var args = [].slice.call(arguments);
return css.apply(null, [el].concat(args));
};
}
/**
* Get the current CSS `prop` value of an `el`.
*
* @param {Element} el
* @param {String} prop
*/
function get (el, prop) {
return computed(el)[prop];
}
/**
* Set a CSS `prop` to `value` on an `element`.
*
* @param {Element} element
* @param {String} prop
* @param {String} value
*/
function set (el, prop, value) {
prop = camel(prop);
if ('number' == typeof value && !ignore[prop]) value += 'px';
el.style[prop] = value;
}