Moves createContextualFragment into try/catch function
This commit is contained in:
parent
d5af96f233
commit
0b9cbd1f82
1 changed files with 8 additions and 4 deletions
12
mithril.js
12
mithril.js
|
|
@ -622,6 +622,13 @@ var m = (function app(window, undefined) {
|
||||||
else if (cached.children.tag) unload(cached.children);
|
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) {
|
function injectHTML(parentElement, index, data) {
|
||||||
var nextSibling = parentElement.childNodes[index];
|
var nextSibling = parentElement.childNodes[index];
|
||||||
if (nextSibling) {
|
if (nextSibling) {
|
||||||
|
|
@ -635,10 +642,7 @@ var m = (function app(window, undefined) {
|
||||||
else nextSibling.insertAdjacentHTML("beforebegin", data);
|
else nextSibling.insertAdjacentHTML("beforebegin", data);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (window.Range && window.Range.prototype.createContextualFragment) {
|
appendTextFragment(parentElement, data);
|
||||||
parentElement.appendChild($document.createRange().createContextualFragment(data));
|
|
||||||
}
|
|
||||||
else parentElement.insertAdjacentHTML("beforeend", data);
|
|
||||||
}
|
}
|
||||||
var nodes = [];
|
var nodes = [];
|
||||||
while (parentElement.childNodes[index] !== nextSibling) {
|
while (parentElement.childNodes[index] !== nextSibling) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue