Skip to content

Commit

Permalink
BREAKING CHANGES: Require service name to be passed as the first para…
Browse files Browse the repository at this point in the history
…meter #CCM-35
  • Loading branch information
OndraM committed Nov 18, 2021
1 parent 85474f8 commit 6801656
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 4 deletions.
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Load the script and initialize the plugin right before ending `</body>` tag:
<script defer src="https://cdn.jsdelivr.net/npm/@lmc-eu/cookie-consent-manager@0.5/init.js"></script>
<script>
window.addEventListener('load', function () {
initLmcCookieConsentManager();
initLmcCookieConsentManager('demo.example'); // use the name of your service, like jobs.cz, seduo.pl etc.
});
</script>
```
Expand Down Expand Up @@ -84,7 +84,7 @@ via npm package [@lmc-eu/cookie-consent-manager](https://www.npmjs.com/package/@
import LmcCookieConsentManager from '@lmc-eu/cookie-consent-manager';
window.addEventListener('load', function () {
LmcCookieConsentManager(/* plugin configuration */);
LmcCookieConsentManager('demo.example'/* , optional plugin configuration */);
});
```
Expand Down Expand Up @@ -145,6 +145,7 @@ To execute custom code which depends on cookie consent use callbacks:
```js
// ...
initLmcCookieConsentManager(
'demo.example',
{
onAcceptAll: (cookie, cookieConsent) => {
if (cookieConsent.allowedCategory('functionality')) {
Expand Down Expand Up @@ -172,6 +173,7 @@ This feature is enabled by default. If you'd like to disable it, you can do so b
```js
initLmcCookieConsentManager(
'demo.example',
{
config: {
page_scripts: false
Expand All @@ -182,10 +184,12 @@ initLmcCookieConsentManager(
## Configuration
Optional config parameters could be provided on plugin initialization in the configuration object.
Optional config parameters could be provided on plugin initialization as the second parameter,
encapsulated in the configuration object.
```js
initLmcCookieConsentManager( // when loaded as a module, these options are passed to `LmcCookieConsentManager()` instead
'demo.example', // provide the name of your service, like jobs.cz, seduo.pl etc.
{
defaultLang: 'cs',
autodetectLang: false,
Expand Down
1 change: 1 addition & 0 deletions examples/callbacks.html
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ <h3 class="mt-4">Callbacks</h3>
<script>
window.addEventListener('load', function () {
window.ccm = initLmcCookieConsentManager( // note we store cookieConsent instance in global window.ccm variable
'github.example',
{
autodetectLang: false, // do not detect language from the browser
defaultLang: 'en', // use 'en' language by default
Expand Down
1 change: 1 addition & 0 deletions examples/configuration.html
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ <h3 class="mt-4">Use cookieConsent instance</h3>
<script>
window.addEventListener('load', function () {
window.ccm = initLmcCookieConsentManager( // note we store cookieConsent instance in global window.ccm variable
'github.example',
{
autodetectLang: false, // do not detect language from the browser
defaultLang: 'en', // use 'en' language by default
Expand Down
1 change: 1 addition & 0 deletions examples/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ <h3 class="mt-4">Allowed consent categories</h3>
<script>
window.addEventListener('load', function () {
initLmcCookieConsentManager(
'github.example',
{
autodetectLang: false, // do not detect language from the browser
defaultLang: 'en', // use 'en' language by default
Expand Down
1 change: 1 addition & 0 deletions examples/theming.html
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ <h3 class="mt-4">TODO</h3>
<script>
window.addEventListener('load', function () {
initLmcCookieConsentManager(
'github.example',
{
autodetectLang: false, // do not detect language from the browser
defaultLang: 'en', // use 'en' language by default
Expand Down
7 changes: 6 additions & 1 deletion src/LmcCookieConsentManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const defaultOptions = {
};

/**
* @param {string} serviceName - Identifier of the source service (website/application). Must be provided.
* @param {Object} [args] - Options for cookie consent manager
* @param {string} [args.defaultLang] - Default language. Must be one of predefined languages.
* @param {boolean} [args.autodetectLang] - Autodetect language from the browser
Expand All @@ -34,7 +35,11 @@ const defaultOptions = {
* @param {Object} [args.config] - Override default config. See https://github.com/orestbida/cookieconsent/blob/master/Readme.md#all-available-options
* @returns {Object} Instance of the underlying CookieConsent component. For available API, see https://github.com/orestbida/cookieconsent#apis--configuration-parameters
*/
const LmcCookieConsentManager = (args) => {
const LmcCookieConsentManager = (serviceName, args) => {
if (!serviceName || serviceName === '' || typeof serviceName !== 'string') {
throw new Error('serviceName is a required parameter and must be a string');
}

const options = { ...defaultOptions, ...args };
const {
defaultLang,
Expand Down

0 comments on commit 6801656

Please sign in to comment.