Skip to content

Commit

Permalink
Fixed initialization of the original plugin when a page is too small …
Browse files Browse the repository at this point in the history
…and DOM is already loaded before an event `window.addEventListener('load', ...)` is attached.
  • Loading branch information
tg666 committed Dec 31, 2021
1 parent e5a41a7 commit f105241
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Fixed

- Fixed initialization of the original plugin when a page is too small and DOM is already loaded before an event `window.addEventListener('load', ...)` is attached.

## [0.3.0] - 2021-12-28

### Added
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "68publishers-cookie-consent",
"version": "0.3.0",
"version": "0.3.1-beta.0",
"description": "Cookie consent wrapper based on orestbida/cookieconsent with GTM integration.",
"homepage": "http://www.68publishers.io/",
"main": "index.js",
Expand Down
10 changes: 8 additions & 2 deletions src/CookieConsentWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class CookieConsentWrapper {
}
}

window.addEventListener('load', function () {
const windowLoadedCallback = function () {
// init cookie consent
self._cookieConsent = initCookieConsent();
const consentManager = new ConsentManager(self._cookieConsent, self._storagePool, Object.values(self._eventTriggers), self._gtag);
Expand Down Expand Up @@ -138,7 +138,13 @@ class CookieConsentWrapper {
}

self._eventBus.dispatch(Events.ON_INIT, self);
});
};

if ('complete' === document.readyState) {
windowLoadedCallback();
} else {
window.addEventListener('load', windowLoadedCallback);
}

this._initialized = true;
}
Expand Down

0 comments on commit f105241

Please sign in to comment.