1/** 2 * Copyright (C) 2012 Chris Wharton ([email protected]) 3 * 4 * This program is free software: you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation, either version 3 of the License, or 7 * (at your option) any later version. 8 * 9 * THIS SOFTWARE AND DOCUMENTATION IS PROVIDED "AS IS," AND COPYRIGHT 10 * HOLDERS MAKE NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, 11 * INCLUDING BUT NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY OR 12 * FITNESS FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF THE SOFTWARE 13 * OR DOCUMENTATION WILL NOT INFRINGE ANY THIRD PARTY PATENTS, 14 * COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS.COPYRIGHT HOLDERS WILL NOT 15 * BE LIABLE FOR ANY DIRECT, INDIRECT, SPECIAL OR CONSEQUENTIAL 16 * DAMAGES ARISING OUT OF ANY USE OF THE SOFTWARE OR DOCUMENTATION. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with this program. If not, see <http://gnu.org/licenses/>. 20 21 Documentation available at http://cookiecuttr.com 22 23 */ 24(function ($) { 25 $.cookieCuttr = function (options) { 26 27 var options = $.extend(defaults, options); 28 var message = defaults.cookieMessage.replace('{{cookiePolicyLink}}', defaults.cookiePolicyLink); 29 30 defaults.cookieMessage = 'We use cookies on this website, you can <a href="' + defaults.cookiePolicyLink + '" title="read about our cookies">read about them here</a>. To use the website as intended please...'; 31 32 //convert options 33 var cookiePolicyLinkIn = options.cookiePolicyLink; 34 var cookieCutter = options.cookieCutter; 35 var cookieCutterDeclineOnly = options.cookieCutterDeclineOnly; 36 var cookieAnalytics = options.cookieAnalytics; 37 var cookieDeclineButton = options.cookieDeclineButton; 38 var cookieAcceptButton = options.cookieAcceptButton; 39 var cookieResetButton = options.cookieResetButton; 40 var cookieOverlayEnabled = options.cookieOverlayEnabled; 41 var cookiePolicyLink = options.cookiePolicyLink; 42 var cookieMessage = message; 43 var cookieAnalyticsMessage = options.cookieAnalyticsMessage; 44 var cookieErrorMessage = options.cookieErrorMessage; 45 var cookieDisable = options.cookieDisable; 46 var cookieWhatAreTheyLink = options.cookieWhatAreTheyLink; 47 var cookieAcceptButtonText = options.cookieAcceptButtonText; 48 var cookieDeclineButtonText = options.cookieDeclineButtonText; 49 var cookieResetButtonText = options.cookieResetButtonText; 50 var cookieWhatAreLinkText = options.cookieWhatAreLinkText; 51 var cookieNotificationLocationBottom = options.cookieNotificationLocationBottom; 52 var cookiePolicyPageMessage = options.cookiePolicyPageMessage; 53 var cookieDiscreetLink = options.cookieDiscreetLink; 54 var cookieDiscreetReset= options.cookieDiscreetReset; 55 var cookieDiscreetLinkText = options.cookieDiscreetLinkText; 56 var cookieDiscreetPosition = options.cookieDiscreetPosition; 57 var cookieNoMessage = options.cookieNoMessage; 58 59 var cookieAnalyticsId = options.cookieAnalyticsId; 60 cookieDomain = options.cookieDomain; 61 62 var cookiePolicyPage = $('input#cookiecuttr_privacypage').length == 1; 63 if(cookiePolicyPage) 64 { 65 cookieDeclineButton = true; 66 cookieAcceptButton = true; 67 } 68 69 // cookie identifier 70 $.cookieCuttr.accepted = $.cookieCuttr.GetCookie('cc_cookie_accept') == "cc_cookie_accept"; 71 $.cookieCuttr.declined = $.cookieCuttr.GetCookie('cc_cookie_decline') == "cc_cookie_decline"; 72 73 74 var $cookieAccepted = $.cookieCuttr.GetCookie('cc_cookie_accept') == "cc_cookie_accept"; 75 $.cookieAccepted = function () { 76 return $cookieAccepted; 77 }; 78 79 var $cookieDeclined = $.cookieCuttr.GetCookie('cc_cookie_decline') == "cc_cookie_decline"; 80 $.cookieDeclined = function () { 81 return $cookieDeclined; 82 }; 83 84 // write cookie accept button
85 if (cookieAcceptButton) { 86 var cookieAccept = ' <a href="#accept" class="cc-cookie-accept">'+cookieAcceptButtonText+'</a> '; 87 } else { 88 var cookieAccept = ""; 89 } 90 // write cookie decline button 91 if (cookieDeclineButton) { 92 var cookieDecline = ' <a href="#decline" class="cc-cookie-decline">'+cookieDeclineButtonText+'</a> '; 93 } else { 94 var cookieDecline = ""; 95 } 96 97 // write extra class for overlay 98 if (cookieOverlayEnabled) { 99 var cookieOverlay = 'cc-overlay'; 100 } else { 101 var cookieOverlay = ""; 102 } 103 104 105 // to prepend or append, that is the question? 106 if( (cookieNotificationLocationBottom) || (cookieDiscreetPosition == "bottomright") || (cookieDiscreetPosition == "bottomleft") ) { 107 var appOrPre = true; 108 } else { 109 var appOrPre = false; 110 } 111 112 if (($cookieAccepted) || ($cookieDeclined)) { 113 // write cookie reset button 114 if( (cookieResetButton) && (cookieDiscreetReset) ) { 115 116 if(appOrPre) { 117 $('body').append('<div class="cc-cookies cc-discreet"><a class="cc-cookie-reset" href="#" title="'+ cookieResetButtonText +'">'+cookieResetButtonText+'</a></div>'); 118 } else { 119 $('body').prepend('<div class="cc-cookies cc-discreet"><a class="cc-cookie-reset" href="#" title="'+ cookieResetButtonText +'">'+cookieResetButtonText+'</a></div>'); 120 } 121 //add appropriate CSS depending on position chosen 122 if (cookieDiscreetPosition == "topleft") { 123 $('div.cc-cookies').css("top", "0"); 124 $('div.cc-cookies').css("left", "0"); 125 } 126 if (cookieDiscreetPosition == "topright") { 127 $('div.cc-cookies').css("top", "0"); 128 $('div.cc-cookies').css("right", "0"); 129 } 130 if (cookieDiscreetPosition == "bottomleft") { 131 $('div.cc-cookies').css("bottom", "0"); 132 $('div.cc-cookies').css("left", "0"); 133 } 134 if (cookieDiscreetPosition == "bottomright") { 135 $('div.cc-cookies').css("bottom", "0"); 136 $('div.cc-cookies').css("right", "0"); 137 } 138 139 140 } else if(cookieResetButton) { 141 if(appOrPre) { 142 $('body').append('<div class="cc-cookies"><a href="#" class="cc-cookie-reset">'+cookieResetButtonText+'</a></div>'); 143 } else { 144 $('body').prepend('<div class="cc-cookies"><a href="#" class="cc-cookie-reset">'+cookieResetButtonText+'</a></div>'); 145 } 146 } else { 147 var cookieResetButton = ""; 148 } 149 } else { 150 151 // add message to just after opening body tag 152 153 if( (cookieNoMessage)&& (!cookiePolicyPage) ) { 154 // show no link on any pages APART from the policy page 155 } else if ( (cookieDiscreetLink) && (!cookiePolicyPage) ) { // show discreet link 156 if(appOrPre) { 157 $('body').append('<div class="cc-cookies cc-discreet">
157<a href="' + cookiePolicyLinkIn + '" title="'+ cookieDiscreetLinkText +'">'+cookieDiscreetLinkText+'</a></div>'); 158 } else { 159 $('body').prepend('<div class="cc-cookies cc-discreet"><a href="' + cookiePolicyLinkIn + '" title="'+ cookieDiscreetLinkText +'">'+cookieDiscreetLinkText+'</a></div>'); 160 } 161 //add appropriate CSS depending on position chosen 162 if (cookieDiscreetPosition == "topleft") { 163 $('div.cc-cookies').css("top", "0"); 164 $('div.cc-cookies').css("left", "0"); 165 } 166 if (cookieDiscreetPosition == "topright") { 167 $('div.cc-cookies').css("top", "0"); 168 $('div.cc-cookies').css("right", "0"); 169 } 170 if (cookieDiscreetPosition == "bottomleft") { 171 $('div.cc-cookies').css("bottom", "0"); 172 $('div.cc-cookies').css("left", "0"); 173 } 174 if (cookieDiscreetPosition == "bottomright") { 175 $('div.cc-cookies').css("bottom", "0"); 176 $('div.cc-cookies').css("right", "0"); 177 } 178 179 } else if (cookieAnalytics) { // show analytics overlay 180 if(appOrPre) { 181 $('body').append('<div class="cc-cookies ' + cookieOverlay + '">' + cookieAnalyticsMessage + cookieAccept + cookieDecline + '<a href="' + co
181okieWhatAreTheyLink + '" title="Visit All about cookies (External link)">'+cookieWhatAreLinkText+'</a></div>'); 182 } else { 183 $('body').prepend('<div class="cc-cookies ' + cookieOverlay + '">' + cookieAnalyticsMessage + cookieAccept + cookieDecline + '<a href="' + cookieWhatAreTheyLink + '" title="Visit All about cookies (External link)">'+cookieWhatAreLinkText+'</a></div>'); 184 } 185 } 186 if (cookiePolicyPage) { // show policy page overlay 187 if(appOrPre) { 188 $('body').append('<div class="cc-cookies ' + cookieOverlay + '">' + cookiePolicyPageMessage + " " + ' <a href="#accept" class="cc-cookie-accept">'+cookieAcceptButtonText+'</a> ' + ' <a href="#decline" class="cc-cookie-decline">'+cookieDeclineButtonText+'</a> ' + '</div>'); 189 } else { 190 $('body').prepend('<div class="cc-cookies ' + cookieOverlay + '">' + cookiePolicyPageMessage + " " + ' <a href="#accept" class="cc-cookie-accept">'+cookieAcceptButtonText+'</a> ' + ' <a href="#decline" class="cc-cookie-decline">'+cookieDeclineButtonText+'</a> ' + '</div>'); 191 } 192 } else if ((!cookieAnalytics) && (!cookieDiscreetLink) ) { // show privacy policy option 193 if(appOrPre) { 194 $('body').append('<div class="cc-cookies ' + cookieOverlay + '">' + cookieMessage + cookieAccept + cookieDecline + '</div>'); 195 } else { 196 $('body').prepend('<div class="cc-cookies ' + cookieOverlay + '">' + cookieMessage + cookieAccept + cookieDecline + '</div>'); 197 } 198 } 199 200 } 201 202 if ( (cookieCutter) && (!cookieCutterDeclineOnly) && ( ($cookieDeclined) || (!$cookieAccepted) ) ) { 203 $(cookieDisable).html('<div class="cc-cookies-error">' + cookieErrorMessage + ' <a href="#accept" class="cc-cookie-accept">'+cookieAcceptButtonText+'</a> ' + '</div>'); 204 } 205 206 if ( (cookieCutter) && (cookieCutterDeclineOnly) && ($cookieDeclined) ) { 207 $(cookieDisable).html('<div class="cc-cookies-error">' + cookieErrorMessage + ' <a href="#accept" class="cc-cookie-accept">'+cookieAcceptButtonText+'</a> ' + '</div>'); 208 } 209 210 // if bottom is true, switch div to bottom if not in discreet mode 211 if( (cookieNotificationLocationBottom) && (!cookieDiscreetLink) ) { 212 $('div.cc-cookies').css("top", "auto"); 213 $('div.cc-cookies').css("bottom", "0"); 214 } 215 if( (cookieNotificationLocationBottom) && (cookieDiscreetLink) && (cookiePolicyPage) ) { 216 $('div.cc-cookies').css("top", "auto"); 217 $('div.cc-cookies').css("bottom", "0"); 218 } 219 220 221 // setting the cookies 222 223 // for top bar 224 $('.cc-cookie-accept, .cc-cookie-decline').click(function (e) { 225 e.preventDefault(); 226 if ($(this).is('[href$="#decline"]')) { 227 $.cookieCuttr.SetCookie("cc_cookie_accept", null, "/"); 228 $.cookieCuttr.SetCookie("cc_cookie_decline", "cc_cookie_decline", "/"); 229 // clear down known google analytics cookies 230 if(cookieDomain) { 231 $.cookieCuttr.SetCookie("__utma", null, "/"); 232 $.cookieCuttr.SetCookie("__utmb", null, "/"); 233 $.cookieCuttr.SetCookie("__utmc", null, "/"); 234 $.cookieCuttr.SetCookie("__utmz", null, "/"); 235 } 236 } else { 237 $.cookieCuttr.SetCookie("cc_cookie_decline", null, "/"); 238 $.cookieCuttr.SetCookie("cc_cookie_accept", "cc_cookie_accept", "/"); 239 } 240 $(".cc-cookies").fadeOut(function () { 241 // reload page to activate cookies 242 location.reload(); 243 }); 244 245 }); 246 247 //reset cookies 248 $('a.cc-cookie-reset').click(function(f) { 249 f.preventDefault(); 250 $.cookieCuttr.SetCookie("cc_cookie_accept", null, "/"); 251 $.cookieCuttr.SetCookie("cc_cookie_decline", null, "/"); 252 $(".cc-cookies").fadeOut(function () { 253 // reload page to activate cookies 254 location.reload(); 255 });
256 }); 257 258 //cookie error accept 259 $('.cc-cookies-error a.cc-cookie-accept').click(function(g) { 260 g.preventDefault(); 261 $.cookieCuttr.SetCookie("cc_cookie_decline", null, "/"); 262 $.cookieCuttr.SetCookie("cc_cookie_accept", "cc_cookie_accept", "/"); 263 // reload page to activate cookies 264 location.reload(); 265 }); 266 267 }; 268 269 $.cookieCuttr.SetCookie = function(name, value, path) 270 { 271 var expires = ''; 272 if(value != null) 273 { 274 ccToday = new Date(); 275 ccExpire = new Date(); 276 ccExpire.setTime(ccToday.getTime() + 3600000*24*365); 277 278 expires = ';expires='+ccExpire.toGMTString(); 279 } 280 else 281 { 282 expires = ';expires=Thu, 01-Jan-1970 00:00:01 GMT'; 283 value = ''; 284 } 285 286 if(cookieDomain) { 287 document.cookie = name + '=' +escape(value) + ';path='+path + ';domain=.'+cookieDomain + expires; 288 } else { 289 document.cookie = name + '=' +escape(value) + ';path='+path + expires; 290 } 291 }; 292 $.cookieCuttr.GetCookie = function(name) 293 { 294 if(name.length > 0) 295 { 296 var cookies = ' ' + document.cookie; 297 var start = cookies.indexOf(' ' + name + '='); 298 299 if(start == -1) 300 { 301 start = cookies.indexOf(';' + name + '='); 302 303 if(start == -1) 304 { 305 return ''; 306 } 307 } 308 309 var end = cookies.indexOf(';', start + 1); 310 311 if(end == -1) 312 { 313 end = cookies.length; 314 } 315 316 return unescape(cookies.substring(start + name.length + 2, end)); 317 } 318 }; 319 320// temporarily set variables for first load 321$.cookieCuttr.accepted = $.cookieCuttr.GetCookie('cc_cookie_accept') == "cc_cookie_accept"; 322$.cookieCuttr.declined = $.cookieCuttr.GetCookie('cc_cookie_decline') == "cc_cookie_decline"; 323 324// launch plugin on doc ready 325$(document).ready(function(){ 326 $.cookieCuttr(); 327}); 328 329})(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.