Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "rangy",
"description": "A cross-browser DOM range and selection library",
"version": "1.3.1-dev",
"version": "1.3.2-dev",
"author": {
"name": "Tim Down",
"email": "[email protected]",
Expand Down
14 changes: 12 additions & 2 deletions src/core/domrange.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
var util = api.util;
var DomPosition = dom.DomPosition;
var DOMException = api.DOMException;

var voidElements = ["area", "base", "br", "col", "command", "embed", "hr", "img", "input", "keygen", "link", "meta", "param", "source", "track", "wbr"];
var isCharacterDataNode = dom.isCharacterDataNode;
var getNodeIndex = dom.getNodeIndex;
var isOrIsAncestorOf = dom.isOrIsAncestorOf;
Expand Down Expand Up @@ -54,7 +54,11 @@
n.parentNode.insertBefore(node, o == 0 ? n : splitDataNode(n, o));
}
} else if (o >= n.childNodes.length) {
n.appendChild(node);
if (canAppendChild(n)) {
n.appendChild(node);
} else {
n.parentNode.insertBefore(node, n);
}
} else {
n.insertBefore(node, n.childNodes[o]);
}
Expand All @@ -75,6 +79,12 @@
return touchingIsIntersecting ? startComparison <= 0 && endComparison >= 0 : startComparison < 0 && endComparison > 0;
}

function canAppendChild(element) {
var nodeName = element.tagName.toLowerCase();

return voidElements.indexOf(nodeName) === -1;
}

function cloneSubtree(iterator) {
var partiallySelected;
for (var node, frag = getRangeDocument(iterator.range).createDocumentFragment(), subIterator; node = iterator.next(); ) {
Expand Down