/* Maple GDPR Cookies - Admin JavaScript */ (function ($) { "use strict"; $(document).ready(function () { // Initialize color picker if ($.fn.wpColorPicker) { $(".mgc-color-picker").wpColorPicker(); } // Custom color input preview function updateColorPreview(input) { var color = $(input).val(); var hexPattern = /^#[0-9A-F]{6}$/i; if (hexPattern.test(color)) { $(input).css({ "border-left": "5px solid " + color, "border-color": color, }); } else { $(input).css({ "border-left": "", "border-color": "", }); } } // Add event listeners for custom color inputs $("#mgc_custom_button_color, #mgc_custom_button_hover_color").on( "input change", function () { updateColorPreview(this); }, ); // Initialize preview on page load $("#mgc_custom_button_color, #mgc_custom_button_hover_color").each( function () { updateColorPreview(this); }, ); // Preview functionality $("#mgc-preview-button").on("click", function (e) { e.preventDefault(); // Trigger preview update updatePreview(); }); function updatePreview() { // Simple preview update logic console.log("Preview updated"); } // Handle preference display type radio buttons var $preferenceRadios = $('input[name="mgc_preference_display_type"]'); var $gdprWarning = $("#mgc-gdpr-warning"); // Function to toggle GDPR warning visibility function toggleGdprWarning() { var selectedType = $( 'input[name="mgc_preference_display_type"]:checked', ).val(); if (selectedType === "neither") { // Create warning if it doesn't exist if ($gdprWarning.length === 0) { var warningHtml = '
' + '⚠️ GDPR Compliance Reminder:' + '

To remain GDPR compliant, you must add this shortcode to your footer or make it easily accessible on all pages:

' + '[mgc_cookie_preferences]' + '

GDPR requires users to have easy access to withdraw their consent at any time.

' + "
"; $(warningHtml).insertAfter($preferenceRadios.last().parent()); $gdprWarning = $("#mgc-gdpr-warning"); } $gdprWarning.slideDown(200); } else { if ($gdprWarning.length > 0) { $gdprWarning.slideUp(200); } } } // Initialize warning on page load toggleGdprWarning(); // Handle radio button changes $preferenceRadios.on("change", function () { toggleGdprWarning(); }); // Form validation $("form").on("submit", function (e) { // Validate hex colors var customColor = $("#mgc_custom_button_color").val(); var customHoverColor = $("#mgc_custom_button_hover_color").val(); var hexPattern = /^#[0-9A-F]{6}$/i; if (customColor && !hexPattern.test(customColor)) { alert("Custom Button Color must be a valid hex color (e.g., #3498db)"); $("#mgc_custom_button_color").focus(); return false; } if (customHoverColor && !hexPattern.test(customHoverColor)) { alert( "Custom Button Hover Color must be a valid hex color (e.g., #2980b9)", ); $("#mgc_custom_button_hover_color").focus(); return false; } return true; }); }); })(jQuery);