Expand page templates and configure page visibility

This commit is contained in:
2026-11-22 12:54:01 +08:00
parent 931d333ca7
commit f23c3b95ba
27 changed files with 293 additions and 44 deletions
+44 -9
View File
@@ -306,8 +306,7 @@ jQuery(function ($) {
const $alignTools = $elementTools.find('[data-element-align]');
const alignments = ['left', 'center', 'right'];
const alignmentClasses = alignments.map((value) => 'studio-align-' + value);
const heroOrOptional = '[data-studio-field="accent"], [data-studio-field="lead"], [data-studio-part="lead"], [data-studio-action], [data-studio-nav-index]';
const canvasFields = heroOrOptional + ', [data-studio-field="heading"], [data-studio-part="title"]';
const canvasFields = '[data-studio-field="heading"], [data-studio-field="accent"], [data-studio-field="lead"], [data-studio-part="title"], [data-studio-part="lead"], [data-studio-action], [data-studio-nav-index]';
const bodyElements = 'a, article, blockquote, details, div, dl, dt, dd, figure, h1, h2, h3, h4, h5, h6, hr, li, ol, p, pre, progress, table, ul';
const mediaTargets = '[data-studio-hero-image], [data-studio-part="body"] img, [data-studio-part="body"] audio, [data-studio-part="body"] video';
const $handle = $studio.find('[data-media-handle]');
@@ -359,7 +358,7 @@ jQuery(function ($) {
const $moduleForm = $moduleDialog.find('form');
const moduleInput = (name) => $moduleForm.find('[name="' + name + '"]');
let editedModule;
let deletedModules = [];
let deletedSections = [];
const propertyInput = (name) => $propertyForm.find('[name="' + name + '"]');
const pageInput = (name) => $settings.find('[name="' + name + '"]');
const settingsSnapshot = () => $settings.serializeArray()
@@ -402,7 +401,7 @@ jQuery(function ($) {
if (feedChanged) edit.feed = feed;
return [edit];
});
return [...edits, ...deletedModules];
return [...edits, ...deletedSections];
}
$settings.on('studio:sync', () => pageInput('canvas_sections').val(JSON.stringify(sectionChanges())));
@@ -514,6 +513,15 @@ jQuery(function ($) {
}
function bindPage($doc) {
const visibilityTargets = {header: '.masthead', hero: '[data-studio-hero-content], .page-photo-credit', footer: '.site-footer'};
for (const [area, selector] of Object.entries(visibilityTargets)) {
const $input = pageInput('show_' + area);
const $target = $doc.find(selector);
$input.on('change.canvas', () => {
selectElement(null);
$target.prop('hidden', $input.val() === '0');
});
}
const labels = {name: '页面名称', heading: '首屏标题', accent: '标题第二行', lead: '首屏简介'};
$doc.find('[data-studio-field]').each(function () {
const field = this.dataset.studioField;
@@ -622,6 +630,20 @@ jQuery(function ($) {
return $navContent.find('[data-studio-nav-index="' + (index + 1) + '"]').get(0);
});
$navInput.on('input.canvas', syncNavigation);
heroControls.set('remove-section-links', (key) => {
const anchor = '#' + key;
$navInput.val(navLines().filter((line) => {
const separator = line.indexOf('|');
return separator < 0 || line.slice(separator + 1).trim() !== anchor;
}).join('\n'));
syncNavigation();
for (const index of [1, 2]) {
const $url = pageInput('url' + index);
if ($url.val().trim() !== anchor) continue;
pageInput('label' + index).val('');
$url.val('').trigger('input');
}
});
heroControls.set('navigation', () => {
openProperties('本页目录', {quicklinks: $navInput.val()}, ({quicklinks}) => {
$navInput.val(quicklinks);
@@ -832,7 +854,10 @@ jQuery(function ($) {
const aligned = dynamic ? null : alignmentTarget(node);
syncAlignmentButtons(aligned);
$elementTools.find('[data-element-copy]').prop('hidden', !canCopy);
$elementTools.find('[data-element-delete]').prop('hidden', !dynamic && !inBody && !selectedMedia && !node.matches(heroOrOptional));
const deleteLabel = node.dataset.studioField === 'heading' ? '删除首屏'
: node.dataset.studioPart === 'title' ? '删除区块' : '删除';
$elementTools.find('[data-element-delete]').attr({'aria-label': deleteLabel, title: deleteLabel})
.prop('hidden', !dynamic && !inBody && !selectedMedia && !node.matches(canvasFields));
$elementTools.find('[data-element-properties]').prop('hidden', !hasProperties);
if (target) showMediaWidth(currentMediaWidth(target));
selectionObserver?.observe(target || aligned || node);
@@ -848,6 +873,15 @@ jQuery(function ($) {
return;
}
const {studioField, studioAction, studioNavIndex} = node.dataset;
if (!copy && studioField === 'heading') {
pageInput('show_hero').val('0').trigger('change');
$studio.find('[data-canvas-status]').text('首屏已移除,可在页面设置中恢复。');
return;
}
if (!copy && node.dataset.studioPart === 'title') {
changeModule(sections.find((section) => section.node === node.closest('[data-studio-section]')), false);
return;
}
const inBody = node.closest('[data-studio-part="body"]') !== null;
selectElement(null);
if (inBody) {
@@ -958,9 +992,10 @@ jQuery(function ($) {
function removeSection(section) {
if (section.node.contains(activeBody)) selectBody(null);
if (section.node.contains(selectedElement)) selectElement(null);
if (section.version !== null) deletedModules.push({key: section.key, version: section.version, delete: true});
if (section.version !== null) deletedSections.push({key: section.key, version: section.version, delete: true});
section.node.remove();
sections = sections.filter((entry) => entry !== section);
heroControls.get('remove-section-links')(section.key);
section.$pending?.remove();
$pending.prop('hidden', !$pending.children().length);
}
@@ -989,9 +1024,9 @@ jQuery(function ($) {
function changeModule(section, copy) {
if (!section) return;
if (!copy) {
if (window.confirm('删除此模块?保存页面后生效。')) {
if (window.confirm('删除此区块?保存页面后生效。')) {
removeSection(section);
$studio.find('[data-canvas-status]').text('模块已移除,保存页面后生效。');
$studio.find('[data-canvas-status]').text('区块已移除,保存页面后生效。');
}
return;
}
@@ -1178,7 +1213,7 @@ jQuery(function ($) {
selectElement(null);
$pending.empty().prop('hidden', true);
sections = [];
deletedModules = [];
deletedSections = [];
$doc.find('[data-studio-section]').each((_, section) => registerSection(section));
$doc.on('focusin.canvas', '[contenteditable]', function () {