gutenberg
4 years ago
debug-page.js
4 years ago
jquery.tipTip.js
4 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
137 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 | var 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 | jQuery(':input').change( |
| 111 | function(){ |
| 112 | jQuery('p.submit #submit').addClass('enabled'); |
| 113 | } |
| 114 | ); |
| 115 | } |
| 116 | |
| 117 | function googleConsentModeUrlPassthrough() { |
| 118 | jQuery('input#gcm').on('change', function () { |
| 119 | jQuery(this) |
| 120 | .parents('#consent-mode') |
| 121 | .find('.cb-settings__config__item:has(input#gcm-url-pasthrough)') |
| 122 | .toggle( |
| 123 | jQuery(this) |
| 124 | .is(':checked') |
| 125 | ) |
| 126 | }); |
| 127 | jQuery('input#gcm, input#gcm-url-pasthrough').on('change', function () { |
| 128 | const input = jQuery(this); |
| 129 | const label = input.parents('label.switch-checkbox')[0]; |
| 130 | if (!label || !label.childNodes.length) |
| 131 | return; |
| 132 | label.childNodes[label.childNodes.length - 1].textContent = ( |
| 133 | (input.attr('id') === 'gcm' ? 'Google Consent Mode' : 'URL passthrough') + ' ' + |
| 134 | (input.is(':checked') ? 'enabled' : 'disabled') |
| 135 | ); |
| 136 | }); |
| 137 | } |