|
|
@@ -7,34 +7,33 @@ var namespaces = {
|
|
|
module.exports = {
|
|
|
|
|
|
bind: function () {
|
|
|
- // check namespaced attributes
|
|
|
- if (this.el.namespaceURI.slice(-3) === 'svg') {
|
|
|
- var name = this.arg
|
|
|
- var colonIndex = name.indexOf(':')
|
|
|
- if (colonIndex > 0) {
|
|
|
- this.localName = name.slice(colonIndex + 1)
|
|
|
- this.namespace = namespaces[name.slice(0, colonIndex)]
|
|
|
- }
|
|
|
- }
|
|
|
- },
|
|
|
-
|
|
|
- update: function (value) {
|
|
|
- var el = this.el
|
|
|
- var ns = this.namespace
|
|
|
var name = this.arg
|
|
|
- if (value || value === 0) {
|
|
|
- if (ns) {
|
|
|
- el.setAttributeNS(ns, name, value)
|
|
|
- } else {
|
|
|
- el.setAttribute(name, value)
|
|
|
- }
|
|
|
+ var colonIndex = name.indexOf(':')
|
|
|
+ // check namespaced attributes
|
|
|
+ if (colonIndex > 0) {
|
|
|
+ this.localName = name.slice(colonIndex + 1)
|
|
|
+ this.namespace = namespaces[name.slice(0, colonIndex)]
|
|
|
+ this.update = namespaceHandler
|
|
|
} else {
|
|
|
- if (ns) {
|
|
|
- el.removeAttributeNS(ns, this.localName)
|
|
|
- } else {
|
|
|
- el.removeAttribute(name)
|
|
|
- }
|
|
|
+ this.update = defaultHandler
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+}
|
|
|
+
|
|
|
+function defaultHandler (value) {
|
|
|
+ if (value != null) {
|
|
|
+ this.el.setAttribute(this.arg, value)
|
|
|
+ } else {
|
|
|
+ this.el.removeAttribute(this.arg)
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+function namespaceHandler (value) {
|
|
|
+ var ns = this.namespace
|
|
|
+ if (value != null) {
|
|
|
+ this.el.setAttributeNS(ns, this.arg, value)
|
|
|
+ } else {
|
|
|
+ this.el.removeAttributeNS(ns, this.localName)
|
|
|
+ }
|
|
|
}
|