| 1 |
jQuery( document ).ready( function ( $ ) { |
| 2 |
let cookieBlockingMode = cookiebotNetworkSettings.cbm |
| 3 |
$( 'input[type=radio][name=cookiebot-cookie-blocking-mode]' ).on( 'change', function () { |
| 4 |
if ( this.value === 'auto' && cookieBlockingMode !== this.value ) { |
| 5 |
$( '#cookiebot-setting-async, #cookiebot-setting-hide-popup' ).css( 'opacity', 0.4 ) |
| 6 |
$( '#declaration-tag').addClass('disabled__item'); |
| 7 |
$( 'input[type=radio][name=cookiebot-script-tag-uc-attribute], input[name=cookiebot-nooutput]' ).prop( 'disabled', true ) |
| 8 |
} |
| 9 |
if ( this.value === 'manual' && cookieBlockingMode !== this.value ) { |
| 10 |
$( '#cookiebot-setting-async, #cookiebot-setting-hide-popup' ).css( 'opacity', 1 ) |
| 11 |
$( '#declaration-tag, #cookie-popup').removeClass('disabled__item'); |
| 12 |
$( 'input[type=radio][name=cookiebot-script-tag-uc-attribute], input[name=cookiebot-nooutput]' ).prop( 'disabled', false ) |
| 13 |
} |
| 14 |
cookieBlockingMode = this.value |
| 15 |
} ) |
| 16 |
if ( cookieBlockingMode === 'auto' ) { |
| 17 |
$( '#cookiebot-setting-async, #cookiebot-setting-hide-popup' ).css( 'opacity', 0.4 ) |
| 18 |
$( 'input[type=radio][name=cookiebot-script-tag-uc-attribute], input[name=cookiebot-nooutput]' ).prop( 'disabled', true ) |
| 19 |
} |
| 20 |
|
| 21 |
jQuery('.cb-submit__msg').on('click',function(){ |
| 22 |
jQuery(this).addClass('hidden'); |
| 23 |
}); |
| 24 |
|
| 25 |
const initialValues = jQuery('form').serialize(); |
| 26 |
const events = { |
| 27 |
change: 'input:not([type=text]), select', |
| 28 |
input: 'input[type="text"], textarea' |
| 29 |
}; |
| 30 |
|
| 31 |
Object.entries(events).forEach(entry => { |
| 32 |
const [eventName, elements] = entry; |
| 33 |
jQuery(document).on(eventName,elements,{initialValues: initialValues},function(event){ |
| 34 |
checkValues(event.data.initialValues) |
| 35 |
}); |
| 36 |
}); |
| 37 |
|
| 38 |
ruleset_id(); |
| 39 |
remove_account(); |
| 40 |
} ) |
| 41 |
|
| 42 |
function check_id_frame(){ |
| 43 |
const cbFrameReg = /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/; |
| 44 |
return cbFrameReg.test(jQuery( '#cookiebot-cbid' ).val()) |
| 45 |
} |
| 46 |
|
| 47 |
function ruleset_id(){ |
| 48 |
const cbidField = jQuery( '#cookiebot-cbid' ); |
| 49 |
const cbidCheck = jQuery( '.cookiebot-cbid-check' ); |
| 50 |
let fieldTimer; |
| 51 |
let fieldInterval = 3000; |
| 52 |
|
| 53 |
cbidField.on('keyup', function () { |
| 54 |
clearTimeout(fieldTimer); |
| 55 |
cbidField.addClass('check-progress'); |
| 56 |
cbidCheck.removeClass('check-pass').addClass('check-progress'); |
| 57 |
fieldTimer = setTimeout(show_ruleset_selector, fieldInterval); |
| 58 |
}); |
| 59 |
|
| 60 |
cbidField.on('keydown', function () { |
| 61 |
clearTimeout(fieldTimer); |
| 62 |
}); |
| 63 |
} |
| 64 |
function show_ruleset_selector() { |
| 65 |
const cbidField = jQuery( '#cookiebot-cbid' ); |
| 66 |
const cbidCheck = jQuery( '.cookiebot-cbid-check' ); |
| 67 |
const cbidRulesetSelector = jQuery('#cookiebot-ruleset-id-selector'); |
| 68 |
const cbidSubmit = jQuery('.cookiebot-cbid-container p.submit #submit'); |
| 69 |
const cbidError = jQuery('.cookiebot-cbid-error'); |
| 70 |
|
| 71 |
cbidCheck.removeClass('check-progress'); |
| 72 |
cbidField.removeClass('check-progress'); |
| 73 |
|
| 74 |
if(!cbidField.val()){ |
| 75 |
cbidCheck.removeClass('check-pass'); |
| 76 |
cbidRulesetSelector.addClass('hidden'); |
| 77 |
cbidSubmit.addClass('disabled'); |
| 78 |
cbidError.addClass('hidden'); |
| 79 |
return; |
| 80 |
} |
| 81 |
|
| 82 |
// Validate that the field has exactly 9, 14 or 36 characters |
| 83 |
const fieldLength = cbidField.val().length; |
| 84 |
if(fieldLength !== 9 && fieldLength !== 14 && fieldLength !== 36){ |
| 85 |
cbidCheck.removeClass('check-pass'); |
| 86 |
cbidRulesetSelector.addClass('hidden'); |
| 87 |
cbidSubmit.addClass('disabled'); |
| 88 |
cbidError.removeClass('hidden'); |
| 89 |
return; |
| 90 |
} |
| 91 |
|
| 92 |
// Valid input - hide error message |
| 93 |
cbidError.addClass('hidden'); |
| 94 |
|
| 95 |
!check_id_frame() ? cbidRulesetSelector.removeClass('hidden') : cbidRulesetSelector.addClass('hidden'); |
| 96 |
|
| 97 |
cbidSubmit.removeClass('disabled'); |
| 98 |
} |
| 99 |
|
| 100 |
function remove_account(){ |
| 101 |
const removeCta = jQuery('#cookiebot-cbid-reset-dialog'); |
| 102 |
const cbidAlert = jQuery('.cb-cbid-alert__msg'); |
| 103 |
const confirmCta = jQuery('#cookiebot-cbid-reset'); |
| 104 |
const cancelCta = jQuery('#cookiebot-cbid-cancel'); |
| 105 |
removeCta.on('click', function(){ |
| 106 |
cbidAlert.removeClass('hidden'); |
| 107 |
removeCta.addClass('disabled'); |
| 108 |
}); |
| 109 |
confirmCta.on('click', function(){ |
| 110 |
jQuery('#cookiebot-cbid').val('').removeClass('cbid-active'); |
| 111 |
|
| 112 |
// If the account was disconnected set blocking mode to 'auto' and 'Hide cookie popup' to false. |
| 113 |
jQuery('input[type=radio][name=cookiebot-cookie-blocking-mode][value=auto]').prop('checked', true); |
| 114 |
jQuery('input[name=cookiebot-nooutput]').prop( 'checked', false ) |
| 115 |
|
| 116 |
jQuery('.cb-settings__header p.submit #submit').click(); |
| 117 |
}); |
| 118 |
cancelCta.on('click', function(){ |
| 119 |
cbidAlert.addClass('hidden'); |
| 120 |
removeCta.removeClass('disabled'); |
| 121 |
}); |
| 122 |
} |
| 123 |
|
| 124 |
function checkValues(initialValues){ |
| 125 |
let submitBtn = jQuery('p.submit #submit'); |
| 126 |
let newValues = jQuery('form').serialize(); |
| 127 |
if(newValues !== initialValues) { |
| 128 |
submitBtn.addClass('enabled'); |
| 129 |
}else{ |
| 130 |
submitBtn.removeClass('enabled'); |
| 131 |
} |
| 132 |
} |