Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added config to enable refreshing the page after setting the cookie #12

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 6 additions & 2 deletions client/dist/javascript/jquery.cookie.policy.js
Expand Up @@ -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('<style>#cookie_container { display: none; position: fixed; ' + options.position + ': 0; left: ' + options.leftPadding + '; right: ' + 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; }</style>');
Expand All @@ -123,6 +124,9 @@
} else if (options.hideAnimation == 'slideUp') {
$('#cookie_container').slideUp();
}
if (options.reload == true) {
window.location.reload();
}
});
// detect cookie
$(this).ready(function() {
Expand All @@ -133,6 +137,6 @@
});
}
$.getJSON($('base')[0].href + 'fetchcookiepolicy', function(data) {
$('body').cookieNotify({btnText: data.CookiePolicyButtonTitle, text: data.CookiePolicyDescription, position: data.CookiePolicyPosition});
$('body').cookieNotify({btnText: data.CookiePolicyButtonTitle, text: data.CookiePolicyDescription, position: data.CookiePolicyPosition, reload: data.Reload});
});
}(jQuery));
18 changes: 1 addition & 17 deletions client/dist/javascript/jquery.cookie.policy.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions src/CookiePolicy.php
Expand Up @@ -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();
Expand Down
6 changes: 6 additions & 0 deletions src/CookiePolicyController.php
Expand Up @@ -25,6 +25,7 @@ public function index(HTTPRequest $request)
'CookiePolicyButtonTitle' => $this->owner->getCookiePolicyButtonTitle(),
'CookiePolicyDescription' => $this->owner->getCookiePolicyDescription(),
'CookiePolicyPosition' => $this->owner->getCookiePolicyPosition(),
'Reload' => $this->getReload(),
]));

$this->getResponse()->addHeader("Content-type", "application/json");
Expand Down Expand Up @@ -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;
Expand Down