-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstyle.js
46 lines (42 loc) · 1.01 KB
/
style.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
var prefixes = ['-webkit-', '-moz-', '-ms-']
var importantRE = /!important;?$/
module.exports = {
bind: function () {
var prop = this.arg
if (!prop) return
if (prop.charAt(0) === '$') {
// properties that start with $ will be auto-prefixed
prop = prop.slice(1)
this.prefixed = true
}
this.prop = prop
},
update: function (value) {
var prop = this.prop
// cast possible numbers/booleans into strings
if (value != null) {
value += ''
}
if (prop) {
var isImportant = importantRE.test(value)
? 'important'
: ''
if (isImportant) {
value = value.replace(importantRE, '').trim()
}
this.el.style.setProperty(prop, value, isImportant)
if (this.prefixed) {
var i = prefixes.length
while (i--) {
this.el.style.setProperty(
prefixes[i] + prop,
value,
isImportant
)
}
}
} else {
this.el.style.cssText = value
}
}
}