| 955 | return this.each(d3_selection_on(type, listener, capture)); |
| 956 | }; |
| 957 | function d3_selection_on(type, listener, capture) { |
| 958 | var name = "__on" + type, i = type.indexOf("."), wrap = d3_selection_onListener; |
| 959 | if (i > 0) type = type.substring(0, i); |
| 960 | var filter = d3_selection_onFilters.get(type); |
| 961 | if (filter) type = filter, wrap = d3_selection_onFilter; |
| 962 | function onRemove() { |
| 963 | var l = this[name]; |
| 964 | if (l) { |
| 965 | this.removeEventListener(type, l, l.$); |
| 966 | delete this[name]; |
| 967 | } |
| 968 | } |
| 969 | function onAdd() { |
| 970 | var l = wrap(listener, d3_array(arguments)); |
| 971 | onRemove.call(this); |
| 972 | this.addEventListener(type, this[name] = l, l.$ = capture); |
| 973 | l._ = listener; |
| 974 | } |
| 975 | function removeAll() { |
| 976 | var re = new RegExp("^__on([^.]+)" + d3.requote(type) + "$"), match; |
| 977 | for (var name in this) { |
| 978 | if (match = name.match(re)) { |
| 979 | var l = this[name]; |
| 980 | this.removeEventListener(match[1], l, l.$); |
| 981 | delete this[name]; |
| 982 | } |
| 983 | } |
| 984 | } |
| 985 | return i ? listener ? onAdd : onRemove : listener ? d3_noop : removeAll; |
| 986 | } |
| 987 | var d3_selection_onFilters = d3.map({ |
| 988 | mouseenter: "mouseover", |
| 989 | mouseleave: "mouseout" |