| 639 | return this.each(d3_selection_attr(name, value)); |
| 640 | }; |
| 641 | function d3_selection_attr(name, value) { |
| 642 | name = d3.ns.qualify(name); |
| 643 | function attrNull() { |
| 644 | this.removeAttribute(name); |
| 645 | } |
| 646 | function attrNullNS() { |
| 647 | this.removeAttributeNS(name.space, name.local); |
| 648 | } |
| 649 | function attrConstant() { |
| 650 | this.setAttribute(name, value); |
| 651 | } |
| 652 | function attrConstantNS() { |
| 653 | this.setAttributeNS(name.space, name.local, value); |
| 654 | } |
| 655 | function attrFunction() { |
| 656 | var x = value.apply(this, arguments); |
| 657 | if (x == null) this.removeAttribute(name); else this.setAttribute(name, x); |
| 658 | } |
| 659 | function attrFunctionNS() { |
| 660 | var x = value.apply(this, arguments); |
| 661 | if (x == null) this.removeAttributeNS(name.space, name.local); else this.setAttributeNS(name.space, name.local, x); |
| 662 | } |
| 663 | return value == null ? name.local ? attrNullNS : attrNull : typeof value === "function" ? name.local ? attrFunctionNS : attrFunction : name.local ? attrConstantNS : attrConstant; |
| 664 | } |
| 665 | function d3_collapse(s) { |
| 666 | return s.trim().replace(/\s+/g, " "); |
| 667 | } |