1jQuery(document).ready(function ($) { 2 const { pro_version_enabled, debug_mode, banner_params } = simpleBannerScriptParams; 3 4 banner_params.forEach((bannerParams, i) => { 5 const banner_id = i === 0 ? '' : `_${i+1}`; 6 const { 7 simple_banner_text, 8 simple_banner_disabled_page_paths, 9 disabled_on_current_page, 10 close_button_enabled, 11 close_button_expiration, 12 simple_banner_insert_inside_element, 13 simple_banner_prepend_element, 14 keep_site_custom_css, 15 keep_site_custom_js, 16 wp_body_open, 17 wp_body_open_enabled, 18 } = bannerParams; 19 20 const strings = { 21 simpleBanner: `simple-banner${banner_id}`, 22 simpleBannerText: `simple-banner-text${banner_id}`, 23 simpleBannerCloseButton: `simple-banner-close-button${banner_id}`, 24 simpleBannerButton: `simple-banner-button${banner_id}`, 25 simpleBannerScrolling: `simple-banner-scrolling${banner_id}`, 26 simpleBannerSiteCustomCss: `simple-banner-site-custom-css${banner_id}`, 27 simpleBannerSiteCustomJs: `simple-banner-site-custom-js${banner_id}`, 28 simpleBannerHeaderMargin: `simple-banner-header-margin${banner_id}`, 29 simpleBannerHeaderPadding: `simple-banner-header-padding${banner_id}`, 30 simpleBannerClosedCookie: `simplebannerclosed${banner_id}`, 31 } 32 33 const isSimpleBannerTextSet = simple_banner_text && simple_banner_text !== undefined && simple_banner_text !== ""; 34 const isDisabledByPagePath = simple_banner_disabled_page_paths ? simple_banner_disabled_page_paths.split(',') 35 .filter(Boolean) 36 .some(path => { 37 const pathname = path.trim(); 38 if (pathname.at(0) === '*' && pathname.at(-1) === '*') { 39 return window.location.pathname.includes(pathname.slice(1, -1)); 40 } 41 if (pathname.at(0) === '*') { 42 return window.location.pathname.endsWith(pathname.slice(1)); 43 } 44 if (pathname.at(-1) === '*') { 45 return window.location.pathname.startsWith(pathname.slice(0, -1)); 46 } 47 return window.location.pathname === pathname; 48 }) : false; 49 const isSimpleBannerEnabledOnPage = !pro_version_enabled || 50 (pro_version_enabled && !disabled_on_current_page && !isDisabledByPagePath); 51 const isSimpleBannerVisible = isSimpleBannerTextSet && isSimpleBannerEnabledOnPage; 52 53 if (isSimpleBannerVisible) { 54 if (!wp_body_open || !wp_body_open_enabled) { 55 const closeButton = close_button_enabled ? `<button aria-label="Close" id="${strings.simpleBannerCloseButton}" class="${strings.simpleBannerButton}">✕</button>` : ''; 56 const prependElement = document.querySelector(simple_banner_insert_inside_element || simple_banner_prepend_element || 'body'); 57 58 $( 59 `<div id="${strings.simpleBanner}" class="${strings.simpleBanner}"><div class="${strings.simpleBannerText}"><span>${simple_banner_text}</span></div>${closeButton}</div>` 60 ).prependTo(prependElement || 'body'); 61 } 62 63 // could move this out of the loop but not entirely necessary 64 const bodyPaddingLeft = $('body').css('padding-left') 65 const bodyPaddingRight = $('body').css('padding-right') 66 67 if (bodyPaddingLeft != "0px") { 68 $('head').append(`<style type="text/css" media="screen">.${strings.simpleBanner}{margin-left:-${bodyPaddingLeft};padding-left:${bodyPaddingLeft};}</style>`); 69 } 70 if (bodyPaddingRight != "0px") { 71 $('head').append(`<style type="text/css" media="screen">.${strings.simpleBanner}{margin-right:-${bodyPaddingRight};padding-right:${bodyPaddingRight};}</style>`); 72 } 73 74 // Add scrolling class 75 function scrollClass() { 76 const scroll = document.documentElement.scrollTop; 77 if (scroll >
77 $(`#${strings.simpleBanner}`).height()) { 78 $(`#${strings.simpleBanner}`).addClass(strings.simpleBannerScrolling); 79 } else { 80 $(`#${strings.simpleBanner}`).removeClass(strings.simpleBannerScrolling); 81 } 82 } 83 document.addEventListener("scroll", scrollClass); 84 } 85 86 // Add close button function to close button and close if cookie found 87 function closeBanner() { 88 if (!keep_site_custom_css && document.getElementById(strings.simpleBannerSiteCustomCss)) document.getElementById(strings.simpleBannerSiteCustomCss).remove(); 89 if (!keep_site_custom_js && document.getElementById(strings.simpleBannerSiteCustomJs)) document.getElementById(strings.simpleBannerSiteCustomJs).remove(); 90 // Header Margin/Padding only available for Banner #1 91 if (document.getElementById(strings.simpleBannerHeaderMargin)) document.getElementById(strings.simpleBannerHeaderMargin).remove(); 92 if (document.getElementById(strings.simpleBannerHeaderPadding)) document.getElementById(strings.simpleBannerHeaderPadding).remove(); 93 if (document.getElementById(strings.simpleBanner)) document.getElementById(strings.simpleBanner).remove(); 94 } 95 96 if (isSimpleBannerVisible) { 97 const sbCookie = strings.simpleBannerClosedCookie; 98 99 if (close_button_enabled){ 100 if (getCookie(sbCookie) === "true") { 101 closeBanner(); 102 // Set cookie again here in case the expiration has changed 103 setCookie(sbCookie, "true", close_button_expiration); 104 } else { 105 document.getElementById(strings.simpleBannerCloseButton).onclick = function() { 106 closeBanner(); 107 setCookie(sbCookie, "true", close_button_expiration); 108 }; 109 } 110 } else { 111 // disable cookie if it exists 112 if (getCookie(sbCookie) === "true") { 113 document.cookie = `${strings.simpleBannerClosedCookie}=true; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;`; 114 } 115 } 116 } 117 118 }) 119 120 // Cookie Getter/Setter 121 function setCookie(cname,cvalue,expiration) { 122 let d; 123 if (expiration === '' || expiration === '0' || parseFloat(expiration)) { 124 const exdays = parseFloat(expiration) || 0; 125 d = new Date(); 126 d.setTime(d.getTime() + (exdays*24*60*60*1000)); 127 } else { 128 d = new Date(expiration); 129 } 130 const expires = "expires=" + d.toUTCString(); 131 document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/"; 132 } 133 function getCookie(cname) { 134 const name = cname + "="; 135 const decodedCookie = decodeURIComponent(document.cookie); 136 const ca = decodedCookie.split(';'); 137 for(let i = 0; i < ca.length; i++) { 138 let c = ca[i]; 139 while (c.charAt(0) == ' ') { 140 c = c.substring(1); 141 } 142 if (c.indexOf(name) == 0) { 143 return c.substring(name.length, c.length); 144 } 145 } 146 return ""; 147 } 148 149 // Debug Mode 150 // Console log all variables 151 if (pro_version_enabled && debug_mode) { 152 console.log(simpleBannerScriptParams); 153 } 154});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.