(function ($) { $(document).ready(function () { // Listen for changes in the theme selection $("body").on("click", ".theme-actions .button.activate", function (e) { e.preventDefault(); _this = this; let url = $(_this).prop("href"); // Display a modal with a form asking for the reason for the switch var modalHtml = "
'; modalHtml += '
'; modalHtml += '
'; modalHtml += '
'; modalHtml += '
'; modalHtml += '
'; modalHtml += '
'; modalHtml += '
'; modalHtml += '
'; modalHtml += '

'; modalHtml += 'Explain in a few sentences:

'; modalHtml += ''; modalHtml += ''; modalHtml += ''; modalHtml += "
"; modalHtml += "
"; modalHtml += "
"; $("body").append(modalHtml); $("#theme-switch-modal").fadeIn(); // Close the modal if the user clicks outside of it $(document).on("click", function (e) { if ($(e.target).is("#theme-switch-modal")) { $("#theme-switch-modal").fadeOut(function () { $(this).remove(); }); } }); function attireSendFeedback(data) { $.post('https://demo.wpattire.com/wp-json/atbs/v1/feedback', data, function (data, status) { console.log(data); console.log(status); window.location.href = url; $("#theme-switch-modal").fadeOut(function () { $(this).remove(); }); }); } $('#skip_feedback').on('click', function (e) { $("#theme-switch-modal").fadeOut(function () { $(this).remove(); }); var data = { action: "theme_switch_reason", domain: window.location.origin, reason: 'skipped', description: 'skipped', }; attireSendFeedback(data); }); // Submit the form via AJAX $("#theme-switch-form").on("submit", function (e) { e.preventDefault(); var data = { action: "theme_switch_reason", domain: window.location.origin, reason: $('input[name="switch-reason"]:checked').val(), description: $('textarea[name="switch-description"]').val(), }; attireSendFeedback(data); }); }); }); })(jQuery);