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: 'Le informamos que en esta web solo utilizamos cookies propias para que tu navegación sea más fluida y mejorar nuestros servicios. Puede obtener más información en nuestra polÃtica de cookies.', //Message displayed on bar 28 acceptButton: true, //Set to true to show accept/enable button 29 acceptText: 'Estoy de acuerdo', //Text on accept/enable button 30 acceptFunction: function(cookieValue){if(cookieValue!='enabled' && cookieValue!='accepted') window.location = window.location.href;}, //Function to run after accept 31 declineButton: false, //Set to true to show decline/disable button 32 declineText: 'Disable Cookies', //Text on decline/disable button 33 declineFunction: function(cookieValue){if(cookieValue=='enabled' || cookieValue=='accepted') window.location = window.location.href;}, //Function to run after decline 34 policyButton: true, //Set to true to show Privacy Policy button 35 policyText: 'Política de cookies', //Text on Privacy Policy button 36 policyURL: './PoliticaCookies', //URL of Privacy Policy 37 autoEnable: true, //Set to true for cookies to be accepted automatically. Banner still shows 38 acceptOnContinue: false, //Set to true to accept cookies when visitor moves to another page 39 acceptOnScroll: false, //Set to true to accept cookies when visitor scrolls X pixels up or down 40 acceptAnyClick: false, //Set to true to accept cookies when visitor clicks anywhere on the page 41 expireDays: 365, //Number of days for cookieBar cookie to be stored for 42 renewOnVisit: false, //Renew the cookie upon revisit to website 43 forceShow: false, //Force cookieBar to show regardless of user cookie preference 44 effect: 'fade', //Options: slide, fade, hide 45 element: 'body', //Element to append/prepend cookieBar to. Remember "." for class or "#" for id. 46 append: true, //Set to true for cookieBar HTML to be placed at base of website. Actual position may change according to CSS 47 fixed: true, //Set to true to add the class "fixed" to the cookie bar. Default CSS should fix the position 48 bottom: true, //Force CSS when fixed, so bar appears at bottom of website 49 zindex: '10', //Can be set in CSS, although some may prefer to set here 50 domain: String(window.location.hostname), //Location of privacy policy 51 referrer: String(document.referrer) //Where visitor has come from 52 }; 53 54 55 if (document.getElementById("lblIdioma").textContent == "cat") 56 { 57 58 defaults = { 59 message: 'L´informem que utilitzem cookies pròpies i de tercers per millorar els nostres serveis. Si continua navegant, considerem que accepta el seu ús. Podeu obtenir més informació, o bé conèixer com canviar la configuració del seu navegador.', //Message displayed on bar 60 acceptButton: true, //Set to true to show accept/enable button 61 acceptText: 'Estic d´acord', //Text on accept/enable button 62 acceptFunction: function (cookieValue) { if (cookieValue != 'enabled' && cookieValue != 'accepted') window.location = window.location.href; }, //Function to run after accept 63 declineButton: false, //Set to true to show decline/disable button 64 declineText: 'Disable Cookies', //Text on decline/disable button 65 declineFunction: function (cookieValue) { if (cookieValue == 'enabled' || cookieValue == 'accepted') window.location = window.location.href; }, //Function to run after decline 66 policyButton: true, //Set to true to show Privacy Policy button 67 policyText: 'Política de cookies', //Text on Privacy Policy button
68 policyURL: './PoliticaCookies', //URL of Privacy Policy 69 autoEnable: true, //Set to true for cookies to be accepted automatically. Banner still shows 70 acceptOnContinue: false, //Set to true to accept cookies when visitor moves to another page 71 acceptOnScroll: false, //Set to true to accept cookies when visitor scrolls X pixels up or down 72 acceptAnyClick: false, //Set to true to accept cookies when visitor clicks anywhere on the page 73 expireDays: 365, //Number of days for cookieBar cookie to be stored for 74 renewOnVisit: false, //Renew the cookie upon revisit to website 75 forceShow: false, //Force cookieBar to show regardless of user cookie preference 76 effect: 'fade', //Options: slide, fade, hide 77 element: 'body', //Element to append/prepend cookieBar to. Remember "." for class or "#" for id. 78 append: true, //Set to true for cookieBar HTML to be placed at base of website. Actual position may change according to CSS 79 fixed: true, //Set to true to add the class "fixed" to the cookie bar. Default CSS should fix the position 80 bottom: true, //Force CSS when fixed, so bar appears at bottom of website 81 zindex: '10', //Can be set in CSS, although some may prefer to set here 82 domain: String(window.location.hostname), //Location of privacy policy 83 referrer: String(document.referrer) //Where visitor has come from 84 }; 85 86 87 } 88 89 90 91 92 93 var options = $.extend(defaults,options); 94 95 //Sets expiration date for cookie 96 var expireDate = new Date(); 97 expireDate.setTime(expireDate.getTime()+(options.expireDays*86400000)); 98 expireDate = expireDate.toGMTString(); 99 100 var cookieEntry = 'cb-enabled={value}; expires='+expireDate+'; path=/'; 101 102 //Retrieves current cookie preference 103 var i,cookieValue='',aCookie,aCookies=document.cookie.split('; '); 104 for (i=0;i<aCookies.length;i++){ 105 aCookie = aCookies[i].split('='); 106 if(aCookie[0]=='cb-enabled'){ 107 cookieValue = aCookie[1]; 108 } 109 } 110 //Sets up default cookie preference if not already set 111 if(cookieValue=='' && doReturn!='cookies' && options.autoEnable){ 112 cookieValue = 'enabled'; 113 document.cookie = cookieEntry.replace('{value}','enabled'); 114 }else if((cookieValue=='accepted' || cookieValue=='declined') && doReturn!='cookies' && options.renewOnVisit){ 115 document.cookie = cookieEntry.replace('{value}',cookieValue); 116 } 117 if(options.acceptOnContinue){ 118 if(options.referrer.indexOf(options.domain)>=0 && String(window.location.href).indexOf(options.policyURL)==-1 && doReturn!='cookies' && doReturn!='set' && cookieValue!='accepted' && cookieValue!='declined'){ 119 doReturn = 'set'; 120 val = 'accepted'; 121 } 122 } 123 if(doReturn=='cookies'){ 124 //Returns true if cookies are enabled, false otherwise 125 if(cookieValue=='enabled' || cookieValue=='accepted'){ 126 return true; 127 }else{ 128 return false; 129 } 130 }else if(doReturn=='set' && (val=='accepted' || val=='declined')){ 131 //Sets value of cookie to 'accepted' or 'declined' 132 document.cookie = cookieEntry.replace('{value}',val); 133 if(val=='accepted'){ 134 return true; 135 }else{ 136 return false; 137 } 138 }else{ 139 //Sets up enable/accept button if required 140 var message = options.message.replace('{policy_url}',options.policyURL); 141 142 if(options.acceptButton){ 143 var acceptButton = '<a href="" class="cb-enable">'+options.acceptText+'</a>'; 144 }else{ 145 var acceptButton = ''; 146 } 147 //Sets up disable/decline button if required 148 if(options.declineButton){ 149 var declineButton = '<a href="" class="cb-disable">'+options.declineText+'</a>'; 150 }else{ 151 var declineButton = ''; 152 } 153 //Sets up privacy policy button if required 154 if(options.policyButton){ 155 var policyButton = '<a href="'+options.policyURL+'" class="cb-policy">'+options.policyText+'</a>'; 156 }else{ 157 var policyButton = ''; 158 } 159 //Whether to add "fixed" class to cookie bar 160 if(options.fixed){ 161 if(options.bottom){ 162 var fixed = ' class="fixed bottom"'; 163 }else{ 164 var fixed = ' class="fixed"'; 165 } 166 }else{ 167 var fixed = ''; 168 } 169 if(options.zindex!=''){ 170 var zindex = ' style="z-index:'+options.zindex+';"'; 171 }else{ 172 var zindex = ''; 173 } 174 175 //Displays the cookie bar if arguments met 176 if(options.forceShow || cookieValue=='enabled' || cookieValue==''){ 177 if(options.append){ 178 $(options.element).append('<div id="cookie-bar"'+fixed+zindex+'><p>'+message+acceptButton+declineButton+policyButton+'</p></div>'); 179 }else{ 180 $(options.element).prepend('<div id="cookie-bar"'+fixed+zindex+'><p>'+message+acceptButton+declineButton+policyButton+'</p></div>'); 181 } 182 } 183 184 var removeBar = function(func){ 185 if(options.acceptOnScroll) $(document).off('scroll'); 186 if(typeof(func)==='function') func(cookieValue); 187 if(options.effect=='slide'){ 188 $('#cookie-bar').slideUp(300,function(){$('#cookie-bar').remove();}); 189 }else if(options.effect=='fade'){ 190 $('#cookie-bar').fadeOut(300,function(){$('#cookie-bar').remove();}); 191 }else{ 192 $('#cookie-bar').hide(0,function(){$('#cookie-bar').remove();}); 193 } 194 $(document).unbind('click',anyClick); 195 }; 196 var cookieAccept = function(){ 197 document.cookie = cookieEntry.replace('{value}','accepted'); 198 removeBar(options.acceptFunction); 199 }; 200 var cookieDecline = function(){ 201 var deleteDate = new Date(); 202 deleteDate.setTime(deleteDate.getTime()-(864000000)); 203 deleteDate = deleteDate.toGMTString(); 204 aCookies=document.cookie.split('; '); 205 for (i=0;
205i<aCookies.length;i++){ 206 aCookie = aCookies[i].split('='); 207 if(aCookie[0].indexOf('_')>=0){ 208 document.cookie = aCookie[0]+'=0; expires='+deleteDate+'; domain='+options.domain.replace('www','')+'; path=/'; 209 }else{ 210 document.cookie = aCookie[0]+'=0; expires='+deleteDate+'; path=/'; 211 } 212 } 213 document.cookie = cookieEntry.replace('{value}','declined'); 214 removeBar(options.declineFunction); 215 }; 216 var anyClick = function(e){ 217 if(!$(e.target).hasClass('cb-policy')) cookieAccept(); 218 }; 219 220 $('#cookie-bar .cb-enable').click(function(){cookieAccept();return false;}); 221 $('#cookie-bar .cb-disable').click(function(){cookieDecline();return false;}); 222 if(options.acceptOnScroll){ 223 var scrollStart = $(document).scrollTop(),scrollNew,scrollDiff; 224 $(document).on('scroll',function(){ 225 scrollNew = $(document).scrollTop(); 226 if(scrollNew>scrollStart){ 227 scrollDiff = scrollNew - scrollStart; 228 }else{ 229 scrollDiff = scrollStart - scrollNew; 230 } 231 if(scrollDiff>=Math.round(options.acceptOnScroll)) cookieAccept(); 232 }); 233 } 234 if(options.acceptAnyClick){ 235 $(document).bind('click',anyClick); 236 } 237 } 238 }; 239})(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.