From 0b9cbd1f8219660fab3783858cc5bc63cccec678 Mon Sep 17 00:00:00 2001 From: John Long Date: Tue, 5 Jan 2016 12:20:40 -0700 Subject: [PATCH] Moves createContextualFragment into try/catch function --- mithril.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/mithril.js b/mithril.js index 2e1153bb..f91a8848 100644 --- a/mithril.js +++ b/mithril.js @@ -622,6 +622,13 @@ var m = (function app(window, undefined) { else if (cached.children.tag) unload(cached.children); } } + function appendTextFragment(parentElement, data) { + try { + parentElement.appendChild($document.createRange().createContextualFragment(data)); + } catch (e) { + parentElement.insertAdjacentHTML("beforeend", data); + } + } function injectHTML(parentElement, index, data) { var nextSibling = parentElement.childNodes[index]; if (nextSibling) { @@ -635,10 +642,7 @@ var m = (function app(window, undefined) { else nextSibling.insertAdjacentHTML("beforebegin", data); } else { - if (window.Range && window.Range.prototype.createContextualFragment) { - parentElement.appendChild($document.createRange().createContextualFragment(data)); - } - else parentElement.insertAdjacentHTML("beforeend", data); + appendTextFragment(parentElement, data); } var nodes = []; while (parentElement.childNodes[index] !== nextSibling) {