1(function( $ ) { 2 'use strict'; 3 4 let dataJSON = { 5 'action' : 'prefix_get_banners', 6 '_nonce' : wp_ajax._nonce, 7 'current_id': wp_ajax.current_id, 8 }; 9 10 11 $.ajax({ 12 cache: false, 13 type: "POST", 14 url: wp_ajax.ajax_url, 15 data: dataJSON, 16 success: function( response ){ 17 if (response.success != false){ 18 prepare_alerts_for_show(response); 19 } 20 21 }, 22 error: function( xhr, status, error ) { 23 console.log( 'Status: ' + xhr.status ); 24 console.log( 'Error: ' + xhr.responseText ); 25 }, 26 27 }); 28 29 function prepare_alerts_for_show(response){ 30 let alerts = JSON.parse(response); 31 let showed_alerts = getCookieStartWith('alert_banner_showed'); 32 33 alerts.filter(element => { 34 // filter banners that not in the cookies 35 return !showed_alerts.includes('alert_banner_showed_'+element.id+'_'+element.timestamp); 36 37 }).forEach((element,index) => { 38 39 if(element.views == 'once'){ 40 createCookie('alert_banner_showed_'+element.id+'_'+element.timestamp, element.id, 7) 41 } 42 43 let html = ` 44 <div class="bsite-alert-banner ${element.image == '' ? 'no-image':''}" 45 data-alert='${element.id}' 46 data-timestamp = '${element.timestamp}' 47 data-auto-close='${element.auto_close}' 48 ${element.auto_close ? 'data-close-time="'+element.auto_close_after+'"' :''} 49 style="background-color:${element.background_color}"> 50 ${element.image != '' ? ` 51 52 <div class="alert-img-wrapper"> 53 <img src="${element.image}" /> 54 </div> 55 56 `:''} 57 <div class="alert-text-wrapper" > 58 <div style="color:${element.text_color};">${element.text}</div> 59 </div> 60 <div class="alert-close-wrapper" > 61 <button type="button" style="color:${element.text_color};" class="bsite-alert-banner-close" aria-label="Close"> 62 <span aria-hidden="true">×</span> 63 </button> 64 </div> 65 </div> 66 `; 67 let wrapper = $(`.bsite-alert-banner-wrapper.${element.position}`); 68 if(!wrapper.length){ 69 let wrapper_html = `<div class="bsite-alert-banner-wrapper ${element.position}"></div>`; 70 $('body').append(wrapper_html); 71 wrapper = $(`.bsite-alert-banner-wrapper.${element.position}`); 72 } 73 wrapper.append(html); 74 }); 75 76 $('.bsite-alert-banner-close').click(function(e){ 77 e.preventDefault(); 78 let alert_element = $(this).parent().parent(); 79 let alert_id = alert_element.data('alert'); 80 let alert_timestamp = alert_element.data('timestamp'); 81 82 alert_element.remove(); 83 // createCookie('alert_banner_showed_'+alert_id+'_'+alert_timestamp, alert_id, 1); 84 }); 85 86 let auto_closed_alerts = $('.bsite-alert-banner[data-auto-close="true"]'); 87 auto_closed_alerts.each(function(){ 88 let time = $(this).data('close-time'); 89 removeAfter($(this),time); 90 }); 91 92 } 93 94 95 function getCookieStartWith(name) { 96 // Split cookie string and get all individual name=value pairs in an array 97 let cookieArr = document.cookie.split(";").filter(c => c.trim().startsWith(name)); 98 // let cookeisValues = []; 99 let cookeisNames = []; 100 101 // Loop through the array elements 102 for(let i = 0; i < cookieArr.length; i++) { 103 let cookiePair = cookieArr[i].split("="); 104 cookeisNames.push(decodeURIComponent(cookiePair[0]).trim()); 105 // cookeisValues.push(decodeURIComponent(cookiePair[1])); 106 } 107 108 return cookeisNames; 109 } 110 111 function createCookie(name, value, days, path) { 112 let expires; 113 if (days) { 114 let date = new Date(); 115 date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000)); 116 expires = "; expires=" + date.toGMTString(); 117 } 118 else { 119 expires = ""; 120 } 121 122 if (!path){ 123 path = window.location.pathname; 124 } 125 document.cookie = name + "=" + value + expires + "; path="+path; 126 } 127 128 function removeAfter(element,time){ 129 let timeInSec = time*1000; 130 setTimeout(function(){ 131 element.remove(); 132 },timeInSec); 133 } 134 135})( jQuery );
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.