├── .DS_Store ├── README.md ├── cookiecuttr.css └── jquery.cookiecuttr.js /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cdwharton/cookieCuttr/4dc24d962837c039f50efbf48505b44166989c39/.DS_Store -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | CookieCuttr 2 | =========== 3 | 4 | A tailorable jQuery plugin to deal with the EU Cookie Law. 5 | 6 | **We're not accepting any more pull requests, someone else is working on a new version at the moment, when its ready, we'll link it here.** 7 | 8 | Dependencies 9 | ------------ 10 | 11 | * [jQuery](https://github.com/jquery/jquery) 12 | * [jQuery.cookie](https://github.com/carhartl/jquery-cookie) 13 | 14 | Useage 15 | ------ 16 | 17 | Add `jquery.cookiecuttr.js`, after jQuery and jQuery.cookie, and `cookiecuttr.css` to the head of your HTML document. Then call CookieCuttr on document ready. 18 | 19 | ```javascript 20 | $(document).ready(function () { 21 | $.cookieCuttr(); 22 | }); 23 | ``` 24 | 25 | For any JavaScript you want to disable, you need to wrap the following if statement around it. 26 | 27 | ```javascript 28 | if (jQuery.cookie('cc_cookie_accept') == "cc_cookie_accept") { 29 | // insert the code you do not want to run UNTIL cookies are accepted here 30 | } 31 | ``` 32 | 33 | Example with Google Analytics 34 | ----------------------------- 35 | 36 | ```javascript 37 | if (jQuery.cookie('cc_cookie_accept') == "cc_cookie_accept") { 38 | var _gaq = _gaq || []; 39 | _gaq.push(['_setAccount', 'UA-XXXXXXXX-X']); 40 | _gaq.push(['_trackPageview']); 41 | 42 | (function() { 43 | var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; 44 | ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; 45 | var s = document. getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); 46 | })(); 47 | } 48 | ``` 49 | 50 | Alternatively, you can do the following until cookies are declined. 51 | 52 | ```javascript 53 | if (jQuery.cookie('cc_cookie_decline') == "cc_cookie_decline") { 54 | // do nothing 55 | } else { 56 | var _gaq = _gaq || []; 57 | _gaq.push(['_setAccount', 'UA-XXXXXXXX-X']); 58 | _gaq.push(['_trackPageview']); 59 | 60 | (function() { 61 | var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; 62 | ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; 63 | var s = document. getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); 64 | })(); 65 | } 66 | ``` 67 | 68 | You can also do the following. 69 | 70 | ```javascript 71 | if( $.cookieAccepted() ) { 72 | // insert the code you do not want to run UNTIL cookies are accepted here 73 | } 74 | ``` 75 | 76 | Read More About EU Cookie Law 77 | ----------------------------- 78 | 79 | * [Is the EU's cookie law confusing you too?](http://www.123-reg.co.uk/blog/security-issues/is-the-eus-cookie-law-confusing-you-too/) 80 | * [New EU cookie law (e-Privacy Directive)](http://www.ico.gov.uk/for_organisations/privacy_and_electronic_communications/the_guide/cookies.aspx) 81 | * [Cookies – Doing nothing isn't the right answer](http://chriswharton.me/2012/05/cookies-doing-nothing-isnt-the-right-answer/) 82 | 83 | Using WordPress? 84 | ---------------- 85 | 86 | A Wordpress version is available [here](http://cookiecuttr.com/wordpress-plugin/). 87 | 88 | Options 89 | ------- 90 | 91 | For options, see the [WIKI](/weare2ndfloor/cookieCuttr/wiki/Options). 92 | 93 | Contributing to CookieCuttr 94 | --------------------------- 95 | 96 | * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet 97 | * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it 98 | * Fork the project 99 | * Start a feature/bugfix branch 100 | * Commit and push until you are happy with your contribution 101 | * Initiate a [pull request](https://help.github.com/articles/using-pull-requests) 102 | 103 | Credits 104 | ------- 105 | 106 | * [weare2ndfloor](https://github.com/weare2ndfloor) for the plugin 107 | * [unsymbol](https://github.com/unsymbol) for organising the implementation txt into a readme markdown file 108 | 109 | Copyright 110 | --------- 111 | 112 | Copyright (c) 2012 Chris Wharton. See LICENSE.txt for further details. 113 | -------------------------------------------------------------------------------- /cookiecuttr.css: -------------------------------------------------------------------------------- 1 | /* To be used with cookieCuttr by Chris Wharton (http://cookiecuttr.com) */ 2 | 3 | .cc-cookies { position:fixed; width: 90%; left: 0; top: 0; padding: 0.5em 5%; background: #565656; background: rgba(86,86,86,0.95); color: #fff; font-size: 13px; font-weight: 700; text-shadow: 0 -1px 0 rgba(0,0,0,0.35); z-index: 99999; text-align: center; color: #fff; } 4 | .cc-cookies a, .cc-cookies a:hover { color: #fff; text-decoration: underline; } 5 | .cc-cookies a:hover { text-decoration: none; } 6 | .cc-overlay { height: 100%; padding-top: 25%; } 7 | .cc-cookies-error { float: left; width: 90%; text-align: center; margin: 1em 0 2em 0; background: #fff; padding: 2em 5%; border: 1px solid #ccc; font-size: 18px; color: #333; } 8 | .cc-cookies a.cc-cookie-accept, .cc-cookies-error a.cc-cookie-accept, .cc-cookies a.cc-cookie-decline, .cc-cookies-error a.cc-cookie-decline, .cc-cookies a.cc-cookie-reset { display: inline-block; color: #fff; text-decoration: none; background: #7DAF3B; padding: 0.5em 0.75em; border-radius: 3px; box-shadow: 0 0 2px rgba(0,0,0,0.25); text-shadow: 0 -1px 0 rgba(0,0,0,0.35); -o-transition: background 0.5s ease-in; -webkit-transition: background 0.25s ease-in; -moz-transition: background 0.25s ease-in; } 9 | .cc-cookies a.cc-cookie-decline, .cc-cookies-error a.cc-cookie-decline { background: #af3b3b; margin-left: 0.5em; } 10 | .cc-cookies a.cc-cookie-reset { background: #f15b00; } 11 | .cc-cookies a:hover.cc-cookie-accept, .cc-cookies-error a:hover.cc-cookie-accept, .cc-cookies a:hover.cc-cookie-decline, .cc-cookies-error a:hover.cc-cookie-decline, .cc-cookies a:hover.cc-cookie-reset { background: #000; -o-transition: background 0.5s ease-in; -webkit-transition: background 0.25s ease-in; -moz-transition: background 0.25s ease-in; } 12 | .cc-cookies-error a.cc-cookie-accept, .cc-cookies-error a.cc-cookie-decline { display: block; margin-top: 1em; } 13 | .cc-cookies.cc-discreet { width: auto; padding: 0.5em 1em; left: auto; top: auto; } 14 | .cc-cookies.cc-discreet a.cc-cookie-reset { background: none; text-shadow: none; padding: 0; text-decoration: underline; } 15 | .cc-cookies.cc-discreet a:hover.cc-cookie-reset { text-decoration: none; } 16 | 17 | @media screen and (max-width: 768px) { 18 | .cc-cookies a.cc-cookie-accept, .cc-cookies a.cc-cookie-decline, .cc-cookies a.cc-cookie-reset { display: block; margin: 1em 0; } 19 | } 20 | 21 | @media screen and (max-width: 480px) { 22 | .cc-cookies { position: relative; float: left; } 23 | } -------------------------------------------------------------------------------- /jquery.cookiecuttr.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2012 Chris Wharton (chris@weare2ndfloor.com) 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 . 20 | 21 | Documentation available at http://cookiecuttr.com 22 | 23 | */ 24 | (function ($) { 25 | $.cookieCuttr = function (options) { 26 | var defaults = { 27 | cookieCutter: false, // you'd like to enable the div/section/span etc. hide feature? change this to true 28 | cookieCutterDeclineOnly: false, // you'd like the CookieCutter to only hide when someone has clicked declined set this to true 29 | cookieAnalytics: true, // just using a simple analytics package? change this to true 30 | cookieDeclineButton: false, // this will disable non essential cookies 31 | cookieAcceptButton: true, // this will disable non essential cookies 32 | cookieResetButton: false, 33 | cookieOverlayEnabled: false, // don't want a discreet toolbar? Fine, set this to true 34 | cookiePolicyLink: '/privacy-policy/', // if applicable, enter the link to your privacy policy here... 35 | cookieMessage: 'We use cookies on this website, you can read about them here. To use the website as intended please...', 36 | cookieAnalyticsMessage: 'We use cookies, just to track visits to our website, we store no personal details.', 37 | cookieErrorMessage: "We\'re sorry, this feature places cookies in your browser and has been disabled.
To continue using this functionality, please", 38 | cookieWhatAreTheyLink: "http://www.allaboutcookies.org/", 39 | cookieDisable: '', 40 | cookieExpires: 365, 41 | cookieAcceptButtonText: "ACCEPT COOKIES", 42 | cookieDeclineButtonText: "DECLINE COOKIES", 43 | cookieResetButtonText: "RESET COOKIES FOR THIS WEBSITE", 44 | cookieWhatAreLinkText: "What are cookies?", 45 | cookieNotificationLocationBottom: false, // top or bottom - they are your only options, so true for bottom, false for top 46 | cookiePolicyPage: false, 47 | cookiePolicyPageMessage: 'Please read the information below and then choose from the following options', 48 | cookieDiscreetLink: false, 49 | cookieDiscreetReset: false, 50 | cookieDiscreetLinkText: "Cookies?", 51 | cookieDiscreetPosition: "topleft", //options: topleft, topright, bottomleft, bottomright 52 | cookieNoMessage: false, // change to true hide message from all pages apart from your policy page 53 | cookieDomain: "" 54 | }; 55 | var options = $.extend(defaults, options); 56 | var message = defaults.cookieMessage.replace('{{cookiePolicyLink}}', defaults.cookiePolicyLink); 57 | defaults.cookieMessage = 'We use cookies on this website, you can read about them here. To use the website as intended please...'; 58 | //convert options 59 | var cookiePolicyLinkIn = options.cookiePolicyLink; 60 | var cookieCutter = options.cookieCutter; 61 | var cookieCutterDeclineOnly = options.cookieCutterDeclineOnly; 62 | var cookieAnalytics = options.cookieAnalytics; 63 | var cookieDeclineButton = options.cookieDeclineButton; 64 | var cookieAcceptButton = options.cookieAcceptButton; 65 | var cookieResetButton = options.cookieResetButton; 66 | var cookieOverlayEnabled = options.cookieOverlayEnabled; 67 | var cookiePolicyLink = options.cookiePolicyLink; 68 | var cookieMessage = message; 69 | var cookieAnalyticsMessage = options.cookieAnalyticsMessage; 70 | var cookieErrorMessage = options.cookieErrorMessage; 71 | var cookieDisable = options.cookieDisable; 72 | var cookieWhatAreTheyLink = options.cookieWhatAreTheyLink; 73 | var cookieExpires = options.cookieExpires; 74 | var cookieAcceptButtonText = options.cookieAcceptButtonText; 75 | var cookieDeclineButtonText = options.cookieDeclineButtonText; 76 | var cookieResetButtonText = options.cookieResetButtonText; 77 | var cookieWhatAreLinkText = options.cookieWhatAreLinkText; 78 | var cookieNotificationLocationBottom = options.cookieNotificationLocationBottom; 79 | var cookiePolicyPage = options.cookiePolicyPage; 80 | var cookiePolicyPageMessage = options.cookiePolicyPageMessage; 81 | var cookieDiscreetLink = options.cookieDiscreetLink; 82 | var cookieDiscreetReset = options.cookieDiscreetReset; 83 | var cookieDiscreetLinkText = options.cookieDiscreetLinkText; 84 | var cookieDiscreetPosition = options.cookieDiscreetPosition; 85 | var cookieNoMessage = options.cookieNoMessage; 86 | // cookie identifier 87 | var $cookieAccepted = $.cookie('cc_cookie_accept') == "cc_cookie_accept"; 88 | $.cookieAccepted = function () { 89 | return $cookieAccepted; 90 | }; 91 | var $cookieDeclined = $.cookie('cc_cookie_decline') == "cc_cookie_decline"; 92 | $.cookieDeclined = function () { 93 | return $cookieDeclined; 94 | }; 95 | // write cookie accept button 96 | if (cookieAcceptButton) { 97 | var cookieAccept = ' ' + cookieAcceptButtonText + ' '; 98 | } else { 99 | var cookieAccept = ""; 100 | } 101 | // write cookie decline button 102 | if (cookieDeclineButton) { 103 | var cookieDecline = ' ' + cookieDeclineButtonText + ' '; 104 | } else { 105 | var cookieDecline = ""; 106 | } 107 | // write extra class for overlay 108 | if (cookieOverlayEnabled) { 109 | var cookieOverlay = 'cc-overlay'; 110 | } else { 111 | var cookieOverlay = ""; 112 | } 113 | // to prepend or append, that is the question? 114 | if ((cookieNotificationLocationBottom) || (cookieDiscreetPosition == "bottomright") || (cookieDiscreetPosition == "bottomleft")) { 115 | var appOrPre = true; 116 | } else { 117 | var appOrPre = false; 118 | } 119 | if (($cookieAccepted) || ($cookieDeclined)) { 120 | // write cookie reset button 121 | if ((cookieResetButton) && (cookieDiscreetReset)) { 122 | if (appOrPre) { 123 | $('body').append('
' + cookieResetButtonText + '
'); 124 | } else { 125 | $('body').prepend('
' + cookieResetButtonText + '
'); 126 | } 127 | //add appropriate CSS depending on position chosen 128 | if (cookieDiscreetPosition == "topleft") { 129 | $('div.cc-cookies').css("top", "0"); 130 | $('div.cc-cookies').css("left", "0"); 131 | } 132 | if (cookieDiscreetPosition == "topright") { 133 | $('div.cc-cookies').css("top", "0"); 134 | $('div.cc-cookies').css("right", "0"); 135 | } 136 | if (cookieDiscreetPosition == "bottomleft") { 137 | $('div.cc-cookies').css("bottom", "0"); 138 | $('div.cc-cookies').css("left", "0"); 139 | } 140 | if (cookieDiscreetPosition == "bottomright") { 141 | $('div.cc-cookies').css("bottom", "0"); 142 | $('div.cc-cookies').css("right", "0"); 143 | } 144 | } else if (cookieResetButton) { 145 | if (appOrPre) { 146 | $('body').append('
' + cookieResetButtonText + '
'); 147 | } else { 148 | $('body').prepend('
' + cookieResetButtonText + '
'); 149 | } 150 | } else { 151 | var cookieResetButton = ""; 152 | } 153 | } else { 154 | // add message to just after opening body tag 155 | if ((cookieNoMessage) && (!cookiePolicyPage)) { 156 | // show no link on any pages APART from the policy page 157 | } else if ((cookieDiscreetLink) && (!cookiePolicyPage)) { // show discreet link 158 | if (appOrPre) { 159 | $('body').append('
' + cookieDiscreetLinkText + '
'); 160 | } else { 161 | $('body').prepend('
' + cookieDiscreetLinkText + '
'); 162 | } 163 | //add appropriate CSS depending on position chosen 164 | if (cookieDiscreetPosition == "topleft") { 165 | $('div.cc-cookies').css("top", "0"); 166 | $('div.cc-cookies').css("left", "0"); 167 | } 168 | if (cookieDiscreetPosition == "topright") { 169 | $('div.cc-cookies').css("top", "0"); 170 | $('div.cc-cookies').css("right", "0"); 171 | } 172 | if (cookieDiscreetPosition == "bottomleft") { 173 | $('div.cc-cookies').css("bottom", "0"); 174 | $('div.cc-cookies').css("left", "0"); 175 | } 176 | if (cookieDiscreetPosition == "bottomright") { 177 | $('div.cc-cookies').css("bottom", "0"); 178 | $('div.cc-cookies').css("right", "0"); 179 | } 180 | } else if (cookieAnalytics) { // show analytics overlay 181 | if (appOrPre) { 182 | $('body').append('
' + cookieAnalyticsMessage + cookieAccept + cookieDecline + '' + cookieWhatAreLinkText + '
'); 183 | } else { 184 | $('body').prepend('
' + cookieAnalyticsMessage + cookieAccept + cookieDecline + '' + cookieWhatAreLinkText + '
'); 185 | } 186 | } 187 | if (cookiePolicyPage) { // show policy page overlay 188 | if (appOrPre) { 189 | $('body').append('
' + cookiePolicyPageMessage + " " + ' ' + cookieAcceptButtonText + ' ' + ' ' + cookieDeclineButtonText + ' ' + '
'); 190 | } else { 191 | $('body').prepend('
' + cookiePolicyPageMessage + " " + ' ' + cookieAcceptButtonText + ' ' + ' ' + cookieDeclineButtonText + ' ' + '
'); 192 | } 193 | } else if ((!cookieAnalytics) && (!cookieDiscreetLink)) { // show privacy policy option 194 | if (appOrPre) { 195 | $('body').append('
' + cookieMessage + cookieAccept + cookieDecline + '
'); 196 | } else { 197 | $('body').prepend('
' + cookieMessage + cookieAccept + cookieDecline + '
'); 198 | } 199 | } 200 | } 201 | if ((cookieCutter) && (!cookieCutterDeclineOnly) && (($cookieDeclined) || (!$cookieAccepted))) { 202 | $(cookieDisable).html('
' + cookieErrorMessage + ' ' + cookieAcceptButtonText + ' ' + '
'); 203 | } 204 | if ((cookieCutter) && (cookieCutterDeclineOnly) && ($cookieDeclined)) { 205 | $(cookieDisable).html('
' + cookieErrorMessage + ' ' + cookieAcceptButtonText + ' ' + '
'); 206 | } 207 | // if bottom is true, switch div to bottom if not in discreet mode 208 | if ((cookieNotificationLocationBottom) && (!cookieDiscreetLink)) { 209 | $('div.cc-cookies').css("top", "auto"); 210 | $('div.cc-cookies').css("bottom", "0"); 211 | } 212 | if ((cookieNotificationLocationBottom) && (cookieDiscreetLink) && (cookiePolicyPage)) { 213 | $('div.cc-cookies').css("top", "auto"); 214 | $('div.cc-cookies').css("bottom", "0"); 215 | } 216 | // setting the cookies 217 | 218 | // for top bar 219 | $('.cc-cookie-accept, .cc-cookie-decline').click(function (e) { 220 | e.preventDefault(); 221 | if ($(this).is('[href$=#decline]')) { 222 | $.cookie("cc_cookie_accept", null, { 223 | path: '/' 224 | }); 225 | $.cookie("cc_cookie_decline", "cc_cookie_decline", { 226 | expires: cookieExpires, 227 | path: '/' 228 | }); 229 | if (options.cookieDomain) { 230 | // kill google analytics cookies 231 | $.cookie("__utma", null, { 232 | domain: '.' + options.cookieDomain, 233 | path: '/' 234 | }); 235 | $.cookie("__utmb", null, { 236 | domain: '.' + options.cookieDomain, 237 | path: '/' 238 | }); 239 | $.cookie("__utmc", null, { 240 | domain: '.' + options.cookieDomain, 241 | path: '/' 242 | }); 243 | $.cookie("__utmz", null, { 244 | domain: '.' + options.cookieDomain, 245 | path: '/' 246 | }); 247 | } 248 | } else { 249 | $.cookie("cc_cookie_decline", null, { 250 | path: '/' 251 | }); 252 | $.cookie("cc_cookie_accept", "cc_cookie_accept", { 253 | expires: cookieExpires, 254 | path: '/' 255 | }); 256 | } 257 | $(".cc-cookies").fadeOut(function () { 258 | // reload page to activate cookies 259 | location.reload(); 260 | }); 261 | }); 262 | //reset cookies 263 | $('a.cc-cookie-reset').click(function (f) { 264 | f.preventDefault(); 265 | $.cookie("cc_cookie_accept", null, { 266 | path: '/' 267 | }); 268 | $.cookie("cc_cookie_decline", null, { 269 | path: '/' 270 | }); 271 | $(".cc-cookies").fadeOut(function () { 272 | // reload page to activate cookies 273 | location.reload(); 274 | }); 275 | }); 276 | //cookie error accept 277 | $('.cc-cookies-error a.cc-cookie-accept').click(function (g) { 278 | g.preventDefault(); 279 | $.cookie("cc_cookie_accept", "cc_cookie_accept", { 280 | expires: cookieExpires, 281 | path: '/' 282 | }); 283 | $.cookie("cc_cookie_decline", null, { 284 | path: '/' 285 | }); 286 | // reload page to activate cookies 287 | location.reload(); 288 | }); 289 | }; 290 | })(jQuery); --------------------------------------------------------------------------------