Spaces:
Running
Running
File size: 2,125 Bytes
e7b2eb4 | 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 | import "../core/document";
import "selection";
d3_selectionPrototype.style = function(name, value, priority) {
var n = arguments.length;
if (n < 3) {
// For style(object) or style(object, string), the object specifies the
// names and values of the attributes to set or remove. The values may be
// functions that are evaluated for each element. The optional string
// specifies the priority.
if (typeof name !== "string") {
if (n < 2) value = "";
for (priority in name) this.each(d3_selection_style(priority, name[priority], value));
return this;
}
// For style(string), return the computed style value for the first node.
if (n < 2) {
var node = this.node();
return d3_window(node).getComputedStyle(node, null).getPropertyValue(name);
}
// For style(string, string) or style(string, function), use the default
// priority. The priority is ignored for style(string, null).
priority = "";
}
// Otherwise, a name, value and priority are specified, and handled as below.
return this.each(d3_selection_style(name, value, priority));
};
function d3_selection_style(name, value, priority) {
// For style(name, null) or style(name, null, priority), remove the style
// property with the specified name. The priority is ignored.
function styleNull() {
this.style.removeProperty(name);
}
// For style(name, string) or style(name, string, priority), set the style
// property with the specified name, using the specified priority.
function styleConstant() {
this.style.setProperty(name, value, priority);
}
// For style(name, function) or style(name, function, priority), evaluate the
// function for each element, and set or remove the style property as
// appropriate. When setting, use the specified priority.
function styleFunction() {
var x = value.apply(this, arguments);
if (x == null) this.style.removeProperty(name);
else this.style.setProperty(name, x, priority);
}
return value == null
? styleNull : (typeof value === "function"
? styleFunction : styleConstant);
}
|