From cb72b822e4e933da31d7d9633f52508deecf12ca Mon Sep 17 00:00:00 2001 From: Amauri CHAMPEAUX Date: Thu, 25 Mar 2021 16:58:53 +0100 Subject: [PATCH] Add groupServices option --- tarteaucitron.js | 85 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 82 insertions(+), 3 deletions(-) diff --git a/tarteaucitron.js b/tarteaucitron.js index 10c60b1..c172c18 100644 --- a/tarteaucitron.js +++ b/tarteaucitron.js @@ -220,7 +220,8 @@ var tarteaucitron = { "useExternalCss": false, "useExternalJs": false, "mandatory": true, - "closePopup": false + "closePopup": false, + "groupServices": true }, params = tarteaucitron.parameters; @@ -340,7 +341,7 @@ var tarteaucitron = { html += '
'; html += ' '; html += '
'; - html += ' '; html += ' '; + html += '
'; + html += '
'; + html += ' '; + html += ' '; + html += '
'; + html += ''; + var ul = document.createElement('ul'); + ul.innerHTML = html; + item.insertBefore(ul, item.querySelector('#tarteaucitronServices_'+cat+'')); + document.querySelector('#tarteaucitronServices_' + cat).style.display = 'none'; + tarteaucitron.addClickEventToId("tarteaucitron-toggle-group-" + cat, function () { + tarteaucitron.userInterface.toggle('tarteaucitronServices_' + cat); + }); + tarteaucitron.addClickEventToId("tarteaucitron-accept-group-" + cat, function () { + tarteaucitron.userInterface.respondAll(true, cat); + }); + tarteaucitron.addClickEventToId("tarteaucitron-reject-group-" + cat, function () { + tarteaucitron.userInterface.respondAll(false, cat); + }); + } + }); + } + tarteaucitron.userInterface.color("", true); // add a little timeout to be sure everything is accessible setTimeout(function () { @@ -627,7 +669,7 @@ var tarteaucitron = { tarteaucitron.userInterface.respondAll(true); }); tarteaucitron.addClickEventToId("tarteaucitronAllDenied", function () { - tarteaucitron.userInterface.respondAll(false, '', true); + tarteaucitron.userInterface.respondAll(false); }); tarteaucitron.addClickEventToId("tarteaucitronAllDenied2", function () { tarteaucitron.userInterface.respondAll(false, '', true); @@ -943,6 +985,8 @@ var tarteaucitron = { index, s = tarteaucitron.services; + if (key !== "") { + if (status === true) { document.getElementById(key + 'Line').classList.add('tarteaucitronIsAllowed'); document.getElementById(key + 'Line').classList.remove('tarteaucitronIsDenied'); @@ -1013,6 +1057,41 @@ var tarteaucitron = { } else { tarteaucitron.cookie.checkCount(key); } + + } + + // groups + var cats = document.querySelectorAll('[id^="tarteaucitronServicesTitle_"]') + cats.forEach(function(item) { + var cat = item.getAttribute('id').replace(/^(tarteaucitronServicesTitle_)/, ""), + total = document.getElementById("tarteaucitronServices_"+cat).childElementCount; + var doc = document.getElementById("tarteaucitronServices_"+cat), + groupdenied = 0, + groupallowed = 0; + for (var ii = 0; ii < doc.children.length; ii++) { + if (doc.children[ii].className == "tarteaucitronLine tarteaucitronIsDenied") { + groupdenied++; + } + if (doc.children[ii].className == "tarteaucitronLine tarteaucitronIsAllowed") { + groupallowed++; + } + } + if (total === groupallowed) { + tarteaucitron.userInterface.removeClass('tarteaucitron-group-'+cat, 'tarteaucitronIsDenied'); + tarteaucitron.userInterface.addClass('tarteaucitron-group-'+cat, 'tarteaucitronIsAllowed'); + } + if (total === groupdenied) { + tarteaucitron.userInterface.addClass('tarteaucitron-group-'+cat, 'tarteaucitronIsDenied'); + tarteaucitron.userInterface.removeClass('tarteaucitron-group-'+cat, 'tarteaucitronIsAllowed'); + } + if (total !== groupdenied && total !== groupallowed) { + tarteaucitron.userInterface.removeClass('tarteaucitron-group-'+cat, 'tarteaucitronIsDenied'); + tarteaucitron.userInterface.removeClass('tarteaucitron-group-'+cat, 'tarteaucitronIsAllowed'); + } + groupdenied = 0; + groupallowed = 0; + }); + }, "openPanel": function () { "use strict";