1/* 2 * Copyright (C) 2012 PrimeBox 3 * 4 * This work is licensed under the Creative Commons 5 * Attribution 3.0 Unported License. To view a copy 6 * of this license, visit 7 * http://creativecommons.org/licenses/by/3.0/. 8 * 9 * Documentation available at: 10 * http://www.primebox.co.uk/projects/cookie-bar/ 11 * 12 * When using this software you use it at your own risk. We hold 13 * no responsibility for any damage caused by using this plugin 14 * or the documentation provided. 15 * 16 * Modified Cookie Bar To show newsletter Signup @Contentive 17 * 18 */ 19(function($){ 20 $.signupBar = function(options,val){ 21 if(options=='cookies'){ 22 var doReturn = 'cookies'; 23 }else if(options=='set'){ 24 var doReturn = 'set'; 25 }else{ 26 var doReturn = false; 27 } 28 var defaults = { 29 message: 'We use cookies to track usage and preferences.', //Message displayed on bar 30 acceptButton: true, //Set to true to show accept/enable button 31 acceptText: 'I Understand', //Text on accept/enable button 32 acceptFunction: function(cookieValue){if(cookieValue!='enabled' && cookieValue!='accepted') window.location = window.location.href;}, //Function to run after accept 33 declineButton: false, //Set to true to show decline/disable button 34 declineText: 'Disable Cookies', //Text on decline/disable button 35 declineFunction: function(cookieValue){if(cookieValue=='enabled' || cookieValue=='accepted') window.location = window.location.href;}, //Function to run after decline 36 policyButton: false, //Set to true to show Privacy Policy button 37 policyText: 'Privacy Policy', //Text on Privacy Policy button 38 policyURL: '/privacy-policy/', //URL of Privacy Policy 39 autoEnable: true, //Set to true for cookies to be accepted automatically. Banner still shows 40 acceptOnContinue: false, //Set to true to accept cookies when visitor moves to another page 41 acceptOnScroll: false, //Set to true to accept cookies when visitor scrolls X pixels up or down 42 acceptAnyClick: false, //Set to true to accept cookies when visitor clicks anywhere on the page 43 expireDays: 365, //Number of days for cookieBar cookie to be stored for 44 renewOnVisit: false, //Renew the cookie upon revisit to website 45 forceShow: false, //Force cookieBar to show regardless of user cookie preference 46 effect: 'slide', //Options: slide, fade, hide 47 element: 'body', //Element to append/prepend cookieBar to. Remember "." for class or "#" for id. 48 append: false, //Set to true for cookieBar HTML to be placed at base of website. Actual position may change according to CSS 49 fixed: false, //Set to true to add the class "fixed" to the cookie bar. Default CSS should fix the position 50 bottom: false, //Force CSS when fixed, so bar appears at bottom of website 51 zindex: '', //Can be set in CSS, although some may prefer to set here 52 domain: String(window.location.hostname), //Location of privacy policy 53 referrer: String(document.referrer) //Where visitor has come from 54 }; 55 var options = $.extend(defaults,options); 56 57 //Sets expiration date for cookie 58 var expireDate = new Date(); 59 expireDate.setTime(expireDate.getTime()+(options.expireDays*86400000)); 60 expireDate = expireDate.toGMTString(); 61 62 var cookieEntry = 'sb-enabled={value}; expires='+expireDate+'; path=/'; 63 64 //Retrieves current cookie preference 65 var i,cookieValue='',aCookie,aCookies=document.cookie.split('; '); 66 for (i=0;i<aCookies.length;i++){ 67 aCookie = aCookies[i].split('='); 68 if(aCookie[0]=='sb-enabled'){ 69 cookieValue = aCookie[1]; 70 } 71 } 72 //Sets up default cookie preference if not already set 73 if(cookieValue=='' && doReturn!='cookies' && options.autoEnable){ 74 cookieValue = 'enabled'; 75 document.cookie = cookieEntry.replace('{value}','enabled'); 76 }else if((cookieValue=='accepted' || cookieValue=='declined') && doReturn!='cookies' && options.renewOnVisit){ 77 document.cookie = cookieEntry.replace('{value}',cookieValue); 78 } 79 if(options.acceptOnContinue){ 80 if(options.referrer.indexOf(options.domain)>=0 && String(window.location.href).indexOf(options.policyURL)==-1 && doReturn!='cookies' && doReturn!='set' && cookieValue!='accepted' && cookieValue!='declined'){ 81 doReturn = 'set'; 82 val = 'accepted'; 83 } 84 } 85 if(doReturn=='cookies'){ 86 //Returns true if cookies are enabled, false otherwise 87 if(cookieValue=='enabled' || cookieValue=='accepted'){ 88 return true; 89 }else{ 90 return false;
91 } 92 }else if(doReturn=='set' && (val=='accepted' || val=='declined')){ 93 //Sets value of cookie to 'accepted' or 'declined' 94 document.cookie = cookieEntry.replace('{value}',val); 95 if(val=='accepted'){ 96 return true; 97 }else{ 98 return false; 99 } 100 }else{ 101 //Sets up enable/accept button if required 102 var message = options.message.replace('{policy_url}',options.policyURL); 103 104 if(options.acceptButton){ 105 var acceptButton = '<a href="" class="sb-enable">'+options.acceptText+'</a>'; 106 }else{ 107 var acceptButton = ''; 108 } 109 //Sets up disable/decline button if required 110 if(options.declineButton){ 111 var declineButton = '<a href="" class="sb-disable">'+options.declineText+'</a>'; 112 }else{ 113 var declineButton = ''; 114 } 115 //Sets up privacy policy button if required 116 if(options.policyButton){ 117 var policyButton = '<a href="'+options.policyURL+'" class="sb-policy">'+options.policyText+'</a>'; 118 }else{ 119 var policyButton = ''; 120 } 121 //Whether to add "fixed" class to cookie bar 122 if(options.fixed){ 123 if(options.bottom){ 124 var fixed = ' class="fixed bottom"'; 125 }else{ 126 var fixed = ' class="fixed"'; 127 } 128 }else{ 129 var fixed = ''; 130 } 131 if(options.zindex!=''){ 132 var zindex = ' style="z-index:'+options.zindex+';"'; 133 }else{ 134 var zindex = ''; 135 } 136 137 //Displays the cookie bar if arguments met 138 if(options.forceShow || cookieValue=='enabled' || cookieValue==''){ 139 if(options.append){ 140 $(options.element).append('<div id="signup-bar"'+fixed+zindex+'>'+message+acceptButton+declineButton+policyButton+'</div>'); 141 }else{ 142 $(options.element).prepend('<div id="signup-bar"'+fixed+zindex+'>'+message+acceptButton+declineButton+policyButton+'</div>'); 143 } 144 } 145 146 var removeBar = function(func){ 147 if(options.acceptOnScroll) $(document).off('scroll'); 148 if(typeof(func)==='function') func(cookieValue); 149 if(options.effect=='slide'){ 150 $('#signup-bar').slideUp(300,function(){$('#signup-bar').remove();}); 151 }else if(options.effect=='fade'){ 152 $('#signup-bar').fadeOut(300,function(){$('#signup-bar').remove();}); 153 }else{ 154 $('#signup-bar').hide(0,function(){$('#signup-bar').remove();}); 155 } 156 $(document).unbind('click',anyClick); 157 }; 158 var cookieAccept = function(){ 159 document.cookie = cookieEntry.replace('{value}','accepted'); 160 //removeBar(options.acceptFunction); 161 var url = 'https://clickz.com/get-the-latest-from-clickz/'; // window.location.href + '#newsletter-modal'; 162 window.location.href = url; 163 //window.location.reload(true); 164 }; 165 var cookieDecline = function(){ 166 var deleteDate = new Date(); 167 deleteDate.setTime(deleteDate.getTime()-(864000000)); 168 deleteDate = deleteDate.toGMTString(); 169 aCookies=document.cookie.split('; '); 170 for (i=0;i<aCookies.length;i++){ 171 aCookie = aCookies[i].split('='); 172 if(aCookie[0].indexOf('_')>=0){ 173 document.cookie = aCookie[0]+'=0; expires='+deleteDate+'; domain='+options.domain.replace('www','')+'; path=/'; 174 }else{ 175 document.cookie = aCookie[0]+'=0; expires='+deleteDate+'; path=/'; 176 } 177 } 178 document.cookie = cookieEntry.replace('{value}','declined'); 179 removeBar(options.declineFunction); 180 }; 181 var anyClick = function(e){ 182 if(!$(e.target).hasClass('sb-policy')) cookieAccept(); 183 }; 184 185 $('#signup-bar .sb-enable').click(function(){cookieAccept();return false;}); 186 $('#signup-bar .sb-disable').click(function(){cookieDecline();return false;}); 187 if(options.acceptOnScroll){ 188 var scrollStart = $(document).scrollTop(),scrollNew,scrollDiff; 189 $(document).on('scroll',function(){ 190 scrollNew = $(document).scrollTop(); 191 if(scrollNew>scrollStart){ 192 scrollDiff = scrollNew - scrollStart; 193 }else{ 194 scrollDiff = scrollStart - scrollNew; 195 } 196 if(scrollDiff>=Math.round(options.acceptOnScroll)) cookieAccept(); 197 }); 198 } 199 if(options.acceptAnyClick){ 200 $(document).bind('click',anyClick); 201 } 202 } 203 }; 204})(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.