gutenberg
3 years ago
cookiebot-admin-script.js
3 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
3 years ago
support-page.js
3 years ago
settings-page.js
162 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 | closeSubmitMsg(); |
| 14 | submitEnable(); |
| 15 | googleConsentModeOptions(); |
| 16 | } |
| 17 | |
| 18 | function language_toggle() { |
| 19 | jQuery( '#show_add_language_guide' ).on( 'click', function ( e ) { |
| 20 | e.preventDefault() |
| 21 | jQuery( '#add_language_guide' ).slideDown() |
| 22 | jQuery( this ).hide() |
| 23 | } ) |
| 24 | jQuery( '#hide_add_language_guide' ).on( 'click', function ( e ) { |
| 25 | e.preventDefault() |
| 26 | jQuery( '#add_language_guide' ).slideUp() |
| 27 | jQuery( '#show_add_language_guide' ).show() |
| 28 | } ) |
| 29 | |
| 30 | jQuery( '#cookiebot-language' ).on( 'change', function () { |
| 31 | if ( this.value === '' ) { |
| 32 | jQuery( '#info_lang_autodetect' ).show() |
| 33 | jQuery( '#info_lang_specified' ).hide() |
| 34 | } else { |
| 35 | jQuery( '#info_lang_autodetect' ).hide() |
| 36 | jQuery( '#info_lang_specified' ).show() |
| 37 | } |
| 38 | } ) |
| 39 | } |
| 40 | |
| 41 | function advanced_settings_toggle() { |
| 42 | jQuery( '.cookiebot_fieldset_header' ).on( 'click', function ( e ) { |
| 43 | e.preventDefault() |
| 44 | jQuery( this ).next().slideToggle() |
| 45 | jQuery( this ).toggleClass( 'active' ) |
| 46 | } ) |
| 47 | } |
| 48 | |
| 49 | function resetConsentMapping() { |
| 50 | if ( confirm( 'Are you sure you want to reset to default consent mapping?' ) ) { |
| 51 | jQuery( '.consent_mapping_table input[type=checkbox]' ).each( function () { |
| 52 | if ( !this.disabled ) { |
| 53 | this.checked = ( jQuery( this ).data( 'default-value' ) === '1' ) |
| 54 | } |
| 55 | } ) |
| 56 | } |
| 57 | return false |
| 58 | } |
| 59 | |
| 60 | function cookie_blocking_mode() { |
| 61 | let cookieBlockingMode = cookiebot_settings.cookieBlockingMode; |
| 62 | |
| 63 | jQuery( 'input[type=radio][name=cookiebot-cookie-blocking-mode]' ).on( 'change', function () { |
| 64 | if ( this.value === 'auto' && cookieBlockingMode !== this.value ) { |
| 65 | jQuery( '#cookiebot-setting-async, #cookiebot-setting-hide-popup' ).css( 'opacity', 0.4 ); |
| 66 | jQuery( '#declaration-tag, #cookie-popup, #gcm-cookie-categories, #gtm-cookie-categories').addClass('disabled__item'); |
| 67 | jQuery( 'input[type=radio][name=cookiebot-script-tag-uc-attribute], input[name=cookiebot-nooutput]' ).prop( 'disabled', true ); |
| 68 | jQuery( '#cb-settings__gtm__cookie-types input[type=checkbox]' ).prop( 'disabled', true ); |
| 69 | jQuery( '#cb-settings__gcm__cookie-types input[type=checkbox]' ).prop( 'disabled', true ); |
| 70 | } |
| 71 | if ( this.value === 'manual' && cookieBlockingMode !== this.value ) { |
| 72 | jQuery( '#cookiebot-setting-async, #cookiebot-setting-hide-popup' ).css( 'opacity', 1 ); |
| 73 | jQuery( '#declaration-tag, #cookie-popup, #gcm-cookie-categories, #gtm-cookie-categories').removeClass('disabled__item'); |
| 74 | jQuery( 'input[type=radio][name=cookiebot-script-tag-uc-attribute], input[name=cookiebot-nooutput]' ).prop( 'disabled', false ); |
| 75 | jQuery( '#cb-settings__gtm__cookie-types input[type=checkbox]' ).prop( 'disabled', false ); |
| 76 | jQuery( '#cb-settings__gcm__cookie-types input[type=checkbox]' ).prop( 'disabled', false ); |
| 77 | } |
| 78 | cookieBlockingMode = this.value; |
| 79 | } ) |
| 80 | if ( cookieBlockingMode === 'auto' ) { |
| 81 | jQuery( '#cookiebot-setting-async, #cookiebot-setting-hide-popup' ).css( 'opacity', 0.4 ); |
| 82 | jQuery( 'input[type=radio][name=cookiebot-script-tag-uc-attribute], input[name=cookiebot-nooutput]' ).prop( 'disabled', true ); |
| 83 | jQuery( '#cb-settings__gtm__cookie-types input[type=checkbox]' ).prop( 'disabled', true ); |
| 84 | jQuery( '#cb-settings__gcm__cookie-types input[type=checkbox]' ).prop( 'disabled', true ); |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | function activeSettingsTab() { |
| 89 | jQuery('.cb-settings__tabs__item').on('click', function(){ |
| 90 | let currentTab = jQuery('.cb-settings__tabs__item.active-item').data('tab'); |
| 91 | let tab = jQuery(this).data('tab'); |
| 92 | let tabSelector = '#'+tab; |
| 93 | jQuery('.cb-settings__tabs__item.active-item, .cb-settings__tabs__content--item.active-item').removeClass('active-item'); |
| 94 | jQuery(this).addClass('active-item'); |
| 95 | jQuery(tabSelector).addClass('active-item'); |
| 96 | |
| 97 | window.history.replaceState(null, null, '?page=cookiebot_settings&tab='+tab ); |
| 98 | let referrer = jQuery('input[name="_wp_http_referer"]'); |
| 99 | let referrerVal = referrer.val(); |
| 100 | if(referrerVal.indexOf('tab=')!==-1) { |
| 101 | referrerVal = referrerVal.replace(currentTab,tab); |
| 102 | }else{ |
| 103 | referrerVal += '&tab=' + tab; |
| 104 | } |
| 105 | referrer.val(referrerVal); |
| 106 | }); |
| 107 | } |
| 108 | |
| 109 | function closeSubmitMsg() { |
| 110 | jQuery('.cb-submit__msg').on('click',function(){ |
| 111 | jQuery(this).addClass('hidden'); |
| 112 | }); |
| 113 | } |
| 114 | |
| 115 | function submitEnable() { |
| 116 | const initialValues = jQuery('form').serialize(); |
| 117 | const events = { |
| 118 | change: 'input:not([type=text]), select', |
| 119 | input: 'input[type="text"], textarea' |
| 120 | }; |
| 121 | |
| 122 | Object.entries(events).forEach(entry => { |
| 123 | const [eventName, elements] = entry; |
| 124 | jQuery(document).on(eventName,elements,{initialValues: initialValues},function(event){ |
| 125 | checkValues(event.data.initialValues) |
| 126 | }); |
| 127 | }); |
| 128 | } |
| 129 | |
| 130 | function checkValues(initialValues){ |
| 131 | let submitBtn = jQuery('p.submit #submit'); |
| 132 | let newValues = jQuery('form').serialize(); |
| 133 | if(newValues !== initialValues) { |
| 134 | submitBtn.addClass('enabled'); |
| 135 | }else{ |
| 136 | submitBtn.removeClass('enabled'); |
| 137 | } |
| 138 | } |
| 139 | |
| 140 | function googleConsentModeOptions() { |
| 141 | jQuery('input#gcm').on('change', function () { |
| 142 | const parent = jQuery(this).parents('#consent-mode'); |
| 143 | parent.find('.cb-settings__config__item:has(input#gcm-url-pasthrough)').toggle(); |
| 144 | parent.find('.cb-settings__config__item:has(ul#cb-settings__gcm__cookie-types)').toggle(); |
| 145 | const passthroughInput = jQuery('input#gcm-url-pasthrough'); |
| 146 | const passthroughLabel = passthroughInput.parents('label.switch-checkbox')[0]; |
| 147 | if (!passthroughLabel || !passthroughLabel.childNodes.length) |
| 148 | return; |
| 149 | passthroughLabel.childNodes[passthroughLabel.childNodes.length - 1].textContent = 'URL passthrough' + ' ' + |
| 150 | (passthroughInput.is(':checked') ? 'enabled' : 'disabled'); |
| 151 | }); |
| 152 | jQuery('input#gcm, input#gcm-url-pasthrough').on('change', function () { |
| 153 | const input = jQuery(this); |
| 154 | const label = input.parents('label.switch-checkbox')[0]; |
| 155 | if (!label || !label.childNodes.length) |
| 156 | return; |
| 157 | label.childNodes[label.childNodes.length - 1].textContent = ( |
| 158 | (input.attr('id') === 'gcm' ? 'Google Consent Mode' : 'URL passthrough') + ' ' + |
| 159 | (input.is(':checked') ? 'enabled' : 'disabled') |
| 160 | ); |
| 161 | }); |
| 162 | } |