`
).prependTo(prependElement || 'body');
}
// could move this out of the loop but not entirely necessary
const bodyPaddingLeft = $('body').css('padding-left')
const bodyPaddingRight = $('body').css('padding-right')
if (bodyPaddingLeft != "0px") {
$('head').append(``);
}
if (bodyPaddingRight != "0px") {
$('head').append(``);
}
// Add scrolling class
function scrollClass() {
const scroll = document.documentElement.scrollTop;
if (scroll > $(`#${strings.simpleBanner}`).height()) {
$(`#${strings.simpleBanner}`).addClass(strings.simpleBannerScrolling);
} else {
$(`#${strings.simpleBanner}`).removeClass(strings.simpleBannerScrolling);
}
}
document.addEventListener("scroll", scrollClass);
}
// Add close button function to close button and close if cookie found
function closeBanner() {
if (!keep_site_custom_css && document.getElementById(strings.simpleBannerSiteCustomCss)) document.getElementById(strings.simpleBannerSiteCustomCss).remove();
if (!keep_site_custom_js && document.getElementById(strings.simpleBannerSiteCustomJs)) document.getElementById(strings.simpleBannerSiteCustomJs).remove();
// Header Margin/Padding only available for Banner #1
if (document.getElementById(strings.simpleBannerHeaderMargin)) document.getElementById(strings.simpleBannerHeaderMargin).remove();
if (document.getElementById(strings.simpleBannerHeaderPadding)) document.getElementById(strings.simpleBannerHeaderPadding).remove();
if (document.getElementById(strings.simpleBanner)) document.getElementById(strings.simpleBanner).remove();
}
if (isSimpleBannerVisible) {
const sbCookie = strings.simpleBannerClosedCookie;
if (close_button_enabled){
if (getCookie(sbCookie) === "true") {
closeBanner();
// Set cookie again here in case the expiration has changed
setCookie(sbCookie, "true", close_button_expiration);
} else {
document.getElementById(strings.simpleBannerCloseButton).onclick = function() {
closeBanner();
setCookie(sbCookie, "true", close_button_expiration);
};
}
} else {
// disable cookie if it exists
if (getCookie(sbCookie) === "true") {
document.cookie = `${strings.simpleBannerClosedCookie}=true; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;`;
}
}
}
})
// Cookie Getter/Setter
function setCookie(cname,cvalue,expiration) {
let d;
if (expiration === '' || expiration === '0' || parseFloat(expiration)) {
const exdays = parseFloat(expiration) || 0;
d = new Date();
d.setTime(d.getTime() + (exdays*24*60*60*1000));
} else {
d = new Date(expiration);
}
const expires = "expires=" + d.toUTCString();
document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
}
function getCookie(cname) {
const name = cname + "=";
const decodedCookie = decodeURIComponent(document.cookie);
const ca = decodedCookie.split(';');
for(let i = 0; i < ca.length; i++) {
let c = ca[i];
while (c.charAt(0) == ' ') {
c = c.substring(1);
}
if (c.indexOf(name) == 0) {
return c.substring(name.length, c.length);
}
}
return "";
}
// Debug Mode
// Console log all variables
if (pro_version_enabled && debug_mode) {
console.log(simpleBannerScriptParams);
}
});