1(function ($) { 2 3 // older versions of jQuery need to use the `attr` method to modify node properties, newer versions use `prop` 4 var method = $.fn.jquery.replace(/\.(\d)/g,".0$1").replace(/\.0(\d{2})/g,".$1") > "1.6" ? 'prop' : 'attr'; 5 6 var pwcmb = { 7 attach: function () { 8 if(!pwcmb_settings.status) return; 9 10 window.dataLayer = window.dataLayer || []; 11 12 var cookieMonster = {}; 13 14 cookieMonster.cfg = { 15 wrapper: $('.pwcmb'), 16 notice: $('.pwcmb-widget--notice'), 17 manage: $('.pwcmb-widget--manage'), 18 message: $('.pwcmb-widget--message'), 19 visibleClass: 'js-show', 20 version: pwcmb_settings.version, 21 storedVersion: null, 22 //status: $('#cookie-status'), 23 allow: $('.js-pwcmb-allow-cookies'), 24 block: $('.js-pwcmb-block-cookies'), 25 allowCookies: 'n', //current tracking state 26 allowStorage: (typeof(Storage) !== "undefined"), 27 viewCount : 0, 28 selectionMade: 'n', //whether a selection has been made by the user 29 acceptanceSet: 0 //keeps track of whether acceptance has been set in current page load or not 30 } 31 32 //push acceptance flag to the dataLayer for tag manager to pick up 33 //use flag 'acceptanceSet' to only push acceptance to the datalayer 34 //once (otherwise might get set multiple times in tag manager) 35 cookieMonster.sendTrackingBeacon = function() { 36 dataLayer.push({ 37 event: (cookieMonster.cfg.allowCookies == "y" ? "COOKIE_MONSTER_SET_COOKIES" : "COOKIE_MONSTER_NO_COOKIES"), 38 payload: {status: 1}, 39 }); 40 } 41 42 //event to track accept/decline action 43 cookieMonster.sendActionBeacon = function() { 44 dataLayer.push({ 45 event: (cookieMonster.cfg.allowCookies == "y" ? "COOKIE_MONSTER_USER_ACCEPTS" : "COOKIE_MONSTER_USER_DECLINES"), 46 payload: {status: 1}, 47 }); 48 } 49 50 //set the status of the user preferences (typically on page load) 51 cookieMonster.setStatus = function() { 52 cookieMonster.setUserPreferences(); 53 cookieMonster.sendTrackingBeacon(); 54 } 55 56 //update the preferences of a user, when interacting with the modal widget 57 cookieMonster.updateStatus = function() { 58 cookieMonster.setUserPreferences(); 59 if(cookieMonster.cfg.acceptanceSet < 1) { 60 cookieMonster.cfg.acceptanceSet = 1; //track that a user has accepted already 61 //set this whether accepting or declining to ensure the action is tracked 62 cookieMonster.sendTrackingBeacon(); 63 } 64 } 65 66 //store the user's preferences to local storage 67 cookieMonster.setUserPreferences = function() { 68 if(cookieMonster.cfg.allowStorage) { 69 localStorage.setItem("pwcmbAllowCookies", cookieMonster.cfg.allowCookies); 70 localStorage.setItem("pwcmbSelectionMade", cookieMonster.cfg.selectionMade); 71 localStorage.setItem("pwcmbVersion", cookieMonster.cfg.storedVersion); 72 localStorage.setItem("pwcmbViewCount", cookieMonster.cfg.viewCount); 73 } 74 } 75 76 //set cookieMonster variables when user allows 77 78 /** 79 * 80 * 81 * @param explicit {Boolean} 82 */ 83 cookieMonster.allow = function(explicit) { 84 85 if (explicit) { 86 cookieMonster.cfg.viewCount = -1; 87 } 88 89 cookieMonster.cfg.allowCookies = "y"; 90 cookieMonster.cfg.selectionMade = "y"; 91 cookieMonster.cfg.storedVersion = cookieMonster.cfg.version; 92 cookieMonster.sendActionBeacon(); 93 cookieMonster.updateStatus(); 94 cookieMonster.setUserPreferences(); 95 96 } 97 98 //set cookieMonster variables when user blocks 99 cookieMonster.block = function() { 100 cookieMonster.cfg.allowCookies = "n"; 101 cookieMonster.cfg.selectionMade = "y"; 102 cookieMonster.cfg.storedVersion = cookieMonster.cfg.version; 103 cookieMonster.sendActionBeacon(); 104 cookieMonster.updateStatus(); 105 } 106 107 //cookieMonster UI actions and methods 108 cookieMonster.ui = { 109 cfg: { 110 initialBodyPadding: parseInt($('body').css('padding-top')), 111 }, 112 updateUi: function(animate) { 113 var h = $('.js-show.pwcmb--top_push').outerHeight(); 114 var p = cookieMonster.ui.cfg.initialBodyPadding; 115 116 $('body').animate({ 117 'padding-top': h + p, 118 }, (animate ? 250 : 0)); 119 }, 120 showNotice: function() { 121 var vis = cookieMonster.cfg.visibleClass; 122 cookieMonster.cfg.notice.addClass(vis).siblings().removeClass(vis); 123 }, 124 showManage: function() { 125 var vis = cookieMonster.cfg.visibleClass; 126 cookieMonster.cfg.manage.addClass(vis).siblings().removeClass(vis); 127 }, 128 showMessage: function() { 129 var vis = cookieMonster.cfg.visibleClass; 130 cookieMonster.cfg.message.addClass(vis).siblings().removeClass(vis); 131 cookieMonster.ui.timeoutSuccess(); 132 }, 133 timeoutSuccess: function() { 134 var vis = cookieMonster.cfg.visibleClass; 135 var timer = setTimeout(function() { 136 cookieMonster.cfg.message.removeClass(vis); 137 clearTimeout(timer); 138 }, 1400) 139 }, 140 actions: function() { 141 142 if( 143 cookieMonster.cfg.allowCookies == "y" 144 ) { 145 $('.js-pwcmb-marketing-pref--y')[method]('checked', true); 146 } else if (cookieMonster.cfg.allowCookies == "n") { 147 $('.js-pwcmb-marketing-pref--n')[method]('checked', true); 148 } 149 150 cookieMonster.cfg.allow.click(function allowClick() { 151 152 cookieMonster.cfg.viewCount = -1; 153 if (cookieMonster.cfg.allowCookies !== "y") { 154 cookieMonster.allow(true); 155 } 156 157 cookieMonster.setUserPreferences(); 158 cookieMonster.ui.showMessage(); 159 }); 160 161 if($('.js-show.pwcmb--top_push').length) { 162 cookieMonster.ui.updateUi(true); 163 $(window).resize(function resizeWindow() { 164 cookieMonster.ui.updateUi(false); 165 }) 166 } 167 168 $('.js-pwcmb-manage-cookies').bind('click', function manageClick() { 169 cookieMonster.ui.showManage(); 170 if( 171 cookieMonster.cfg.allowCookies == "y" 172 ) { 173 174 $('.js-pwcmb-marketing-pref--y')[method]('checked', true); 175 } else if (cookieMonster.cfg.allowCookies == "n") { 176 $('.js-pwcmb-marketing-pref--n')[method]('checked', true); 177 } 178 }); 179 180 $('.pwcmb-widget__row-cb').bind('change', function change() { 181 var checked = $(this).is(':checked'); 182 $(this).parents('.pwcmb-option-wrapper').siblings().find('.pwcmb-widget__row-cb')[method]('checked', !checked); 183 }); 184 185 $('.js-pwcmb-save-pref').bind('click', function savePreferenceClick() { 186 var _val = $('.js-pwcmb-marketing-pref--y').is(':checked'); 187 if(_val) { 188 cookieMonster.allow(true); 189 } else { 190 cookieMonster.block(); 191 } 192 cookieMonster.ui.showMessage(); 193 }); 194 195 $('.js-pwcmb-notice-toggle').bind('click', function toggleClick(e) { 196 e.preventDefault(); 197 cookieMonster.ui.show(); 198 cookieMonster.ui.showManage(); 199 }) 200 }, 201 show: function() { 202 //first step 203 cookieMonster.cfg.wrapper.addClass(cookieMonster.cfg.visibleClass); 204 cookieMonster.ui.showNotice(); 205 // add pwcmb class to body when banner is active 206 // not used by this module, but available for devs for their use 207 $('body').addClass('pwcmb-active'); 208 } 209 } 210 211 /** 212 * Entry point to cookie initialization 213 * 214 */ 215 cookieMonster.init = function() { 216 217 /* 218 auto_fire is a truthy value when "EU only" mode is enabled and the visitor is deemed to be NOT from the EU, 219 in which case we want to fire the "set cookies" event immediately, hide any "manage cookies links" in the page, 220 and then ignore all further processing 221 */ 222 if (pwcmb_settings.auto_fire == 'true') { 223 cookieMonster.cfg.allowCookies = 'y'; 224 cookieMonster.sendTrackingBeacon(); 225 $('.js-pwcmb-notice-toggle').remove(); 226 return; 227 } 228 229 if(cookieMonster.cfg.allowStorage) { 230 cookieMonster.cfg.allowCookies = localStorage.getItem("pwcmbAllowCookies"); 231 cookieMonster.cfg.selectionMade = localStorage.getItem("pwcmbSelectionMade"); 232 cookieMonster.cfg.storedVersion = localStorage.getItem("pwcmbVersion"); 233 cookieMonster.cfg.viewCount = localStorage.getItem("pwcmbVie
233wCount") ? parseInt(localStorage.getItem("pwcmbViewCount"), 10) : 0; 234 } else { 235 return; 236 } 237 238 // attach all listeners 239 cookieMonster.ui.actions(); 240 241 // have they implicitly or explicitly made a choice? 242 if (cookieMonster.cfg.selectionMade == "y") { 243 244 // have they implicitly or explicitly made a choice? 245 if (localStorage.getItem('pwcmbViewcount') || ! localStorage.getItem('pwcmbViewCount')) { 246 cookieMonster.cfg.viewCount = -1; 247 cookieMonster.setUserPreferences(); 248 } 249 250 cookieMonster.setStatus(); //on page load 251 252 // if they haven't explicitly accepted it (ie: auto-accept) then display the banner 253 if (pwcmb_settings.auto_accept && cookieMonster.cfg.viewCount != -1) { 254 cookieMonster.ui.show(); 255 } 256 } 257 258 if (pwcmb_settings.auto_accept) { 259 260 if (cookieMonster.cfg.viewCount == -1) { 261 cookieMonster.setUserPreferences(); 262 263 // auto-accept mode is on but they have not explicitly accepted the terms 264 } else { 265 266 // if this is NOT the first page view (ie: 2nd, 3rd, 4th, 5th, ...) pageview, then implicitly allow cookies 267 if (cookieMonster.cfg.viewCount == 1) { 268 cookieMonster.allow(false); 269 } 270 271 // but if they haven't explicitly allowed cookies, then display the banner 272 if (cookieMonster.cfg.viewCount >= 0) { 273 cookieMonster.ui.show(); 274 cookieMonster.cfg.viewCount++; 275 } 276 cookieMonster.setUserPreferences(); 277 } 278 279 // if auto-accept is off and they haven't selected anything, display the banner 280 } else { 281 if (cookieMonster.cfg.selectionMade !== 'y') { 282 cookieMonster.ui.show(); 283 } 284 } 285 }; 286 287 cookieMonster.init(); 288 289 } 290 }; 291 292 pwcmb.attach(); 293 294})(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.