on master help sign in
Fix #671, update links properly
dd55bfdEvan Czaplicki
runtime/Render/Element.js+23−26
@@ -28,20 +28,6 @@ function setProps(elem, node) {
28 node.id = props.tag;
28 node.id = props.tag;
29 }
29 }
30
30
31− if (props.href !== '') {
32− var a = newElement('a');
33− a.href = props.href;
34− a.style.width = '100%';
35− a.style.height = '100%';
36− a.style.top = 0;
37− a.style.left = 0;
38− a.style.display = 'block';
39− a.style.position = 'absolute';
40− node.style.position = 'relative';
41− a.style.pointerEvents = 'auto';
42− node.appendChild(a);
43− }
44−
45 if (props.hover.ctor !== '_Tuple0') {
31 if (props.hover.ctor !== '_Tuple0') {
46 addHover(node, props.hover);
32 addHover(node, props.hover);
47 }
33 }
@@ -50,6 +36,15 @@ function setProps(elem, node) {
50 addClick(node, props.click);
36 addClick(node, props.click);
51 }
37 }
52
38
39+ if (props.href !== '') {
40+ var anchor = newElement('a');
41+ anchor.href = props.href;
42+ anchor.style.display = 'block';
43+ anchor.style.pointerEvents = 'auto';
44+ anchor.appendChild(node);
45+ node = anchor;
46+ }
47+
53 return node;
48 return node;
54}
49}
55
50
@@ -394,19 +389,21 @@ function updateProps(node, curr, next) {
394
389
395 if (nextProps.href !== currProps.href) {
390 if (nextProps.href !== currProps.href) {
396 if (currProps.href === '') {
391 if (currProps.href === '') {
392+ // add a surrounding href
397− var a = newElement('a');
393+ var anchor = newElement('a');
398− a.href = nextProps.href;
394+ anchor.href = nextProps.href;
399− a.style.width = '100%';
400− a.style.height = '100%';
401− a.style.top = 0;
402− a.style.left = 0;
403− a.style.display = 'block';
395+ anchor.style.display = 'block';
404− a.style.position = 'absolute';
405− node.style.position = 'relative';
406− a.style.pointerEvents = 'auto';
396+ anchor.style.pointerEvents = 'auto';
397+
398+ node.parentNode.replaceChild(anchor, node);
407− node.appendChild(a);
399+ anchor.appendChild(node);
400+ } else if (nextProps.href === '') {
401+ // remove the surrounding href
402+ var anchor = node.parentNode;
403+ anchor.parentNode.replaceChild(node, anchor);
408 } else {
404 } else {
405+ // just update the link
409− node.lastNode.href = nextProps.href;
406+ node.parentNode.href = nextProps.href;
410 }
407 }
411 }
408 }
412
409