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
157 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 | googleConsentModeUrlPassthrough(); |
| 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').addClass('disabled__item'); |
| 67 | jQuery( 'input[type=radio][name=cookiebot-script-tag-uc-attribute], input[name=cookiebot-nooutput]' ).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').removeClass('disabled__item'); |
| 72 | jQuery( 'input[type=radio][name=cookiebot-script-tag-uc-attribute], input[name=cookiebot-nooutput]' ).prop( 'disabled', false ) |
| 73 | } |
| 74 | cookieBlockingMode = this.value |
| 75 | } ) |
| 76 | if ( cookieBlockingMode === 'auto' ) { |
| 77 | jQuery( '#cookiebot-setting-async, #cookiebot-setting-hide-popup' ).css( 'opacity', 0.4 ) |
| 78 | jQuery( 'input[type=radio][name=cookiebot-script-tag-uc-attribute], input[name=cookiebot-nooutput]' ).prop( 'disabled', true ) |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | function activeSettingsTab() { |
| 83 | jQuery('.cb-settings__tabs__item').on('click', function(){ |
| 84 | let currentTab = jQuery('.cb-settings__tabs__item.active-item').data('tab'); |
| 85 | let tab = jQuery(this).data('tab'); |
| 86 | let tabSelector = '#'+tab; |
| 87 | jQuery('.cb-settings__tabs__item.active-item, .cb-settings__tabs__content--item.active-item').removeClass('active-item'); |
| 88 | jQuery(this).addClass('active-item'); |
| 89 | jQuery(tabSelector).addClass('active-item'); |
| 90 | |
| 91 | window.history.replaceState(null, null, '?page=cookiebot_settings&tab='+tab ); |
| 92 | let referrer = jQuery('input[name="_wp_http_referer"]'); |
| 93 | let referrerVal = referrer.val(); |
| 94 | if(referrerVal.indexOf('tab=')!==-1) { |
| 95 | referrerVal = referrerVal.replace(currentTab,tab); |
| 96 | }else{ |
| 97 | referrerVal += '&tab=' + tab; |
| 98 | } |
| 99 | referrer.val(referrerVal); |
| 100 | }); |
| 101 | } |
| 102 | |
| 103 | function closeSubmitMsg() { |
| 104 | jQuery('.cb-submit__msg').on('click',function(){ |
| 105 | jQuery(this).addClass('hidden'); |
| 106 | }); |
| 107 | } |
| 108 | |
| 109 | function submitEnable() { |
| 110 | const initialValues = jQuery('form').serialize(); |
| 111 | const events = { |
| 112 | change: 'input:not([type=text]), select', |
| 113 | input: 'input[type="text"], textarea' |
| 114 | }; |
| 115 | |
| 116 | Object.entries(events).forEach(entry => { |
| 117 | const [eventName, elements] = entry; |
| 118 | jQuery(document).on(eventName,elements,{initialValues: initialValues},function(event){ |
| 119 | checkValues(event.data.initialValues) |
| 120 | }); |
| 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 | } |
| 133 | |
| 134 | function googleConsentModeUrlPassthrough() { |
| 135 | jQuery('input#gcm').on('change', function () { |
| 136 | jQuery(this) |
| 137 | .parents('#consent-mode') |
| 138 | .find('.cb-settings__config__item:has(input#gcm-url-pasthrough)') |
| 139 | .toggle() |
| 140 | const input = jQuery('input#gcm-url-pasthrough'); |
| 141 | const label = input.parents('label.switch-checkbox')[0]; |
| 142 | if (!label || !label.childNodes.length) |
| 143 | return; |
| 144 | label.childNodes[label.childNodes.length - 1].textContent = 'URL passthrough' + ' ' + |
| 145 | (input.is(':checked') ? 'enabled' : 'disabled'); |
| 146 | }); |
| 147 | jQuery('input#gcm, input#gcm-url-pasthrough').on('change', function () { |
| 148 | const input = jQuery(this); |
| 149 | const label = input.parents('label.switch-checkbox')[0]; |
| 150 | if (!label || !label.childNodes.length) |
| 151 | return; |
| 152 | label.childNodes[label.childNodes.length - 1].textContent = ( |
| 153 | (input.attr('id') === 'gcm' ? 'Google Consent Mode' : 'URL passthrough') + ' ' + |
| 154 | (input.is(':checked') ? 'enabled' : 'disabled') |
| 155 | ); |
| 156 | }); |
| 157 | } |