source: node_modules/d3-selection/src/selection/attr.js@ e4c61dd

Last change on this file since e4c61dd was e4c61dd, checked in by istevanoska <ilinastevanoska@…>, 6 months ago

Prototype 1.1

  • Property mode set to 100644
File size: 1.4 KB
Line 
1import namespace from "../namespace.js";
2
3function attrRemove(name) {
4 return function() {
5 this.removeAttribute(name);
6 };
7}
8
9function attrRemoveNS(fullname) {
10 return function() {
11 this.removeAttributeNS(fullname.space, fullname.local);
12 };
13}
14
15function attrConstant(name, value) {
16 return function() {
17 this.setAttribute(name, value);
18 };
19}
20
21function attrConstantNS(fullname, value) {
22 return function() {
23 this.setAttributeNS(fullname.space, fullname.local, value);
24 };
25}
26
27function attrFunction(name, value) {
28 return function() {
29 var v = value.apply(this, arguments);
30 if (v == null) this.removeAttribute(name);
31 else this.setAttribute(name, v);
32 };
33}
34
35function attrFunctionNS(fullname, value) {
36 return function() {
37 var v = value.apply(this, arguments);
38 if (v == null) this.removeAttributeNS(fullname.space, fullname.local);
39 else this.setAttributeNS(fullname.space, fullname.local, v);
40 };
41}
42
43export default function(name, value) {
44 var fullname = namespace(name);
45
46 if (arguments.length < 2) {
47 var node = this.node();
48 return fullname.local
49 ? node.getAttributeNS(fullname.space, fullname.local)
50 : node.getAttribute(fullname);
51 }
52
53 return this.each((value == null
54 ? (fullname.local ? attrRemoveNS : attrRemove) : (typeof value === "function"
55 ? (fullname.local ? attrFunctionNS : attrFunction)
56 : (fullname.local ? attrConstantNS : attrConstant)))(fullname, value));
57}
Note: See TracBrowser for help on using the repository browser.