Edit: maintenance-mode.js
jQuery(document).ready(function ($) { function showToast(message, type = 'success') { const toast = $('<div class="dnxte-toast"></div>') .text(message) .addClass(type) .appendTo('body'); setTimeout(() => toast.addClass('show'), 50); setTimeout(() => { toast.removeClass('show'); setTimeout(() => toast.remove(), 300); }, 3000); } /** * Handle form submission. * * @param {HTMLFormElement} formElement */ function handleFormSave(formElement) { const $form = $(formElement); const formData = new FormData(formElement); const $submitBtn = $form.find('input[type="submit"]'); const originalText = $submitBtn.val(); $submitBtn.val('Saving...').prop('disabled', true); $.ajax({ url: DE_EXT_OBJ.ajaxurl, type: 'POST', data: formData, processData: false, contentType: false, success: function (response) { if (response.success) { showToast('Settings saved successfully!', 'success'); } else { showToast(response.data || 'Failed to save settings.', 'error'); } }, error: function (xhr, status, error) { console.error('AJAX Error:', status, error); showToast('An AJAX error occurred. Please check the console.', 'error'); }, complete: function () { $submitBtn.val(originalText).prop('disabled', false); } }); } /** * Handle radio button selection to toggle active class. */ $('.dnext-ee-template-rows input[type="radio"][name="dnext_mm_template"]').on('change', function () { $('.dnext-ee-template-rows .dnext-ee-row').removeClass('active'); $(this).closest('.dnext-ee-row').addClass('active'); }); /** * Handle form submission on button click. */ $('.dnext-ee-wrapper form').on('submit', function (e) { e.preventDefault(); handleFormSave(this); }); // Handle radio button selection to save immediately $('.dnext-ee-template-rows input[type="radio"][name="dnext_mm_template"]').on('change', function () { $('.dnext-ee-template-rows .dnext-ee-row').removeClass('active'); $(this).closest('.dnext-ee-row').addClass('active'); const form = $(this).closest('form').get(0); if (form) { handleFormSave(form); } }); // Toggle maintenance mode fields based on selected type const $mmType = $('#dnext_mm_type'); const $pageRow = $('#dnext_mm_page').closest('.dnext-ee-row'); const $templateItem = $('.dnext-ee-item.dnext-ee-template-item'); function toggleMaintenanceModeFields() { const selectedType = $mmType.val(); if (selectedType === 'page') { $pageRow.show(); $templateItem.hide(); } else if (selectedType === 'template') { $pageRow.hide(); $templateItem.show(); } else { // Hide both if no valid option is selected $pageRow.hide(); $templateItem.hide(); } } // Initial toggle on page load toggleMaintenanceModeFields(); // Toggle on change $mmType.on('change', toggleMaintenanceModeFields); // Toggle section function toggleSection($trigger, sectionSelectors, rotateClass = true) { const $parentItem = $trigger.closest('.dnext-ee-item'); $parentItem.find(sectionSelectors).slideToggle(200); if (rotateClass) { $trigger.toggleClass('rotated'); } } function toggleSaveButtonIfOtherCollapsed($trigger, otherSelector, $wrapper) { const isOtherCollapsed = $(otherSelector).hasClass('rotated'); if (isOtherCollapsed) { $wrapper.find('input.dnext-ee-btn.button-primary').slideToggle(100); } } // Handler for main arrow toggle $('.dnxte-arrow-up').on('click', function() { const $this = $(this); const type = $('select[name="dnext_mm_type"]').val(); const $wrapper = $this.closest('.dnext-ee-items'); if (type === 'page') { // Toggle entire group when type is 'page' toggleSection($this, '.dnext-ee-admin-header-sub-title, .dnext-ee-admin-content, input.dnext-ee-btn.button-primary'); } else { toggleSection($this, '.dnext-ee-admin-header-sub-title, .dnext-ee-admin-content'); toggleSaveButtonIfOtherCollapsed($this, '.dnxte-arrow-up-alt', $wrapper); } }); // Handler for alternate arrow toggle $('.dnxte-arrow-up-alt').on('click', function() { const $this = $(this); const type = $('select[name="dnext_mm_type"]').val(); const $parentItem = $this.closest('.dnext-ee-item.alt'); const $wrapper = $this.closest('.dnext-ee-items'); if (type === 'template') { $parentItem.find('.dnext-ee-admin-content, input.dnext-ee-btn.button-primary').slideToggle(200); toggleSaveButtonIfOtherCollapsed($this, '.dnxte-arrow-up', $wrapper); } $this.toggleClass('rotated'); }); });
Save
Back