From 9d6c10201ea06af3e9a02cf3e7b901b0482b906f Mon Sep 17 00:00:00 2001 From: Laurent Dinclaux Date: Tue, 25 Jan 2022 19:45:55 +1100 Subject: [PATCH] Enable services widgets if serviceDefaultState set to true. --- tarteaucitron.js | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/tarteaucitron.js b/tarteaucitron.js index 9677005..be7b4ec 100644 --- a/tarteaucitron.js +++ b/tarteaucitron.js @@ -774,7 +774,10 @@ var tarteaucitron = { isAllowed = ((cookie.indexOf(service.key + '=true') >= 0) || (!service.needConsent && cookie.indexOf(service.key + '=false') < 0)), isResponded = (cookie.indexOf(service.key + '=false') >= 0 || cookie.indexOf(service.key + '=true') >= 0), isDNTRequested = (navigator.doNotTrack === "1" || navigator.doNotTrack === "yes" || navigator.msDoNotTrack === "1" || window.doNotTrack === "1"), - currentStatus = (isAllowed) ? tarteaucitron.lang.allowed : tarteaucitron.lang.disallowed; + currentStatus = (isAllowed) ? tarteaucitron.lang.allowed : tarteaucitron.lang.disallowed, + state = (undefined !== service.defaultState) ? service.defaultState : + (undefined !== tarteaucitron.parameters.serviceDefaultState ? tarteaucitron.parameters.serviceDefaultState : 'wait'); + if (tarteaucitron.added[service.key] !== true) { tarteaucitron.added[service.key] = true; @@ -866,13 +869,18 @@ var tarteaucitron = { tarteaucitron.state[service.key] = false; tarteaucitron.userInterface.color(service.key, false); } else if (!isResponded) { - tarteaucitron.cookie.create(service.key, service.defaultState || tarteaucitron.parameters.serviceDefaultState); - if (typeof service.fallback === 'function') { - if (typeof tarteaucitronMagic === 'undefined' || tarteaucitronMagic.indexOf("_" + service.key + "_") < 0) { service.fallback(); } + tarteaucitron.cookie.create(service.key, state); + if (typeof tarteaucitronMagic === 'undefined' || tarteaucitronMagic.indexOf("_" + service.key + "_") < 0) { + if(true === state && typeof service.js === 'function') { + service.js(); + } else if (typeof service.fallback === 'function') { + service.fallback(); + } } - tarteaucitron.userInterface.color(service.key, service.defaultState || tarteaucitron.parameters.serviceDefaultState); - if( 'wait' === (service.defaultState || tarteaucitron.parameters.serviceDefaultState) ) { + tarteaucitron.userInterface.color(service.key, state); + + if( 'wait' === state ) { tarteaucitron.userInterface.openAlert(); } }