Merge pull request #477 from sir-gawain/csp

remove onclick html attributes, add callbacks in code.
This commit is contained in:
Amauri CHAMPEAUX 2020-10-05 13:50:01 +02:00 committed by GitHub
commit 716ac1132f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 129 additions and 28 deletions

View File

@ -444,7 +444,8 @@ div#tarteaucitronServices {
background-color: #1B870B;
opacity: 1;
}
#tarteaucitron #tarteaucitronServices #tarteaucitronAllDenied.tarteaucitronIsSelected {
#tarteaucitron #tarteaucitronServices #tarteaucitronAllDenied.tarteaucitronIsSelected,
#tarteaucitron #tarteaucitronServices #tarteaucitronAllDenied2.tarteaucitronIsSelected {
background-color: #9C1A1A;
opacity: 1;
}
@ -516,6 +517,7 @@ div#tarteaucitronServices {
#tarteaucitronAlertBig #tarteaucitronCloseAlert,
#tarteaucitronAlertBig #tarteaucitronPersonalize,
#tarteaucitronAlertBig #tarteaucitronPersonalize2,
.tarteaucitronCTAButton,
#tarteaucitron #tarteaucitronPrivacyUrl,
#tarteaucitron #tarteaucitronPrivacyUrlDialog,
@ -782,3 +784,16 @@ a.tarteaucitronSelfLink {
span.tarteaucitronTitle.tarteaucitronH3 {
margin-top: 12px!important;
}
.spacer-20 {
height: 20px;
display: block;
}
.display-block {
display: block;
}
.display-none {
display: none;
}

View File

@ -292,9 +292,9 @@ var tarteaucitron = {
// Step 3: prepare the html
html += '<div id="tarteaucitronPremium"></div>';
html += '<button type="button" id="tarteaucitronBack" onclick="tarteaucitron.userInterface.closePanel();" aria-label="' + tarteaucitron.lang.close + '"></button>';
html += '<button type="button" id="tarteaucitronBack" aria-label="' + tarteaucitron.lang.close + '"></button>';
html += '<div id="tarteaucitron" role="dialog" aria-labelledby="dialogTitle">';
html += ' <button type="button" id="tarteaucitronClosePanel" onclick="tarteaucitron.userInterface.closePanel();">';
html += ' <button type="button" id="tarteaucitronClosePanel">';
html += ' ' + tarteaucitron.lang.close;
html += ' </button>';
html += ' <div id="tarteaucitronServices">';
@ -304,7 +304,7 @@ var tarteaucitron = {
html += ' ' + tarteaucitron.lang.disclaimer;
if (tarteaucitron.parameters.privacyUrl !== "") {
html += ' <br/><br/>';
html += ' <button type="button" id="tarteaucitronPrivacyUrlDialog" onclick="document.location = tarteaucitron.parameters.privacyUrl">';
html += ' <button type="button" id="tarteaucitronPrivacyUrlDialog">';
html += ' ' + tarteaucitron.lang.privacyUrl;
html += ' </button>';
}
@ -313,18 +313,18 @@ var tarteaucitron = {
html += ' <span class="tarteaucitronH2" role="heading" aria-level="2">' + tarteaucitron.lang.all + '</span>';
html += ' </div>';
html += ' <div class="tarteaucitronAsk" id="tarteaucitronScrollbarAdjust">';
html += ' <button type="button" id="tarteaucitronAllAllowed" class="tarteaucitronAllow" onclick="tarteaucitron.userInterface.respondAll(true);">';
html += ' <button type="button" id="tarteaucitronAllAllowed" class="tarteaucitronAllow">';
html += ' &#10003; ' + tarteaucitron.lang.allowAll;
html += ' </button> ';
html += ' <button type="button" id="tarteaucitronAllDenied" class="tarteaucitronDeny" onclick="tarteaucitron.userInterface.respondAll(false);">';
html += ' <button type="button" id="tarteaucitronAllDenied" class="tarteaucitronDeny">';
html += ' &#10007; ' + tarteaucitron.lang.denyAll;
html += ' </button>';
html += ' </div>';
html += ' </div>';
html += ' <div class="tarteaucitronBorder">';
html += ' <div class="clear"></div><ul>';
if (tarteaucitron.parameters.mandatory == true) {
html += '<li id="tarteaucitronServicesTitle_mandatory">';
html += '<div class="tarteaucitronTitle">';
@ -348,7 +348,7 @@ var tarteaucitron = {
for (i = 0; i < cat.length; i += 1) {
html += ' <li id="tarteaucitronServicesTitle_' + cat[i] + '" class="tarteaucitronHidden">';
html += ' <div class="tarteaucitronTitle">';
html += ' <button type="button" onclick="tarteaucitron.userInterface.toggle(\'tarteaucitronDetails' + cat[i] + '\', \'tarteaucitronInfoBox\');return false">&#10011; ' + tarteaucitron.lang[cat[i]].title + '</button>';
html += ' <button type="button" class="catToggleBtn" data-cat="tarteaucitronDetails' + cat[i] + '">&#10011; ' + tarteaucitron.lang[cat[i]].title + '</button>';
html += ' </div>';
html += ' <div id="tarteaucitronDetails' + cat[i] + '" class="tarteaucitronDetails tarteaucitronInfoBox">';
html += ' ' + tarteaucitron.lang[cat[i]].details;
@ -357,7 +357,7 @@ var tarteaucitron = {
}
html += ' <li id="tarteaucitronNoServicesTitle" class="tarteaucitronLine">' + tarteaucitron.lang.noServices + '</li>';
html += ' </ul>';
html += ' <div class="tarteaucitronHidden" id="tarteaucitronScrollbarChild" style="height:20px;display:block"></div>';
html += ' <div class="tarteaucitronHidden spacer-20" id="tarteaucitronScrollbarChild"></div>';
if (tarteaucitron.parameters.removeCredit === false) {
html += ' <a class="tarteaucitronSelfLink" href="https://tarteaucitron.io/" rel="nofollow noreferrer noopener" target="_blank" title="tarteaucitron ' + tarteaucitron.lang.newWindow + '">🍋 ' + tarteaucitron.lang.credit + '</a>';
}
@ -376,12 +376,12 @@ var tarteaucitron = {
html += ' ' + tarteaucitron.lang.alertBigPrivacy;
html += ' </span>';
//html += ' <span class="tarteaucitronAlertBigBtnWrapper">';
html += ' <button type="button" id="tarteaucitronPersonalize" onclick="tarteaucitron.userInterface.openPanel();">';
html += ' <button type="button" id="tarteaucitronPersonalize">';
html += ' ' + tarteaucitron.lang.personalize;
html += ' </button>';
if (tarteaucitron.parameters.privacyUrl !== "") {
html += ' <button type="button" id="tarteaucitronPrivacyUrl" onclick="document.location = tarteaucitron.parameters.privacyUrl">';
html += ' <button type="button" id="tarteaucitronPrivacyUrl">';
html += ' ' + tarteaucitron.lang.privacyUrl;
html += ' </button>';
}
@ -402,24 +402,24 @@ var tarteaucitron = {
html += ' </span>';
//html += ' <span class="tarteaucitronAlertBigBtnWrapper">';
html += ' <button type="button" id="tarteaucitronPersonalize" onclick="tarteaucitron.userInterface.respondAll(true);">';
html += ' <button type="button" id="tarteaucitronPersonalize2">';
html += ' &#10003; ' + tarteaucitron.lang.acceptAll;
html += ' </button>';
if (tarteaucitron.parameters.DenyAllCta) {
html += ' <button type="button" class="tarteaucitronCTAButton tarteaucitronDeny" onclick="tarteaucitron.userInterface.respondAll(false);">';
html += ' <button type="button" class="tarteaucitronCTAButton tarteaucitronDeny" id="tarteaucitronAllDenied2">';
html += ' &#10007; ' + tarteaucitron.lang.denyAll;
html += ' </button>';
html += ' <br/><br/>';
}
html += ' <button type="button" id="tarteaucitronCloseAlert" onclick="tarteaucitron.userInterface.openPanel();">';
html += ' <button type="button" id="tarteaucitronCloseAlert">';
html += ' ' + tarteaucitron.lang.personalize;
html += ' </button>';
if (tarteaucitron.parameters.privacyUrl !== "") {
html += ' <button type="button" id="tarteaucitronPrivacyUrl" onclick="document.location = tarteaucitron.parameters.privacyUrl">';
html += ' <button type="button" id="tarteaucitronPrivacyUrl">';
html += ' ' + tarteaucitron.lang.privacyUrl;
html += ' </button>';
}
@ -432,7 +432,7 @@ var tarteaucitron = {
if (tarteaucitron.parameters.showAlertSmall === true) {
html += '<div id="tarteaucitronAlertSmall" class="tarteaucitronAlertSmall' + orientation + '">';
html += ' <button type="button" id="tarteaucitronManager" onclick="tarteaucitron.userInterface.openPanel();">';
html += ' <button type="button" id="tarteaucitronManager">';
html += ' ' + tarteaucitron.lang.alertSmall;
html += ' <span id="tarteaucitronDot">';
html += ' <span id="tarteaucitronDotGreen"></span>';
@ -441,9 +441,9 @@ var tarteaucitron = {
html += ' </span>';
if (tarteaucitron.parameters.cookieslist === true) {
html += ' </button><!-- @whitespace';
html += ' --><button type="button" id="tarteaucitronCookiesNumber" onclick="tarteaucitron.userInterface.toggleCookiesList();">0</button>';
html += ' --><button type="button" id="tarteaucitronCookiesNumber">0</button>';
html += ' <div id="tarteaucitronCookiesListContainer">';
html += ' <button type="button" id="tarteaucitronClosePanelCookie" onclick="tarteaucitron.userInterface.closePanel();">';
html += ' <button type="button" id="tarteaucitronClosePanelCookie">';
html += ' ' + tarteaucitron.lang.close;
html += ' </button>';
html += ' <div class="tarteaucitronCookiesListMain" id="tarteaucitronCookiesTitle">';
@ -540,12 +540,12 @@ var tarteaucitron = {
if (tarteaucitron.parameters.adblocker === true) {
setTimeout(function () {
if (tarteaucitronNoAdBlocker === false) {
html = '<div id="tarteaucitronAlertBig" class="tarteaucitronAlertBig' + orientation + '" style="display:block" role="alert" aria-live="polite">';
html = '<div id="tarteaucitronAlertBig" class="tarteaucitronAlertBig' + orientation + ' display-block" role="alert" aria-live="polite">';
html += ' <p id="tarteaucitronDisclaimerAlert">';
html += ' ' + tarteaucitron.lang.adblock + '<br/>';
html += ' <strong>' + tarteaucitron.lang.adblock_call + '</strong>';
html += ' </p>';
html += ' <button type="button" class="tarteaucitronCTAButton" onclick="location.reload();">';
html += ' <button type="button" class="tarteaucitronCTAButton" id="tarteaucitronCTAButton">';
html += ' ' + tarteaucitron.lang.reload;
html += ' </button>';
html += '</div>';
@ -565,6 +565,69 @@ var tarteaucitron = {
}
}, 1500);
}
// Setup events
tarteaucitron.addClickEventToId("tarteaucitronPersonalize", function () {
tarteaucitron.userInterface.openPanel();
});
tarteaucitron.addClickEventToId("tarteaucitronPersonalize2", function () {
tarteaucitron.userInterface.respondAll(true);
});
tarteaucitron.addClickEventToId("tarteaucitronManager", function () {
tarteaucitron.userInterface.openPanel();
});
tarteaucitron.addClickEventToId("tarteaucitronBack", function () {
tarteaucitron.userInterface.closePanel();
});
tarteaucitron.addClickEventToId("tarteaucitronClosePanel", function () {
tarteaucitron.userInterface.closePanel();
});
tarteaucitron.addClickEventToId("tarteaucitronClosePanelCookie", function () {
tarteaucitron.userInterface.closePanel();
});
tarteaucitron.addClickEventToId("tarteaucitronPrivacyUrl", function () {
document.location = tarteaucitron.parameters.privacyUrl;
});
tarteaucitron.addClickEventToId("tarteaucitronPrivacyUrlDialog", function () {
document.location = tarteaucitron.parameters.privacyUrl;
});
tarteaucitron.addClickEventToId("tarteaucitronCookiesNumber", function () {
tarteaucitron.userInterface.toggleCookiesList();
});
tarteaucitron.addClickEventToId("tarteaucitronAllAllowed", function () {
tarteaucitron.userInterface.respondAll(true);
});
tarteaucitron.addClickEventToId("tarteaucitronAllDenied", function () {
tarteaucitron.userInterface.respondAll(false);
});
tarteaucitron.addClickEventToId("tarteaucitronAllDenied2", function () {
tarteaucitron.userInterface.respondAll(false);
});
tarteaucitron.addClickEventToId("tarteaucitronCloseAlert", function () {
tarteaucitron.userInterface.openPanel();
});
tarteaucitron.addClickEventToId("tarteaucitronCTAButton", function () {
location.reload();
});
var toggleBtns = document.getElementsByClassName("catToggleBtn");
for (let i = 0; i < toggleBtns.length; i++) {
tarteaucitron.addClickEventToElement(toggleBtns[i], function () {
tarteaucitron.userInterface.toggle('tarteaucitronDetails' + cat[i], 'tarteaucitronInfoBox');
return false;
});
}
var allowBtns = document.getElementsByClassName("tarteaucitronAllow");
for (let i = 0; i < allowBtns.length; i++) {
tarteaucitron.addClickEventToElement(allowBtns[i], function () {
tarteaucitron.userInterface.respond(this, true);
});
}
var denyBtns = document.getElementsByClassName("tarteaucitronDeny");
for (let i = 0; i < denyBtns.length; i++) {
tarteaucitron.addClickEventToElement(denyBtns[i], function () {
tarteaucitron.userInterface.respond(this, false);
});
}
});
});
@ -616,10 +679,10 @@ var tarteaucitron = {
html += ' </div>';
html += ' <div class="tarteaucitronAsk">';
html += ' <button type="button" id="' + service.key + 'Allowed" class="tarteaucitronAllow" onclick="tarteaucitron.userInterface.respond(this, true);">';
html += ' <button type="button" id="' + service.key + 'Allowed" class="tarteaucitronAllow">';
html += ' &#10003; ' + tarteaucitron.lang.allow;
html += ' </button> ';
html += ' <button type="button" id="' + service.key + 'Denied" class="tarteaucitronDeny" onclick="tarteaucitron.userInterface.respond(this, false);">';
html += ' <button type="button" id="' + service.key + 'Denied" class="tarteaucitronDeny">';
html += ' &#10007; ' + tarteaucitron.lang.deny;
html += ' </button>';
html += ' </div>';
@ -1364,7 +1427,7 @@ var tarteaucitron = {
html += '</div><ul class="cookie-list">';
}
html += '<li class="tarteaucitronCookiesListMain">';
html += ' <div class="tarteaucitronCookiesListLeft"><button type="button" onclick="tarteaucitron.cookie.purge([\'' + tarteaucitron.fixSelfXSS(cookies[i].split('=', 1)) + '\']);tarteaucitron.cookie.number();tarteaucitron.userInterface.jsSizing(\'cookie\');return false"><strong>&times;</strong></button> <strong>' + tarteaucitron.fixSelfXSS(name) + '</strong>';
html += ' <div class="tarteaucitronCookiesListLeft"><button type="button" class="purgeBtn" data-cookie="' + tarteaucitron.fixSelfXSS(cookies[i].split('=', 1)) + '"><strong>&times;</strong></button> <strong>' + tarteaucitron.fixSelfXSS(name) + '</strong>';
html += ' </div>';
html += ' <div class="tarteaucitronCookiesListRight">' + tarteaucitron.fixSelfXSS(cookies[i].split('=').slice(1).join('=')) + '</div>';
html += '</li>';
@ -1377,7 +1440,7 @@ var tarteaucitron = {
html += '</div>';
}
html += '<div class="tarteaucitronHidden" style="height:20px;display:block"></div>';
html += '<div class="tarteaucitronHidden spacer-20"></div>';
if (document.getElementById('tarteaucitronCookiesList') !== null) {
document.getElementById('tarteaucitronCookiesList').innerHTML = html;
@ -1391,6 +1454,16 @@ var tarteaucitron = {
document.getElementById('tarteaucitronCookiesNumberBis').innerHTML = nb + ' cookie' + s;
}
var purgeBtns = document.getElementsByClassName("purgeBtn");
for (let i = 0; i < purgeBtns.length; i++) {
tarteaucitron.addClickEventToElement(purgeBtns[i], function () {
tarteaucitron.cookie.purge([this.dataset.cookie]);
tarteaucitron.cookie.number();
tarteaucitron.userInterface.jsSizing('cookie');
return false;
});
}
for (i = 0; i < tarteaucitron.job.length; i += 1) {
tarteaucitron.cookie.checkCount(tarteaucitron.job[i]);
}
@ -1524,7 +1597,7 @@ var tarteaucitron = {
tarteaucitron.makeAsync.antiGhost += 1;
tarteaucitron.addInternalScript(url, '', function () {
if (document.getElementById(id) !== null) {
document.getElementById(id).innerHTML += "<span style='display:none'>&nbsp;</span>" + tarteaucitron.makeAsync.buffer;
document.getElementById(id).innerHTML += "<span class='display-none'>&nbsp;</span>" + tarteaucitron.makeAsync.buffer;
tarteaucitron.makeAsync.buffer = '';
tarteaucitron.makeAsync.execJS(id);
}
@ -1595,7 +1668,8 @@ var tarteaucitron = {
html += '<div class="tac_activate">';
html += ' <div class="tac_float">';
html += ' ' + engage;
html += ' <button type="button" class="tarteaucitronAllow" id="Eng' + r + 'ed' + id + '" onclick="tarteaucitron.userInterface.respond(this, true);">';
// html += ' <button type="button" class="tarteaucitronAllow" id="Eng' + r + 'ed' + id + '" onclick="tarteaucitron.userInterface.respond(this, true);">';
html += ' <button type="button" class="tarteaucitronAllow" id="Eng' + r + 'ed' + id + '">';
html += ' &#10003; ' + tarteaucitron.lang.allow;
html += ' </button>';
html += ' </div>';
@ -1639,7 +1713,7 @@ var tarteaucitron = {
url += 'status=' + encodeURIComponent(tarteaucitron.proTemp) + '&';
url += '_time=' + timestamp;
div.innerHTML = '<img src="' + url + '" style="display:none" />';
div.innerHTML = '<img src="' + url + '" class="display-none" />';
tarteaucitron.proTemp = '';
}
@ -1664,5 +1738,17 @@ var tarteaucitron = {
},
"getElemHeight": function(elem) {
return elem.getAttribute('height') || elem.clientHeight;
},
"addClickEventToId": function (elemId, func) {
tarteaucitron.addClickEventToElement(document.getElementById(elemId), func);
},
"addClickEventToElement": function (e, func) {
if (e) {
if (e.addEventListener) {
e.addEventListener("click", func);
} else {
e.attachEvent("onclick", func);
}
}
}
};