diff --git a/CHANGELOG.md b/CHANGELOG.md index f830c91..8997751 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,18 @@ +# v1.0.4 +## 04/29/2021 + +1. [](#improved) + * Processing stops if dismiss cookie is set + * Dismiss cookie is unset on plugin config change + # v1.0.3 ## 04/28/2021 1. [](#new) * Added option to choose banner location (top or bottom) +2. [](#improved) + * Improved readme with Screenshots + * Improved config page with sections # v1.0.2 ## 04/28/2021 diff --git a/blueprints.yaml b/blueprints.yaml index 7fb645a..9250e06 100644 --- a/blueprints.yaml +++ b/blueprints.yaml @@ -1,7 +1,7 @@ name: Custom Banner slug: custom-banner type: plugin -version: 1.0.3 +version: 1.0.4 description: Add a custom banner to your Grav site icon: bookmark author: diff --git a/custom-banner.php b/custom-banner.php index e25cbc2..005ace6 100644 --- a/custom-banner.php +++ b/custom-banner.php @@ -49,8 +49,11 @@ public function autoload(): ClassLoader */ public function onPluginsInitialized(): void { - // Don't proceed if we are in the admin plugin + // Do not show banner in admin if ($this->isAdmin()) { + $this->enable([ + 'onAdminSave' => ['onAdminSave', 0], + ]); return; } @@ -66,6 +69,16 @@ public function onPluginsInitialized(): void ]); } + public function onAdminSave(): void + { + // When updating plugin settings delete "dismiss" cookie + if ($this->grav['uri']->basename() == 'custom-banner') { + if (isset($_COOKIE[self::CUSTOM_BANNER_DISMISS])) { + setcookie(self::CUSTOM_BANNER_DISMISS, 'false', time()-1, $this->grav['uri']->rootUrl()); + } + } + } + public function onAssetsInitialized(): void { $this->grav['assets']->addDirCss('plugins://custom-banner/css'); @@ -74,7 +87,6 @@ public function onAssetsInitialized(): void public function onOutputGenerated(): void { - // Get plugin config or fill with default if undefined $config = $this->config(); $config['exclude-pages'] = (array)$config['exclude-pages']; diff --git a/js/custom-banner.js b/js/custom-banner.js index 4e11be7..b7a6709 100644 --- a/js/custom-banner.js +++ b/js/custom-banner.js @@ -1,14 +1,4 @@ -document.addEventListener('DOMContentLoaded', function() { - if (document.getElementsByClassName('custom-banner-dismiss')[0].style.display != 'none') { - if (document.cookie.split('; ').find(row => row.startsWith('custom-banner-dismiss'))) { - document.getElementsByClassName('custom-banner-container')[0].style.display = 'none'; - } - } else { - document.cookie = "custom-banner-dismiss=false; max-age=0"; - } -}); - function custom_button_dismiss() { - document.cookie = 'custom-banner-dismiss=true; max-age=1800'; + document.cookie = 'custom-banner-dismiss=true; max-age=1800;'; document.getElementsByClassName('custom-banner-container')[0].style.display = 'none'; }