Commit f584d356 by Thimo Kraemer

Execute inserted script tags on dom manipulation

parent 2dcfa3a6
/*
* KSS-RPC v0.11-beta
* KSS-RPC v0.12-beta
*
* Copyright (c) 2017, joonis new media
* Author: Thimo Kraemer <thimo.kraemer@joonis.de>
......@@ -61,7 +61,7 @@
******************************************************************************************/
var kss = {
version: '0.11-beta',
version: '0.12-beta',
_initialized: false,
_ruleSheets: {},
_eventBinders: {},
......@@ -1749,42 +1749,61 @@ kss.cssQuery = function(selector, context, dropContext) {
catch (err) { return result; } // IE8
};
kss._execScripts = function(node) {
var scripts = [node];
if (node.tagName.toLowerCase() != 'script')
scripts = node.getElementsByTagName('script');
kss.each(scripts, function(script) {
var cloned = document.createElement('script');
cloned.text = script.text;
kss.each(script.attributes, function(attr) {
cloned.setAttribute(attr.name, attr.value);
});
script.parentNode.replaceChild(cloned, script);
});
};
kss.replaceInnerHTML = function(node, html) {
node.innerHTML = html;
kss._execScripts(node);
kss.applyRules(node);
};
kss.replaceHTML = function(node, html) {
var parent = node.parentNode;
if (document.all && !window.atob
&& node.tagName.toLowerCase() == 'body') {
// IE<=9 does not allow to set body.outerHTML
// The body tag itself will be removed from innerHTML.
document.body.innerHTML = html;
kss.applyRules(parent);
return;
node.innerHTML = html;
}
else {
node.outerHTML = html;
}
node.outerHTML = html;
kss.applyRules(parent);
kss._execScripts(node);
kss.applyRules(node.parentNode);
};
kss.appendHTML = function(node, html) {
node.insertAdjacentHTML('beforeend', html);
kss._execScripts(node.lastElementChild);
kss.applyRules(node);
};
kss.prependHTML = function(node, html) {
node.insertAdjacentHTML('afterbegin', html);
kss._execScripts(node.firstElementChild);
kss.applyRules(node);
};
kss.insertHTMLAfter = function(node, html) {
node.insertAdjacentHTML('afterend', html);
kss._execScripts(node.nextElementSibling);
kss.applyRules(node.parentNode);
};
kss.insertHTMLBefore = function(node, html) {
node.insertAdjacentHTML('beforebegin', html);
kss._execScripts(node.previousElementSibling);
kss.applyRules(node.parentNode);
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment