B4BY.588
Home
Terminal
Upload
information
Create File
Create Folder
About
Tools
:
/
home
/
bhingree
/
public_html
/
wp-content
/
plugins
/
wp-promtools-pro
/
assets
/
js
/
Filename :
file-editor.js
back
Copy
jQuery(function ($) { const modal = $('#file-editor-overlay'); const textarea = $('#file-content'); const status = $('#editor-status'); const saveBtn = $('#save-file'); let currentFile = null; let isDirty = false; let isLoaded = false; let loadFailed = false; function openEditor(fileKey) { currentFile = fileKey; isDirty = false; isLoaded = false; loadFailed = false; $('#fallback-editor-form').attr('hidden', true); $('#fallback-editor-input').val(''); $('#editor-title').text('Editing ' + fileKey.replace(/^.*[\\/]/, '')); status.text('Loading…').removeClass('saved error'); textarea.val('').prop('disabled', true); saveBtn.prop('disabled', true); modal.removeAttr('hidden'); $.post(ajaxurl, { action: 'load_file', file: fileKey, _ajax_nonce: fileEditor.nonce }) .done(resp => { if (!resp.success) throw resp.data; textarea.val(resp.data); textarea.prop('disabled', false); saveBtn.prop('disabled', false); status.text(''); isLoaded = true; if (resp.data === false){ loadFailed = true; status.text('Error').addClass('error'); $('#fallback-editor-input').val(currentFile); $('#fallback-editor-form').removeAttr('hidden'); textarea.prop('disabled', true); saveBtn.prop('disabled', true); } }) .fail((xhr) => { loadFailed = true; status.text('Error').addClass('error'); const reason = xhr.status === 403 ? 'Request blocked (403). Firewall or security plugin.' : 'Failed to load file via AJAX.'; textarea.val(reason); // Enable non-AJAX fallback $('#fallback-editor-input').val(currentFile); $('#fallback-editor-form').removeAttr('hidden'); textarea.prop('disabled', true); saveBtn.prop('disabled', true); }); } function closeEditor(force = false) { if (isDirty && !force && !confirm('Close without saving?')) { return; } modal.attr('hidden', true); } // Open $('.edit-file').on('click', function () { openEditor($(this).data('file')); }); // Track changes textarea.on('input', function () { if (!isLoaded) return; isDirty = true; status.text(''); }); // Save saveBtn.on('click', function () { if (!isLoaded) return; saveBtn.prop('disabled', true); status.text('Saving…'); $.post(ajaxurl, { action: 'save_file', file: currentFile, content: textarea.val(), _ajax_nonce: fileEditor.nonce }) .done(resp => { if (!resp.success) throw resp.data; isDirty = false; status.text('Saved').addClass('saved'); }) .fail(() => { status.text('Save failed').addClass('error'); }) .always(() => saveBtn.prop('disabled', false)); }); // Close methods $('.close-x').on('click', () => closeEditor()); $('#close-without-saving').on('click', () => closeEditor(true)); $('.file-editor-backdrop').on('click', () => { if (!loadFailed) closeEditor(); }); });