Skip to content

Commit

Permalink
Fixes #2077: workaround IE text node splitting issue that can make te…
Browse files Browse the repository at this point in the history
…xt bindings fail.
  • Loading branch information
Steven Orvell committed Jul 14, 2015
1 parent c46ec11 commit 312d11f
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/lib/annotations/annotations.html
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,23 @@
// `annote` is supplied as it is the annote.parent of added annotations
_parseChildNodesAnnotations: function(root, annote, list, callback) {
if (root.firstChild) {
for (var i=0, node=root.firstChild; node; node=node.nextSibling, i++){
for (var i=0, node=root.firstChild; node; node=node.nextSibling, i++) {
if (node.localName === 'template' &&
!node.hasAttribute('preserve-content')) {
this._parseTemplate(node, i, list, annote);
}
//
// collapse adjacent textNodes: fixes an IE issue that can cause
// text nodes to be inexplicably split =(
// note that root.normalize() should work but does not so we do this
// manually.
if (node.nodeType === Node.TEXT_NODE) {
var n = node.nextSibling;
while (n && (n.nodeType === Node.TEXT_NODE)) {
node.textContent += n.textContent;
root.removeChild(n);
n = n.nextSibling;
}
}
var childAnnotation = this._parseNodeAnnotations(node, list, callback);
if (childAnnotation) {
childAnnotation.parent = annote;
Expand Down
43 changes: 43 additions & 0 deletions test/smoke/ie-annotations.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<!doctype html>
<html>
<head>

<title>annotations</title>

<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">

<script src="../../../webcomponentsjs/webcomponents-lite.js"></script>
<link rel="import" href="../../polymer.html">

</head>
<body>

<dom-module id="my-component">
<template>
<p>&copy;</p>
<p>{{myText}}</p>
</template>
</dom-module>

<script>
HTMLImports.whenReady(function() {
Polymer({
is: "my-component",
properties: {
myText: {
type: String,
value: 'Sample'
}
},
});
});
</script>

<h1>Bind correctly?</h1>

<my-component></my-component>


</body>
</html>
29 changes: 29 additions & 0 deletions test/smoke/ie-split-text.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<!doctype html>
<html>
<head>

<title>annotations</title>

<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">

<script src="../../../webcomponentsjs/webcomponents-lite.js"></script>
<link rel="import" href="../../src/polymer-lib.html">

</head>
<body>

<p>&copy;</p>
<p id="binding">{{binding}}</p>
<h4>textNodes above</h4>
<script>
var c$ = binding.childNodes;
for (var i=0; i < c$.length; i++) {
var d = document.createElement('div');
d.innerHTML = c$[i].textContent;
document.body.appendChild(d);
}
</script>

</body>
</html>
19 changes: 19 additions & 0 deletions test/unit/bind-elements.html
Original file line number Diff line number Diff line change
Expand Up @@ -390,3 +390,22 @@
shouldNotChangeChanged: function() { }
});
</script>

<dom-module id="x-entity-and-binding">
<template>
<p>&copy;</p>
<p id="binding">{{myText}}</p>
</template>
</dom-module>

<script>
Polymer({
is: "x-entity-and-binding",
properties: {
myText: {
type: String,
value: 'binding'
}
}
});
</script>
13 changes: 13 additions & 0 deletions test/unit/bind.html
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,19 @@

</script>

<script>
suite('binding corner cases', function() {

// IE can create adjacent text nodes that split bindings; this test
// ensures the code that addresses this is functional
test('text binding after entity', function() {
var el = document.createElement('x-entity-and-binding');
assert.equal(el.$.binding.textContent, 'binding');
});

});
</script>



</body>
Expand Down

0 comments on commit 312d11f

Please sign in to comment.