forked from laysense/laysite
Fix canvas formatting persistence and editor interactions
This commit is contained in:
+31
-2
@@ -1,6 +1,32 @@
|
||||
'use strict';
|
||||
|
||||
jQuery(function ($) {
|
||||
const $actionDialog = $('#admin-action-dialog');
|
||||
const $actionField = $actionDialog.find('[data-action-field]');
|
||||
const $actionValue = $actionField.find('[data-action-value]');
|
||||
|
||||
window.laySiteAction = function ({title, message = '', label, value = '', readOnly = false, accept = '确定'}) {
|
||||
const dialog = $actionDialog.get(0);
|
||||
if (!dialog || dialog.open) return Promise.resolve(null);
|
||||
const hasInput = Boolean(label);
|
||||
$actionDialog.find('[data-action-title]').text(title);
|
||||
$actionDialog.find('[data-action-message]').text(message).prop('hidden', !message);
|
||||
$actionDialog.find('[data-action-label]').text(label || '');
|
||||
$actionField.prop('hidden', !hasInput);
|
||||
$actionValue.val(value).prop({disabled: !hasInput, readOnly});
|
||||
$actionDialog.find('[data-action-accept]').text(accept);
|
||||
return new Promise((resolve) => {
|
||||
dialog.returnValue = '';
|
||||
$actionDialog.one('close', () => {
|
||||
resolve(dialog.returnValue === 'accept' ? (hasInput ? $actionValue.val() : true) : null);
|
||||
});
|
||||
dialog.showModal();
|
||||
if (hasInput) $actionValue.trigger('focus').trigger('select');
|
||||
else $actionDialog.find('[data-action-cancel]').trigger('focus');
|
||||
});
|
||||
};
|
||||
$actionDialog.on('click', '[data-action-cancel]', () => $actionDialog.get(0).close());
|
||||
|
||||
$('[data-page-layout-editor]').each(function () {
|
||||
const {pageLayoutEditor: kind, defaultId} = this.dataset;
|
||||
const $link = $(this);
|
||||
@@ -114,12 +140,15 @@ jQuery(function ($) {
|
||||
if (event.target.form?.method.toLowerCase() === 'post') clearSavedStatus();
|
||||
}, true);
|
||||
|
||||
$('form[method="post"]').on('submit', function (event) {
|
||||
$('form[method="post"]').on('submit', async function (event) {
|
||||
event.preventDefault();
|
||||
const $form = $(this);
|
||||
if ($form.attr('aria-busy') === 'true') return;
|
||||
const submitter = event.originalEvent?.submitter;
|
||||
if (submitter?.dataset.confirm && !window.confirm(submitter.dataset.confirm)) return;
|
||||
if (submitter?.dataset.confirm && !await window.laySiteAction({
|
||||
title: '确认操作', message: submitter.dataset.confirm,
|
||||
accept: submitter.getAttribute('aria-label') || submitter.textContent.trim() || '确定',
|
||||
})) return;
|
||||
clearSavedStatus();
|
||||
const action = $form.attr('action');
|
||||
const isLogin = action === '/admin/login';
|
||||
|
||||
Reference in New Issue
Block a user