gutenberg
3 years ago
account-static.js
10 months ago
account.js
10 months ago
amplitude.js
1 year ago
consent-mapping.js
1 year ago
cookiebot-admin-script.js
1 year ago
dashboard.js
1 year ago
jquery.tipTip.js
3 years ago
multiple-page.js
3 years ago
network-settings-page.js
10 months ago
prior-consent-settings.js
3 years ago
settings-page.js
10 months ago
support-page.js
1 year ago
cookiebot-admin-script.js
357 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 | hideSubmitMessage(); |
| 13 | selectorListeners(); |
| 14 | } |
| 15 | |
| 16 | /** |
| 17 | * Displays popup form. |
| 18 | */ |
| 19 | function deactivateCookiebot( e ) { |
| 20 | e.preventDefault(); |
| 21 | |
| 22 | let deactivationLink = e.target.href; |
| 23 | |
| 24 | populatePopup(); |
| 25 | jQuery( '#cb-review__skip' ).attr( 'href', deactivationLink ); |
| 26 | jQuery( '#cookiebot-review-popup-container' ).addClass( 'cb-opened cb-filled' ); |
| 27 | } |
| 28 | |
| 29 | function populatePopup(){ |
| 30 | if(jQuery( '#cookiebot-review-popup-container' ).hasClass( 'cb-filled' )){ |
| 31 | return; |
| 32 | } |
| 33 | |
| 34 | let popupFormContainer = document.createElement('div'); |
| 35 | const header = renderPopupHeader(); |
| 36 | const form = renderPopupForm(); |
| 37 | popupFormContainer.setAttribute('id','cookiebot-popup'); |
| 38 | popupFormContainer.appendChild(header); |
| 39 | popupFormContainer.appendChild(form); |
| 40 | |
| 41 | jQuery('#cookiebot-review-popup-container').append(popupFormContainer); |
| 42 | } |
| 43 | |
| 44 | function renderPopupHeader() { |
| 45 | let popupHeader = document.createElement('div'); |
| 46 | let headerLogoContainer = document.createElement('div'); |
| 47 | let headerLogo = document.createElement('img'); |
| 48 | let headerTitle = document.createElement('h2'); |
| 49 | let headerClose = document.createElement('div'); |
| 50 | popupHeader.classList.add('cb-review__header'); |
| 51 | headerLogoContainer.classList.add('cb-review__logo'); |
| 52 | headerLogo.setAttribute('src', cb_survey.logo); |
| 53 | headerLogo.setAttribute('alt', 'Usercentrics Cookiebot'); |
| 54 | headerTitle.setAttribute('id', 'cb-review__title'); |
| 55 | headerTitle.innerHTML = cb_survey.popup_header_title; |
| 56 | headerClose.setAttribute('id', 'cb-review__close'); |
| 57 | headerClose.classList.add('dashicons','dashicons-dismiss'); |
| 58 | popupHeader.appendChild(headerLogoContainer).appendChild(headerLogo); |
| 59 | popupHeader.appendChild(headerTitle); |
| 60 | popupHeader.appendChild(headerClose); |
| 61 | return popupHeader; |
| 62 | } |
| 63 | |
| 64 | function renderPopupForm(){ |
| 65 | let popupForm = document.createElement('form'); |
| 66 | popupForm.setAttribute('id', 'cb-review__form'); |
| 67 | popupForm.setAttribute('method', 'POST'); |
| 68 | let firstMsg = document.createElement('p'); |
| 69 | firstMsg.innerText = cb_survey.first_msg; |
| 70 | const labelContainer = renderFormLabels(); |
| 71 | const consentLabel = renderConsentLabel(); |
| 72 | const consentActions = renderPopupActions(); |
| 73 | popupForm.appendChild(firstMsg); |
| 74 | popupForm.appendChild(labelContainer); |
| 75 | popupForm.appendChild(consentLabel); |
| 76 | popupForm.appendChild(consentActions); |
| 77 | return popupForm |
| 78 | } |
| 79 | |
| 80 | function renderFormLabels(){ |
| 81 | let labelsContainer = document.createElement('div'); |
| 82 | let options = cb_survey.options; |
| 83 | options.forEach((option)=>{ |
| 84 | let labelContainer = document.createElement('div'); |
| 85 | let labelChild = document.createElement('label'); |
| 86 | let labelInput = document.createElement('input'); |
| 87 | labelChild.classList.add('cb-review__form--item'); |
| 88 | labelInput.setAttribute('type', 'radio'); |
| 89 | labelInput.setAttribute('name', 'cookiebot-review-option'); |
| 90 | labelInput.setAttribute('value', option.value); |
| 91 | let labelText = document.createElement('span'); |
| 92 | labelText.innerText = option.text; |
| 93 | labelChild.appendChild(labelInput); |
| 94 | labelChild.appendChild(labelText); |
| 95 | labelContainer.appendChild(labelChild); |
| 96 | |
| 97 | if(option.value === '8'){ |
| 98 | let extraContainer = document.createElement('div'); |
| 99 | let labelChild = document.createElement('label'); |
| 100 | let labelText = document.createElement('span'); |
| 101 | labelText.innerText = 'Tell us more (optional)...'; |
| 102 | labelChild.appendChild(labelText); |
| 103 | extraContainer.appendChild(labelChild); |
| 104 | |
| 105 | let extraText = document.createElement('textarea'); |
| 106 | extraContainer.classList.add('cb-review__form--item__custom'); |
| 107 | extraText.setAttribute('id','cb-review__other-description'); |
| 108 | extraText.setAttribute('name','other-description'); |
| 109 | extraText.setAttribute('placeholder',option.extra); |
| 110 | extraText.setAttribute('row','1'); |
| 111 | labelContainer.appendChild(extraContainer).appendChild(extraText); |
| 112 | } |
| 113 | labelsContainer.appendChild(labelContainer); |
| 114 | }) |
| 115 | return labelsContainer; |
| 116 | } |
| 117 | |
| 118 | function renderConsentLabel(){ |
| 119 | let labelContainer = document.createElement('div'); |
| 120 | labelContainer.classList.add('consent-item'); |
| 121 | labelContainer.classList.add('show-consent'); |
| 122 | let consentLabel = document.createElement('label'); |
| 123 | consentLabel.classList.add('cb-review__form--item'); |
| 124 | let consentInput = document.createElement('input'); |
| 125 | consentInput.setAttribute('id','cb-review__debug-reason'); |
| 126 | consentInput.setAttribute('type','checkbox'); |
| 127 | consentInput.setAttribute('name','cookiebot-review-debug'); |
| 128 | consentInput.setAttribute('value','true'); |
| 129 | consentInput.setAttribute('data-custom-field','true'); |
| 130 | let consentDescription = document.createElement('span'); |
| 131 | let consentOpt = document.createElement('b'); |
| 132 | consentOpt.innerText = cb_survey.consent.optional; |
| 133 | let consentLink = document.createElement('a'); |
| 134 | consentLink.setAttribute('href', 'mailto:unsubscribe@usercentrics.com'); |
| 135 | consentLink.innerText = 'unsubscribe@usercentrics.com'; |
| 136 | consentDescription.appendChild(consentOpt); |
| 137 | let firstText = document.createElement('span'); |
| 138 | firstText.innerText = cb_survey.consent.first; |
| 139 | consentDescription.appendChild(firstText); |
| 140 | consentDescription.appendChild(document.createElement('br')); |
| 141 | let secondText = document.createElement('span'); |
| 142 | secondText.innerText = cb_survey.consent.second; |
| 143 | consentDescription.appendChild(secondText); |
| 144 | consentDescription.appendChild(consentLink); |
| 145 | consentLabel.appendChild(consentInput); |
| 146 | consentLabel.appendChild(consentDescription); |
| 147 | labelContainer.appendChild(consentLabel); |
| 148 | return labelContainer; |
| 149 | } |
| 150 | |
| 151 | function renderPopupActions(){ |
| 152 | let reviewContainer = document.createElement('div'); |
| 153 | let reviewAlert = document.createElement('div'); |
| 154 | reviewAlert.setAttribute('id','cb-review__alert'); |
| 155 | reviewAlert.innerText = cb_survey.alert; |
| 156 | let reviewActionContainer = document.createElement('div'); |
| 157 | reviewActionContainer.classList.add('cb-review__actions'); |
| 158 | let skipCta = document.createElement('a'); |
| 159 | skipCta.setAttribute('id','cb-review__skip'); |
| 160 | skipCta.setAttribute('href','#'); |
| 161 | skipCta.innerText = cb_survey.actions.skip; |
| 162 | let submitCta = document.createElement('input'); |
| 163 | submitCta.setAttribute('type', 'submit'); |
| 164 | submitCta.setAttribute('id', 'cb-review__submit'); |
| 165 | submitCta.setAttribute('value', cb_survey.actions.submit); |
| 166 | let reviewPolicy = document.createElement('p'); |
| 167 | reviewPolicy.classList.add('cb-review__policy'); |
| 168 | reviewPolicy.innerText = 'See our '; |
| 169 | let policyLink = document.createElement('a'); |
| 170 | policyLink.setAttribute('href', 'https://www.cookiebot.com/en/privacy-policy/?utm_source=wordpress&utm_medium=referral&utm_campaign=banner'); |
| 171 | policyLink.setAttribute('target', '_blank'); |
| 172 | policyLink.setAttribute('rel', 'noopener'); |
| 173 | policyLink.innerText = 'Privacy Policy'; |
| 174 | reviewPolicy.appendChild(policyLink); |
| 175 | let reviewInput = document.createElement('input'); |
| 176 | reviewInput.setAttribute('type','hidden'); |
| 177 | reviewInput.setAttribute('name','cookiebot-review-send'); |
| 178 | reviewInput.setAttribute('value','Cookiebot_Review_Send'); |
| 179 | reviewActionContainer.appendChild(skipCta); |
| 180 | reviewActionContainer.appendChild(submitCta); |
| 181 | |
| 182 | reviewContainer.appendChild(reviewAlert); |
| 183 | reviewContainer.appendChild(reviewActionContainer); |
| 184 | reviewContainer.appendChild(reviewPolicy); |
| 185 | reviewContainer.appendChild(reviewInput); |
| 186 | return reviewContainer; |
| 187 | } |
| 188 | |
| 189 | /** |
| 190 | * Close popup form. |
| 191 | */ |
| 192 | |
| 193 | function closeSurveyPopup(e) { |
| 194 | const popup = jQuery(e.target).closest('.cookiebot-popup-container'); |
| 195 | popup.removeClass('cb-opened'); |
| 196 | jQuery('#cb-review__alert').removeClass('show-alert'); |
| 197 | document.getElementById('cb-review__form').reset(); |
| 198 | } |
| 199 | |
| 200 | /** |
| 201 | * Popup submit |
| 202 | */ |
| 203 | function submitSurveyPopup(e){ |
| 204 | e.preventDefault(); |
| 205 | const deactivateLink = jQuery( '#cb-review__skip' ).attr( 'href' ); |
| 206 | const button = jQuery('#cb-review__submit', '#cb-review__form'); |
| 207 | if (button.hasClass('disabled')) { |
| 208 | return; |
| 209 | } |
| 210 | |
| 211 | const option = jQuery('input[type="radio"]:checked', '#cb-review__form'); |
| 212 | if(0 === option.length){ |
| 213 | jQuery('#cb-review__alert').addClass('show-alert'); |
| 214 | return; |
| 215 | } |
| 216 | |
| 217 | // Add loading state |
| 218 | const loadingOverlay = document.createElement('div'); |
| 219 | loadingOverlay.className = 'loading-overlay'; |
| 220 | loadingOverlay.innerHTML = ` |
| 221 | <div class="loading-content"> |
| 222 | <div class="loading-spinner"></div> |
| 223 | <h2>Thank you for being part of our journey.</h2> |
| 224 | <p>We\'re deactivating the plugin and saving your feedback.</p> |
| 225 | </div> |
| 226 | `; |
| 227 | document.body.classList.add('has-loading-overlay'); |
| 228 | document.body.appendChild(loadingOverlay); |
| 229 | |
| 230 | const otherReason = jQuery('#cb-review__other-description'); |
| 231 | const debugReason = jQuery('#cb-review__debug-reason'); |
| 232 | |
| 233 | |
| 234 | // Load Amplitude SDK and track deactivation |
| 235 | const script = document.createElement('script'); |
| 236 | script.src = 'https://cdn.eu.amplitude.com/script/3573fa11b8c5b4bcf577ec4c8e9d5cb6.js'; |
| 237 | script.async = true; |
| 238 | script.onload = function() { |
| 239 | const amplitude = window.amplitude; |
| 240 | amplitude.init('3573fa11b8c5b4bcf577ec4c8e9d5cb6', { |
| 241 | serverZone: 'EU', |
| 242 | fetchRemoteConfig: true, |
| 243 | defaultTracking: false |
| 244 | }); |
| 245 | |
| 246 | // Track deactivation event |
| 247 | amplitude.track('Plugin Deactivated', { |
| 248 | reason: option.closest('label').text().trim(), |
| 249 | additional_info: otherReason.val() ? otherReason.val().trim() : '', |
| 250 | }); |
| 251 | }; |
| 252 | document.head.appendChild(script); |
| 253 | |
| 254 | jQuery.ajax({ |
| 255 | url: cb_ajax.ajax_url, |
| 256 | type: 'POST', |
| 257 | data: { |
| 258 | action: 'cb_submit_survey', |
| 259 | reason_id: (0 === option.length) ? null : option.val(), |
| 260 | reason_text: (0 === option.length) ? 'none' : option.closest('label').text(), |
| 261 | reason_info: (0 !== otherReason.length) ? otherReason.val().trim() : '', |
| 262 | reason_debug: (debugReason?.length > 0) ? debugReason[0].checked : 'false', |
| 263 | survey_nonce: cb_survey.survey_nonce, |
| 264 | survey_check: 'ODUwODA1' |
| 265 | }, |
| 266 | beforeSend: function() { |
| 267 | button.addClass('disabled'); |
| 268 | button.attr('value','Please wait...'); |
| 269 | }, |
| 270 | complete: function(response) { |
| 271 | const code = JSON.parse(response.responseText).code; |
| 272 | const msg = JSON.parse(response.responseText).data; |
| 273 | |
| 274 | if(code===400||code===401){ |
| 275 | jQuery('#cb-review__alert').text(msg).addClass('show-alert'); |
| 276 | button.removeClass('disabled'); |
| 277 | return; |
| 278 | } |
| 279 | window.location.href = deactivateLink; |
| 280 | } |
| 281 | }); |
| 282 | } |
| 283 | |
| 284 | function hideSubmitMessage(){ |
| 285 | let submitMsg = jQuery('.cb-submit__msg'); |
| 286 | if(submitMsg){ |
| 287 | setTimeout(function(){ |
| 288 | submitMsg.fadeOut(); |
| 289 | },2000) |
| 290 | } |
| 291 | } |
| 292 | |
| 293 | function selectorListeners(){ |
| 294 | openItemList(); |
| 295 | closeitemList(); |
| 296 | selectListItem(); |
| 297 | searchListItem(); |
| 298 | } |
| 299 | |
| 300 | function openItemList() { |
| 301 | jQuery(document).on('click','.cb-settings__selector__container .cb-settings__selector-selector',function(){ |
| 302 | jQuery('.cb-settings__selector-list-container').addClass('hidden'); |
| 303 | jQuery(this).siblings('.cb-settings__selector-list-container').removeClass('hidden'); |
| 304 | }); |
| 305 | } |
| 306 | |
| 307 | function closeitemList() { |
| 308 | jQuery(document).on('click','.cb-settings__selector__container .cb-settings__selector-veil',function(){ |
| 309 | jQuery(this).parent('.cb-settings__selector-list-container').addClass('hidden'); |
| 310 | jQuery(this).siblings('.cb-settings__selector-search').val('').trigger('keyup'); |
| 311 | jQuery(this).siblings('.cb-settings__selector-list').scrollTop(0); |
| 312 | }); |
| 313 | } |
| 314 | |
| 315 | function selectListItem() { |
| 316 | jQuery(document).on('click','.cb-settings__selector__container .cb-settings__selector-list-item',function(){ |
| 317 | const item = jQuery(this); |
| 318 | const mainParent = item.closest('.cb-settings__selector__container'); |
| 319 | const itemList = item.parent('.cb-settings__selector-list'); |
| 320 | const itemValue = item.data('value'); |
| 321 | const itemAttr = 'cookiebot-tcf-disallowed['+itemValue+']'; |
| 322 | const itemName = item.text(); |
| 323 | |
| 324 | if(!itemList.data('multiple')){ |
| 325 | itemList.find('.selected').removeClass('selected'); |
| 326 | } |
| 327 | |
| 328 | item.addClass('selected'); |
| 329 | mainParent.find('.cb-settings__selector-selector').text(itemName); |
| 330 | mainParent.find('.cb-settings__selector__container-input').val(itemValue).attr('name',itemAttr).trigger('change'); |
| 331 | mainParent.find('.cb-settings__selector-search').val('').trigger('keyup'); |
| 332 | itemList.scrollTop(0); |
| 333 | |
| 334 | item.closest('.cb-settings__selector-list-container').addClass('hidden'); |
| 335 | }); |
| 336 | } |
| 337 | |
| 338 | function searchListItem() { |
| 339 | jQuery(document).on('keyup','.cb-settings__selector-search',function(){ |
| 340 | const searchName = jQuery(this).val().toLowerCase(); |
| 341 | const itemList = jQuery(this).siblings('.search-list'); |
| 342 | |
| 343 | itemList.children().each(function(){ |
| 344 | const item = jQuery(this); |
| 345 | if(searchName.length>0) { |
| 346 | const itemName = item.text().trim().toLowerCase(); |
| 347 | if(itemName.indexOf(searchName) != -1){ |
| 348 | item.removeClass('hidden'); |
| 349 | }else{ |
| 350 | item.addClass('hidden'); |
| 351 | } |
| 352 | }else{ |
| 353 | item.removeClass('hidden'); |
| 354 | } |
| 355 | }); |
| 356 | }); |
| 357 | } |