feat(widgets): complete phase 3 atomic integration
This commit is contained in:
+41
-2
@@ -16,8 +16,29 @@
|
||||
if (output) this.addEventListener('input', () => { output.textContent = this.value; });
|
||||
});
|
||||
evaluateDependencies($root);
|
||||
updateWidgetTitle($root);
|
||||
updatePlacementWarning($root);
|
||||
}
|
||||
|
||||
function updateWidgetTitle(root) {
|
||||
const $root = $(root);
|
||||
const title = String($root.find('.aksrt-widget-field[data-field-id="title"] input').first().val() || '').trim();
|
||||
if (!title) return;
|
||||
$root.closest('.widget').find('.widget-title h3, .widget-title-action + h3').first().contents().filter(function () {
|
||||
return this.nodeType === Node.TEXT_NODE;
|
||||
}).first().replaceWith(`${title} `);
|
||||
}
|
||||
|
||||
function updatePlacementWarning(root) {
|
||||
const $widget = $(root).closest('.widget');
|
||||
const $hint = $widget.find('.aksrt-widget-placement-hint').first();
|
||||
if (!$hint.length) return;
|
||||
const size = String($hint.data('widget-size') || 'any');
|
||||
const area = String($widget.closest('.widgets-sortables').attr('id') || '');
|
||||
const isSidebar = /sidebar/.test(area);
|
||||
$hint.toggleClass('is-warning', (size === 'wide' && isSidebar) || (size === 'sidebar' && !isSidebar && area !== ''));
|
||||
}
|
||||
|
||||
function loadForm(container) {
|
||||
const $container = $(container);
|
||||
if ($container.data('loading') || $container.data('loaded')) return;
|
||||
@@ -82,7 +103,11 @@
|
||||
$(document)
|
||||
.on('click', '.aksrt-widget-form-lazy__load', function () { loadForm($(this).closest('.aksrt-widget-form-lazy')); })
|
||||
.on('click', '.widget.open .aksrt-widget-form-lazy', function () { loadForm(this); })
|
||||
.on('change input', '.aksrt-widget-form input, .aksrt-widget-form select, .aksrt-widget-form textarea', function () { evaluateDependencies($(this).closest('.aksrt-widget-form')); })
|
||||
.on('change input', '.aksrt-widget-form input, .aksrt-widget-form select, .aksrt-widget-form textarea', function () {
|
||||
const $form = $(this).closest('.aksrt-widget-form');
|
||||
evaluateDependencies($form);
|
||||
updateWidgetTitle($form);
|
||||
})
|
||||
.on('click', '.aksrt-widget-repeater__add', function () {
|
||||
const $repeater = $(this).closest('.aksrt-widget-repeater');
|
||||
const max = Number($repeater.data('max-items') || 50);
|
||||
@@ -116,10 +141,24 @@
|
||||
const $wrap = $(this).closest('.aksrt-widget-upload');
|
||||
$wrap.find('input[type="url"]').val('').trigger('change');
|
||||
$wrap.find('img').remove();
|
||||
});
|
||||
})
|
||||
.on('click', '.aksrt-widget-template-preview', function () {
|
||||
const $form = $(this).closest('form');
|
||||
const $output = $('.aksrt-widget-template-preview-output').first();
|
||||
$output.prop('hidden', false).html('<p>正在生成预览…</p>');
|
||||
$.post(config.ajaxUrl, {
|
||||
action: 'aksrt_widgets_template_preview',
|
||||
nonce: config.transferNonce,
|
||||
template: $form.find('[name="template"]').val(),
|
||||
}).done((response) => {
|
||||
if (!response?.success) throw new Error('Invalid response');
|
||||
$output.html(response.data.html || '<p>模板为空。</p>');
|
||||
}).fail(() => $output.html('<p class="notice notice-error">预览加载失败。</p>'));
|
||||
});
|
||||
|
||||
$(document).on('widget-added widget-updated', function (_event, widget) {
|
||||
$(widget).find('.aksrt-widget-form-lazy').each(function () { loadForm(this); });
|
||||
updatePlacementWarning(widget);
|
||||
});
|
||||
|
||||
$(function () {
|
||||
|
||||
Reference in New Issue
Block a user