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