Skip to content
Browse files

Adding acceptance of Cookies (cookieCuttr)

  • Loading branch information...
1 parent 46020b0 commit d8b27b8d5f63d27f4bd75e16a745570ef9b976f0 @credmp committed Jan 13, 2013
View
6 _includes/analytics
@@ -1,11 +1,13 @@
<script type="text/javascript">
+if (jQuery.cookie('cc_cookie_accept') == "cc_cookie_accept") {
var _gaq = _gaq || [];
- _gaq.push(['_setAccount', 'UA-28805964-1']);
+ _gaq.push(['_setAccount', 'UA-37483360-1']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
-</script>
+}
+</script>
View
7 _includes/custom-js.js
@@ -1,4 +1,6 @@
<script src="http://code.jquery.com/jquery-1.7.2.min.js" type="text/javascript" ></script>
+<script src="/assets/js/jquery.cookie.js" type="text/javascript" ></script>
+<script src="/assets/js/jquery.cookiecuttr.js" type="text/javascript" ></script>
<script type="text/javascript">
$(function(){
@@ -11,4 +13,7 @@
});
});
-</script>
+ $(document).ready(function () {
+ $.cookieCuttr();
+ });
+</script>
View
5 _layouts/default.html
@@ -12,15 +12,16 @@
<meta name="description" content="{{ page.meta_description }}" />
{% endif %}
- <link rel="stylesheet" type="text/css" href="/assets/pygments.css"/>
+ <link rel="stylesheet" type="text/css" href="/assets/css/pygments.css"/>
+ <link rel="stylesheet" type="text/css" href="/assets/css/cookiecuttr.css"/>
<link rel="stylesheet" type="text/css" href="/bootstrap/css/bootstrap.min.css"/>
{% include bootstrap.js.html %}
<!-- Fonts -->
<link href='http://fonts.googleapis.com/css?family=Open+Sans:400,700,600' rel='stylesheet' type='text/css'>
{% include custom-js.js %}
-
+ {% include analytics %}
</head>
<body>
View
23 assets/css/cookiecuttr.css
@@ -0,0 +1,23 @@
+/* To be used with cookieCuttr by Chris Wharton (http://cookiecuttr.com) */
+
+.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; }
+.cc-cookies a, .cc-cookies a:hover { color: #fff; text-decoration: underline; }
+.cc-cookies a:hover { text-decoration: none; }
+.cc-overlay { height: 100%; padding-top: 25%; }
+.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; }
+.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; }
+.cc-cookies a.cc-cookie-decline, .cc-cookies-error a.cc-cookie-decline { background: #af3b3b; margin-left: 0.5em; }
+.cc-cookies a.cc-cookie-reset { background: #f15b00; }
+.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; }
+.cc-cookies-error a.cc-cookie-accept, .cc-cookies-error a.cc-cookie-decline { display: block; margin-top: 1em; }
+.cc-cookies.cc-discreet { width: auto; padding: 0.5em 1em; left: auto; top: auto; }
+.cc-cookies.cc-discreet a.cc-cookie-reset { background: none; text-shadow: none; padding: 0; text-decoration: underline; }
+.cc-cookies.cc-discreet a:hover.cc-cookie-reset { text-decoration: none; }
+
+@media screen and (max-width: 768px) {
+.cc-cookies a.cc-cookie-accept, .cc-cookies a.cc-cookie-decline, .cc-cookies a.cc-cookie-reset { display: block; margin: 1em 0; }
+}
+
+@media screen and (max-width: 480px) {
+.cc-cookies { position: relative; float: left; }
+}
View
0 assets/pygments.css → assets/css/pygments.css
File renamed without changes.
View
72 assets/js/jquery.cookie.js
@@ -0,0 +1,72 @@
+/*!
+ * jQuery Cookie Plugin v1.3
+ * https://github.com/carhartl/jquery-cookie
+ *
+ * Copyright 2011, Klaus Hartl
+ * Dual licensed under the MIT or GPL Version 2 licenses.
+ * http://www.opensource.org/licenses/mit-license.php
+ * http://www.opensource.org/licenses/GPL-2.0
+ */
+(function ($, document, undefined) {
+
+ var pluses = /\+/g;
+
+ function raw(s) {
+ return s;
+ }
+
+ function decoded(s) {
+ return decodeURIComponent(s.replace(pluses, ' '));
+ }
+
+ var config = $.cookie = function (key, value, options) {
+
+ // write
+ if (value !== undefined) {
+ options = $.extend({}, config.defaults, options);
+
+ if (value === null) {
+ options.expires = -1;
+ }
+
+ if (typeof options.expires === 'number') {
+ var days = options.expires, t = options.expires = new Date();
+ t.setDate(t.getDate() + days);
+ }
+
+ value = config.json ? JSON.stringify(value) : String(value);
+
+ return (document.cookie = [
+ encodeURIComponent(key), '=', config.raw ? value : encodeURIComponent(value),
+ options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
+ options.path ? '; path=' + options.path : '',
+ options.domain ? '; domain=' + options.domain : '',
+ options.secure ? '; secure' : ''
+ ].join(''));
+ }
+
+ // read
+ var decode = config.raw ? raw : decoded;
+ var cookies = document.cookie.split('; ');
+ for (var i = 0, l = cookies.length; i < l; i++) {
+ var parts = cookies[i].split('=');
+ if (decode(parts.shift()) === key) {
+ var cookie = decode(parts.join('='));
+ return config.json ? JSON.parse(cookie) : cookie;
+ }
+ }
+
+ return null;
+ };
+
+ config.defaults = {};
+
+ $.removeCookie = function (key, options) {
+ if ($.cookie(key) !== null) {
+ $.cookie(key, null, options);
+ return true;
+ }
+ return false;
+ };
+
+})(jQuery, document);
View
290 assets/js/jquery.cookiecuttr.js
@@ -0,0 +1,290 @@
+/**
+ * Copyright (C) 2012 Chris Wharton (chris@weare2ndfloor.com)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * THIS SOFTWARE AND DOCUMENTATION IS PROVIDED "AS IS," AND COPYRIGHT
+ * HOLDERS MAKE NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED,
+ * INCLUDING BUT NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY OR
+ * FITNESS FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF THE SOFTWARE
+ * OR DOCUMENTATION WILL NOT INFRINGE ANY THIRD PARTY PATENTS,
+ * COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS.COPYRIGHT HOLDERS WILL NOT
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, SPECIAL OR CONSEQUENTIAL
+ * DAMAGES ARISING OUT OF ANY USE OF THE SOFTWARE OR DOCUMENTATION.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://gnu.org/licenses/>.
+
+ Documentation available at http://cookiecuttr.com
+
+ */
+(function ($) {
+ $.cookieCuttr = function (options) {
+ var defaults = {
+ cookieCutter: false, // you'd like to enable the div/section/span etc. hide feature? change this to true
+ cookieCutterDeclineOnly: false, // you'd like the CookieCutter to only hide when someone has clicked declined set this to true
+ cookieAnalytics: true, // just using a simple analytics package? change this to true
+ cookieDeclineButton: false, // this will disable non essential cookies
+ cookieAcceptButton: true, // this will disable non essential cookies
+ cookieResetButton: false,
+ cookieOverlayEnabled: false, // don't want a discreet toolbar? Fine, set this to true
+ cookiePolicyLink: '/privacy-policy/', // if applicable, enter the link to your privacy policy here...
+ cookieMessage: 'We use cookies on this website, you can <a href="{{cookiePolicyLink}}" title="read about our cookies">read about them here</a>. To use the website as intended please...',
+ cookieAnalyticsMessage: 'We use cookies, just to track visits to our website, we store no personal details.',
+ cookieErrorMessage: "We\'re sorry, this feature places cookies in your browser and has been disabled. <br>To continue using this functionality, please",
+ cookieWhatAreTheyLink: "http://www.allaboutcookies.org/",
+ cookieDisable: '',
+ cookieExpires: 365,
+ cookieAcceptButtonText: "ACCEPT COOKIES",
+ cookieDeclineButtonText: "DECLINE COOKIES",
+ cookieResetButtonText: "RESET COOKIES FOR THIS WEBSITE",
+ cookieWhatAreLinkText: "What are cookies?",
+ cookieNotificationLocationBottom: false, // top or bottom - they are your only options, so true for bottom, false for top
+ cookiePolicyPage: false,
+ cookiePolicyPageMessage: 'Please read the information below and then choose from the following options',
+ cookieDiscreetLink: false,
+ cookieDiscreetReset: false,
+ cookieDiscreetLinkText: "Cookies?",
+ cookieDiscreetPosition: "topleft", //options: topleft, topright, bottomleft, bottomright
+ cookieNoMessage: false, // change to true hide message from all pages apart from your policy page
+ cookieDomain: ""
+ };
+ var options = $.extend(defaults, options);
+ var message = defaults.cookieMessage.replace('{{cookiePolicyLink}}', defaults.cookiePolicyLink);
+ 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...';
+ //convert options
+ var cookiePolicyLinkIn = options.cookiePolicyLink;
+ var cookieCutter = options.cookieCutter;
+ var cookieCutterDeclineOnly = options.cookieCutterDeclineOnly;
+ var cookieAnalytics = options.cookieAnalytics;
+ var cookieDeclineButton = options.cookieDeclineButton;
+ var cookieAcceptButton = options.cookieAcceptButton;
+ var cookieResetButton = options.cookieResetButton;
+ var cookieOverlayEnabled = options.cookieOverlayEnabled;
+ var cookiePolicyLink = options.cookiePolicyLink;
+ var cookieMessage = message;
+ var cookieAnalyticsMessage = options.cookieAnalyticsMessage;
+ var cookieErrorMessage = options.cookieErrorMessage;
+ var cookieDisable = options.cookieDisable;
+ var cookieWhatAreTheyLink = options.cookieWhatAreTheyLink;
+ var cookieExpires = options.cookieExpires;
+ var cookieAcceptButtonText = options.cookieAcceptButtonText;
+ var cookieDeclineButtonText = options.cookieDeclineButtonText;
+ var cookieResetButtonText = options.cookieResetButtonText;
+ var cookieWhatAreLinkText = options.cookieWhatAreLinkText;
+ var cookieNotificationLocationBottom = options.cookieNotificationLocationBottom;
+ var cookiePolicyPage = options.cookiePolicyPage;
+ var cookiePolicyPageMessage = options.cookiePolicyPageMessage;
+ var cookieDiscreetLink = options.cookieDiscreetLink;
+ var cookieDiscreetReset = options.cookieDiscreetReset;
+ var cookieDiscreetLinkText = options.cookieDiscreetLinkText;
+ var cookieDiscreetPosition = options.cookieDiscreetPosition;
+ var cookieNoMessage = options.cookieNoMessage;
+ // cookie identifier
+ var $cookieAccepted = $.cookie('cc_cookie_accept') == "cc_cookie_accept";
+ $.cookieAccepted = function () {
+ return $cookieAccepted;
+ };
+ var $cookieDeclined = $.cookie('cc_cookie_decline') == "cc_cookie_decline";
+ $.cookieDeclined = function () {
+ return $cookieDeclined;
+ };
+ // write cookie accept button
+ if (cookieAcceptButton) {
+ var cookieAccept = ' <a href="#accept" class="cc-cookie-accept">' + cookieAcceptButtonText + '</a> ';
+ } else {
+ var cookieAccept = "";
+ }
+ // write cookie decline button
+ if (cookieDeclineButton) {
+ var cookieDecline = ' <a href="#decline" class="cc-cookie-decline">' + cookieDeclineButtonText + '</a> ';
+ } else {
+ var cookieDecline = "";
+ }
+ // write extra class for overlay
+ if (cookieOverlayEnabled) {
+ var cookieOverlay = 'cc-overlay';
+ } else {
+ var cookieOverlay = "";
+ }
+ // to prepend or append, that is the question?
+ if ((cookieNotificationLocationBottom) || (cookieDiscreetPosition == "bottomright") || (cookieDiscreetPosition == "bottomleft")) {
+ var appOrPre = true;
+ } else {
+ var appOrPre = false;
+ }
+ if (($cookieAccepted) || ($cookieDeclined)) {
+ // write cookie reset button
+ if ((cookieResetButton) && (cookieDiscreetReset)) {
+ if (appOrPre) {
+ $('body').append('<div class="cc-cookies cc-discreet"><a class="cc-cookie-reset" href="#" title="' + cookieResetButtonText + '">' + cookieResetButtonText + '</a></div>');
+ } else {
+ $('body').prepend('<div class="cc-cookies cc-discreet"><a class="cc-cookie-reset" href="#" title="' + cookieResetButtonText + '">' + cookieResetButtonText + '</a></div>');
+ }
+ //add appropriate CSS depending on position chosen
+ if (cookieDiscreetPosition == "topleft") {
+ $('div.cc-cookies').css("top", "0");
+ $('div.cc-cookies').css("left", "0");
+ }
+ if (cookieDiscreetPosition == "topright") {
+ $('div.cc-cookies').css("top", "0");
+ $('div.cc-cookies').css("right", "0");
+ }
+ if (cookieDiscreetPosition == "bottomleft") {
+ $('div.cc-cookies').css("bottom", "0");
+ $('div.cc-cookies').css("left", "0");
+ }
+ if (cookieDiscreetPosition == "bottomright") {
+ $('div.cc-cookies').css("bottom", "0");
+ $('div.cc-cookies').css("right", "0");
+ }
+ } else if (cookieResetButton) {
+ if (appOrPre) {
+ $('body').append('<div class="cc-cookies"><a href="#" class="cc-cookie-reset">' + cookieResetButtonText + '</a></div>');
+ } else {
+ $('body').prepend('<div class="cc-cookies"><a href="#" class="cc-cookie-reset">' + cookieResetButtonText + '</a></div>');
+ }
+ } else {
+ var cookieResetButton = "";
+ }
+ } else {
+ // add message to just after opening body tag
+ if ((cookieNoMessage) && (!cookiePolicyPage)) {
+ // show no link on any pages APART from the policy page
+ } else if ((cookieDiscreetLink) && (!cookiePolicyPage)) { // show discreet link
+ if (appOrPre) {
+ $('body').append('<div class="cc-cookies cc-discreet"><a href="' + cookiePolicyLinkIn + '" title="' + cookieDiscreetLinkText + '">' + cookieDiscreetLinkText + '</a></div>');
+ } else {
+ $('body').prepend('<div class="cc-cookies cc-discreet"><a href="' + cookiePolicyLinkIn + '" title="' + cookieDiscreetLinkText + '">' + cookieDiscreetLinkText + '</a></div>');
+ }
+ //add appropriate CSS depending on position chosen
+ if (cookieDiscreetPosition == "topleft") {
+ $('div.cc-cookies').css("top", "0");
+ $('div.cc-cookies').css("left", "0");
+ }
+ if (cookieDiscreetPosition == "topright") {
+ $('div.cc-cookies').css("top", "0");
+ $('div.cc-cookies').css("right", "0");
+ }
+ if (cookieDiscreetPosition == "bottomleft") {
+ $('div.cc-cookies').css("bottom", "0");
+ $('div.cc-cookies').css("left", "0");
+ }
+ if (cookieDiscreetPosition == "bottomright") {
+ $('div.cc-cookies').css("bottom", "0");
+ $('div.cc-cookies').css("right", "0");
+ }
+ } else if (cookieAnalytics) { // show analytics overlay
+ if (appOrPre) {
+ $('body').append('<div class="cc-cookies ' + cookieOverlay + '">' + cookieAnalyticsMessage + cookieAccept + cookieDecline + '<a href="' + cookieWhatAreTheyLink + '" title="Visit All about cookies (External link)">' + cookieWhatAreLinkText + '</a></div>');
+ } else {
+ $('body').prepend('<div class="cc-cookies ' + cookieOverlay + '">' + cookieAnalyticsMessage + cookieAccept + cookieDecline + '<a href="' + cookieWhatAreTheyLink + '" title="Visit All about cookies (External link)">' + cookieWhatAreLinkText + '</a></div>');
+ }
+ }
+ if (cookiePolicyPage) { // show policy page overlay
+ if (appOrPre) {
+ $('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>');
+ } else {
+ $('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>');
+ }
+ } else if ((!cookieAnalytics) && (!cookieDiscreetLink)) { // show privacy policy option
+ if (appOrPre) {
+ $('body').append('<div class="cc-cookies ' + cookieOverlay + '">' + cookieMessage + cookieAccept + cookieDecline + '</div>');
+ } else {
+ $('body').prepend('<div class="cc-cookies ' + cookieOverlay + '">' + cookieMessage + cookieAccept + cookieDecline + '</div>');
+ }
+ }
+ }
+ if ((cookieCutter) && (!cookieCutterDeclineOnly) && (($cookieDeclined) || (!$cookieAccepted))) {
+ $(cookieDisable).html('<div class="cc-cookies-error">' + cookieErrorMessage + ' <a href="#accept" class="cc-cookie-accept">' + cookieAcceptButtonText + '</a> ' + '</div>');
+ }
+ if ((cookieCutter) && (cookieCutterDeclineOnly) && ($cookieDeclined)) {
+ $(cookieDisable).html('<div class="cc-cookies-error">' + cookieErrorMessage + ' <a href="#accept" class="cc-cookie-accept">' + cookieAcceptButtonText + '</a> ' + '</div>');
+ }
+ // if bottom is true, switch div to bottom if not in discreet mode
+ if ((cookieNotificationLocationBottom) && (!cookieDiscreetLink)) {
+ $('div.cc-cookies').css("top", "auto");
+ $('div.cc-cookies').css("bottom", "0");
+ }
+ if ((cookieNotificationLocationBottom) && (cookieDiscreetLink) && (cookiePolicyPage)) {
+ $('div.cc-cookies').css("top", "auto");
+ $('div.cc-cookies').css("bottom", "0");
+ }
+ // setting the cookies
+
+ // for top bar
+ $('.cc-cookie-accept, .cc-cookie-decline').click(function (e) {
+ e.preventDefault();
+ if ($(this).is('[href$=#decline]')) {
+ $.cookie("cc_cookie_accept", null, {
+ path: '/'
+ });
+ $.cookie("cc_cookie_decline", "cc_cookie_decline", {
+ expires: cookieExpires,
+ path: '/'
+ });
+ if (options.cookieDomain) {
+ // kill google analytics cookies
+ $.cookie("__utma", null, {
+ domain: '.' + options.cookieDomain,
+ path: '/'
+ });
+ $.cookie("__utmb", null, {
+ domain: '.' + options.cookieDomain,
+ path: '/'
+ });
+ $.cookie("__utmc", null, {
+ domain: '.' + options.cookieDomain,
+ path: '/'
+ });
+ $.cookie("__utmz", null, {
+ domain: '.' + options.cookieDomain,
+ path: '/'
+ });
+ }
+ } else {
+ $.cookie("cc_cookie_decline", null, {
+ path: '/'
+ });
+ $.cookie("cc_cookie_accept", "cc_cookie_accept", {
+ expires: cookieExpires,
+ path: '/'
+ });
+ }
+ $(".cc-cookies").fadeOut(function () {
+ // reload page to activate cookies
+ location.reload();
+ });
+ });
+ //reset cookies
+ $('a.cc-cookie-reset').click(function (f) {
+ f.preventDefault();
+ $.cookie("cc_cookie_accept", null, {
+ path: '/'
+ });
+ $.cookie("cc_cookie_decline", null, {
+ path: '/'
+ });
+ $(".cc-cookies").fadeOut(function () {
+ // reload page to activate cookies
+ location.reload();
+ });
+ });
+ //cookie error accept
+ $('.cc-cookies-error a.cc-cookie-accept').click(function (g) {
+ g.preventDefault();
+ $.cookie("cc_cookie_accept", "cc_cookie_accept", {
+ expires: cookieExpires,
+ path: '/'
+ });
+ $.cookie("cc_cookie_decline", null, {
+ path: '/'
+ });
+ // reload page to activate cookies
+ location.reload();
+ });
+ };
+})(jQuery);

0 comments on commit d8b27b8

Please sign in to comment.
Something went wrong with that request. Please try again.