| 1 | import defaultView from "../window.js";
|
|---|
| 2 |
|
|---|
| 3 | function styleRemove(name) {
|
|---|
| 4 | return function() {
|
|---|
| 5 | this.style.removeProperty(name);
|
|---|
| 6 | };
|
|---|
| 7 | }
|
|---|
| 8 |
|
|---|
| 9 | function styleConstant(name, value, priority) {
|
|---|
| 10 | return function() {
|
|---|
| 11 | this.style.setProperty(name, value, priority);
|
|---|
| 12 | };
|
|---|
| 13 | }
|
|---|
| 14 |
|
|---|
| 15 | function styleFunction(name, value, priority) {
|
|---|
| 16 | return function() {
|
|---|
| 17 | var v = value.apply(this, arguments);
|
|---|
| 18 | if (v == null) this.style.removeProperty(name);
|
|---|
| 19 | else this.style.setProperty(name, v, priority);
|
|---|
| 20 | };
|
|---|
| 21 | }
|
|---|
| 22 |
|
|---|
| 23 | export default function(name, value, priority) {
|
|---|
| 24 | return arguments.length > 1
|
|---|
| 25 | ? this.each((value == null
|
|---|
| 26 | ? styleRemove : typeof value === "function"
|
|---|
| 27 | ? styleFunction
|
|---|
| 28 | : styleConstant)(name, value, priority == null ? "" : priority))
|
|---|
| 29 | : styleValue(this.node(), name);
|
|---|
| 30 | }
|
|---|
| 31 |
|
|---|
| 32 | export function styleValue(node, name) {
|
|---|
| 33 | return node.style.getPropertyValue(name)
|
|---|
| 34 | || defaultView(node).getComputedStyle(node, null).getPropertyValue(name);
|
|---|
| 35 | }
|
|---|