From: Alexander Ebert Date: Sun, 21 Aug 2016 22:22:27 +0000 (+0200) Subject: Fixed insert order of elements X-Git-Tag: 3.0.0_Beta_1~604 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=4dbd720323b7e252888d5078b2a490649ac5cdab;p=GitHub%2FWoltLab%2FWCF.git Fixed insert order of elements Prepending an element would cause script tags to be prepended first, causing any JavaScript to be executed immediately. This could be an issue if the code relies on the DOM that originally preceeded it. --- diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Dom/Util.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Dom/Util.js index d8d2d0cae6..e3370a0471 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Dom/Util.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Dom/Util.js @@ -275,25 +275,39 @@ define(['Environment', 'StringUtil'], function(Environment, StringUtil) { var element = elCreate('div'); this.setInnerHtml(element, html); + var node; if (insertMethod === 'append' || insertMethod === 'after') { while (element.childNodes.length) { + node = element.childNodes[0]; + if (insertMethod === 'append') { - referenceElement.appendChild(element.childNodes[0]); + referenceElement.appendChild(node); } else { - this.insertAfter(element.childNodes[0], referenceElement); + this.insertAfter(node, referenceElement); } } } else if (insertMethod === 'prepend' || insertMethod === 'before') { + var scriptTags = []; for (var i = element.childNodes.length - 1; i >= 0; i--) { + node = element.childNodes[i]; + if (node.nodeType === Node.ELEMENT_NODE && node.nodeName === 'SCRIPT') { + scriptTags.push(node); + continue; + } + if (insertMethod === 'prepend') { - this.prepend(element.childNodes[i], referenceElement); + this.prepend(node, referenceElement); } else { - referenceElement.parentNode.insertBefore(element.childNodes[i], referenceElement); + referenceElement.parentNode.insertBefore(node, referenceElement); } } + + scriptTags.forEach(function (scriptTag) { + document.body.appendChild(scriptTag); + }); } else { throw new Error("Unknown insert method '" + insertMethod + "'.");