Skip to content

Commit

Permalink
Improve browser compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
Manuel Baclet committed Apr 9, 2017
1 parent ec45a15 commit dc81db0
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/barbiche.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,11 @@ function Barbiche(opt) {
if (attrFound) node.setAttribute(prefixedGlobalAttr, JSON.stringify(bbAttrs));
if (node.nodeName === TEMPLATE) {
compile(node.content, template);
if (!attrFound) node.parentNode.replaceChild(node.content, node);
// Some browsers such as Safari 6.2 does not support replaceChild(docFrag,...)
if (!attrFound) {
node.parentNode.insertBefore(node.content, node);
node.parentNode.removeChild(node);
}
} else {
ArrayFrom.call(node.childNodes).forEach(function(child) {
compile(child, template);
Expand Down Expand Up @@ -272,14 +276,16 @@ function Barbiche(opt) {
node.parentNode.replaceChild(node.ownerDocument.createTextNode(value), node);
} else node.parentNode.removeChild(node);
} else if (bbAttrs.html) {
// Some browsers such as Safari 6.2 does not support replaceChild(docFrag,...)
value = (template.closures[bbAttrs.html])();
if (value instanceof Node) node.parentNode.replaceChild(value, node);
if (value instanceof Node) node.parentNode.insertBefore(value, node);
else if (value != null) {
(function(t) {
t.innerHTML = value;
node.parentNode.replaceChild(t.content, node);
node.parentNode.insertBefore(t.content, node);
})(createTemplate());
} else node.parentNode.removeChild(node);
}
node.parentNode.removeChild(node);
} else if (node.nodeName === TEMPLATE && !node.hasAttribute(prefixedInertAttr)) {
if (bbAttrs.repeat) {
if (!nodeContext) {
Expand Down

0 comments on commit dc81db0

Please sign in to comment.