Merge pull request #436 from Manoz/fix/duplicate-code
[Enhancement] Duplicate code
This commit is contained in:
commit
de701ba421
200
tarteaucitron.js
200
tarteaucitron.js
|
|
@ -42,128 +42,37 @@ var tarteaucitron = {
|
||||||
alreadyLaunch = 1;
|
alreadyLaunch = 1;
|
||||||
if (window.addEventListener) {
|
if (window.addEventListener) {
|
||||||
window.addEventListener("load", function () {
|
window.addEventListener("load", function () {
|
||||||
tarteaucitron.load();
|
tarteaucitron.initEvents.loadEvent(false);
|
||||||
tarteaucitron.fallback(['tarteaucitronOpenPanel'], function (elem) {
|
|
||||||
elem.addEventListener("click", function (event) {
|
|
||||||
tarteaucitron.userInterface.openPanel();
|
|
||||||
event.preventDefault();
|
|
||||||
}, false);
|
|
||||||
}, true);
|
|
||||||
}, false);
|
}, false);
|
||||||
window.addEventListener("scroll", function () {
|
window.addEventListener("scroll", function () {
|
||||||
var scrollPos = window.pageYOffset || document.documentElement.scrollTop,
|
tarteaucitron.initEvents.scrollEvent();
|
||||||
heightPosition;
|
|
||||||
if (document.getElementById('tarteaucitronAlertBig') !== null && !tarteaucitron.highPrivacy) {
|
|
||||||
if (document.getElementById('tarteaucitronAlertBig').style.display === 'block') {
|
|
||||||
heightPosition = document.getElementById('tarteaucitronAlertBig').offsetHeight + 'px';
|
|
||||||
|
|
||||||
if (scrollPos > (screen.height * 2)) {
|
|
||||||
tarteaucitron.userInterface.respondAll(true);
|
|
||||||
} else if (scrollPos > (screen.height / 2)) {
|
|
||||||
document.getElementById('tarteaucitronDisclaimerAlert').innerHTML = '<strong>' + tarteaucitron.lang.alertBigScroll + '</strong> ' + tarteaucitron.lang.alertBig;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (tarteaucitron.orientation === 'top') {
|
|
||||||
document.getElementById('tarteaucitronPercentage').style.top = heightPosition;
|
|
||||||
} else {
|
|
||||||
document.getElementById('tarteaucitronPercentage').style.bottom = heightPosition;
|
|
||||||
}
|
|
||||||
document.getElementById('tarteaucitronPercentage').style.width = ((100 / (screen.height * 2)) * scrollPos) + '%';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, false);
|
}, false);
|
||||||
|
|
||||||
window.addEventListener("keydown", function (evt) {
|
window.addEventListener("keydown", function (evt) {
|
||||||
if (evt.keyCode === 27) {
|
tarteaucitron.initEvents.keydownEvent(false, evt);
|
||||||
tarteaucitron.userInterface.closePanel();
|
|
||||||
}
|
|
||||||
}, false);
|
}, false);
|
||||||
window.addEventListener("hashchange", function () {
|
window.addEventListener("hashchange", function () {
|
||||||
if (document.location.hash === tarteaucitron.hashtag && tarteaucitron.hashtag !== '') {
|
tarteaucitron.initEvents.hashchangeEvent();
|
||||||
tarteaucitron.userInterface.openPanel();
|
|
||||||
}
|
|
||||||
}, false);
|
}, false);
|
||||||
window.addEventListener("resize", function () {
|
window.addEventListener("resize", function () {
|
||||||
if (document.getElementById('tarteaucitron') !== null) {
|
tarteaucitron.initEvents.resizeEvent();
|
||||||
if (document.getElementById('tarteaucitron').style.display === 'block') {
|
|
||||||
tarteaucitron.userInterface.jsSizing('main');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (document.getElementById('tarteaucitronCookiesListContainer') !== null) {
|
|
||||||
if (document.getElementById('tarteaucitronCookiesListContainer').style.display === 'block') {
|
|
||||||
tarteaucitron.userInterface.jsSizing('cookie');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, false);
|
}, false);
|
||||||
} else {
|
} else {
|
||||||
window.attachEvent("onload", function () {
|
window.attachEvent("onload", function () {
|
||||||
tarteaucitron.load();
|
tarteaucitron.initEvents.loadEvent(true);
|
||||||
tarteaucitron.fallback(['tarteaucitronOpenPanel'], function (elem) {
|
|
||||||
elem.attachEvent("onclick", function (event) {
|
|
||||||
tarteaucitron.userInterface.openPanel();
|
|
||||||
event.preventDefault();
|
|
||||||
});
|
|
||||||
}, true);
|
|
||||||
});
|
});
|
||||||
window.attachEvent("onscroll", function () {
|
window.attachEvent("onscroll", function () {
|
||||||
var scrollPos = window.pageYOffset || document.documentElement.scrollTop,
|
tarteaucitron.initEvents.scrollEvent();
|
||||||
heightPosition;
|
|
||||||
if (document.getElementById('tarteaucitronAlertBig') !== null && !tarteaucitron.highPrivacy) {
|
|
||||||
if (document.getElementById('tarteaucitronAlertBig').style.display === 'block') {
|
|
||||||
heightPosition = document.getElementById('tarteaucitronAlertBig').offsetHeight + 'px';
|
|
||||||
|
|
||||||
if (scrollPos > (screen.height * 2)) {
|
|
||||||
tarteaucitron.userInterface.respondAll(true);
|
|
||||||
} else if (scrollPos > (screen.height / 2)) {
|
|
||||||
document.getElementById('tarteaucitronDisclaimerAlert').innerHTML = '<strong>' + tarteaucitron.lang.alertBigScroll + '</strong> ' + tarteaucitron.lang.alertBig;
|
|
||||||
}
|
|
||||||
if (tarteaucitron.orientation === 'top') {
|
|
||||||
document.getElementById('tarteaucitronPercentage').style.top = heightPosition;
|
|
||||||
} else {
|
|
||||||
document.getElementById('tarteaucitronPercentage').style.bottom = heightPosition;
|
|
||||||
}
|
|
||||||
document.getElementById('tarteaucitronPercentage').style.width = ((100 / (screen.height * 2)) * scrollPos) + '%';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
window.attachEvent("onkeydown", function (evt) {
|
window.attachEvent("onkeydown", function (evt) {
|
||||||
if (evt.keyCode === 27) {
|
tarteaucitron.initEvents.keydownEvent(true, evt);
|
||||||
tarteaucitron.userInterface.closePanel();
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( evt.keyCode === 9 && focusableEls.indexOf(evt.target) >= 0) {
|
|
||||||
if ( evt.shiftKey ) /* shift + tab */ {
|
|
||||||
if (document.activeElement === firstFocusableEl) {
|
|
||||||
lastFocusableEl.focus();
|
|
||||||
evt.preventDefault();
|
|
||||||
}
|
|
||||||
} else /* tab */ {
|
|
||||||
if (document.activeElement === lastFocusableEl) {
|
|
||||||
firstFocusableEl.focus();
|
|
||||||
evt.preventDefault();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
});
|
||||||
window.attachEvent("onhashchange", function () {
|
window.attachEvent("onhashchange", function () {
|
||||||
if (document.location.hash === tarteaucitron.hashtag && tarteaucitron.hashtag !== '') {
|
tarteaucitron.initEvents.hashchangeEvent();
|
||||||
tarteaucitron.userInterface.openPanel();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
window.attachEvent("onresize", function () {
|
window.attachEvent("onresize", function () {
|
||||||
if (document.getElementById('tarteaucitron') !== null) {
|
tarteaucitron.initEvents.resizeEvent();
|
||||||
if (document.getElementById('tarteaucitron').style.display === 'block') {
|
|
||||||
tarteaucitron.userInterface.jsSizing('main');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (document.getElementById('tarteaucitronCookiesListContainer') !== null) {
|
|
||||||
if (document.getElementById('tarteaucitronCookiesListContainer').style.display === 'block') {
|
|
||||||
tarteaucitron.userInterface.jsSizing('cookie');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -200,6 +109,89 @@ var tarteaucitron = {
|
||||||
tarteaucitron.events.init();
|
tarteaucitron.events.init();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"initEvents": {
|
||||||
|
"loadEvent": function (isOldBrowser) {
|
||||||
|
tarteaucitron.load();
|
||||||
|
tarteaucitron.fallback(['tarteaucitronOpenPanel'], function (elem) {
|
||||||
|
if (isOldBrowser) {
|
||||||
|
elem.attachEvent("onclick", function (event) {
|
||||||
|
tarteaucitron.userInterface.openPanel();
|
||||||
|
event.preventDefault();
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
elem.addEventListener("click", function (event) {
|
||||||
|
tarteaucitron.userInterface.openPanel();
|
||||||
|
event.preventDefault();
|
||||||
|
}, false);
|
||||||
|
}
|
||||||
|
}, true);
|
||||||
|
},
|
||||||
|
"keydownEvent": function (isOldBrowser, evt) {
|
||||||
|
if (evt.keyCode === 27) {
|
||||||
|
tarteaucitron.userInterface.closePanel();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isOldBrowser) {
|
||||||
|
if ( evt.keyCode === 9 && focusableEls.indexOf(evt.target) >= 0) {
|
||||||
|
if ( evt.shiftKey ) /* shift + tab */ {
|
||||||
|
if (document.activeElement === firstFocusableEl) {
|
||||||
|
lastFocusableEl.focus();
|
||||||
|
evt.preventDefault();
|
||||||
|
}
|
||||||
|
} else /* tab */ {
|
||||||
|
if (document.activeElement === lastFocusableEl) {
|
||||||
|
firstFocusableEl.focus();
|
||||||
|
evt.preventDefault();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"hashchangeEvent": function () {
|
||||||
|
if (document.location.hash === tarteaucitron.hashtag && tarteaucitron.hashtag !== '') {
|
||||||
|
tarteaucitron.userInterface.openPanel();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"resizeEvent": function () {
|
||||||
|
var tacElem = document.getElementById('tarteaucitron');
|
||||||
|
var tacCookieContainer = document.getElementById('tarteaucitronCookiesListContainer');
|
||||||
|
|
||||||
|
if (tacElem && tacElem.style.display === 'block') {
|
||||||
|
tarteaucitron.userInterface.jsSizing('main');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tacCookieContainer && tacCookieContainer.style.display === 'block') {
|
||||||
|
tarteaucitron.userInterface.jsSizing('cookie');
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"scrollEvent": function () {
|
||||||
|
var scrollPos = window.pageYOffset || document.documentElement.scrollTop;
|
||||||
|
var heightPosition;
|
||||||
|
var tacPercentage = document.getElementById('tarteaucitronPercentage');
|
||||||
|
var tacAlertBig = document.getElementById('tarteaucitronAlertBig');
|
||||||
|
|
||||||
|
if (tacAlertBig && !tarteaucitron.highPrivacy) {
|
||||||
|
if (tacAlertBig.style.display === 'block') {
|
||||||
|
heightPosition = tacAlertBig.offsetHeight + 'px';
|
||||||
|
|
||||||
|
if (scrollPos > (screen.height * 2)) {
|
||||||
|
tarteaucitron.userInterface.respondAll(true);
|
||||||
|
} else if (scrollPos > (screen.height / 2)) {
|
||||||
|
document.getElementById('tarteaucitronDisclaimerAlert').innerHTML = '<strong>' + tarteaucitron.lang.alertBigScroll + '</strong> ' + tarteaucitron.lang.alertBig;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tacPercentage) {
|
||||||
|
if (tarteaucitron.orientation === 'top') {
|
||||||
|
tacPercentage.style.top = heightPosition;
|
||||||
|
} else {
|
||||||
|
tacPercentage.style.bottom = heightPosition;
|
||||||
|
}
|
||||||
|
tacPercentage.style.width = ((100 / (screen.height * 2)) * scrollPos) + '%';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
"load": function () {
|
"load": function () {
|
||||||
"use strict";
|
"use strict";
|
||||||
var cdn = tarteaucitron.cdn,
|
var cdn = tarteaucitron.cdn,
|
||||||
|
|
@ -225,7 +217,7 @@ var tarteaucitron = {
|
||||||
"useExternalJs": false
|
"useExternalJs": false
|
||||||
},
|
},
|
||||||
params = tarteaucitron.parameters;
|
params = tarteaucitron.parameters;
|
||||||
|
|
||||||
// Don't show the middle bar if we are on the privacy policy page
|
// Don't show the middle bar if we are on the privacy policy page
|
||||||
if (window.location.href == tarteaucitron.parameters.privacyUrl && tarteaucitron.parameters.orientation == "middle") {
|
if (window.location.href == tarteaucitron.parameters.privacyUrl && tarteaucitron.parameters.orientation == "middle") {
|
||||||
tarteaucitron.parameters.orientation = "bottom";
|
tarteaucitron.parameters.orientation = "bottom";
|
||||||
|
|
@ -457,7 +449,7 @@ var tarteaucitron = {
|
||||||
document.body.appendChild(wrapper);*/
|
document.body.appendChild(wrapper);*/
|
||||||
|
|
||||||
div.id = 'tarteaucitronRoot';
|
div.id = 'tarteaucitronRoot';
|
||||||
if (tarteaucitron.parameters.bodyPosition === 'top') {
|
if (tarteaucitron.parameters.bodyPosition === 'top') {
|
||||||
// Prepend tarteaucitron: #tarteaucitronRoot first-child of the body for better accessibility
|
// Prepend tarteaucitron: #tarteaucitronRoot first-child of the body for better accessibility
|
||||||
var bodyFirstChild = body.firstChild;
|
var bodyFirstChild = body.firstChild;
|
||||||
body.insertBefore(div, bodyFirstChild);
|
body.insertBefore(div, bodyFirstChild);
|
||||||
|
|
@ -536,7 +528,7 @@ var tarteaucitron = {
|
||||||
html += '<div id="tarteaucitronPremium"></div>';
|
html += '<div id="tarteaucitronPremium"></div>';
|
||||||
|
|
||||||
div.id = 'tarteaucitronRoot';
|
div.id = 'tarteaucitronRoot';
|
||||||
if (tarteaucitron.parameters.bodyPosition === 'top') {
|
if (tarteaucitron.parameters.bodyPosition === 'top') {
|
||||||
// Prepend tarteaucitron: #tarteaucitronRoot first-child of the body for better accessibility
|
// Prepend tarteaucitron: #tarteaucitronRoot first-child of the body for better accessibility
|
||||||
var bodyFirstChild = body.firstChild;
|
var bodyFirstChild = body.firstChild;
|
||||||
body.insertBefore(div, bodyFirstChild);
|
body.insertBefore(div, bodyFirstChild);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue