1/* 2 * Copyright (C) 2012 PrimeBox ([email protected]) 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(function($){ 17 $.cookieBar = function(options,val){ 18 if(options=='cookies'){ 19 var doReturn = 'cookies'; 20 }else if(options=='set'){ 21 var doReturn = 'set'; 22 }else{ 23 var doReturn = false; 24 } 25 var defaults = { 26 message: 'Usiamo i cookie per offrirti la migliore esperienza sul nostro sito. Utilizzando il sito web si acconsente uso dei cookie anche di terze parti.', //Message displayed on bar 27 acceptButton: true, //Set to true to show accept/enable button 28 acceptText: 'Accetto', //Text on accept/enable button 29 acceptFunction: function(cookieValue){if(cookieValue!='enabled' && cookieValue!='accepted') window.location = window.location.href;}, //Function to run after accept 30 declineButton: false, //Set to true to show decline/disable button 31 declineText: 'Disable Cookies', //Text on decline/disable button 32 declineFunction: function(cookieValue){if(cookieValue=='enabled' || cookieValue=='accepted') window.location = window.location.href;}, //Function to run after decline 33 policyButton: true, //Set to true to show Privacy Policy button 34 policyText: 'Privacy Policy', //Text on Privacy Policy button 35 policyURL: 'https://www.medianet-group.it/privacy/informativaprivacy2018.php?codstru=businit&ling=i', //URL of Privacy Policy 36 autoEnable: true, //Set to true for cookies to be accepted automatically. Banner still shows 37 acceptOnContinue: false, //Set to true to silently accept cookies when visitor moves to another page 38 acceptOnScroll: false, //Set to true to silently accept cookies when visitor scrolls X pixels up or down 39 expireDays: 365, //Number of days for cookieBar cookie to be stored for 40 renewOnVisit: false, //Renew the cookie upon revisit to website 41 forceShow: false, //Force cookieBar to show regardless of user cookie preference 42 effect: 'slide', //Options: slide, fade, hide 43 element: 'body', //Element to append/prepend cookieBar to. Remember "." for class or "#" for id. 44 append: true, //Set to true for cookieBar HTML to be placed at base of website. Actual position may change according to CSS 45 fixed: true, //Set to true to add the class "fixed" to the cookie bar. Default CSS should fix the position 46 bottom: true, //Force CSS when fixed, so bar appears at bottom of website 47 zindex: '', //Can be set in CSS, although some may prefer to set here 48 domain: String(window.location.hostname), //Location of privacy policy 49 referrer: String(document.referrer) //Where visitor has come from 50 }; 51 var options = $.extend(defaults,options); 52 53 //Sets expiration date for cookie 54 var expireDate = new Date(); 55 expireDate.setTime(expireDate.getTime()+(options.expireDays*86400000)); 56 expireDate = expireDate.toGMTString(); 57 58 var cookieEntry = 'cb-enabled={value}; expires='+expireDate+'; path=/'; 59 60 //Retrieves current cookie preference 61 var i,cookieValue='',aCookie,aCookies=document.cookie.split('; '); 62 for (i=0;i<aCookies.length;i++){ 63 aCookie = aCookies[i].split('='); 64 if(aCookie[0]=='cb-enabled'){ 65 cookieValue = aCookie[1]; 66 } 67 } 68 //Sets up default cookie preference if not already set 69 if(cookieValue=='' && doReturn!='cookies' && options.autoEnable){ 70 cookieValue = 'enabled'; 71 document.cookie = cookieEntry.replace('{value}','enabled'); 72 }else if((cookieValue=='accepted' || cookieValue=='declined') && doReturn!='cookies' && options.renewOnVisit){ 73 document.cookie = cookieEntry.replace('{value}',cookieValue); 74 } 75 if(options.acceptOnContinue){ 76 if(options.referrer.indexOf(options.domain)>=0 && String(window.location.href).indexOf(options.policyURL)==-1 && doReturn!='cookies' && doReturn!='set' && cookieValue!='accepted' && cookieValue!='declined'){ 77 doReturn = 'set'; 78 val = 'accepted'; 79 } 80 }
81 if(doReturn=='cookies'){ 82 //Returns true if cookies are enabled, false otherwise 83 if(cookieValue=='enabled' || cookieValue=='accepted'){ 84 return true; 85 }else{ 86 return false; 87 } 88 }else if(doReturn=='set' && (val=='accepted' || val=='declined')){ 89 //Sets value of cookie to 'accepted' or 'declined' 90 document.cookie = cookieEntry.replace('{value}',val); 91 if(val=='accepted'){ 92 return true; 93 }else{ 94 return false; 95 } 96 }else{ 97 //Sets up enable/accept button if required 98 var message = options.message.replace('{policy_url}',options.policyURL); 99 100 if(options.acceptButton){ 101 var acceptButton = '<a href="" class="cb-enable">'+options.acceptText+'</a>'; 102 }else{ 103 var acceptButton = ''; 104 } 105 //Sets up disable/decline button if required 106 if(options.declineButton){ 107 var declineButton = '<a href="" class="cb-disable">'+options.declineText+'</a>'; 108 }else{ 109 var declineButton = ''; 110 } 111 //Sets up privacy policy button if required 112 if(options.policyButton){ 113 var policyButton = '<a href="'+options.policyURL+'" class="cb-policy" target="_blank">'+options.policyText+'</a>'; 114 }else{ 115 var policyButton = ''; 116 } 117 //Whether to add "fixed" class to cookie bar 118 if(options.fixed){ 119 if(options.bottom){ 120 var fixed = ' class="fixed bottom"'; 121 }else{ 122 var fixed = ' class="fixed"'; 123 } 124 }else{ 125 var fixed = ''; 126 } 127 if(options.zindex!=''){ 128 var zindex = ' style="z-index:'+options.zindex+';"'; 129 }else{ 130 var zindex = ''; 131 } 132 133 //Displays the cookie bar if arguments met 134 if(options.forceShow || cookieValue=='enabled' || cookieValue==''){ 135 if(options.append){ 136 $(options.element).append('<div id="cookie-bar"'+fixed+zindex+'><p>'+message+acceptButton+declineButton+policyButton+'</p></div>'); 137 }else{ 138 $(options.element).prepend('<div id="cookie-bar"'+fixed+zindex+'><p>'+message+acceptButton+declineButton+policyButton+'</p></div>'); 139 } 140 } 141 142 var removeBar = function(func){ 143 if(options.acceptOnScroll) $(document).off('scroll'); 144 if(typeof(func)==='function') func(cookieValue); 145 if(options.effect=='slide'){ 146 $('#cookie-bar').slideUp(300,function(){$('#cookie-bar').remove();}); 147 }else if(options.effect=='fade'){ 148 $('#cookie-bar').fadeOut(300,function(){$('#cookie-bar').remove();}); 149 }else{ 150 $('#cookie-bar').hide(0,function(){$('#cookie-bar').remove();}); 151 } 152 }; 153 var cookieAccept = function(){ 154 document.cookie = cookieEntry.replace('{value}','accepted'); 155 removeBar(options.acceptFunction); 156 }; 157 var cookieDecline = function(){ 158 var deleteDate = new Date(); 159 deleteDate.setTime(deleteDate.getTime()-(864000000)); 160 deleteDate = deleteDate.toGMTString(); 161 aCookies=document.cookie.split('; '); 162 for (i=0;i<aCookies.length;i++){ 163 aCookie = aCookies[i].split('='); 164 if(aCookie[0].indexOf('_')>=0){ 165 document.cookie = aCookie[0]+'=0; expires='+deleteDate+'; domain='+options.domain.replace('www','')+'; path=/'; 166 }else{ 167 document.cookie = aCookie[0]+'=0; expires='+deleteDate+'; path=/'; 168 } 169 } 170 document.cookie = cookieEntry.replace('{value}','declined'); 171 removeBar(options.declineFunction); 172 }; 173 174 $('#cookie-bar .cb-enable').click(function(){cookieAccept();return false;}); 175 $('#cookie-bar .cb-disable').click(function(){cookieDecline();return false;}); 176 if(options.acceptOnScroll){ 177 var scrollStart = $(document).scrollTop(),scrollNew,scrollDiff; 178 $(document).on('scroll',function(){ 179 scrollNew = $(document).scrollTop(); 180 if(scrollNew>scrollStart){ 181 scrollDiff = scrollNew - scrollStart; 182 }else{ 183 scrollDiff = scrollStart - scrollNew; 184 } 185 if(scrollDiff>=Math.round(options.acceptOnScroll)) cookieAccept(); 186 }); 187 } 188 } 189 }; 190})(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.