From 7923b6a0daffb00720a8e0c9d8b3b82aa879fd5f Mon Sep 17 00:00:00 2001 From: Makreig Date: Wed, 10 Feb 2021 14:18:45 +0000 Subject: [PATCH 1/2] tried adding config for reloading the page --- client/dist/javascript/jquery.cookie.policy.js | 9 +++++++-- .../javascript/jquery.cookie.policy.min.js | 18 +----------------- src/CookiePolicy.php | 9 +++++++++ src/CookiePolicyController.php | 6 ++++++ 4 files changed, 23 insertions(+), 19 deletions(-) diff --git a/client/dist/javascript/jquery.cookie.policy.js b/client/dist/javascript/jquery.cookie.policy.js index 6ee2dcb..4ddc1b9 100644 --- a/client/dist/javascript/jquery.cookie.policy.js +++ b/client/dist/javascript/jquery.cookie.policy.js @@ -105,7 +105,8 @@ position: 'top', // info bar position leftPadding: '0', // info bar left spacing, accepts px or % values rightPadding: '0', // info bar right spacing, accepts px or % values - hideAnimation: 'fadeOut' // on click hide animation, options are fadeOut, slideUp + hideAnimation: 'fadeOut', // on click hide animation, options are fadeOut, slideUp + reload: false // force a page reload after save }, options); // create stylesheet $('head').append(''); @@ -123,6 +124,9 @@ } else if (options.hideAnimation == 'slideUp') { $('#cookie_container').slideUp(); } + if (options.reload == true) { + window.location.reload(); + } }); // detect cookie $(this).ready(function() { @@ -133,6 +137,7 @@ }); } $.getJSON($('base')[0].href + 'fetchcookiepolicy', function(data) { - $('body').cookieNotify({btnText: data.CookiePolicyButtonTitle, text: data.CookiePolicyDescription, position: data.CookiePolicyPosition}); + console.log(data); + $('body').cookieNotify({btnText: data.CookiePolicyButtonTitle, text: data.CookiePolicyDescription, position: data.CookiePolicyPosition, reload: data.Reload}); }); }(jQuery)); diff --git a/client/dist/javascript/jquery.cookie.policy.min.js b/client/dist/javascript/jquery.cookie.policy.min.js index ebd490f..c34d3a1 100644 --- a/client/dist/javascript/jquery.cookie.policy.min.js +++ b/client/dist/javascript/jquery.cookie.policy.min.js @@ -1,17 +1 @@ -/* - * UK COOKIE POLICY NOTICE - * Written by Lee Jones (mail@leejones.me.uk) - * Project Home Page: https://github.com/prolificjones82/uk_cookie_policy_notice - * Released under GNU Lesser General Public License (http://www.gnu.org/copyleft/lgpl.html) - * - * Please submit all problems or questions to the Issues page on the projects GitHub page: - * https://github.com/prolificjones82/uk_cookie_policy_notice - * - * - * jQuery Cookie Plugin v1.3.1 - * https://github.com/carhartl/jquery-cookie - * - * Copyright 2013 Klaus Hartl - * Released under the MIT license - */ -!function(o){"function"==typeof define&&define.amd?define(["jquery"],o):o(jQuery)}(function(o){var e=/\+/g;function i(o){return n.raw?o:decodeURIComponent(o.replace(e," "))}function t(o){0===o.indexOf('"')&&(o=o.slice(1,-1).replace(/\\"/g,'"').replace(/\\\\/g,"\\")),o=i(o);try{return n.json?JSON.parse(o):o}catch(o){}}var n=o.cookie=function(e,r,c){if(void 0!==r){if("number"==typeof(c=o.extend({},n.defaults,c)).expires){var a=c.expires,d=c.expires=new Date;d.setDate(d.getDate()+a)}return r=n.json?JSON.stringify(r):String(r),document.cookie=[n.raw?e:encodeURIComponent(e),"=",n.raw?r:encodeURIComponent(r),c.expires?"; expires="+c.expires.toUTCString():"",c.path?"; path="+c.path:"",c.domain?"; domain="+c.domain:"",c.secure?"; secure":""].join("")}for(var p=document.cookie.split("; "),s=e?void 0:{},l=0,u=p.length;l#cookie_container { display: none; position: fixed; "+e.position+": 0; left: "+e.leftPadding+"; \tright: "+e.rightPadding+"; z-index: 999; padding: 10px; background-color:"+e.bgColor+"; color:"+e.textColor+"; } .cookie_inner { width: 90%; margin: 0 auto; } .cookie_inner p { margin: 0; padding-top: 4px; } #setCookie { float: right; padding: 5px 10px; text-decoration: none; background-color: "+e.btnColor+"; color: "+e.btnTextColor+"; } #setCookie:hover { background-color: #AAAAAA !important; color: #000000 !important; }"),o('").appendTo(this),o(document.body).on("click","#setCookie",function(i){i.preventDefault(),o.cookie("cookie_policy","true",{expires:365,path:"/"}),"fadeOut"==e.hideAnimation?o("#cookie_container").fadeOut():"slideUp"==e.hideAnimation&&o("#cookie_container").slideUp()}),o(this).ready(function(){o.cookie("cookie_policy")||o("#cookie_container").show()})},o.getJSON(o("base")[0].href+"fetchcookiepolicy",function(e){o("body").cookieNotify({btnText:e.CookiePolicyButtonTitle,text:e.CookiePolicyDescription,position:e.CookiePolicyPosition})})}(jQuery); +!function(factory){"function"==typeof define&&define.amd?define(["jquery"],factory):factory(jQuery)}((function($){var pluses=/\+/g;function decode(s){return config.raw?s:decodeURIComponent(s.replace(pluses," "))}function decodeAndParse(s){0===s.indexOf('"')&&(s=s.slice(1,-1).replace(/\\"/g,'"').replace(/\\\\/g,"\\")),s=decode(s);try{return config.json?JSON.parse(s):s}catch(e){}}var config=$.cookie=function(key,value,options){if(void 0!==value){if("number"==typeof(options=$.extend({},config.defaults,options)).expires){var days=options.expires,t=options.expires=new Date;t.setDate(t.getDate()+days)}return value=config.json?JSON.stringify(value):String(value),document.cookie=[config.raw?key:encodeURIComponent(key),"=",config.raw?value:encodeURIComponent(value),options.expires?"; expires="+options.expires.toUTCString():"",options.path?"; path="+options.path:"",options.domain?"; domain="+options.domain:"",options.secure?"; secure":""].join("")}for(var cookies=document.cookie.split("; "),result=key?void 0:{},i=0,l=cookies.length;i#cookie_container { display: none; position: fixed; "+options.position+": 0; left: "+options.leftPadding+"; \tright: "+options.rightPadding+"; z-index: 999; padding: 10px; background-color:"+options.bgColor+"; color:"+options.textColor+"; } .cookie_inner { width: 90%; margin: 0 auto; } .cookie_inner p { margin: 0; padding-top: 4px; } #setCookie { float: right; padding: 5px 10px; text-decoration: none; background-color: "+options.btnColor+"; color: "+options.btnTextColor+"; } #setCookie:hover { background-color: #AAAAAA !important; color: #000000 !important; }"),$('").appendTo(this),$(document.body).on("click","#setCookie",(function(e){e.preventDefault(),$.cookie("cookie_policy","true",{expires:365,path:"/"}),"fadeOut"==options.hideAnimation?$("#cookie_container").fadeOut():"slideUp"==options.hideAnimation&&$("#cookie_container").slideUp(),1==options.reload&&window.location.reload()})),$(this).ready((function(){var cookie;$.cookie("cookie_policy")||$("#cookie_container").show()}))},$.getJSON($("base")[0].href+"fetchcookiepolicy",(function(data){console.log(data),$("body").cookieNotify({btnText:data.CookiePolicyButtonTitle,text:data.CookiePolicyDescription,position:data.CookiePolicyPosition,reload:data.Reload})}))}(jQuery); \ No newline at end of file diff --git a/src/CookiePolicy.php b/src/CookiePolicy.php index 70a1364..37cd99e 100644 --- a/src/CookiePolicy.php +++ b/src/CookiePolicy.php @@ -16,6 +16,15 @@ class CookiePolicy extends Extension private static $load_jquery_defer = false; private static $load_script_defer = true; + /** + * If true, the page will reload after setting the cookie. + * + * @config + * + * @var boolean + */ + private static $reload_on_accept = false; + public function onBeforeInit() { $siteConfig = SiteConfig::current_site_config(); diff --git a/src/CookiePolicyController.php b/src/CookiePolicyController.php index b56558d..ffd3af0 100644 --- a/src/CookiePolicyController.php +++ b/src/CookiePolicyController.php @@ -25,6 +25,7 @@ public function index(HTTPRequest $request) 'CookiePolicyButtonTitle' => $this->owner->getCookiePolicyButtonTitle(), 'CookiePolicyDescription' => $this->owner->getCookiePolicyDescription(), 'CookiePolicyPosition' => $this->owner->getCookiePolicyPosition(), + 'Reload' => $this->owner->getreload(), ])); $this->getResponse()->addHeader("Content-type", "application/json"); @@ -53,6 +54,11 @@ public function getCookiePolicyPosition() return self::$current_site_config->CookiePolicyPosition; } + public function getReload() + { + return Config::inst()->get(CookiePolicy::class, 'reload_on_accept'); + } + public static function set_current_site_config($input) { self::$current_site_config = $input; From ea3816bd71c5b8da75fc6bf1c911e6d8e6f62cea Mon Sep 17 00:00:00 2001 From: Makreig Date: Wed, 10 Feb 2021 15:37:23 +0000 Subject: [PATCH 2/2] fixed reload config --- client/dist/javascript/jquery.cookie.policy.js | 1 - client/dist/javascript/jquery.cookie.policy.min.js | 2 +- src/CookiePolicyController.php | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/client/dist/javascript/jquery.cookie.policy.js b/client/dist/javascript/jquery.cookie.policy.js index 4ddc1b9..8e6106a 100644 --- a/client/dist/javascript/jquery.cookie.policy.js +++ b/client/dist/javascript/jquery.cookie.policy.js @@ -137,7 +137,6 @@ }); } $.getJSON($('base')[0].href + 'fetchcookiepolicy', function(data) { - console.log(data); $('body').cookieNotify({btnText: data.CookiePolicyButtonTitle, text: data.CookiePolicyDescription, position: data.CookiePolicyPosition, reload: data.Reload}); }); }(jQuery)); diff --git a/client/dist/javascript/jquery.cookie.policy.min.js b/client/dist/javascript/jquery.cookie.policy.min.js index c34d3a1..cbe9f3d 100644 --- a/client/dist/javascript/jquery.cookie.policy.min.js +++ b/client/dist/javascript/jquery.cookie.policy.min.js @@ -1 +1 @@ -!function(factory){"function"==typeof define&&define.amd?define(["jquery"],factory):factory(jQuery)}((function($){var pluses=/\+/g;function decode(s){return config.raw?s:decodeURIComponent(s.replace(pluses," "))}function decodeAndParse(s){0===s.indexOf('"')&&(s=s.slice(1,-1).replace(/\\"/g,'"').replace(/\\\\/g,"\\")),s=decode(s);try{return config.json?JSON.parse(s):s}catch(e){}}var config=$.cookie=function(key,value,options){if(void 0!==value){if("number"==typeof(options=$.extend({},config.defaults,options)).expires){var days=options.expires,t=options.expires=new Date;t.setDate(t.getDate()+days)}return value=config.json?JSON.stringify(value):String(value),document.cookie=[config.raw?key:encodeURIComponent(key),"=",config.raw?value:encodeURIComponent(value),options.expires?"; expires="+options.expires.toUTCString():"",options.path?"; path="+options.path:"",options.domain?"; domain="+options.domain:"",options.secure?"; secure":""].join("")}for(var cookies=document.cookie.split("; "),result=key?void 0:{},i=0,l=cookies.length;i#cookie_container { display: none; position: fixed; "+options.position+": 0; left: "+options.leftPadding+"; \tright: "+options.rightPadding+"; z-index: 999; padding: 10px; background-color:"+options.bgColor+"; color:"+options.textColor+"; } .cookie_inner { width: 90%; margin: 0 auto; } .cookie_inner p { margin: 0; padding-top: 4px; } #setCookie { float: right; padding: 5px 10px; text-decoration: none; background-color: "+options.btnColor+"; color: "+options.btnTextColor+"; } #setCookie:hover { background-color: #AAAAAA !important; color: #000000 !important; }"),$('").appendTo(this),$(document.body).on("click","#setCookie",(function(e){e.preventDefault(),$.cookie("cookie_policy","true",{expires:365,path:"/"}),"fadeOut"==options.hideAnimation?$("#cookie_container").fadeOut():"slideUp"==options.hideAnimation&&$("#cookie_container").slideUp(),1==options.reload&&window.location.reload()})),$(this).ready((function(){var cookie;$.cookie("cookie_policy")||$("#cookie_container").show()}))},$.getJSON($("base")[0].href+"fetchcookiepolicy",(function(data){console.log(data),$("body").cookieNotify({btnText:data.CookiePolicyButtonTitle,text:data.CookiePolicyDescription,position:data.CookiePolicyPosition,reload:data.Reload})}))}(jQuery); \ No newline at end of file +!function(factory){"function"==typeof define&&define.amd?define(["jquery"],factory):factory(jQuery)}((function($){var pluses=/\+/g;function decode(s){return config.raw?s:decodeURIComponent(s.replace(pluses," "))}function decodeAndParse(s){0===s.indexOf('"')&&(s=s.slice(1,-1).replace(/\\"/g,'"').replace(/\\\\/g,"\\")),s=decode(s);try{return config.json?JSON.parse(s):s}catch(e){}}var config=$.cookie=function(key,value,options){if(void 0!==value){if("number"==typeof(options=$.extend({},config.defaults,options)).expires){var days=options.expires,t=options.expires=new Date;t.setDate(t.getDate()+days)}return value=config.json?JSON.stringify(value):String(value),document.cookie=[config.raw?key:encodeURIComponent(key),"=",config.raw?value:encodeURIComponent(value),options.expires?"; expires="+options.expires.toUTCString():"",options.path?"; path="+options.path:"",options.domain?"; domain="+options.domain:"",options.secure?"; secure":""].join("")}for(var cookies=document.cookie.split("; "),result=key?void 0:{},i=0,l=cookies.length;i#cookie_container { display: none; position: fixed; "+options.position+": 0; left: "+options.leftPadding+"; \tright: "+options.rightPadding+"; z-index: 999; padding: 10px; background-color:"+options.bgColor+"; color:"+options.textColor+"; } .cookie_inner { width: 90%; margin: 0 auto; } .cookie_inner p { margin: 0; padding-top: 4px; } #setCookie { float: right; padding: 5px 10px; text-decoration: none; background-color: "+options.btnColor+"; color: "+options.btnTextColor+"; } #setCookie:hover { background-color: #AAAAAA !important; color: #000000 !important; }"),$('").appendTo(this),$(document.body).on("click","#setCookie",(function(e){e.preventDefault(),$.cookie("cookie_policy","true",{expires:365,path:"/"}),"fadeOut"==options.hideAnimation?$("#cookie_container").fadeOut():"slideUp"==options.hideAnimation&&$("#cookie_container").slideUp(),1==options.reload&&window.location.reload()})),$(this).ready((function(){var cookie;$.cookie("cookie_policy")||$("#cookie_container").show()}))},$.getJSON($("base")[0].href+"fetchcookiepolicy",(function(data){$("body").cookieNotify({btnText:data.CookiePolicyButtonTitle,text:data.CookiePolicyDescription,position:data.CookiePolicyPosition,reload:data.Reload})}))}(jQuery); \ No newline at end of file diff --git a/src/CookiePolicyController.php b/src/CookiePolicyController.php index ffd3af0..b45b326 100644 --- a/src/CookiePolicyController.php +++ b/src/CookiePolicyController.php @@ -25,7 +25,7 @@ public function index(HTTPRequest $request) 'CookiePolicyButtonTitle' => $this->owner->getCookiePolicyButtonTitle(), 'CookiePolicyDescription' => $this->owner->getCookiePolicyDescription(), 'CookiePolicyPosition' => $this->owner->getCookiePolicyPosition(), - 'Reload' => $this->owner->getreload(), + 'Reload' => $this->getReload(), ])); $this->getResponse()->addHeader("Content-type", "application/json");