1var YJACookieConsent = function() { 2 const CONSENT_COOKIE_NAME = 'yja_cookie_acceptance'; 3 4 const SUPPORT_COOKIE_NAME = 'yja_cookie_support'; 5 6 const IS_HTTPS = window.location.href.toString().indexOf('https:') !== -1; 7 8 let config = function() { 9 let elem = document.getElementById('yja-cookie-consent'); 10 let data = {}; 11 ['uuid', 'checkCookie', 'lang', 'style'].forEach(key => data[key] = elem?.dataset[key] || ''); 12 13 return data 14 }(); 15 16 if (config?.checkCookie === 'true') { 17 checkCookie(); 18 } 19 20 function checkCookie() { 21 if (isDoNotTrackEnabled()) { 22 // YJAY-5551 23 setCookie(CONSENT_COOKIE_NAME, 'min', 365); 24 return 25 } 26 27 if (!areCookiesSupported()) { 28 return 29 } 30 31 if (!cookieExists(CONSENT_COOKIE_NAME)) { 32 loadDialog(); 33 } 34 } 35 36 function getCookie(name) { 37 name += '='; 38 39 var ca = decodeURIComponent(document.cookie).split(';'); 40 for (var i = 0; i < ca.length; i++) { 41 var c = ca[i]; 42 while (c.charAt(0) === ' ') { 43 c = c.substring(1); 44 } 45 if (c.indexOf(name) === 0) { 46 return c.substring(name.length, c.length); 47 } 48 } 49 50 return undefined; 51 } 52 53 function cookieExists(name) { 54 var cookie = getCookie(name); 55 return (cookie && cookie !== ''); 56 } 57 58 function setCookie(name, value, daysToExpire) { 59 var cookieString = name + '=' + escape(value) + ';' 60 61 if (daysToExpire) { 62 var expirationDate = new Date(); 63 expirationDate.setTime(expirationDate.getTime() + (daysToExpire * 24 * 60 * 60 * 1000)); 64 cookieString += 'expires=' + expirationDate.toUTCString() + ';' 65 } 66 67 cookieString += ';path=/;samesite=lax'; 68 69 if (IS_HTTPS) { 70 cookieString += ';secure'; 71 } 72 73 document.cookie = cookieString; 74 } 75 76 function removeCookie(name) { 77 var expires = 'expires=Thu, 01 Jan 1970 00:00:00 UTC'; 78 document.cookie = name + '=' + '' + ';' + expires + ';path=/'; 79 } 80 81 function areCookiesSupported() { 82 setCookie(SUPPORT_COOKIE_NAME, 'true') 83 84 var cookieSupported = getCookie(SUPPORT_COOKIE_NAME) === 'true'; 85 if (cookieSupported) { 86 removeCookie(SUPPORT_COOKIE_NAME); 87 } 88 89 return cookieSupported; 90 } 91 92 function isDoNotTrackEnabled() { 93 // Check does browser support "Do Not Track" 94 if (window.doNotTrack || navigator.doNotTrack || navigator.globalPrivacyControl) { 95 // Check is "Do Not Track"" enabled 96 if (window.doNotTrack === '1' || navigator.doNotTrack === 'yes' || navigator.doNotTrack === '1' || navigator.globalPrivacyControl === true) { 97 return true; 98 } 99 } 100 101 return false; 102 } 103 104 function loadDialog() { 105 AUI().ready('liferay-portlet-url', function(A) { 106 var url = '/o/yja-cookie-consent/' + config.uuid 107 if (config.lang) { 108 url += '?languageId=' + config.lang; 109 } 110 111 A.use('aui-io-request', function(A) { 112 A.io.request(url, { 113 method: 'GET', 114 dataType: 'JSON', 115 on: { 116 success: function(event, id, response) { 117 var parsedData = JSON.parse(response.response); 118 showDialog(parsedData.title, parsedData.content, parsedData.acceptAll, parsedData.acceptNecessary) 119 }, 120 failure: function(error) { 121 122 } 123 } 124 }); 125 }); 126 }); 127 } 128 129 function showDialog(title, content, acceptAll, acceptNecessary) { 130 // strip possible <pre> tags 131 var parsedContent = content.replace(/<pre?[^>]+>|<\/pre>/g, ''); 132 133 // Construct dialog HTML 134 var html = 135 '<div role="dialog" tabindex="-1" id="yja-cookie-dialog" class="yja-cookie-dialog__theme-' + config.style + '">' + 136 '<section data-nosnippet aria-label="' + title + '" aria-describedby="yja-cookie-dialog-note-text" tabindex="-1" class="yja-cookie-dialog-content">' + 137 '<div id="yja-cookie-dialog-note-text" class="yja-cookie-dialog-note">' + parsedContent + '</div>' + 138 '<div tabindex="-1" class="yja-cookie-dialog-buttons">' + 139 '<button id="yja-cookie-accept" class="btn btn-primary">' + acceptAll + '</button>' + 140 '<button id="yja-cookie-reject" class="btn btn-primary">' + acceptNecessary + '</button>' + 141 '</div>' + 142 '</section>' + 143 '</div>'; 144 145 // Add dialog to end of body 146 document.body.insertAdjacentHTML('afterbegin', html); 147 148 var cookieDialog = document.getElementById('yja-cookie-dialog'); 149 var acceptButton = document.getElementById('yja-cookie-accept'); 150 var rejectButton = document.getElementById('yja-cookie-reject'); 151 152 if (acceptButton && rejectButton) { 153 async function forceRefresh() { 154 await fetch(window.location.href, { cache: "reload" }); 155 window.location.reload(); 156 } 157 158 acceptButton.addEventListener('click', async function(event) {
159 setCookie(CONSENT_COOKIE_NAME, 'all', 365); 160 await forceRefresh(); 161 }); 162 rejectButton.addEventListener('click', async function(event) { 163 setCookie(CONSENT_COOKIE_NAME, 'min', 365); 164 await forceRefresh(); 165 }); 166 } 167 if (cookieDialog) { 168 cookieDialog.style.display = 'block'; 169 cookieDialog.focus(); 170 } 171 } 172 173 function hideDialog() { 174 var cookieDialog = document.getElementById('yja-cookie-dialog'); 175 if (cookieDialog) { 176 cookieDialog.style.display = 'node'; 177 cookieDialog.remove(); 178 } 179 } 180 181 return { 182 clearCookie: function() { 183 removeCookie(CONSENT_COOKIE_NAME); 184 }, 185 setAcceptAllCookie: function() { 186 removeCookie(CONSENT_COOKIE_NAME); 187 setCookie(CONSENT_COOKIE_NAME, 'all', 365); 188 }, 189 setAcceptOnlyNecessaryCookie: function() { 190 removeCookie(CONSENT_COOKIE_NAME); 191 setCookie(CONSENT_COOKIE_NAME, 'min', 365); 192 }, 193 showConsentDialog: function() { 194 removeCookie(CONSENT_COOKIE_NAME); 195 loadDialog(); 196 }, 197 hideConsentDialog: function() { 198 hideDialog(); 199 } 200 } 201}();
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.