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

Don't pass CSS if no_css option is selected #39

Merged
merged 4 commits into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/backend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/frontend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
55 changes: 21 additions & 34 deletions js/src/forum/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,48 +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 getAttribute = (key) => app.forum.attribute(`fof-cookie-consent.${key}`);

const popup = {};
const button = {};
let settings = {
theme: getAttribute('ccTheme'),
content: {
message: getAttribute('consentText'),
dismiss: getAttribute('buttonText'),
link: getAttribute('learnMoreLinkText'),
href: getAttribute('learnMoreLinkUrl'),
},
};

if (backgroundColor) popup.background = backgroundColor;
if (textColor) popup.text = textColor;

if (buttonBackgroundColor) button.background = buttonBackgroundColor;
if (buttonTextColor) button.text = buttonTextColor;

try {
const settings = {
palette: {
popup,
button,
if (getAttribute('ccTheme') !== 'no_css') {
settings.palette = {
popup: {
background: getAttribute('backgroundColor') || undefined,
text: getAttribute('textColor') || undefined,
},
theme: ccTheme,
content: {
message: consentText,
dismiss: buttonText,
link: learnMoreLinkText,
href: learnMoreLinkUrl,
button: {
background: getAttribute('buttonBackgroundColor') || undefined,
text: getAttribute('buttonTextColor') || undefined,
},
};
}

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;
Expand Down
2 changes: 1 addition & 1 deletion src/Providers/AssetProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
Expand Down
Loading