PluginProbe ʕ •ᴥ•ʔ
Cookiebot by Usercentrics – Automatic Cookie Banner for GDPR/CCPA & Google Consent Mode / 4.3.11
Cookiebot by Usercentrics – Automatic Cookie Banner for GDPR/CCPA & Google Consent Mode v4.3.11
4.7.2 4.7.1 trunk 2.3.0 2.4.0 2.4.1 2.4.2 2.5.0 3.0.0 3.0.1 3.1.0 3.10.0 3.10.1 3.11.1 3.11.2 3.11.3 3.2.0 3.3.0 3.3.1 3.4.0 3.4.1 3.4.2 3.5.0 3.6.0 3.6.1 3.6.2 3.6.5 3.6.6 3.7.0 3.7.1 3.8.0 3.9.0 4.0.0 4.0.1 4.0.2 4.0.3 4.1.0 4.1.1 4.2.0 4.2.1 4.2.10 4.2.11 4.2.12 4.2.13 4.2.14 4.2.2 4.2.3 4.2.4 4.2.5 4.2.6 4.2.7 4.2.8 4.2.9 4.3.0 4.3.1 4.3.10 4.3.11 4.3.12 4.3.2 4.3.3 4.3.4 4.3.5 4.3.6 4.3.7 4.3.7.1 4.3.8 4.3.9 4.3.9.1 4.4.0 4.4.1 4.4.2 4.5.0 4.5.1 4.5.10 4.5.11 4.5.2 4.5.3 4.5.4 4.5.5 4.5.6 4.5.7 4.5.8 4.5.9 4.6.0 4.6.1 4.6.2 4.6.3 4.6.4 4.6.5 4.6.6 4.6.7 4.7.0
cookiebot / assets / js / backend / settings-page.js
cookiebot / assets / js / backend Last commit date
gutenberg 3 years ago consent-mapping.js 2 years ago cookiebot-admin-script.js 2 years ago debug-page.js 3 years ago jquery.tipTip.js 3 years ago multiple-page.js 3 years ago network-settings-page.js 3 years ago prior-consent-settings.js 3 years ago settings-page.js 1 year ago support-page.js 3 years ago
settings-page.js
305 lines
1 /**
2 * Load init function when the page is ready
3 *
4 * @since 1.8.0
5 */
6 jQuery( document ).ready( init );
7
8 function init() {
9 language_toggle();
10 advanced_settings_toggle();
11 cookie_blocking_mode();
12 activeSettingsTab();
13 initialCheckActiveVendors();
14 closeSubmitMsg();
15 submitEnable();
16 googleConsentModeOptions();
17 tcfOptions();
18 vendorListRequire();
19 selectAllListItem();
20 deselectAllListItem();
21 onAddRestriction();
22 showRestrictionPurposes();
23 onVendorSelection();
24 removeRestriction();
25 }
26
27 function language_toggle() {
28 jQuery( '#show_add_language_guide' ).on( 'click', function ( e ) {
29 e.preventDefault()
30 jQuery( '#add_language_guide' ).slideDown()
31 jQuery( this ).hide()
32 } )
33 jQuery( '#hide_add_language_guide' ).on( 'click', function ( e ) {
34 e.preventDefault()
35 jQuery( '#add_language_guide' ).slideUp()
36 jQuery( '#show_add_language_guide' ).show()
37 } )
38
39 jQuery( '#cookiebot-language' ).on( 'change', function () {
40 if ( this.value === '' ) {
41 jQuery( '#info_lang_autodetect' ).show()
42 jQuery( '#info_lang_specified' ).hide()
43 } else {
44 jQuery( '#info_lang_autodetect' ).hide()
45 jQuery( '#info_lang_specified' ).show()
46 }
47 } )
48 }
49
50 function advanced_settings_toggle() {
51 jQuery( '.cookiebot_fieldset_header' ).on( 'click', function ( e ) {
52 e.preventDefault()
53 jQuery( this ).next().slideToggle()
54 jQuery( this ).toggleClass( 'active' )
55 } )
56 }
57
58 function cookie_blocking_mode() {
59 let cookieBlockingMode = cookiebot_settings.cookieBlockingMode;
60
61 jQuery( 'input[type=radio][name=cookiebot-cookie-blocking-mode]' ).on( 'change', function () {
62 if ( this.value === 'auto' && cookieBlockingMode !== this.value ) {
63 jQuery( '#cookiebot-setting-async, #cookiebot-setting-hide-popup' ).css( 'opacity', 0.4 );
64 jQuery( '#declaration-tag, #cookie-popup, #gcm-cookie-categories, #gtm-cookie-categories').addClass('disabled__item');
65 jQuery( 'input[type=radio][name=cookiebot-script-tag-uc-attribute], input[name=cookiebot-nooutput]' ).prop( 'disabled', true );
66 jQuery( '#cb-settings__gtm__cookie-types input[type=checkbox]' ).prop( 'disabled', true );
67 jQuery( '#cb-settings__gcm__cookie-types input[type=checkbox]' ).prop( 'disabled', true );
68 }
69 if ( this.value === 'manual' && cookieBlockingMode !== this.value ) {
70 jQuery( '#cookiebot-setting-async, #cookiebot-setting-hide-popup' ).css( 'opacity', 1 );
71 jQuery( '#declaration-tag, #cookie-popup, #gcm-cookie-categories, #gtm-cookie-categories').removeClass('disabled__item');
72 jQuery( 'input[type=radio][name=cookiebot-script-tag-uc-attribute], input[name=cookiebot-nooutput]' ).prop( 'disabled', false );
73 jQuery( '#cb-settings__gtm__cookie-types input[type=checkbox]' ).prop( 'disabled', false );
74 jQuery( '#cb-settings__gcm__cookie-types input[type=checkbox]' ).prop( 'disabled', false );
75 }
76 cookieBlockingMode = this.value;
77 } )
78 if ( cookieBlockingMode === 'auto' ) {
79 jQuery( '#cookiebot-setting-async, #cookiebot-setting-hide-popup' ).css( 'opacity', 0.4 );
80 jQuery( 'input[type=radio][name=cookiebot-script-tag-uc-attribute], input[name=cookiebot-nooutput]' ).prop( 'disabled', true );
81 jQuery( '#cb-settings__gtm__cookie-types input[type=checkbox]' ).prop( 'disabled', true );
82 jQuery( '#cb-settings__gcm__cookie-types input[type=checkbox]' ).prop( 'disabled', true );
83 }
84 }
85
86 function activeSettingsTab() {
87 jQuery('.cb-settings__tabs__item').on('click', function(){
88 let currentTab = jQuery('.cb-settings__tabs__item.active-item').data('tab');
89 let tab = jQuery(this).data('tab');
90 let tabSelector = '#'+tab;
91 jQuery('.cb-settings__tabs__item.active-item, .cb-settings__tabs__content--item.active-item').removeClass('active-item');
92 jQuery(this).addClass('active-item');
93 jQuery(tabSelector).addClass('active-item');
94
95 window.history.replaceState(null, null, '?page=cookiebot_settings&tab='+tab );
96 let referrer = jQuery('input[name="_wp_http_referer"]');
97 let referrerVal = referrer.val();
98 if(referrerVal.indexOf('tab=')!==-1) {
99 referrerVal = referrerVal.replace(currentTab,tab);
100 }else{
101 referrerVal += '&tab=' + tab;
102 }
103 referrer.val(referrerVal);
104 });
105 }
106
107 function closeSubmitMsg() {
108 jQuery('.cb-submit__msg').on('click',function(){
109 jQuery(this).addClass('hidden');
110 });
111 }
112
113 function submitEnable() {
114 const initialValues = jQuery('form').serialize();
115 const events = {
116 change: 'input:not([type=text]), select',
117 input: 'input[type="text"], textarea'
118 };
119
120 Object.entries(events).forEach(entry => {
121 const [eventName, elements] = entry;
122 jQuery(document).on(eventName,elements,{initialValues: initialValues},function(event){
123 checkValues(event.data.initialValues)
124 });
125 });
126 }
127
128 function checkValues(initialValues){
129 let submitBtn = jQuery('p.submit #submit');
130 let newValues = jQuery('form').serialize();
131 if(newValues !== initialValues) {
132 submitBtn.addClass('enabled');
133 }else{
134 submitBtn.removeClass('enabled');
135 }
136 checkActiveVendors();
137 }
138
139 function googleConsentModeOptions() {
140 jQuery('input#gcm').on('change', function () {
141 const parent = jQuery(this).parents('#consent-mode');
142 parent.find('.cb-settings__config__item:has(input#gcm-url-pasthrough)').toggle();
143 parent.find('.cb-settings__config__item:has(ul#cb-settings__gcm__cookie-types)').toggle();
144 const passthroughInput = jQuery('input#gcm-url-pasthrough');
145 const passthroughLabel = passthroughInput.parents('label.switch-checkbox')[0];
146 if (!passthroughLabel || !passthroughLabel.childNodes.length)
147 return;
148 passthroughLabel.childNodes[passthroughLabel.childNodes.length - 1].textContent = 'URL passthrough' + ' ' +
149 (passthroughInput.is(':checked') ? 'enabled' : 'disabled');
150 });
151 jQuery('input#gcm, input#gcm-url-pasthrough').on('change', function () {
152 const input = jQuery(this);
153 const label = input.parents('label.switch-checkbox')[0];
154 if (!label || !label.childNodes.length)
155 return;
156 label.childNodes[label.childNodes.length - 1].textContent = (
157 (input.attr('id') === 'gcm' ? 'Google Consent Mode' : 'URL passthrough') + ' ' +
158 (input.is(':checked') ? 'enabled' : 'disabled')
159 );
160 });
161 }
162
163 function tcfOptions() {
164 jQuery('input#cookiebot-iab').on('change', function () {
165 const parent = jQuery(this).parents('#iab');
166 parent.find('.cb-settings__config__item:has(input.tcf-option)').toggle();
167 });
168 }
169
170 function checkIabActive() {
171 return jQuery('input#cookiebot-iab:checked').length;
172 }
173
174 function initialCheckActiveVendors() {
175 if(!checkIabActive()){
176 return;
177 }
178
179 const allVendorInputChecked = jQuery('input[name^="cookiebot-tcf-vendors"]:checked').length;
180 if(!allVendorInputChecked) {
181 jQuery('.vendor-selected-items-message').removeClass('hidden');
182 jQuery('.cb-vendor-alert__msg').removeClass('hidden');
183 }
184 }
185
186 function checkActiveVendors() {
187 if(!checkIabActive()){
188 return;
189 }
190
191 let submitBtn = jQuery('p.submit #submit');
192 const allVendorInputChecked = jQuery('input[name^="cookiebot-tcf-vendors"]:checked').length;
193 if(!allVendorInputChecked) {
194 jQuery('.vendor-selected-items-message').removeClass('hidden');
195 jQuery('.cb-vendor-alert__msg').removeClass('hidden');
196 submitBtn.removeClass('enabled');
197 }else{
198 jQuery('.vendor-selected-items-message').addClass('hidden');
199 jQuery('.cb-vendor-alert__msg').addClass('hidden');
200 if(!submitBtn.hasClass('enabled')) {
201 submitBtn.addClass('enabled');
202 }
203 }
204 }
205
206 function selectAllListItem(){
207 jQuery(document).on('click','.cb-settings__selector-all',function(){
208 const itemList = jQuery(this).siblings('.search-list');
209 itemList.children().each(function(){
210 jQuery(this).find('input').prop('checked', true);
211 })
212 checkActiveVendors();
213 })
214 }
215
216 function deselectAllListItem(){
217 jQuery(document).on('click','.cb-settings__selector-none',function(){
218 const itemList = jQuery(this).siblings('.search-list');
219 itemList.children().each(function(){
220 jQuery(this).find('input').prop('checked', false);
221 })
222 checkActiveVendors();
223 })
224 }
225
226 function vendorListRequire(){
227 jQuery( document ).on('change', 'input[name^="cookiebot-tcf-vendors"]', function () {
228 checkActiveVendors();
229 });
230 }
231
232 function onAddRestriction() {
233 jQuery('.restriction-vendor-add').on('click', function () {
234 const allCurrentVendors = jQuery( '.cb-settings__vendor__restrictions' ).length;
235 const baseElement = jQuery( '.cb-settings__vendor__restrictions:last' );
236 let newElement = baseElement.clone();
237 newElement.find('.vendor-selector').attr('name','');
238 newElement.find('option').removeAttr('selected');
239 newElement.find('.purpose-item').each(function(index){
240 const itemId = 'cookiebot-vendorx'+( allCurrentVendors + 1 )+'-purposes'+(index+1);
241 jQuery(this).attr('name','');
242 jQuery(this).attr('id',itemId);
243 jQuery(this).removeAttr('checked');
244 jQuery(this).parent().attr('for',itemId);
245 });
246
247 newElement.insertAfter(baseElement);
248 });
249 }
250
251 function showRestrictionPurposes() {
252 jQuery(document).on('click','.vendor-purposes-show', function () {
253 const parent = jQuery(this).parents('.cb-settings__vendor__restrictions');
254 parent.find('.vendor-purposes-restrictions').toggle();
255 });
256 }
257
258 function onVendorSelection() {
259 jQuery(document).on('change', '.cb-settings__selector__container-input', function () {
260 const vendorId = jQuery(this).val();
261 const parent = jQuery(this).parents('.cb-settings__vendor__restrictions');
262 const vendorPurposes = parent.find('.vendor-purposes-restrictions .purpose-item');
263 const fieldName = 'cookiebot-tcf-disallowed[$s]';
264 const purposeFieldName = '[purposes][]';
265
266 jQuery(this).attr('name', fieldName.replace('$s', vendorId));
267 vendorPurposes.each(function(index){
268 const purposeAttribute = fieldName.replace('$s', vendorId) + purposeFieldName;
269 const itemId = 'cookiebot-vendor' + vendorId + '-purposes' + (index+1);
270 jQuery(this).attr('name', purposeAttribute);
271 jQuery(this).attr('id', itemId);
272 jQuery(this).parent().attr('for',itemId);
273 });
274 });
275 }
276
277 function removeRestriction(){
278 const initialValues = jQuery('form').serialize();
279 let submitBtn = jQuery('p.submit #submit');
280 jQuery(document).on('click','.cb-settings__vendor__restrictions .remove__restriction', function(){
281 const restriction = jQuery(this).closest( '.cb-settings__vendor__restrictions' );
282 const allRestrictions = jQuery( '.cb-settings__vendor__restrictions' );
283 if(allRestrictions.length === 1){
284 const selector = restriction.find('.cb-settings__selector-selector');
285 console.log(selector.data('placeholder'));
286 selector.text(selector.data('placeholder'));
287 restriction.find('.cb-settings__selector__container-input').val('');
288 restriction.find('.cb-settings__selector__container-input').attr('name','');
289 restriction.find('.cb-settings__selector-list-item.selected').removeClass('selected');
290 const vendorPurposes = restriction.find('.purpose-item');
291 vendorPurposes.each(function(){
292 jQuery(this).prop( 'checked', false );
293 jQuery(this).attr( 'name', '' );
294 });
295 }else{
296 restriction.remove();
297 }
298 let newValues = jQuery('form').serialize();
299 if(newValues !== initialValues) {
300 submitBtn.addClass('enabled');
301 }else{
302 submitBtn.removeClass('enabled');
303 }
304 });
305 }