Files
wordpress-theme-aksrt/assets/js/admin-messages.js
T
kate522andClaude Fable 5 6195508481 feat(admin): move message compose into a header-button dialog
Replace the inline <details> compose card on users.php?page=aksrt_messages
with a primary header button that opens a native <dialog>. NativeUi::header()
gains dialog-type actions via NativeUi::button_dialog(). The dialog reopens
automatically after a failed send.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-10-30 16:42:56 +08:00

41 lines
1.6 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* 消息管理后台页(users.php?page=aksrt_messages)的「发送系统消息」弹窗。
* - 页头按钮 [data-aksrt-dialog-open] 打开对应 <dialog>;
* - 关闭按钮 / 点击遮罩关闭;发送失败回跳时(data-aksrt-dialog-autoopen)自动打开;
* - 提交后禁用发送按钮防重复提交。
* 标记由 src/Admin/Native/UsersMenusMessages.php 与 NativeUi::button_dialog() 输出。
*/
(function () {
'use strict';
document.querySelectorAll('[data-aksrt-dialog-open]').forEach(function (button) {
var dialog = document.getElementById(button.getAttribute('data-aksrt-dialog-open'));
if (!dialog || typeof dialog.showModal !== 'function') {
button.hidden = true;
return;
}
var form = dialog.querySelector('form');
var submit = dialog.querySelector('[data-aksrt-dialog-submit]');
function open() {
if (submit) submit.disabled = false;
dialog.showModal();
var first = dialog.querySelector('textarea:not([disabled]), input:not([type="hidden"]):not([type="radio"])');
if (first) first.focus();
}
button.addEventListener('click', open);
dialog.querySelectorAll('[data-aksrt-dialog-close]').forEach(function (close) {
close.addEventListener('click', function () { dialog.close(); });
});
// 点击遮罩(dialog 自身而非内容区)关闭。
dialog.addEventListener('click', function (event) {
if (event.target === dialog) dialog.close();
});
if (form && submit) {
form.addEventListener('submit', function () { submit.disabled = true; });
}
if (dialog.hasAttribute('data-aksrt-dialog-autoopen')) open();
});
})();