From b375c792c8d7cea6c51fc9e8a8e86273acbd9b05 Mon Sep 17 00:00:00 2001 From: Davide Iadeluca Date: Wed, 7 Feb 2024 11:19:57 +0100 Subject: [PATCH 1/4] chore: use 1.x branch for workflows --- .github/workflows/backend.yml | 2 +- .github/workflows/frontend.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/backend.yml b/.github/workflows/backend.yml index 722189b..6837dbd 100644 --- a/.github/workflows/backend.yml +++ b/.github/workflows/backend.yml @@ -4,7 +4,7 @@ on: [workflow_dispatch, push, pull_request] jobs: run: - uses: flarum/framework/.github/workflows/REUSABLE_backend.yml@main + uses: flarum/framework/.github/workflows/REUSABLE_backend.yml@1.x with: enable_backend_testing: false enable_phpstan: true diff --git a/.github/workflows/frontend.yml b/.github/workflows/frontend.yml index e8edd8c..223eed1 100644 --- a/.github/workflows/frontend.yml +++ b/.github/workflows/frontend.yml @@ -4,7 +4,7 @@ on: [workflow_dispatch, push, pull_request] jobs: run: - uses: flarum/framework/.github/workflows/REUSABLE_frontend.yml@main + uses: flarum/framework/.github/workflows/REUSABLE_frontend.yml@1.x with: enable_bundlewatch: false enable_prettier: true From e0496fc70faa3ca7fcb1e1fee103e05006dafb1b Mon Sep 17 00:00:00 2001 From: Davide Iadeluca Date: Wed, 7 Feb 2024 11:38:54 +0100 Subject: [PATCH 2/4] fix: use updated namespace for resolving setting --- src/Providers/AssetProvider.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Providers/AssetProvider.php b/src/Providers/AssetProvider.php index 368302f..eab2cc3 100644 --- a/src/Providers/AssetProvider.php +++ b/src/Providers/AssetProvider.php @@ -20,7 +20,7 @@ class AssetProvider extends AbstractServiceProvider public function boot() { $this->container->resolving('flarum.assets.forum', function (Assets $assets) { - if (resolve('flarum.settings')->get('reflar-cookie-consent.ccTheme') != 'no_css') { + if (resolve('flarum.settings')->get('fof-cookie-consent.ccTheme') != 'no_css') { $assets->css(function (SourceCollector $sources) { $sources->addFile(__DIR__.'/../../resources/less/forum.less'); }); From 300680596f2acade93e89658bbe7dc767a3e5749 Mon Sep 17 00:00:00 2001 From: Davide Iadeluca Date: Wed, 7 Feb 2024 12:05:25 +0100 Subject: [PATCH 3/4] fix: don't pass color palette if 'no_css' is selected --- js/src/forum/index.js | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/js/src/forum/index.js b/js/src/forum/index.js index ebc7ef5..4da04e2 100644 --- a/js/src/forum/index.js +++ b/js/src/forum/index.js @@ -16,18 +16,16 @@ app.initializers.add('fof-cookie-consent', () => { const popup = {}; const button = {}; - if (backgroundColor) popup.background = backgroundColor; - if (textColor) popup.text = textColor; + if (ccTheme !== 'no_css') { + if (backgroundColor) popup.background = backgroundColor; + if (textColor) popup.text = textColor; - if (buttonBackgroundColor) button.background = buttonBackgroundColor; - if (buttonTextColor) button.text = buttonTextColor; + if (buttonBackgroundColor) button.background = buttonBackgroundColor; + if (buttonTextColor) button.text = buttonTextColor; + } try { const settings = { - palette: { - popup, - button, - }, theme: ccTheme, content: { message: consentText, @@ -37,6 +35,13 @@ app.initializers.add('fof-cookie-consent', () => { }, }; + if (ccTheme !== 'no_css') { + settings.palette = { + popup, + button, + }; + } + cookieconsent.initialise(settings); } catch (err) { if (app.forum.attribute('adminUrl')) { From 2abd4e4c96b6919f4dfe9eff10bbfec3f307d302 Mon Sep 17 00:00:00 2001 From: Davide Iadeluca Date: Wed, 7 Feb 2024 12:30:27 +0100 Subject: [PATCH 4/4] refactor: reduce code repetition --- js/src/forum/index.js | 66 ++++++++++++++++--------------------------- 1 file changed, 24 insertions(+), 42 deletions(-) diff --git a/js/src/forum/index.js b/js/src/forum/index.js index 4da04e2..3fffbc0 100644 --- a/js/src/forum/index.js +++ b/js/src/forum/index.js @@ -3,53 +3,35 @@ import 'cookieconsent'; app.initializers.add('fof-cookie-consent', () => { $(document).ready(() => { - const ccTheme = app.forum.attribute('fof-cookie-consent.ccTheme'); - const backgroundColor = app.forum.attribute('fof-cookie-consent.backgroundColor'); - const textColor = app.forum.attribute('fof-cookie-consent.textColor'); - const consentText = app.forum.attribute('fof-cookie-consent.consentText'); - const buttonText = app.forum.attribute('fof-cookie-consent.buttonText'); - const buttonBackgroundColor = app.forum.attribute('fof-cookie-consent.buttonBackgroundColor'); - const buttonTextColor = app.forum.attribute('fof-cookie-consent.buttonTextColor'); - const learnMoreLinkText = app.forum.attribute('fof-cookie-consent.learnMoreLinkText'); - const learnMoreLinkUrl = app.forum.attribute('fof-cookie-consent.learnMoreLinkUrl'); - - const popup = {}; - const button = {}; - - if (ccTheme !== 'no_css') { - if (backgroundColor) popup.background = backgroundColor; - if (textColor) popup.text = textColor; - - if (buttonBackgroundColor) button.background = buttonBackgroundColor; - if (buttonTextColor) button.text = buttonTextColor; - } - - try { - const settings = { - theme: ccTheme, - content: { - message: consentText, - dismiss: buttonText, - link: learnMoreLinkText, - href: learnMoreLinkUrl, + const getAttribute = (key) => app.forum.attribute(`fof-cookie-consent.${key}`); + + let settings = { + theme: getAttribute('ccTheme'), + content: { + message: getAttribute('consentText'), + dismiss: getAttribute('buttonText'), + link: getAttribute('learnMoreLinkText'), + href: getAttribute('learnMoreLinkUrl'), + }, + }; + + if (getAttribute('ccTheme') !== 'no_css') { + settings.palette = { + popup: { + background: getAttribute('backgroundColor') || undefined, + text: getAttribute('textColor') || undefined, + }, + button: { + background: getAttribute('buttonBackgroundColor') || undefined, + text: getAttribute('buttonTextColor') || undefined, }, }; + } - if (ccTheme !== 'no_css') { - settings.palette = { - popup, - button, - }; - } - + try { cookieconsent.initialise(settings); } catch (err) { - if (app.forum.attribute('adminUrl')) { - console.error('An error occurred initializing the Cookie Consent library. Please make sure you have set all the settings properly.'); - console.error("Please report the following error if you don't think the issue is on your end\n\n", err); - } else { - console.error('An error occurred with the cookie consent prompt. Please contact an administrator so they can fix the issue.'); - } + console.error('An error occurred initializing the Cookie Consent library:', err); } delete window.cookieconsent;