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
cookiebot-admin-script.js
101 lines
| 1 | /** |
| 2 | * Load init function when the page is ready |
| 3 | * |
| 4 | * @since 4.2.10 |
| 5 | */ |
| 6 | jQuery( document ).ready( cbInit ); |
| 7 | |
| 8 | function cbInit() { |
| 9 | jQuery( document ).on( 'click', 'tr[data-slug="cookiebot"] .cb-deactivate-action', event => deactivateCookiebot( event ) ); |
| 10 | jQuery( document ).on( 'click', '#cb-review__close', event => closeSurveyPopup( event ) ); |
| 11 | jQuery( document ).on( 'submit', '#cb-review__form', event => submitSurveyPopup( event ) ); |
| 12 | jQuery( document ).on( 'change', 'input[name="cookiebot-review-option"]', event => showOptionalConsent( event ) ) |
| 13 | } |
| 14 | |
| 15 | /** |
| 16 | * Displays popup form. |
| 17 | */ |
| 18 | function deactivateCookiebot( e ) { |
| 19 | e.preventDefault(); |
| 20 | |
| 21 | let deactivationLink = e.target.href; |
| 22 | |
| 23 | jQuery( '#cb-review__skip' ).attr( 'href', deactivationLink ); |
| 24 | jQuery( '.cookiebot-popup-container' ).addClass( 'cb-opened' ); |
| 25 | } |
| 26 | |
| 27 | /** |
| 28 | * Close popup form. |
| 29 | */ |
| 30 | |
| 31 | function closeSurveyPopup(e) { |
| 32 | const popup = jQuery(e.target).closest('.cookiebot-popup-container'); |
| 33 | popup.removeClass('cb-opened'); |
| 34 | jQuery('#cb-review__alert').removeClass('show-alert'); |
| 35 | document.getElementById('cb-review__form').reset(); |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * Shows optional consent. |
| 40 | */ |
| 41 | |
| 42 | function showOptionalConsent(e) { |
| 43 | const option = e.target.value; |
| 44 | const optionalConsentBox = jQuery('.consent-item'); |
| 45 | const optionalConsent = jQuery('#cb-review__debug-reason'); |
| 46 | |
| 47 | if(option!=='7'){ |
| 48 | optionalConsentBox.removeClass('show-consent'); |
| 49 | if(optionalConsent.checked){ |
| 50 | optionalConsent.checked = false; |
| 51 | } |
| 52 | }else{ |
| 53 | optionalConsentBox.addClass('show-consent'); |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * Popup submit |
| 59 | */ |
| 60 | function submitSurveyPopup(e){ |
| 61 | e.preventDefault(); |
| 62 | const deactivateLink = jQuery( '#cb-review__skip' ).attr( 'href' ); |
| 63 | const button = jQuery('#cb-review__submit', '#cb-review__form'); |
| 64 | if (button.hasClass('disabled')) { |
| 65 | return; |
| 66 | } |
| 67 | const option = jQuery('input[type="radio"]:checked', '#cb-review__form'); |
| 68 | if(0 === option.length){ |
| 69 | jQuery('#cb-review__alert').addClass('show-alert'); |
| 70 | return; |
| 71 | } |
| 72 | const otherReason = jQuery('#cb-review__other-description'); |
| 73 | const debugReason = jQuery('#cb-review__debug-reason'); |
| 74 | jQuery.ajax({ |
| 75 | url: cb_ajax.ajax_url, |
| 76 | type: 'POST', |
| 77 | data: { |
| 78 | action: 'cb_submit_survey', |
| 79 | reason_id: (0 === option.length) ? null : option.val(), |
| 80 | reason_text: (0 === option.length) ? 'none' : option.closest('label').text(), |
| 81 | reason_info: (0 !== otherReason.length) ? otherReason.val().trim() : '', |
| 82 | reason_debug: (!debugReason) ? null : debugReason.val(), |
| 83 | survey_nonce: cb_ajax.survey_nonce, |
| 84 | survey_check: 'ODUwODA1' |
| 85 | }, |
| 86 | beforeSend: function() { |
| 87 | button.addClass('disabled'); |
| 88 | }, |
| 89 | complete: function(response) { |
| 90 | const code = JSON.parse(response.responseText).code; |
| 91 | const msg = JSON.parse(response.responseText).data; |
| 92 | |
| 93 | if(code===400||code===401){ |
| 94 | jQuery('#cb-review__alert').text(msg).addClass('show-alert'); |
| 95 | button.removeClass('disabled'); |
| 96 | }else{ |
| 97 | window.location.href = deactivateLink; |
| 98 | } |
| 99 | } |
| 100 | }); |
| 101 | } |