git ssb

1+

Matt McKegg / mutant



Commit 2225e7077f112ee10318157443adbbdb5748a50e

html-element: fix attribute namespace handling

Matt McKegg committed on 7/15/2016, 4:42:25 AM
Parent: 4cc5d7c35493700dc9a40f3cb6da6a2b6e3ce7dc

Files changed

html-element.jschanged
lib/apply-properties.jschanged
html-element.jsView
@@ -32,24 +32,23 @@
3232 var node = namespace
3333 ? document.createElementNS(namespace, tag.tagName)
3434 : document.createElement(tag.tagName)
3535
36- if (!namespace) {
37- if (tag.id) {
38- node.id = tag.id
39- }
40- if (tag.classes && tag.classes.length) {
41- node.className = tag.classes.join(' ')
42- }
36 + if (tag.id) {
37 + node.id = tag.id
4338 }
4439
40 + if (tag.classes && tag.classes.length) {
41 + node.className = tag.classes.join(' ')
42 + }
43 +
4544 var data = {
4645 targets: new Map(),
4746 releases: new Map()
4847 }
4948
5049 caches.set(node, data)
51- applyProperties(node, properties, namespace)
50 + applyProperties(node, properties)
5251 if (children != null) {
5352 appendChild(document, node, data, children)
5453 }
5554
lib/apply-properties.jsView
@@ -4,9 +4,9 @@
44 var caches = new global.WeakMap()
55
66 module.exports = applyProperties
77
8-function applyProperties (target, properties, namespace) {
8 +function applyProperties (target, properties) {
99 var data = caches.get(target)
1010 if (!data) {
1111 data = { releases: [] }
1212 caches.set(target, data)
@@ -31,21 +31,23 @@
3131 if (styleObs) {
3232 data.releases.push(bindStyle(target, styleObs, k))
3333 }
3434 }
35 + } else if (key === 'hooks') {
36 + value.forEach(function (v) {
37 + var release = v(target)
38 + if (typeof release === 'function') {
39 + data.releases.push(release)
40 + }
41 + })
3542 } else if (key === 'attributes') {
3643 for (var k in value) {
3744 var attrValue = resolve(value[k])
3845 var attrObs = isObservable(value[k]) ? value[k] : null
46 + target.setAttribute(k, attrValue)
3947
40- if (namespace) {
41- target.setAttributeNS(namespace, k, attrValue)
42- } else {
43- target.setAttribute(k, attrValue)
44- }
45-
4648 if (attrObs) {
47- data.releases.push(bindAttr(target, attrObs, k, namespace))
49 + data.releases.push(bindAttr(target, attrObs, k))
4850 }
4951 }
5052 } else if (key === 'events') {
5153 for (var name in value) {
@@ -93,38 +95,23 @@
9395 target.style.setProperty(key, value)
9496 })
9597 }
9698
97-function bindAttr (target, attrObs, key, namespace) {
99 +function bindAttr (target, attrObs, key) {
98100 return attrObs(function (value) {
99101 if (value == null) {
100- if (namespace) {
101- target.removeAttributeNS(namespace, key)
102- } else {
103- target.removeAttribute(key)
104- }
102 + target.removeAttribute(key)
105103 } else {
106- if (namespace) {
107- target.setAttributeNS(namespace, key, value)
108- } else {
109- target.setAttribute(key, value)
110- }
104 + target.setAttribute(key, value)
111105 }
112106 })
113107 }
114108
115-function bind (target, obs, key, namespace) {
109 +function bind (target, obs, key) {
116110 return obs(function (toValue) {
117- var fromValue = namespace
118- ? target.getAttributeNS(namespace, key)
119- : target.getAttribute(key)
120-
111 + var fromValue = target.getAttribute(key)
121112 if (fromValue !== toValue) {
122- if (namespace) {
123- target.setAttributeNS(namespace, key, toValue)
124- } else {
125- target.setAttribute(key, toValue)
126- }
113 + target.setAttribute(key, toValue)
127114 }
128115 })
129116 }
130117

Built with git-ssb-web