Skip to content
Code-Schnipsel Gruppen Projekte
Commit 6e4b9c8e erstellt von Jan Wennrich's avatar Jan Wennrich
Dateien durchsuchen

Merge branch 'next-2.x' into 'main'

Release

See merge request !28
Übergeordnete 77802b5f 03e6bfcc
No related branches found
Tags 2.0.3
2 Merge Requests!31Update 'next-3.x' with latest changes from 'main',!28Release
Pipeline #9314 mit Warnungen bestanden mit Phasen
in 1 Minute und 9 Sekunden
......@@ -184,7 +184,7 @@ define('package/quiqqer/html-snippets/bin/backend/Snippets', [
if (!this.$Project) {
return;
}
console.log(123);
require([
'package/quiqqer/html-snippets/bin/backend/controls/windows/AddSnippet'
], (AddSnippet) => {
......
(function() {
'use strict';
const loadNode = function(Node) {
if (Node.getAttribute('data-qui-html-snippet-gdpr-loaded')) {
return;
}
const processSnippetNodes = function(nodes) {
// Gather all HTML snippet nodes ("template" elements with a specific "data-" attribute)
const SnippetsNodeList = document.querySelectorAll('template[data-qui-html-snippet="gdpr"]');
Node.innerHTML = atob(Node.innerHTML);
const scripts = Array.from(Node.getElementsByTagName('script'));
SnippetsNodeList.forEach((SnippetNode) => {
const gdprCategory = SnippetNode.getAttribute('data-qui-html-snippet-gdpr-category');
scripts.forEach((script) => {
const newScript = document.createElement('script');
newScript.textContent = script.textContent;
// Only decode (and execute) the snippet node, if the corresponding gdpr category was accepted
window.GDPR.waitForCookieCategoryAcceptance(gdprCategory).then(() => {
decodeSnippetNode(SnippetNode);
});
});
};
const decodeSnippetNode = function(SnippetNode) {
// The node's inner HTML is base64 encoded, turn it back to normal HTML
SnippetNode.innerHTML = atob(SnippetNode.innerHTML);
// The snippet code is in a wrapping <template> node and thus isn't interpreted
// Therefore we have to move all nodes inside this template snippet node into the document
// We do that by iterating over all direct children of the template element and...
Array.from(SnippetNode.content.children).forEach(ChildNode => {
let NodeToInsert = ChildNode;
let i, len, attribute;
// ...if it is a script tag it needs special treatment
if (ChildNode.tagName === 'SCRIPT') {
// "script" tags are not executed when moved from the snippet node to the document
// Therefore a new element has to be created instead
// The new element is executed when added to the document
NodeToInsert = createExecutableCopyOfScriptNode(ChildNode);
for (i = 0, len = script.attributes.length; i < len; i++) {
attribute = script.attributes[i];
newScript.setAttribute(attribute.name, attribute.value);
// Remove the original script node as we are using the copy now
ChildNode.remove();
}
script.parentNode.replaceChild(newScript, script);
// ...moving the child node from inside the template snippet node in front of the snippet node
SnippetNode.insertAdjacentElement('beforebegin', NodeToInsert);
});
Node.setAttribute('data-qui-html-snippet-gdpr-loaded', 1);
Node.style.display = '';
// ...and deleting the now empty snippet node
SnippetNode.remove();
};
const fetchNodes = function(nodes) {
nodes.forEach((Node) => {
const gdprCategory = Node.getAttribute('data-qui-html-snippet-gdpr-category');
const createExecutableCopyOfScriptNode = function (ScriptNode) {
const ExecutableScriptNode = document.createElement('script');
if (window.GDPR.isCookieCategoryAccepted(gdprCategory)) {
loadNode(Node);
} else {
window.GDPR.waitForCookieCategoryAcceptance(gdprCategory).then(() => {
loadNode(Node);
});
}
// Copy the script's text content (the JavaScript code)
ExecutableScriptNode.textContent = ScriptNode.textContent;
// Copy all the script's attributes
Array.from(ScriptNode.attributes).forEach(ScriptAttribute => {
ExecutableScriptNode.setAttribute(ScriptAttribute.name, ScriptAttribute.value);
});
return ExecutableScriptNode;
};
fetchNodes(document.querySelectorAll('[data-qui-html-snippet="gdpr"]'));
processSnippetNodes();
window.whenQuiLoaded().then(() => {
fetchNodes(document.querySelectorAll('[data-qui-html-snippet="gdpr"]'));
});
window.whenQuiLoaded().then(processSnippetNodes);
})();
......@@ -67,17 +67,19 @@ class SnippetTemplateEvent
continue;
}
// consider gdpr status
$div = '<script ';
$div .= ' data-qui-html-snippet="gdpr"';
$div .= ' data-qui-html-snippet-gdpr-category="' . $snippet['gdpr'] . '"';
$div .= ' style="display: none"';
$div .= ' type="text/plain"';
$div .= '>';
$div .= base64_encode($snippet['snippet']);
$div .= '</script>';
$Collector->append($div);
$snippetGdprCategory = $snippet['gdpr'];
$snippetContentEncoded = base64_encode($snippet['snippet']);
$snippetHtml = <<<EOF
<template
data-qui-html-snippet="gdpr"
data-qui-html-snippet-gdpr-category="$snippetGdprCategory"
>
$snippetContentEncoded
</template>
EOF;
$Collector->append($snippetHtml);
}
}
}
0% oder .
You are about to add 0 people to the discussion. Proceed with caution.
Bearbeitung dieser Nachricht zuerst beenden!
Bitte registrieren oder zum Kommentieren