-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathcomputed.js
More file actions
74 lines (60 loc) · 1.47 KB
/
computed.js
File metadata and controls
74 lines (60 loc) · 1.47 KB
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
/**
* Module Dependencies
*/
var debug = require('debug')('css:computed');
var withinDocument = require('within-document');
var styles = require('./styles');
var camelcase = require('to-camel-case');
var hooks = require('./hooks');
/**
* Expose `computed`
*/
module.exports = computed;
/**
* Get the computed style
*
* @param {Element} el
* @param {String} prop
* @param {Array} precomputed (optional)
* @return {Array}
* @api private
*/
function computed(el, prop, precomputed) {
var computed = precomputed || styles(el);
var ret;
if (!computed) return;
if (computed.getPropertyValue) {
ret = computed.getPropertyValue(prop) || computed[prop];
} else {
ret = computed[prop];
}
if ('' === ret && !withinDocument(el)) {
debug('element not within document, try finding from style attribute');
ret = get(el, prop);
}
debug('computed value of %s: %s', prop, ret);
// Support: IE
// IE returns zIndex value as an integer.
return undefined === ret ? ret : ret + '';
}
/**
* Get the style
*
* @param {Element} el
* @param {String} prop
* @param {Mixed} extra
* @return {String}
*/
function get(el, prop, extra) {
var style = el.style;
var hook = hooks[prop] || hooks[orig];
var orig = camelcase(prop);
var ret;
if (hook && hook.get && undefined !== (ret = hook.get(el, false, extra))) {
debug('get hook defined, returning: %s', ret);
return ret;
}
ret = style[prop];
debug('getting %s', ret);
return ret;
}