Merge pull request #182 from d4rk694/languages

Ability to custimise all the texts
This commit is contained in:
Amauri CHAMPEAUX 2018-07-31 10:52:32 +02:00 committed by GitHub
commit 2685a08d8d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 115 additions and 95 deletions

View File

@ -7,10 +7,13 @@ var scripts = document.getElementsByTagName('script'),
alreadyLaunch = (alreadyLaunch === undefined) ? 0 : alreadyLaunch, alreadyLaunch = (alreadyLaunch === undefined) ? 0 : alreadyLaunch,
tarteaucitronForceLanguage = (tarteaucitronForceLanguage === undefined) ? '' : tarteaucitronForceLanguage, tarteaucitronForceLanguage = (tarteaucitronForceLanguage === undefined) ? '' : tarteaucitronForceLanguage,
tarteaucitronForceExpire = (tarteaucitronForceExpire === undefined) ? '' : tarteaucitronForceExpire, tarteaucitronForceExpire = (tarteaucitronForceExpire === undefined) ? '' : tarteaucitronForceExpire,
tarteaucitronCustomText = (tarteaucitronCustomText === undefined) ? '' : tarteaucitronCustomText,
timeExipre = 31536000000, timeExipre = 31536000000,
tarteaucitronProLoadServices, tarteaucitronProLoadServices,
tarteaucitronNoAdBlocker = false; tarteaucitronNoAdBlocker = false;
var tarteaucitron = { var tarteaucitron = {
"version": 323, "version": 323,
"cdn": cdn, "cdn": cdn,
@ -27,7 +30,7 @@ var tarteaucitron = {
"init": function (params) { "init": function (params) {
"use strict"; "use strict";
var origOpen; var origOpen;
tarteaucitron.parameters = params; tarteaucitron.parameters = params;
if (alreadyLaunch === 0) { if (alreadyLaunch === 0) {
alreadyLaunch = 1; alreadyLaunch = 1;
@ -47,13 +50,13 @@ var tarteaucitron = {
if (document.getElementById('tarteaucitronAlertBig') !== null && !tarteaucitron.highPrivacy) { if (document.getElementById('tarteaucitronAlertBig') !== null && !tarteaucitron.highPrivacy) {
if (document.getElementById('tarteaucitronAlertBig').style.display === 'block') { if (document.getElementById('tarteaucitronAlertBig').style.display === 'block') {
heightPosition = document.getElementById('tarteaucitronAlertBig').offsetHeight + 'px'; heightPosition = document.getElementById('tarteaucitronAlertBig').offsetHeight + 'px';
if (scrollPos > (screen.height * 2)) { if (scrollPos > (screen.height * 2)) {
tarteaucitron.userInterface.respondAll(true); tarteaucitron.userInterface.respondAll(true);
} else if (scrollPos > (screen.height / 2)) { } else if (scrollPos > (screen.height / 2)) {
document.getElementById('tarteaucitronDisclaimerAlert').innerHTML = '<b>' + tarteaucitron.lang.alertBigScroll + '</b> ' + tarteaucitron.lang.alertBig; document.getElementById('tarteaucitronDisclaimerAlert').innerHTML = '<b>' + tarteaucitron.lang.alertBigScroll + '</b> ' + tarteaucitron.lang.alertBig;
} }
if (tarteaucitron.orientation === 'top') { if (tarteaucitron.orientation === 'top') {
document.getElementById('tarteaucitronPercentage').style.top = heightPosition; document.getElementById('tarteaucitronPercentage').style.top = heightPosition;
} else { } else {
@ -79,7 +82,7 @@ var tarteaucitron = {
tarteaucitron.userInterface.jsSizing('main'); tarteaucitron.userInterface.jsSizing('main');
} }
} }
if (document.getElementById('tarteaucitronCookiesListContainer') !== null) { if (document.getElementById('tarteaucitronCookiesListContainer') !== null) {
if (document.getElementById('tarteaucitronCookiesListContainer').style.display === 'block') { if (document.getElementById('tarteaucitronCookiesListContainer').style.display === 'block') {
tarteaucitron.userInterface.jsSizing('cookie'); tarteaucitron.userInterface.jsSizing('cookie');
@ -102,7 +105,7 @@ var tarteaucitron = {
if (document.getElementById('tarteaucitronAlertBig') !== null && !tarteaucitron.highPrivacy) { if (document.getElementById('tarteaucitronAlertBig') !== null && !tarteaucitron.highPrivacy) {
if (document.getElementById('tarteaucitronAlertBig').style.display === 'block') { if (document.getElementById('tarteaucitronAlertBig').style.display === 'block') {
heightPosition = document.getElementById('tarteaucitronAlertBig').offsetHeight + 'px'; heightPosition = document.getElementById('tarteaucitronAlertBig').offsetHeight + 'px';
if (scrollPos > (screen.height * 2)) { if (scrollPos > (screen.height * 2)) {
tarteaucitron.userInterface.respondAll(true); tarteaucitron.userInterface.respondAll(true);
} else if (scrollPos > (screen.height / 2)) { } else if (scrollPos > (screen.height / 2)) {
@ -133,7 +136,7 @@ var tarteaucitron = {
tarteaucitron.userInterface.jsSizing('main'); tarteaucitron.userInterface.jsSizing('main');
} }
} }
if (document.getElementById('tarteaucitronCookiesListContainer') !== null) { if (document.getElementById('tarteaucitronCookiesListContainer') !== null) {
if (document.getElementById('tarteaucitronCookiesListContainer').style.display === 'block') { if (document.getElementById('tarteaucitronCookiesListContainer').style.display === 'block') {
tarteaucitron.userInterface.jsSizing('cookie'); tarteaucitron.userInterface.jsSizing('cookie');
@ -141,11 +144,11 @@ var tarteaucitron = {
} }
}); });
} }
if (typeof XMLHttpRequest !== 'undefined') { if (typeof XMLHttpRequest !== 'undefined') {
origOpen = XMLHttpRequest.prototype.open; origOpen = XMLHttpRequest.prototype.open;
XMLHttpRequest.prototype.open = function () { XMLHttpRequest.prototype.open = function () {
if (window.addEventListener) { if (window.addEventListener) {
this.addEventListener("load", function () { this.addEventListener("load", function () {
if (typeof tarteaucitronProLoadServices === 'function') { if (typeof tarteaucitronProLoadServices === 'function') {
@ -163,7 +166,7 @@ var tarteaucitron = {
setTimeout(tarteaucitronProLoadServices, 1000); setTimeout(tarteaucitronProLoadServices, 1000);
} }
} }
try { try {
origOpen.apply(this, arguments); origOpen.apply(this, arguments);
} catch (err) {} } catch (err) {}
@ -189,12 +192,12 @@ var tarteaucitron = {
"handleBrowserDNTRequest": false "handleBrowserDNTRequest": false
}, },
params = tarteaucitron.parameters; params = tarteaucitron.parameters;
// Step 0: get params // Step 0: get params
if (params !== undefined) { if (params !== undefined) {
tarteaucitron.extend(defaults, params); tarteaucitron.extend(defaults, params);
} }
// global // global
tarteaucitron.orientation = defaults.orientation; tarteaucitron.orientation = defaults.orientation;
tarteaucitron.hashtag = defaults.hashtag; tarteaucitron.hashtag = defaults.hashtag;
@ -209,6 +212,10 @@ var tarteaucitron = {
// Step 2: load language and services // Step 2: load language and services
tarteaucitron.addScript(pathToLang, '', function () { tarteaucitron.addScript(pathToLang, '', function () {
if(tarteaucitronCustomText !== ''){
tarteaucitron.lang = tarteaucitron.AddOrUpdate(tarteaucitron.lang, tarteaucitronCustomText);
}
tarteaucitron.addScript(pathToServices, '', function () { tarteaucitron.addScript(pathToServices, '', function () {
var body = document.body, var body = document.body,
@ -218,7 +225,7 @@ var tarteaucitron = {
orientation = 'Top', orientation = 'Top',
cat = ['ads', 'analytic', 'api', 'comment', 'social', 'support', 'video', 'other'], cat = ['ads', 'analytic', 'api', 'comment', 'social', 'support', 'video', 'other'],
i; i;
cat = cat.sort(function (a, b) { cat = cat.sort(function (a, b) {
if (tarteaucitron.lang[a].title > tarteaucitron.lang[b].title) { return 1; } if (tarteaucitron.lang[a].title > tarteaucitron.lang[b].title) { return 1; }
if (tarteaucitron.lang[a].title < tarteaucitron.lang[b].title) { return -1; } if (tarteaucitron.lang[a].title < tarteaucitron.lang[b].title) { return -1; }
@ -270,11 +277,11 @@ var tarteaucitron = {
html += ' </div>'; html += ' </div>';
html += ' </div>'; html += ' </div>';
html += '</div>'; html += '</div>';
if (defaults.orientation === 'bottom') { if (defaults.orientation === 'bottom') {
orientation = 'Bottom'; orientation = 'Bottom';
} }
if (defaults.highPrivacy) { if (defaults.highPrivacy) {
html += '<div id="tarteaucitronAlertBig" class="tarteaucitronAlertBig' + orientation + '">'; html += '<div id="tarteaucitronAlertBig" class="tarteaucitronAlertBig' + orientation + '">';
html += ' <span id="tarteaucitronDisclaimerAlert">'; html += ' <span id="tarteaucitronDisclaimerAlert">';
@ -298,7 +305,7 @@ var tarteaucitron = {
html += '</div>'; html += '</div>';
html += '<div id="tarteaucitronPercentage"></div>'; html += '<div id="tarteaucitronPercentage"></div>';
} }
if (defaults.showAlertSmall === true) { if (defaults.showAlertSmall === true) {
html += '<div id="tarteaucitronAlertSmall" class="tarteaucitronAlertSmall' + orientation + '">'; html += '<div id="tarteaucitronAlertSmall" class="tarteaucitronAlertSmall' + orientation + '">';
html += ' <div id="tarteaucitronManager" onclick="tarteaucitron.userInterface.openPanel();">'; html += ' <div id="tarteaucitronManager" onclick="tarteaucitron.userInterface.openPanel();">';
@ -325,7 +332,7 @@ var tarteaucitron = {
} }
html += '</div>'; html += '</div>';
} }
tarteaucitron.addScript(tarteaucitron.cdn + 'advertising.js?v=' + tarteaucitron.version, '', function () { tarteaucitron.addScript(tarteaucitron.cdn + 'advertising.js?v=' + tarteaucitron.version, '', function () {
if (tarteaucitronNoAdBlocker === true || defaults.adblocker === false) { if (tarteaucitronNoAdBlocker === true || defaults.adblocker === false) {
div.id = 'tarteaucitronRoot'; div.id = 'tarteaucitronRoot';
@ -340,7 +347,7 @@ var tarteaucitron = {
} else { } else {
tarteaucitron.job = [] tarteaucitron.job = []
} }
tarteaucitron.isAjax = true; tarteaucitron.isAjax = true;
tarteaucitron.job.push = function (id) { tarteaucitron.job.push = function (id) {
@ -363,16 +370,16 @@ var tarteaucitron = {
tarteaucitron.launch[id] = false; tarteaucitron.launch[id] = false;
tarteaucitron.addService(id); tarteaucitron.addService(id);
}; };
if (document.location.hash === tarteaucitron.hashtag && tarteaucitron.hashtag !== '') { if (document.location.hash === tarteaucitron.hashtag && tarteaucitron.hashtag !== '') {
tarteaucitron.userInterface.openPanel(); tarteaucitron.userInterface.openPanel();
} }
tarteaucitron.cookie.number(); tarteaucitron.cookie.number();
setInterval(tarteaucitron.cookie.number, 60000); setInterval(tarteaucitron.cookie.number, 60000);
} }
}, defaults.adblocker); }, defaults.adblocker);
if (defaults.adblocker === true) { if (defaults.adblocker === true) {
setTimeout(function () { setTimeout(function () {
if (tarteaucitronNoAdBlocker === false) { if (tarteaucitronNoAdBlocker === false) {
@ -416,7 +423,7 @@ var tarteaucitron = {
if (tarteaucitron.added[service.key] !== true) { if (tarteaucitron.added[service.key] !== true) {
tarteaucitron.added[service.key] = true; tarteaucitron.added[service.key] = true;
html += '<div id="' + service.key + 'Line" class="tarteaucitronLine">'; html += '<div id="' + service.key + 'Line" class="tarteaucitronLine">';
html += ' <div class="tarteaucitronName">'; html += ' <div class="tarteaucitronName">';
html += ' <b>' + service.name + '</b><br/>'; html += ' <b>' + service.name + '</b><br/>';
@ -438,13 +445,13 @@ var tarteaucitron = {
html += ' </div>'; html += ' </div>';
html += ' </div>'; html += ' </div>';
html += '</div>'; html += '</div>';
tarteaucitron.userInterface.css('tarteaucitronServicesTitle_' + service.type, 'display', 'block'); tarteaucitron.userInterface.css('tarteaucitronServicesTitle_' + service.type, 'display', 'block');
if (document.getElementById('tarteaucitronServices_' + service.type) !== null) { if (document.getElementById('tarteaucitronServices_' + service.type) !== null) {
document.getElementById('tarteaucitronServices_' + service.type).innerHTML += html; document.getElementById('tarteaucitronServices_' + service.type).innerHTML += html;
} }
tarteaucitron.userInterface.order(service.type); tarteaucitron.userInterface.order(service.type);
} }
@ -453,7 +460,7 @@ var tarteaucitron = {
isAllowed = true; isAllowed = true;
tarteaucitron.cookie.create(service.key, true); tarteaucitron.cookie.create(service.key, true);
} }
if ((!isResponded && (isAutostart || (isNavigating && isWaiting)) && !tarteaucitron.highPrivacy) || isAllowed) { if ((!isResponded && (isAutostart || (isNavigating && isWaiting)) && !tarteaucitron.highPrivacy) || isAllowed) {
if (!isAllowed) { if (!isAllowed) {
tarteaucitron.cookie.create(service.key, true); tarteaucitron.cookie.create(service.key, true);
@ -495,7 +502,7 @@ var tarteaucitron = {
out = [], out = [],
obj = {}, obj = {},
s = tarteaucitron.services; s = tarteaucitron.services;
for (i = 0; i < len; i += 1) { for (i = 0; i < len; i += 1) {
if (!obj[arr[i]]) { if (!obj[arr[i]]) {
obj[arr[i]] = {}; obj[arr[i]] = {};
@ -504,13 +511,13 @@ var tarteaucitron = {
} }
} }
} }
out = out.sort(function (a, b) { out = out.sort(function (a, b) {
if (s[a].type + s[a].key > s[b].type + s[b].key) { return 1; } if (s[a].type + s[a].key > s[b].type + s[b].key) { return 1; }
if (s[a].type + s[a].key < s[b].type + s[b].key) { return -1; } if (s[a].type + s[a].key < s[b].type + s[b].key) { return -1; }
return 0; return 0;
}); });
return out; return out;
}, },
"userInterface": { "userInterface": {
@ -526,7 +533,7 @@ var tarteaucitron = {
service, service,
key, key,
index = 0; index = 0;
for (index = 0; index < tarteaucitron.job.length; index += 1) { for (index = 0; index < tarteaucitron.job.length; index += 1) {
service = s[tarteaucitron.job[index]]; service = s[tarteaucitron.job[index]];
key = service.key; key = service.key;
@ -547,16 +554,16 @@ var tarteaucitron = {
"respond": function (el, status) { "respond": function (el, status) {
"use strict"; "use strict";
var key = el.id.replace(new RegExp("(Eng[0-9]+|Allow|Deni)ed", "g"), ''); var key = el.id.replace(new RegExp("(Eng[0-9]+|Allow|Deni)ed", "g"), '');
// return if same state // return if same state
if (tarteaucitron.state[key] === status) { if (tarteaucitron.state[key] === status) {
return; return;
} }
if (status === false && tarteaucitron.launch[key] === true) { if (status === false && tarteaucitron.launch[key] === true) {
tarteaucitron.reloadThePage = true; tarteaucitron.reloadThePage = true;
} }
// if not already launched... launch the service // if not already launched... launch the service
if (status === true) { if (status === true) {
if (tarteaucitron.launch[key] !== true) { if (tarteaucitron.launch[key] !== true) {
@ -603,11 +610,11 @@ var tarteaucitron = {
nbAllowed += 1; nbAllowed += 1;
} }
} }
tarteaucitron.userInterface.css(c + 'DotGreen', 'width', ((100 / sum) * nbAllowed) + '%'); tarteaucitron.userInterface.css(c + 'DotGreen', 'width', ((100 / sum) * nbAllowed) + '%');
tarteaucitron.userInterface.css(c + 'DotYellow', 'width', ((100 / sum) * nbPending) + '%'); tarteaucitron.userInterface.css(c + 'DotYellow', 'width', ((100 / sum) * nbPending) + '%');
tarteaucitron.userInterface.css(c + 'DotRed', 'width', ((100 / sum) * nbDenied) + '%'); tarteaucitron.userInterface.css(c + 'DotRed', 'width', ((100 / sum) * nbDenied) + '%');
if (nbDenied === 0 && nbPending === 0) { if (nbDenied === 0 && nbPending === 0) {
tarteaucitron.userInterface.css(c + 'AllAllowed', 'backgroundColor', greenDark); tarteaucitron.userInterface.css(c + 'AllAllowed', 'backgroundColor', greenDark);
tarteaucitron.userInterface.css(c + 'AllDenied', 'backgroundColor', gray); tarteaucitron.userInterface.css(c + 'AllDenied', 'backgroundColor', gray);
@ -618,16 +625,16 @@ var tarteaucitron = {
tarteaucitron.userInterface.css(c + 'AllAllowed', 'backgroundColor', gray); tarteaucitron.userInterface.css(c + 'AllAllowed', 'backgroundColor', gray);
tarteaucitron.userInterface.css(c + 'AllDenied', 'backgroundColor', gray); tarteaucitron.userInterface.css(c + 'AllDenied', 'backgroundColor', gray);
} }
// close the alert if all service have been reviewed // close the alert if all service have been reviewed
if (nbPending === 0) { if (nbPending === 0) {
tarteaucitron.userInterface.closeAlert(); tarteaucitron.userInterface.closeAlert();
} }
if (tarteaucitron.services[key].cookies.length > 0 && status === false) { if (tarteaucitron.services[key].cookies.length > 0 && status === false) {
tarteaucitron.cookie.purge(tarteaucitron.services[key].cookies); tarteaucitron.cookie.purge(tarteaucitron.services[key].cookies);
} }
if (status === true) { if (status === true) {
if (document.getElementById('tacCL' + key) !== null) { if (document.getElementById('tacCL' + key) !== null) {
document.getElementById('tacCL' + key).innerHTML = '...'; document.getElementById('tacCL' + key).innerHTML = '...';
@ -648,17 +655,17 @@ var tarteaucitron = {
}, },
"closePanel": function () { "closePanel": function () {
"use strict"; "use strict";
if (document.location.hash === tarteaucitron.hashtag) { if (document.location.hash === tarteaucitron.hashtag) {
document.location.hash = ''; document.location.hash = '';
} }
tarteaucitron.userInterface.css('tarteaucitron', 'display', 'none'); tarteaucitron.userInterface.css('tarteaucitron', 'display', 'none');
tarteaucitron.userInterface.css('tarteaucitronCookiesListContainer', 'display', 'none'); tarteaucitron.userInterface.css('tarteaucitronCookiesListContainer', 'display', 'none');
tarteaucitron.fallback(['tarteaucitronInfoBox'], function (elem) { tarteaucitron.fallback(['tarteaucitronInfoBox'], function (elem) {
elem.style.display = 'none'; elem.style.display = 'none';
}, true); }, true);
if (tarteaucitron.reloadThePage === true) { if (tarteaucitron.reloadThePage === true) {
window.location.reload(); window.location.reload();
} else { } else {
@ -683,11 +690,11 @@ var tarteaucitron = {
"toggleCookiesList": function () { "toggleCookiesList": function () {
"use strict"; "use strict";
var div = document.getElementById('tarteaucitronCookiesListContainer'); var div = document.getElementById('tarteaucitronCookiesListContainer');
if (div === null) { if (div === null) {
return; return;
} }
if (div.style.display !== 'block') { if (div.style.display !== 'block') {
tarteaucitron.cookie.number(); tarteaucitron.cookie.number();
div.style.display = 'block'; div.style.display = 'block';
@ -706,11 +713,11 @@ var tarteaucitron = {
"toggle": function (id, closeClass) { "toggle": function (id, closeClass) {
"use strict"; "use strict";
var div = document.getElementById(id); var div = document.getElementById(id);
if (div === null) { if (div === null) {
return; return;
} }
if (closeClass !== undefined) { if (closeClass !== undefined) {
tarteaucitron.fallback([closeClass], function (elem) { tarteaucitron.fallback([closeClass], function (elem) {
if (elem.id !== id) { if (elem.id !== id) {
@ -718,7 +725,7 @@ var tarteaucitron = {
} }
}, true); }, true);
} }
if (div.style.display !== 'block') { if (div.style.display !== 'block') {
div.style.display = 'block'; div.style.display = 'block';
} else { } else {
@ -735,9 +742,9 @@ var tarteaucitron = {
if (main === null) { if (main === null) {
return; return;
} }
allDivs = main.childNodes; allDivs = main.childNodes;
if (typeof Array.prototype.map === 'function') { if (typeof Array.prototype.map === 'function') {
Array.prototype.map.call(main.children, Object).sort(function (a, b) { Array.prototype.map.call(main.children, Object).sort(function (a, b) {
if (tarteaucitron.services[a.id.replace(/Line/g, '')].name > tarteaucitron.services[b.id.replace(/Line/g, '')].name) { return 1; } if (tarteaucitron.services[a.id.replace(/Line/g, '')].name > tarteaucitron.services[b.id.replace(/Line/g, '')].name) { return 1; }
@ -767,18 +774,18 @@ var tarteaucitron = {
paddingBox, paddingBox,
alertSmallHeight, alertSmallHeight,
cookiesNumberHeight; cookiesNumberHeight;
if (type === 'box') { if (type === 'box') {
if (document.getElementById('tarteaucitronAlertSmall') !== null && document.getElementById('tarteaucitronCookiesNumber') !== null) { if (document.getElementById('tarteaucitronAlertSmall') !== null && document.getElementById('tarteaucitronCookiesNumber') !== null) {
// reset // reset
tarteaucitron.userInterface.css('tarteaucitronCookiesNumber', 'padding', '0px 10px'); tarteaucitron.userInterface.css('tarteaucitronCookiesNumber', 'padding', '0px 10px');
// calculate // calculate
alertSmallHeight = document.getElementById('tarteaucitronAlertSmall').offsetHeight; alertSmallHeight = document.getElementById('tarteaucitronAlertSmall').offsetHeight;
cookiesNumberHeight = document.getElementById('tarteaucitronCookiesNumber').offsetHeight; cookiesNumberHeight = document.getElementById('tarteaucitronCookiesNumber').offsetHeight;
paddingBox = (alertSmallHeight - cookiesNumberHeight) / 2; paddingBox = (alertSmallHeight - cookiesNumberHeight) / 2;
// apply // apply
tarteaucitron.userInterface.css('tarteaucitronCookiesNumber', 'padding', paddingBox + 'px 10px'); tarteaucitron.userInterface.css('tarteaucitronCookiesNumber', 'padding', paddingBox + 'px 10px');
} }
@ -792,79 +799,79 @@ var tarteaucitron = {
// height of the services list container // height of the services list container
if (document.getElementById('tarteaucitron') !== null && document.getElementById('tarteaucitronClosePanel') !== null && document.getElementById('tarteaucitronMainLineOffset') !== null) { if (document.getElementById('tarteaucitron') !== null && document.getElementById('tarteaucitronClosePanel') !== null && document.getElementById('tarteaucitronMainLineOffset') !== null) {
// reset // reset
tarteaucitron.userInterface.css('tarteaucitronScrollbarParent', 'height', 'auto'); tarteaucitron.userInterface.css('tarteaucitronScrollbarParent', 'height', 'auto');
// calculate // calculate
mainHeight = document.getElementById('tarteaucitron').offsetHeight; mainHeight = document.getElementById('tarteaucitron').offsetHeight;
closeButtonHeight = document.getElementById('tarteaucitronClosePanel').offsetHeight; closeButtonHeight = document.getElementById('tarteaucitronClosePanel').offsetHeight;
headerHeight = document.getElementById('tarteaucitronMainLineOffset').offsetHeight; headerHeight = document.getElementById('tarteaucitronMainLineOffset').offsetHeight;
// apply // apply
servicesHeight = (mainHeight - closeButtonHeight - headerHeight + 1); servicesHeight = (mainHeight - closeButtonHeight - headerHeight + 1);
tarteaucitron.userInterface.css('tarteaucitronScrollbarParent', 'height', servicesHeight + 'px'); tarteaucitron.userInterface.css('tarteaucitronScrollbarParent', 'height', servicesHeight + 'px');
} }
// align the main allow/deny button depending on scrollbar width // align the main allow/deny button depending on scrollbar width
if (document.getElementById('tarteaucitronScrollbarParent') !== null && document.getElementById('tarteaucitronScrollbarChild') !== null) { if (document.getElementById('tarteaucitronScrollbarParent') !== null && document.getElementById('tarteaucitronScrollbarChild') !== null) {
// media query // media query
if (e[a + 'Width'] <= 479) { if (e[a + 'Width'] <= 479) {
tarteaucitron.userInterface.css('tarteaucitronScrollbarAdjust', 'marginLeft', '11px'); tarteaucitron.userInterface.css('tarteaucitronScrollbarAdjust', 'marginLeft', '11px');
} else if (e[a + 'Width'] <= 767) { } else if (e[a + 'Width'] <= 767) {
scrollbarMarginRight = 12; scrollbarMarginRight = 12;
} }
scrollbarWidthParent = document.getElementById('tarteaucitronScrollbarParent').offsetWidth; scrollbarWidthParent = document.getElementById('tarteaucitronScrollbarParent').offsetWidth;
scrollbarWidthChild = document.getElementById('tarteaucitronScrollbarChild').offsetWidth; scrollbarWidthChild = document.getElementById('tarteaucitronScrollbarChild').offsetWidth;
tarteaucitron.userInterface.css('tarteaucitronScrollbarAdjust', 'marginRight', ((scrollbarWidthParent - scrollbarWidthChild) + scrollbarMarginRight) + 'px'); tarteaucitron.userInterface.css('tarteaucitronScrollbarAdjust', 'marginRight', ((scrollbarWidthParent - scrollbarWidthChild) + scrollbarMarginRight) + 'px');
} }
// center the main panel // center the main panel
if (document.getElementById('tarteaucitron') !== null) { if (document.getElementById('tarteaucitron') !== null) {
// media query // media query
if (e[a + 'Width'] <= 767) { if (e[a + 'Width'] <= 767) {
mainTop = 0; mainTop = 0;
} else { } else {
mainTop = ((windowInnerHeight - document.getElementById('tarteaucitron').offsetHeight) / 2) - 21; mainTop = ((windowInnerHeight - document.getElementById('tarteaucitron').offsetHeight) / 2) - 21;
} }
// correct // correct
if (mainTop < 0) { if (mainTop < 0) {
mainTop = 0; mainTop = 0;
} }
if (document.getElementById('tarteaucitronMainLineOffset') !== null) { if (document.getElementById('tarteaucitronMainLineOffset') !== null) {
if (document.getElementById('tarteaucitron').offsetHeight < (windowInnerHeight / 2)) { if (document.getElementById('tarteaucitron').offsetHeight < (windowInnerHeight / 2)) {
mainTop -= document.getElementById('tarteaucitronMainLineOffset').offsetHeight; mainTop -= document.getElementById('tarteaucitronMainLineOffset').offsetHeight;
} }
} }
// apply // apply
tarteaucitron.userInterface.css('tarteaucitron', 'top', mainTop + 'px'); tarteaucitron.userInterface.css('tarteaucitron', 'top', mainTop + 'px');
} }
} else if (type === 'cookie') { } else if (type === 'cookie') {
// put cookies list at bottom // put cookies list at bottom
if (document.getElementById('tarteaucitronAlertSmall') !== null) { if (document.getElementById('tarteaucitronAlertSmall') !== null) {
tarteaucitron.userInterface.css('tarteaucitronCookiesListContainer', 'bottom', (document.getElementById('tarteaucitronAlertSmall').offsetHeight) + 'px'); tarteaucitron.userInterface.css('tarteaucitronCookiesListContainer', 'bottom', (document.getElementById('tarteaucitronAlertSmall').offsetHeight) + 'px');
} }
// height of cookies list // height of cookies list
if (document.getElementById('tarteaucitronCookiesListContainer') !== null) { if (document.getElementById('tarteaucitronCookiesListContainer') !== null) {
// reset // reset
tarteaucitron.userInterface.css('tarteaucitronCookiesList', 'height', 'auto'); tarteaucitron.userInterface.css('tarteaucitronCookiesList', 'height', 'auto');
// calculate // calculate
cookiesListHeight = document.getElementById('tarteaucitronCookiesListContainer').offsetHeight; cookiesListHeight = document.getElementById('tarteaucitronCookiesListContainer').offsetHeight;
cookiesCloseHeight = document.getElementById('tarteaucitronClosePanelCookie').offsetHeight; cookiesCloseHeight = document.getElementById('tarteaucitronClosePanelCookie').offsetHeight;
cookiesTitleHeight = document.getElementById('tarteaucitronCookiesTitle').offsetHeight; cookiesTitleHeight = document.getElementById('tarteaucitronCookiesTitle').offsetHeight;
// apply // apply
tarteaucitron.userInterface.css('tarteaucitronCookiesList', 'height', (cookiesListHeight - cookiesCloseHeight - cookiesTitleHeight - 2) + 'px'); tarteaucitron.userInterface.css('tarteaucitronCookiesList', 'height', (cookiesListHeight - cookiesCloseHeight - cookiesTitleHeight - 2) + 'px');
} }
@ -917,7 +924,7 @@ var tarteaucitron = {
"purge": function (arr) { "purge": function (arr) {
"use strict"; "use strict";
var i; var i;
for (i = 0; i < arr.length; i += 1) { for (i = 0; i < arr.length; i += 1) {
document.cookie = arr[i] + '=; expires=Thu, 01 Jan 2000 00:00:00 GMT; path=/;'; document.cookie = arr[i] + '=; expires=Thu, 01 Jan 2000 00:00:00 GMT; path=/;';
document.cookie = arr[i] + '=; expires=Thu, 01 Jan 2000 00:00:00 GMT; path=/; domain=.' + location.hostname + ';'; document.cookie = arr[i] + '=; expires=Thu, 01 Jan 2000 00:00:00 GMT; path=/; domain=.' + location.hostname + ';';
@ -932,7 +939,7 @@ var tarteaucitron = {
html = '', html = '',
i, i,
status = document.cookie.indexOf(key + '=true'); status = document.cookie.indexOf(key + '=true');
if (status >= 0 && nb === 0) { if (status >= 0 && nb === 0) {
html += tarteaucitron.lang.useNoCookie; html += tarteaucitron.lang.useNoCookie;
} else if (status >= 0) { } else if (status >= 0) {
@ -947,7 +954,7 @@ var tarteaucitron = {
} }
} }
} }
if (nbCurrent > 0) { if (nbCurrent > 0) {
html += tarteaucitron.lang.useCookieCurrent + ' ' + nbCurrent + ' cookie'; html += tarteaucitron.lang.useCookieCurrent + ' ' + nbCurrent + ' cookie';
if (nbCurrent > 1) { if (nbCurrent > 1) {
@ -966,7 +973,7 @@ var tarteaucitron = {
} }
html += '.'; html += '.';
} }
if (document.getElementById('tacCL' + key) !== null) { if (document.getElementById('tacCL' + key) !== null) {
document.getElementById('tacCL' + key).innerHTML = html; document.getElementById('tacCL' + key).innerHTML = html;
} }
@ -997,7 +1004,7 @@ var tarteaucitron = {
regex = /^https?\:\/\/([^\/?#]+)(?:[\/?#]|$)/i, regex = /^https?\:\/\/([^\/?#]+)(?:[\/?#]|$)/i,
regexedDomain = (tarteaucitron.cdn.match(regex) !== null) ? tarteaucitron.cdn.match(regex)[1] : tarteaucitron.cdn, regexedDomain = (tarteaucitron.cdn.match(regex) !== null) ? tarteaucitron.cdn.match(regex)[1] : tarteaucitron.cdn,
host = (tarteaucitron.domain !== undefined) ? tarteaucitron.domain : regexedDomain; host = (tarteaucitron.domain !== undefined) ? tarteaucitron.domain : regexedDomain;
cookies = cookies.sort(function (a, b) { cookies = cookies.sort(function (a, b) {
namea = a.split('=', 1).toString().replace(/ /g, ''); namea = a.split('=', 1).toString().replace(/ /g, '');
nameb = b.split('=', 1).toString().replace(/ /g, ''); nameb = b.split('=', 1).toString().replace(/ /g, '');
@ -1007,7 +1014,7 @@ var tarteaucitron = {
if (c + a < d + b) { return -1; } if (c + a < d + b) { return -1; }
return 0; return 0;
}); });
if (document.cookie !== '') { if (document.cookie !== '') {
for (i = 0; i < nb; i += 1) { for (i = 0; i < nb; i += 1) {
name = cookies[i].split('=', 1).toString().replace(/ /g, ''); name = cookies[i].split('=', 1).toString().replace(/ /g, '');
@ -1038,21 +1045,21 @@ var tarteaucitron = {
html += ' <div class="tarteaucitronCookiesListRight"></div>'; html += ' <div class="tarteaucitronCookiesListRight"></div>';
html += '</div>'; html += '</div>';
} }
html += '<div class="tarteaucitronHidden" style="height:20px;display:block"></div>'; html += '<div class="tarteaucitronHidden" style="height:20px;display:block"></div>';
if (document.getElementById('tarteaucitronCookiesList') !== null) { if (document.getElementById('tarteaucitronCookiesList') !== null) {
document.getElementById('tarteaucitronCookiesList').innerHTML = html; document.getElementById('tarteaucitronCookiesList').innerHTML = html;
} }
if (document.getElementById('tarteaucitronCookiesNumber') !== null) { if (document.getElementById('tarteaucitronCookiesNumber') !== null) {
document.getElementById('tarteaucitronCookiesNumber').innerHTML = nb; document.getElementById('tarteaucitronCookiesNumber').innerHTML = nb;
} }
if (document.getElementById('tarteaucitronCookiesNumberBis') !== null) { if (document.getElementById('tarteaucitronCookiesNumberBis') !== null) {
document.getElementById('tarteaucitronCookiesNumberBis').innerHTML = nb + ' cookie' + s; document.getElementById('tarteaucitronCookiesNumberBis').innerHTML = nb + ' cookie' + s;
} }
for (i = 0; i < tarteaucitron.job.length; i += 1) { for (i = 0; i < tarteaucitron.job.length; i += 1) {
tarteaucitron.cookie.checkCount(tarteaucitron.job[i]); tarteaucitron.cookie.checkCount(tarteaucitron.job[i]);
} }
@ -1061,7 +1068,7 @@ var tarteaucitron = {
"getLanguage": function () { "getLanguage": function () {
"use strict"; "use strict";
if (!navigator) { return 'en'; } if (!navigator) { return 'en'; }
var availableLanguages = 'cs,en,fr,es,it,de,nl,pt,pl,ru', var availableLanguages = 'cs,en,fr,es,it,de,nl,pt,pl,ru',
defaultLanguage = 'en', defaultLanguage = 'en',
lang = navigator.language || navigator.browserLanguage || lang = navigator.language || navigator.browserLanguage ||
@ -1073,7 +1080,7 @@ var tarteaucitron = {
return tarteaucitronForceLanguage; return tarteaucitronForceLanguage;
} }
} }
if (availableLanguages.indexOf(userLanguage) === -1) { if (availableLanguages.indexOf(userLanguage) === -1) {
return defaultLanguage; return defaultLanguage;
} }
@ -1082,11 +1089,11 @@ var tarteaucitron = {
"getLocale": function () { "getLocale": function () {
"use strict"; "use strict";
if (!navigator) { return 'en_US'; } if (!navigator) { return 'en_US'; }
var lang = navigator.language || navigator.browserLanguage || var lang = navigator.language || navigator.browserLanguage ||
navigator.systemLanguage || navigator.userLang || null, navigator.systemLanguage || navigator.userLang || null,
userLanguage = lang.substr(0, 2); userLanguage = lang.substr(0, 2);
if (userLanguage === 'fr') { if (userLanguage === 'fr') {
return 'fr_FR'; return 'fr_FR';
} else if (userLanguage === 'en') { } else if (userLanguage === 'en') {
@ -1109,7 +1116,7 @@ var tarteaucitron = {
"use strict"; "use strict";
var script, var script,
done = false; done = false;
if (execute === false) { if (execute === false) {
if (typeof callback === 'function') { if (typeof callback === 'function') {
callback(); callback();
@ -1120,7 +1127,7 @@ var tarteaucitron = {
script.id = (id !== undefined) ? id : ''; script.id = (id !== undefined) ? id : '';
script.async = true; script.async = true;
script.src = url; script.src = url;
if (attrName !== undefined && attrVal !== undefined) { if (attrName !== undefined && attrVal !== undefined) {
script.setAttribute(attrName, attrVal); script.setAttribute(attrName, attrVal);
} }
@ -1134,7 +1141,7 @@ var tarteaucitron = {
} }
}; };
} }
document.getElementsByTagName('head')[0].appendChild(script); document.getElementsByTagName('head')[0].appendChild(script);
} }
}, },
@ -1152,12 +1159,12 @@ var tarteaucitron = {
document.writeln = function (content) { document.writeln = function (content) {
tarteaucitron.makeAsync.buffer += content.concat("\n"); tarteaucitron.makeAsync.buffer += content.concat("\n");
}; };
setTimeout(function () { setTimeout(function () {
document.write = savedWrite; document.write = savedWrite;
document.writeln = savedWriteln; document.writeln = savedWriteln;
}, 20000); }, 20000);
tarteaucitron.makeAsync.getAndParse(url, id); tarteaucitron.makeAsync.getAndParse(url, id);
}, },
"getAndParse": function (url, id) { "getAndParse": function (url, id) {
@ -1185,7 +1192,7 @@ var tarteaucitron = {
if (document.getElementById(id) === null) { if (document.getElementById(id) === null) {
return; return;
} }
scripts = document.getElementById(id).getElementsByTagName('script'); scripts = document.getElementById(id).getElementsByTagName('script');
for (i = 0; i < scripts.length; i += 1) { for (i = 0; i < scripts.length; i += 1) {
type = (scripts[i].getAttribute('type') !== null) ? scripts[i].getAttribute('type') : ''; type = (scripts[i].getAttribute('type') !== null) ? scripts[i].getAttribute('type') : '';
@ -1231,7 +1238,7 @@ var tarteaucitron = {
"use strict"; "use strict";
var html = '', var html = '',
r = Math.floor(Math.random() * 100000); r = Math.floor(Math.random() * 100000);
html += '<div class="tac_activate">'; html += '<div class="tac_activate">';
html += ' <div class="tac_float">'; html += ' <div class="tac_float">';
html += ' <b>' + tarteaucitron.services[id].name + '</b> ' + tarteaucitron.lang.fallback; html += ' <b>' + tarteaucitron.services[id].name + '</b> ' + tarteaucitron.lang.fallback;
@ -1240,7 +1247,7 @@ var tarteaucitron = {
html += ' </div>'; html += ' </div>';
html += ' </div>'; html += ' </div>';
html += '</div>'; html += '</div>';
return html; return html;
}, },
"extend": function (a, b) { "extend": function (a, b) {
@ -1269,21 +1276,34 @@ var tarteaucitron = {
var div = document.getElementById('tarteaucitronPremium'), var div = document.getElementById('tarteaucitronPremium'),
timestamp = new Date().getTime(), timestamp = new Date().getTime(),
url = '//opt-out.ferank.eu/premium.php?'; url = '//opt-out.ferank.eu/premium.php?';
if (div === null) { if (div === null) {
return; return;
} }
url += 'domain=' + tarteaucitron.domain + '&'; url += 'domain=' + tarteaucitron.domain + '&';
url += 'uuid=' + tarteaucitron.uuid + '&'; url += 'uuid=' + tarteaucitron.uuid + '&';
url += 'c=' + encodeURIComponent(tarteaucitron.proTemp) + '&'; url += 'c=' + encodeURIComponent(tarteaucitron.proTemp) + '&';
url += '_' + timestamp; url += '_' + timestamp;
div.innerHTML = '<img src="' + url + '" style="display:none" />'; div.innerHTML = '<img src="' + url + '" style="display:none" />';
tarteaucitron.proTemp = ''; tarteaucitron.proTemp = '';
} }
tarteaucitron.cookie.number(); tarteaucitron.cookie.number();
},
"AddOrUpdate" : function(source, custom){
/**
Utility function to Add or update the fields of obj1 with the ones in obj2
*/
for(key in custom){
if(custom[key] instanceof Object){
source[key] = tarteaucitron.AddOrUpdate(source[key], custom[key]);
}else{
source[key] = custom[key];
}
}
return source;
} }
}; };