Better detection for Range support.
This commit is contained in:
parent
9a42242454
commit
713b458aea
1 changed files with 19 additions and 6 deletions
25
mithril.js
25
mithril.js
|
|
@ -624,6 +624,23 @@ var m = (function app(window, undefined) {
|
||||||
else if (cached.children.tag) unload(cached.children);
|
else if (cached.children.tag) unload(cached.children);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var insertAdjacentBeforeEnd = (function () {
|
||||||
|
var rangeStrategy = function (parentElement, data) {
|
||||||
|
parentElement.appendChild($document.createRange().createContextualFragment(data));
|
||||||
|
};
|
||||||
|
var insertAdjacentStrategy = function (parentElement, data) {
|
||||||
|
parentElement.insertAdjacentHTML("beforeend", data);
|
||||||
|
};
|
||||||
|
|
||||||
|
try {
|
||||||
|
$document.createRange().createContextualFragment('x');
|
||||||
|
return rangeStrategy;
|
||||||
|
} catch (e) {
|
||||||
|
return insertAdjacentStrategy;
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
|
||||||
function injectHTML(parentElement, index, data) {
|
function injectHTML(parentElement, index, data) {
|
||||||
var nextSibling = parentElement.childNodes[index];
|
var nextSibling = parentElement.childNodes[index];
|
||||||
if (nextSibling) {
|
if (nextSibling) {
|
||||||
|
|
@ -636,12 +653,8 @@ var m = (function app(window, undefined) {
|
||||||
}
|
}
|
||||||
else nextSibling.insertAdjacentHTML("beforebegin", data);
|
else nextSibling.insertAdjacentHTML("beforebegin", data);
|
||||||
}
|
}
|
||||||
else {
|
else insertAdjacentBeforeEnd(parentElement, data);
|
||||||
if (window.Range && window.Range.prototype.createContextualFragment) {
|
|
||||||
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) {
|
||||||
nodes.push(parentElement.childNodes[index]);
|
nodes.push(parentElement.childNodes[index]);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue