Skip to content

Commit

Permalink
Merge pull request #20 from danielsitek/feature/ds-fix-circular-depen…
Browse files Browse the repository at this point in the history
…dency

Fix circular dependency
  • Loading branch information
danielsitek authored Feb 5, 2025
2 parents 68964e8 + cf649d5 commit 45b15a7
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 31 deletions.
3 changes: 1 addition & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import { ConsentService } from '@/services/consent-service';
import type { CookieConsentTranslations } from '@/services/translation-service';
import type { CookieConsentTheme } from '@/services/theme-service';
import type { CookieConsentSettings } from '@/services/settings-service';
import { initConsentModal } from '@/init/initConsentModal';
import { initConsentBadge } from '@/init/initConsentBadge';
import { initConsentModal, initConsentBadge } from '@/init/init';

type WindowCookieConsent = ConsentService;

Expand Down
27 changes: 25 additions & 2 deletions src/init/initConsentModal.ts → src/init/init.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
import '@/elements/consent-dialog/consent-dialog';
import { BADGE_ELEMENT_NAME, DIALOG_ELEMENT_NAME, EVENT_CONSENT_HIDE, EVENT_CONSENT_SHOW } from '@/config';
import { initConsentBadge } from './initConsentBadge';
import '@/elements/consent-badge/consent-badge';
import { BADGE_ELEMENT_NAME, DIALOG_ELEMENT_NAME, EVENT_BADGE_CLICK, EVENT_CONSENT_HIDE, EVENT_CONSENT_SHOW } from '@/config';
import { createVElement } from '@/utils/elements';
import { settingsService } from '@/services/settings-service';

interface BadgeElement extends HTMLElement {
hideBadge: () => void;
}

const settings = settingsService();

const handleBadgeClick = (): void => {
initConsentModal();

window.removeEventListener(EVENT_BADGE_CLICK, handleBadgeClick);
};

const handleConsentHide = (): void => {
initConsentBadge();

Expand All @@ -32,3 +41,17 @@ export const initConsentModal = (): void => {

window.addEventListener(EVENT_CONSENT_SHOW, handleConsentShow);
};

export const initConsentBadge = (): void => {
if (settings.disableBadge === true) {
return;
}

if (document.querySelectorAll(BADGE_ELEMENT_NAME).length) {
return;
}

window.addEventListener(EVENT_BADGE_CLICK, handleBadgeClick);

document.body.append(createVElement(BADGE_ELEMENT_NAME));
};
27 changes: 0 additions & 27 deletions src/init/initConsentBadge.ts

This file was deleted.

0 comments on commit 45b15a7

Please sign in to comment.