| @@ -2,33 +2,47 @@ | ||
| 2 | 2 | |
| 3 | 3 | jQuery(document).ready(function($){ |
| 4 | 4 | |
| 5 | 5 | var law = ''; |
| 6 | + var mediaUploader; | |
| 6 | 7 | |
| 7 | - function cookieadminSelectFooterLayout(){ | |
| 8 | - $("input[name=cookieadmin_position]").prop("checked", false); | |
| 9 | - $(".consent-position").slideDown(); | |
| 10 | - $(".cookieadmin_foter_layout").fadeIn(800); | |
| 11 | - $(".cookieadmin_box_layout").hide(); | |
| 12 | - $(".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 | + } | |
| 13 | 42 | } |
| 14 | - $("#cookieadmin_layout_footer").on("change", cookieadminSelectFooterLayout); | |
| 15 | - | |
| 16 | - function cookieadminSelectBoxLayout(){ | |
| 17 | - $("input[name=cookieadmin_position]").prop("checked", false); | |
| 18 | - $(".consent-position").slideDown(); | |
| 19 | - $(".cookieadmin_foter_layout").hide(); | |
| 20 | - $(".cookieadmin_box_layout").fadeIn(800); | |
| 21 | - $(".consent-modal-layout").slideDown(); | |
| 22 | - } | |
| 23 | - $("#cookieadmin_layout_box").on("change", cookieadminSelectBoxLayout); | |
| 24 | 43 | |
| 25 | - function cookieadminSelectPopLayout(){ | |
| 26 | - $("input[name=cookieadmin_position]").prop("checked", false); | |
| 27 | - $(".consent-position").slideUp(); | |
| 28 | - $(".consent-modal-layout").slideUp(); | |
| 29 | - } | |
| 30 | - $("#cookieadmin_layout_popup").on("change", cookieadminSelectPopLayout); | |
| 44 | + $('input[name="cookieadmin_layout"]').on('change', toggle_type_options); | |
| 31 | 45 | |
| 32 | 46 | setTimeout( function(){ |
| 33 | 47 | $('.updated, .error').not('.no-autohide').fadeOut('slow'); |
| 34 | 48 | }, 5000); |
| @@ -181,9 +195,9 @@ | ||
| 181 | 195 | |
| 182 | 196 | if(!!law.cookieadmin_position){ |
| 183 | 197 | $("#cookieadmin_position_"+law.cookieadmin_position).prop("checked", true); |
| 184 | 198 | }else{ |
| 185 | - $(".consent-position").hide(); | |
| 199 | + $(".consent-position").closest('label').hide(); | |
| 186 | 200 | } |
| 187 | 201 | $("#cookieadmin_modal_" + law.cookieadmin_modal).prop("checked", true); |
| 188 | 202 | $(".cookieadmin_cookie_modal").addClass("cookieadmin_" + law.cookieadmin_modal); |
| 189 | 203 | |
| @@ -259,17 +273,15 @@ | ||
| 259 | 273 | } |
| 260 | 274 | } |
| 261 | 275 | |
| 262 | 276 | function cookieadminShowPreview(){ |
| 263 | - if($("#cookieadmin_layout_popup").prop("checked")){ | |
| 264 | - show_modal(); | |
| 265 | - }else{ | |
| 266 | - $(".cookieadmin_law_container").toggle(); | |
| 267 | - } | |
| 277 | + $('#cookieadmin_show_preview').toggle(); | |
| 278 | + $('.cookieadmin_law_container').toggle(); | |
| 279 | + $('#cookieadmin_hide_preview').toggle(); | |
| 268 | 280 | } |
| 269 | - $("#cookieadmin_show_preview").on("click", cookieadminShowPreview); | |
| 281 | + $('#cookieadmin_show_preview, #cookieadmin_hide_preview').on('click', cookieadminShowPreview); | |
| 270 | 282 | |
| 271 | - $(".cookieadmin_customize_btn").on("click", function(){ | |
| 283 | + $('.cookieadmin_customize_btn').on('click', function(){ | |
| 272 | 284 | show_modal(); |
| 273 | 285 | }); |
| 274 | 286 | |
| 275 | 287 | $(".cookieadmin_close_pref").on("click", function(){ |
| @@ -285,13 +297,13 @@ | ||
| 285 | 297 | $("[id^=cookieadmin_layout_]").prop("checked", false); |
| 286 | 298 | $("#cookieadmin_layout_"+cookieadmin_policy[law].cookieadmin_layout).prop("checked", true); |
| 287 | 299 | |
| 288 | 300 | if(cookieadmin_policy[law].cookieadmin_layout == "box"){ |
| 289 | - $(".cookieadmin_foter_layout").hide(); | |
| 290 | - $(".cookieadmin_box_layout").show(); | |
| 301 | + $(".cookieadmin_footer_layout").closest('label').hide(); | |
| 302 | + $(".cookieadmin_box_layout").closest('label').show(); | |
| 291 | 303 | }else{ |
| 292 | - $(".cookieadmin_foter_layout").show(); | |
| 293 | - $(".cookieadmin_box_layout").hide(); | |
| 304 | + $(".cookieadmin_footer_layout").closest('label').show(); | |
| 305 | + $(".cookieadmin_box_layout").closest('label').hide(); | |
| 294 | 306 | } |
| 295 | 307 | |
| 296 | 308 | $("[id^=cookieadmin_position_]").prop("checked", false); |
| 297 | 309 | $("#cookieadmin_position_"+cookieadmin_policy[law].cookieadmin_position).prop("checked", true); |
| @@ -369,21 +381,21 @@ | ||
| 369 | 381 | } |
| 370 | 382 | $("#consent_submenu").submit(cookieadminSubmitConsent); |
| 371 | 383 | |
| 372 | 384 | function cookieadminPreloadCookies(){ |
| 373 | - | |
| 374 | - if(!($(".setting-prior").find("[id$=_preload]:checked").length - 1) && $(".cookieadmin-settings").find(".cookieadmin-collapsible-notice").length){ | |
| 375 | - $(".cookieadmin-settings").find(".cookieadmin-collapsible-notice").remove(); | |
| 376 | - 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 | + } | |
| 377 | 395 | } |
| 378 | - | |
| 379 | - if(!$(".cookieadmin-settings").find(".cookieadmin-collapsible-notice").length){ | |
| 380 | - $(".setting-prior").after("<p class=\"cookieadmin-collapsible-notice\">Loading cookies prior to receiving user consent will make your website non-compliant with GDPR.</p>"); | |
| 381 | - $(".cookieadmin-collapsible-notice").show(); | |
| 382 | - } | |
| 383 | - | |
| 384 | 396 | } |
| 385 | - $("[id$=_preload]").on("click", cookieadminPreloadCookies); | |
| 397 | + $('[name="cookieadmin_preload[]"]').on('click', cookieadminPreloadCookies); | |
| 386 | 398 | |
| 387 | 399 | function cookieadminScanCookies(){ |
| 388 | 400 | |
| 389 | 401 | let cookieadmin_btn_val = $(this).prop('value'); |
| @@ -430,8 +442,10 @@ | ||
| 430 | 442 | $(this).prop("disabled", true); |
| 431 | 443 | |
| 432 | 444 | //set 0 to add real id to delete |
| 433 | 445 | cookie_id = $(this).attr("cookieadmin_cookie_id"); |
| 446 | + // Get the patterns | |
| 447 | + const patterns = $("#cookieadmin-dialog-cookie-patterns").val(); | |
| 434 | 448 | |
| 435 | 449 | let cookie_info = { |
| 436 | 450 | name: $("#cookieadmin-dialog-cookie-name").val(), |
| 437 | 451 | id: cookie_id, |
| @@ -438,8 +452,12 @@ | ||
| 438 | 452 | description: $("#cookieadmin-dialog-cookie-desc").val(), |
| 439 | 453 | duration: $("#cookieadmin-dialog-cookie-duration").val(), |
| 440 | 454 | type: $("#cookieadmin-dialog-cookie-category").val() |
| 441 | 455 | }; |
| 456 | + | |
| 457 | + if(patterns){ | |
| 458 | + cookie_info.patterns = patterns; | |
| 459 | + } | |
| 442 | 460 | |
| 443 | 461 | $.each(cookie_info, function (i, val){ |
| 444 | 462 | if(!val){ |
| 445 | 463 | cookie_info = null; |
| @@ -489,8 +507,13 @@ | ||
| 489 | 507 | |
| 490 | 508 | $("input[type=color]").on("input", function(){ |
| 491 | 509 | elemt = $(this).attr("id").replace("_box", ""); |
| 492 | 510 | $("#"+elemt).val($(this).val()); |
| 511 | + | |
| 512 | + // Updating the background color of the reconsent icon list | |
| 513 | + if(elemt === 'cookieadmin_re_consent_bg_color'){ | |
| 514 | + $('.cookieadmin-reconsent-icon').css('background-color', $(this).val()); | |
| 515 | + } | |
| 493 | 516 | }); |
| 494 | 517 | |
| 495 | 518 | |
| 496 | 519 | function cookieadminDeleteCookie(){ |
| @@ -548,8 +571,9 @@ | ||
| 548 | 571 | $("#cookieadmin_dialog_save_btn").attr("cookieadmin_cookie_id", cookie_id); |
| 549 | 572 | $("#cookieadmin-dialog-cookie-name").val(categorized_cookies[cookie_id]['cookie_name']); |
| 550 | 573 | $("#cookieadmin-dialog-cookie-desc").val(categorized_cookies[cookie_id]['description']); |
| 551 | 574 | $("#cookieadmin-dialog-cookie-duration").val(categorized_cookies[cookie_id]['expires']); |
| 575 | + $("#cookieadmin-dialog-cookie-patterns").val(categorized_cookies[cookie_id]['patterns']); | |
| 552 | 576 | if(!!categorized_cookies[cookie_id]['category']){ |
| 553 | 577 | $("#cookieadmin-dialog-cookie-category").val(categorized_cookies[cookie_id]['category']); |
| 554 | 578 | }else{ |
| 555 | 579 | $("#cookieadmin-dialog-cookie-category").val("unknown"); |
| @@ -580,9 +604,44 @@ | ||
| 580 | 604 | $tbody.removeClass('collapsed'); |
| 581 | 605 | } |
| 582 | 606 | } |
| 583 | 607 | $('.cookieadmin-metabox-holder').on('click', '.cookieadmin-cookie-categorized tbody > tr:first-child', cookieadminExpandCollapseCookiesList); |
| 608 | + | |
| 609 | + function cookieadminUploadReconsentIcon(e){ | |
| 610 | + | |
| 611 | + e.preventDefault(); | |
| 612 | + | |
| 613 | + if(mediaUploader){ | |
| 614 | + mediaUploader.open(); | |
| 615 | + return; | |
| 616 | + } | |
| 617 | + | |
| 618 | + mediaUploader = wp.media({ | |
| 619 | + title: 'Select or Upload Icon', | |
| 620 | + button: {text: 'Use this icon'}, | |
| 621 | + multiple: false, | |
| 622 | + library: {type: 'image'} | |
| 623 | + }); | |
| 624 | + | |
| 625 | + mediaUploader.on('select', function() { | |
| 626 | + const attachment = mediaUploader.state().get('selection').first().toJSON(); | |
| 627 | + $('#cookieadmin_reconsent_img_url').val(attachment.url); | |
| 628 | + }); | |
| 629 | + | |
| 630 | + mediaUploader.open(); | |
| 631 | + | |
| 632 | + } | |
| 633 | + $('.cookieadmin-metabox-holder').on('click', '#cookieadmin_upload_icon_btn', cookieadminUploadReconsentIcon); | |
| 584 | 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 | + | |
| 585 | 644 | // Tooltip |
| 586 | 645 | let cookieadminToolTip; |
| 587 | 646 | |
| 588 | 647 | function cookieadminCreateTooltip(){ |
| @@ -635,9 +694,44 @@ | ||
| 635 | 694 | |
| 636 | 695 | cookieadminToolTip.css('opacity', 0); |
| 637 | 696 | }); |
| 638 | 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 | + }); | |
| 639 | 732 | |
| 733 | + | |
| 640 | 734 | }); |
| 641 | 735 | |
| 642 | 736 | function cookieadminAddCookieToTable(cookie_info){ |
| 643 | 737 | |
| @@ -649,8 +743,9 @@ | ||
| 649 | 743 | categorized_cookies[cookie_info.id]['cookie_name'] = cookie_info.name; |
| 650 | 744 | categorized_cookies[cookie_info.id]['description'] = cookie_info.description; |
| 651 | 745 | categorized_cookies[cookie_info.id]['expires'] = cookie_info.duration; |
| 652 | 746 | categorized_cookies[cookie_info.id]['category'] = cookie_info.type; |
| 747 | + categorized_cookies[cookie_info.id]['patterns'] = cookie_info.patterns; | |
| 653 | 748 | |
| 654 | 749 | if(cookie_info.duration > 0){ |
| 655 | 750 | cookie_info.duration += ' ' + cookieadmin_policy.lang.days; |
| 656 | 751 | }else{ |
| @@ -671,5 +766,5 @@ | ||
| 671 | 766 | |
| 672 | 767 | if(!categorized_cookies[cookie_id]){ |
| 673 | 768 | jQuery('.cookieadmin_modal-container').find('input,textarea,select').val(''); |
| 674 | 769 | } |
| 675 | -} | |
| 770 | +} | |