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 26 var defaults = { 27 message: 'We use cookies to track usage and preferences.', //Message displayed on bar 28 acceptButton: true, //Set to true to show accept/enable button 29 acceptText: 'I Understand', //Text on accept/enable button 30 declineButton: false, //Set to true to show decline/disable button 31 declineText: 'Disable Cookies', //Text on decline/disable button 32 policyButton: false, //Set to true to show Privacy Policy button 33 policyText: 'Privacy Policy', //Text on Privacy Policy button 34 policyURL: '/privacy-policy/', //URL of Privacy Policy 35 autoEnable: true, //Set to true for cookies to be accepted automatically. Banner still shows 36 acceptOnContinue: false, //Set to true to silently accept cookies when visitor moves to another page 37 expireDays: 365, //Number of days for cookieBar cookie to be stored for 38 forceShow: false, //Force cookieBar to show regardless of user cookie preference 39 effect: 'slide', //Options: slide, fade, hide 40 element: 'body', //Element to append/prepend cookieBar to. Remember "." for class or "#" for id. 41 append: false, //Set to true for cookieBar HTML to be placed at base of website. Actual position may change according to CSS 42 fixed: false, //Set to true to add the class "fixed" to the cookie bar. Default CSS should fix the position 43 bottom: false, //Force CSS when fixed, so bar appears at bottom of website 44 zindex: '', //Can be set in CSS, although some may prefer to set here 45 redirect: String(window.location.href), //Current location 46 domain: String(window.location.hostname), //Location of privacy policy 47 referrer: String(document.referrer) //Where visitor has come from 48 }; 49 var options = $.extend(defaults,options); 50 51 //Sets expiration date for cookie 52 var expireDate = new Date(); 53 expireDate.setTime(expireDate.getTime()+(options.expireDays*24*60*60*1000)); 54 expireDate = expireDate.toGMTString(); 55 56 var cookieEntry = 'cb-enabled={value}; expires='+expireDate+'; path=/'; 57 58 //Retrieves current cookie preference 59 var i,cookieValue='',aCookie,aCookies=document.cookie.split('; '); 60 for (i=0;i<aCookies.length;i++){ 61 aCookie = aCookies[i].split('='); 62 if(aCookie[0]=='cb-enabled'){ 63 cookieValue = aCookie[1]; 64 } 65 } 66 //Sets up default cookie preference if not already set 67 if(cookieValue=='' && options.autoEnable){ 68 cookieValue = 'enabled'; 69 document.cookie = cookieEntry.replace('{value}','enabled'); 70 } 71 if(options.acceptOnContinue){ 72 if(options.referrer.indexOf(options.domain)>=0 && String(window.location.href).indexOf(options.policyURL)==-1 && doReturn!='cookies' && doReturn!='set' && cookieValue!='accepted' && cookieValue!='declined'){ 73 doReturn = 'set'; 74 val = 'accepted'; 75 } 76 } 77 if(doReturn=='cookies'){ 78 //Returns true if cookies are enabled, false otherwise 79 if(cookieValue=='enabled' || cookieValue=='accepted'){ 80 return true; 81 }else{ 82 return false; 83 } 84 }else if(doReturn=='set' && (val=='accepted' || val=='declined')){ 85 //Sets value of cookie to 'accepted' or 'declined' 86 document.cookie = cookieEntry.replace('{value}',val); 87 if(val=='accepted'){ 88 return true; 89 }else{ 90 return false; 91 } 92 }else{ 93 //Sets up enable/accept button if required 94 var message = options.message.replace('{policy_url}',options.policyURL); 95 96 if(options.acceptButton){ 97 var acceptButton = '<a href="" class="cb-enable">'+options.acceptText+'</a>'; 98 }else{ 99 var acceptButton = ''; 100 } 101 //Sets up disable/decline button if required 102 if(options.declineButton){ 103 var declineButton = '<a href="" class="cb-disable">'+options.declineText+'</a>'; 104 }else{ 105 var declineButton = ''; 106 } 107 //Sets up privacy policy button if required 108 if(options.policyButton){ 109 var policyButton = '<a href="'+options.policyURL+'" class="cb-policy">
109'+options.policyText+'</a>'; 110 }else{ 111 var policyButton = ''; 112 } 113 //Whether to add "fixed" class to cookie bar 114 if(options.fixed){ 115 if(options.bottom){ 116 var fixed = ' class="fixed bottom"'; 117 }else{ 118 var fixed = ' class="fixed"'; 119 } 120 }else{ 121 var fixed = ''; 122 } 123 if(options.zindex!=''){ 124 var zindex = ' style="z-index:'+options.zindex+';"'; 125 }else{ 126 var zindex = ''; 127 } 128 129 //Displays the cookie bar if arguments met 130 if(options.forceShow || cookieValue=='enabled' || cookieValue==''){ 131 if(options.append){ 132 $(options.element).append('<div id="cookie-bar"'+fixed+zindex+'><p>'+message+acceptButton+declineButton+policyButton+'</p></div>'); 133 }else{ 134 $(options.element).prepend('<div id="cookie-bar"'+fixed+zindex+'><p>'+message+acceptButton+declineButton+policyButton+'</p></div>'); 135 } 136 } 137 138 //Sets the cookie preference to accepted if enable/accept button pressed 139 $('#cookie-bar .cb-enable').click(function(){ 140 document.cookie = cookieEntry.replace('{value}','accepted'); 141 if(cookieValue!='enabled' && cookieValue!='accepted'){ 142 window.location = options.currentLocation; 143 }else{ 144 if(options.effect=='slide'){ 145 $('#cookie-bar').slideUp(300,function(){$('#cookie-bar').remove();}); 146 }else if(options.effect=='fade'){ 147 $('#cookie-bar').fadeOut(300,function(){$('#cookie-bar').remove();}); 148 }else{ 149 $('#cookie-bar').hide(0,function(){$('#cookie-bar').remove();}); 150 } 151 return false; 152 } 153 }); 154 //Sets the cookie preference to declined if disable/decline button pressed 155 $('#cookie-bar .cb-disable').click(function(){ 156 var deleteDate = new Date(); 157 deleteDate.setTime(deleteDate.getTime()-(864000000)); 158 deleteDate = deleteDate.toGMTString(); 159 aCookies=document.cookie.split('; '); 160 for (i=0;i<aCookies.length;i++){ 161 aCookie = aCookies[i].split('='); 162 if(aCookie[0].indexOf('_')>=0){ 163 document.cookie = aCookie[0]+'=0; expires='+deleteDate+'; domain='+options.domain.replace('www','')+'; path=/'; 164 }else{ 165 document.cookie = aCookie[0]+'=0; expires='+deleteDate+'; path=/'; 166 } 167 } 168 document.cookie = cookieEntry.replace('{value}','declined'); 169 if(cookieValue=='enabled' && cookieValue!='accepted'){ 170 window.location = options.currentLocation; 171 }else{ 172 if(options.effect=='slide'){ 173 $('#cookie-bar').slideUp(300,function(){$('#cookie-bar').remove();}); 174 }else if(options.effect=='fade'){ 175 $('#cookie-bar').fadeOut(300,function(){$('#cookie-bar').remove();}); 176 }else{ 177 $('#cookie-bar').hide(0,function(){$('#cookie-bar').remove();}); 178 } 179 return false; 180 } 181 }); 182 } 183 }; 184})(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.