| @@ -4,32 +4,45 @@ | ||
| 4 | 4 | |
| 5 | 5 | var law = ''; |
| 6 | 6 | var mediaUploader; |
| 7 | 7 | |
| 8 | - function cookieadminSelectFooterLayout(){ | |
| 9 | - $("input[name=cookieadmin_position]").prop("checked", false); | |
| 10 | - $(".consent-position").slideDown(); | |
| 11 | - $(".cookieadmin_foter_layout").fadeIn(800); | |
| 12 | - $(".cookieadmin_box_layout").hide(); | |
| 13 | - $(".consent-modal-layout").show(); | |
| 8 | + // Handling the General Setting position toggles | |
| 9 | + function toggle_type_options(){ | |
| 10 | + let jEle = $(this), | |
| 11 | + type_value = $(this).val(); | |
| 12 | + | |
| 13 | + if(!type_value){ | |
| 14 | + return; | |
| 15 | + } | |
| 16 | + | |
| 17 | + let box_layout = $('.cookieadmin_box_layout').closest('label'), | |
| 18 | + footer_layout = $('.cookieadmin_footer_layout').closest('label'); | |
| 19 | + | |
| 20 | + $('input[name=cookieadmin_position]').prop('checked', false); | |
| 21 | + | |
| 22 | + switch(type_value){ | |
| 23 | + case 'footer': | |
| 24 | + $('.consent-position').slideDown(); | |
| 25 | + $('.consent-modal-layout').slideDown(); | |
| 26 | + box_layout.hide(); | |
| 27 | + footer_layout.show(); | |
| 28 | + break; | |
| 29 | + | |
| 30 | + case 'popup': | |
| 31 | + $('.consent-position').slideUp(); | |
| 32 | + $('.consent-modal-layout').slideUp(); | |
| 33 | + break; | |
| 34 | + | |
| 35 | + default: | |
| 36 | + $('.consent-position').slideDown(); | |
| 37 | + $('.consent-modal-layout').slideDown(); | |
| 38 | + footer_layout.hide(); | |
| 39 | + box_layout.show(); | |
| 40 | + break; | |
| 41 | + } | |
| 14 | 42 | } |
| 15 | - $("#cookieadmin_layout_footer").on("change", cookieadminSelectFooterLayout); | |
| 16 | - | |
| 17 | - function cookieadminSelectBoxLayout(){ | |
| 18 | - $("input[name=cookieadmin_position]").prop("checked", false); | |
| 19 | - $(".consent-position").slideDown(); | |
| 20 | - $(".cookieadmin_foter_layout").hide(); | |
| 21 | - $(".cookieadmin_box_layout").fadeIn(800); | |
| 22 | - $(".consent-modal-layout").slideDown(); | |
| 23 | - } | |
| 24 | - $("#cookieadmin_layout_box").on("change", cookieadminSelectBoxLayout); | |
| 25 | 43 | |
| 26 | - function cookieadminSelectPopLayout(){ | |
| 27 | - $("input[name=cookieadmin_position]").prop("checked", false); | |
| 28 | - $(".consent-position").slideUp(); | |
| 29 | - $(".consent-modal-layout").slideUp(); | |
| 30 | - } | |
| 31 | - $("#cookieadmin_layout_popup").on("change", cookieadminSelectPopLayout); | |
| 44 | + $('input[name="cookieadmin_layout"]').on('change', toggle_type_options); | |
| 32 | 45 | |
| 33 | 46 | setTimeout( function(){ |
| 34 | 47 | $('.updated, .error').not('.no-autohide').fadeOut('slow'); |
| 35 | 48 | }, 5000); |
| @@ -182,9 +195,9 @@ | ||
| 182 | 195 | |
| 183 | 196 | if(!!law.cookieadmin_position){ |
| 184 | 197 | $("#cookieadmin_position_"+law.cookieadmin_position).prop("checked", true); |
| 185 | 198 | }else{ |
| 186 | - $(".consent-position").hide(); | |
| 199 | + $(".consent-position").closest('label').hide(); | |
| 187 | 200 | } |
| 188 | 201 | $("#cookieadmin_modal_" + law.cookieadmin_modal).prop("checked", true); |
| 189 | 202 | $(".cookieadmin_cookie_modal").addClass("cookieadmin_" + law.cookieadmin_modal); |
| 190 | 203 | |
| @@ -260,17 +273,15 @@ | ||
| 260 | 273 | } |
| 261 | 274 | } |
| 262 | 275 | |
| 263 | 276 | function cookieadminShowPreview(){ |
| 264 | - if($("#cookieadmin_layout_popup").prop("checked")){ | |
| 265 | - show_modal(); | |
| 266 | - }else{ | |
| 267 | - $(".cookieadmin_law_container").toggle(); | |
| 268 | - } | |
| 277 | + $('#cookieadmin_show_preview').toggle(); | |
| 278 | + $('.cookieadmin_law_container').toggle(); | |
| 279 | + $('#cookieadmin_hide_preview').toggle(); | |
| 269 | 280 | } |
| 270 | - $("#cookieadmin_show_preview").on("click", cookieadminShowPreview); | |
| 281 | + $('#cookieadmin_show_preview, #cookieadmin_hide_preview').on('click', cookieadminShowPreview); | |
| 271 | 282 | |
| 272 | - $(".cookieadmin_customize_btn").on("click", function(){ | |
| 283 | + $('.cookieadmin_customize_btn').on('click', function(){ | |
| 273 | 284 | show_modal(); |
| 274 | 285 | }); |
| 275 | 286 | |
| 276 | 287 | $(".cookieadmin_close_pref").on("click", function(){ |
| @@ -286,13 +297,13 @@ | ||
| 286 | 297 | $("[id^=cookieadmin_layout_]").prop("checked", false); |
| 287 | 298 | $("#cookieadmin_layout_"+cookieadmin_policy[law].cookieadmin_layout).prop("checked", true); |
| 288 | 299 | |
| 289 | 300 | if(cookieadmin_policy[law].cookieadmin_layout == "box"){ |
| 290 | - $(".cookieadmin_foter_layout").hide(); | |
| 291 | - $(".cookieadmin_box_layout").show(); | |
| 301 | + $(".cookieadmin_footer_layout").closest('label').hide(); | |
| 302 | + $(".cookieadmin_box_layout").closest('label').show(); | |
| 292 | 303 | }else{ |
| 293 | - $(".cookieadmin_foter_layout").show(); | |
| 294 | - $(".cookieadmin_box_layout").hide(); | |
| 304 | + $(".cookieadmin_footer_layout").closest('label').show(); | |
| 305 | + $(".cookieadmin_box_layout").closest('label').hide(); | |
| 295 | 306 | } |
| 296 | 307 | |
| 297 | 308 | $("[id^=cookieadmin_position_]").prop("checked", false); |
| 298 | 309 | $("#cookieadmin_position_"+cookieadmin_policy[law].cookieadmin_position).prop("checked", true); |
| @@ -370,21 +381,21 @@ | ||
| 370 | 381 | } |
| 371 | 382 | $("#consent_submenu").submit(cookieadminSubmitConsent); |
| 372 | 383 | |
| 373 | 384 | function cookieadminPreloadCookies(){ |
| 374 | - | |
| 375 | - if(!($(".setting-prior").find("[id$=_preload]:checked").length - 1) && $(".cookieadmin-settings").find(".cookieadmin-collapsible-notice").length){ | |
| 376 | - $(".cookieadmin-settings").find(".cookieadmin-collapsible-notice").remove(); | |
| 377 | - return; | |
| 385 | + let notice = $('.cookieadmin-collapsible-notice'); | |
| 386 | + | |
| 387 | + if($('[name="cookieadmin_preload[]"]:checked').length > 1){ | |
| 388 | + if(notice.css('display') == 'none'){ | |
| 389 | + notice.show(); | |
| 390 | + } | |
| 391 | + } else { | |
| 392 | + if(notice.css('display') !== 'none'){ | |
| 393 | + notice.hide(); | |
| 394 | + } | |
| 378 | 395 | } |
| 379 | - | |
| 380 | - if(!$(".cookieadmin-settings").find(".cookieadmin-collapsible-notice").length){ | |
| 381 | - $(".setting-prior").after("<p class=\"cookieadmin-collapsible-notice\">Loading cookies prior to receiving user consent will make your website non-compliant with GDPR.</p>"); | |
| 382 | - $(".cookieadmin-collapsible-notice").show(); | |
| 383 | - } | |
| 384 | - | |
| 385 | 396 | } |
| 386 | - $("[id$=_preload]").on("click", cookieadminPreloadCookies); | |
| 397 | + $('[name="cookieadmin_preload[]"]').on('click', cookieadminPreloadCookies); | |
| 387 | 398 | |
| 388 | 399 | function cookieadminScanCookies(){ |
| 389 | 400 | |
| 390 | 401 | let cookieadmin_btn_val = $(this).prop('value'); |
| @@ -431,8 +442,10 @@ | ||
| 431 | 442 | $(this).prop("disabled", true); |
| 432 | 443 | |
| 433 | 444 | //set 0 to add real id to delete |
| 434 | 445 | cookie_id = $(this).attr("cookieadmin_cookie_id"); |
| 446 | + // Get the patterns | |
| 447 | + const patterns = $("#cookieadmin-dialog-cookie-patterns").val(); | |
| 435 | 448 | |
| 436 | 449 | let cookie_info = { |
| 437 | 450 | name: $("#cookieadmin-dialog-cookie-name").val(), |
| 438 | 451 | id: cookie_id, |
| @@ -439,8 +452,12 @@ | ||
| 439 | 452 | description: $("#cookieadmin-dialog-cookie-desc").val(), |
| 440 | 453 | duration: $("#cookieadmin-dialog-cookie-duration").val(), |
| 441 | 454 | type: $("#cookieadmin-dialog-cookie-category").val() |
| 442 | 455 | }; |
| 456 | + | |
| 457 | + if(patterns){ | |
| 458 | + cookie_info.patterns = patterns; | |
| 459 | + } | |
| 443 | 460 | |
| 444 | 461 | $.each(cookie_info, function (i, val){ |
| 445 | 462 | if(!val){ |
| 446 | 463 | cookie_info = null; |
| @@ -554,8 +571,9 @@ | ||
| 554 | 571 | $("#cookieadmin_dialog_save_btn").attr("cookieadmin_cookie_id", cookie_id); |
| 555 | 572 | $("#cookieadmin-dialog-cookie-name").val(categorized_cookies[cookie_id]['cookie_name']); |
| 556 | 573 | $("#cookieadmin-dialog-cookie-desc").val(categorized_cookies[cookie_id]['description']); |
| 557 | 574 | $("#cookieadmin-dialog-cookie-duration").val(categorized_cookies[cookie_id]['expires']); |
| 575 | + $("#cookieadmin-dialog-cookie-patterns").val(categorized_cookies[cookie_id]['patterns']); | |
| 558 | 576 | if(!!categorized_cookies[cookie_id]['category']){ |
| 559 | 577 | $("#cookieadmin-dialog-cookie-category").val(categorized_cookies[cookie_id]['category']); |
| 560 | 578 | }else{ |
| 561 | 579 | $("#cookieadmin-dialog-cookie-category").val("unknown"); |
| @@ -613,8 +631,17 @@ | ||
| 613 | 631 | |
| 614 | 632 | } |
| 615 | 633 | $('.cookieadmin-metabox-holder').on('click', '#cookieadmin_upload_icon_btn', cookieadminUploadReconsentIcon); |
| 616 | 634 | |
| 635 | + // Content Blocking Toggle | |
| 636 | + $("#cookieadmin_content_blocking").on("change", function(){ | |
| 637 | + if($(this).prop("checked")){ | |
| 638 | + $(".cookieadmin-content-blocking-options").fadeIn(250); | |
| 639 | + }else{ | |
| 640 | + $(".cookieadmin-content-blocking-options").fadeOut(250); | |
| 641 | + } | |
| 642 | + }); | |
| 643 | + | |
| 617 | 644 | // Tooltip |
| 618 | 645 | let cookieadminToolTip; |
| 619 | 646 | |
| 620 | 647 | function cookieadminCreateTooltip(){ |
| @@ -667,9 +694,44 @@ | ||
| 667 | 694 | |
| 668 | 695 | cookieadminToolTip.css('opacity', 0); |
| 669 | 696 | }); |
| 670 | 697 | |
| 698 | + // Recommended plugins install/activate handler | |
| 699 | + $(document).on('click', '.cookieadmin-plugin-install-btn, .cookieadmin-plugin-activate-btn', function(e){ | |
| 700 | + e.preventDefault(); | |
| 701 | + var $btn = $(this); | |
| 702 | + var slug = $btn.data('slug'); | |
| 703 | + var is_install = $btn.hasClass('cookieadmin-plugin-install-btn'); | |
| 704 | + var originalText = $btn.text(); | |
| 705 | + | |
| 706 | + $btn.text(cookieadmin_policy.lang.processing).prop('disabled', true); | |
| 707 | + | |
| 708 | + $.ajax({ | |
| 709 | + url: ajaxurl, | |
| 710 | + method: 'POST', | |
| 711 | + data: { | |
| 712 | + action: 'cookieadmin_ajax_handler', | |
| 713 | + cookieadmin_act: is_install ? 'install_recommended_plugin' : 'activate_recommended_plugin', | |
| 714 | + cookieadmin_security: cookieadmin_policy.cookieadmin_nonce, | |
| 715 | + plugin: slug, | |
| 716 | + }, | |
| 717 | + dataType: 'json', | |
| 718 | + success: function(data){ | |
| 719 | + if(data.success){ | |
| 720 | + $btn.replaceWith('<span class="cookieadmin-badge cookieadmin-success">' + cookieadmin_policy.lang.active + '</span>'); | |
| 721 | + }else{ | |
| 722 | + $btn.text(originalText).prop('disabled', false); | |
| 723 | + alert(data.data && data.data.message ? data.data.message : cookieadmin_policy.lang.install_failed); | |
| 724 | + } | |
| 725 | + }, | |
| 726 | + error: function(){ | |
| 727 | + $btn.text(originalText).prop('disabled', false); | |
| 728 | + alert(cookieadmin_policy.lang.error_occurred); | |
| 729 | + }, | |
| 730 | + }); | |
| 731 | + }); | |
| 671 | 732 | |
| 733 | + | |
| 672 | 734 | }); |
| 673 | 735 | |
| 674 | 736 | function cookieadminAddCookieToTable(cookie_info){ |
| 675 | 737 | |
| @@ -681,8 +743,9 @@ | ||
| 681 | 743 | categorized_cookies[cookie_info.id]['cookie_name'] = cookie_info.name; |
| 682 | 744 | categorized_cookies[cookie_info.id]['description'] = cookie_info.description; |
| 683 | 745 | categorized_cookies[cookie_info.id]['expires'] = cookie_info.duration; |
| 684 | 746 | categorized_cookies[cookie_info.id]['category'] = cookie_info.type; |
| 747 | + categorized_cookies[cookie_info.id]['patterns'] = cookie_info.patterns; | |
| 685 | 748 | |
| 686 | 749 | if(cookie_info.duration > 0){ |
| 687 | 750 | cookie_info.duration += ' ' + cookieadmin_policy.lang.days; |
| 688 | 751 | }else{ |