Edit shared headers and footers as page types
This commit is contained in:
+52
-12
@@ -308,7 +308,7 @@ jQuery(function ($) {
|
||||
const buttonClasses = {solid: 'button-primary', outline: 'button-outline', underline: 'button-underline', plain: 'button-plain'};
|
||||
const alignmentClasses = alignments.map((value) => 'studio-align-' + value);
|
||||
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, button, details, div, dl, dt, dd, figure, figcaption, h1, h2, h3, h4, h5, h6, hr, li, ol, p, pre, progress, section, summary, table, ul';
|
||||
const bodyElements = 'a, article, blockquote, button, details, div, dl, dt, dd, figure, figcaption, footer, h1, h2, h3, h4, h5, h6, header, hr, li, nav, ol, p, pre, progress, section, summary, 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]');
|
||||
const $mediaSize = $sizing.find('[data-media-size]');
|
||||
@@ -371,7 +371,7 @@ jQuery(function ($) {
|
||||
const propertyInput = (name) => $propertyForm.find('[name="' + name + '"]');
|
||||
const pageInput = (name) => $settings.find('[name="' + name + '"]');
|
||||
const settingsSnapshot = () => $settings.serializeArray()
|
||||
.filter(({name}) => !['csrf', 'canvas_sections', 'canvas_order'].includes(name));
|
||||
.filter(({name}) => !['csrf', 'canvas_sections', 'canvas_order', 'provider_secret'].includes(name));
|
||||
let savedSettings = JSON.stringify(settingsSnapshot());
|
||||
let dialogAction;
|
||||
let doc;
|
||||
@@ -496,6 +496,14 @@ jQuery(function ($) {
|
||||
return JSON.stringify(sections.filter(({fixed}) => !fixed).map(({key}) => key));
|
||||
}
|
||||
|
||||
function syncMemberSettings() {
|
||||
const $auth = $settings.find('[data-shared-auth]');
|
||||
if (!$auth.length) return;
|
||||
const member = Boolean(doc?.querySelector('#main-content [data-studio-part="body"] a.studio-member-slot'));
|
||||
$auth.prop('hidden', !member).find('[data-provider-settings]').prop('disabled', !member);
|
||||
$auth.find('[name=provider_mode]').triggerHandler('change.layoutProvider');
|
||||
}
|
||||
|
||||
function sectionChanges(withEdits = true) {
|
||||
const edits = sections.flatMap((entry) => {
|
||||
const {key, version, fields, source, template, copyOf, feed, initialFeed, initialPresentation} = entry;
|
||||
@@ -530,6 +538,7 @@ jQuery(function ($) {
|
||||
|
||||
$settings.on('studio:sync', () => {
|
||||
if (!doc || initialOrder === undefined) return;
|
||||
syncMemberSettings();
|
||||
syncPagePresentation();
|
||||
pageInput('canvas_sections').val(JSON.stringify(sectionChanges()));
|
||||
pageInput('canvas_order').val(canvasOrder() === initialOrder ? '' : canvasOrder());
|
||||
@@ -540,7 +549,8 @@ jQuery(function ($) {
|
||||
$settings.prop('inert', busy);
|
||||
});
|
||||
$(window).on('beforeunload', (event) => {
|
||||
if (!saveComplete && (sectionChanges(false).length || initialOrder !== undefined && canvasOrder() !== initialOrder
|
||||
if (!saveComplete && (sectionChanges(false).length || pageInput('provider_secret').filter(':enabled').val()
|
||||
|| initialOrder !== undefined && canvasOrder() !== initialOrder
|
||||
|| JSON.stringify(settingsSnapshot()) !== savedSettings)) {
|
||||
event.preventDefault();
|
||||
event.originalEvent.returnValue = '';
|
||||
@@ -791,13 +801,33 @@ 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);
|
||||
const $body = $doc.find('body');
|
||||
const visibilityInputs = ['show_hero', 'header_choice', 'footer_choice'];
|
||||
const $heroInput = pageInput('show_hero');
|
||||
$heroInput.on('change.canvas', () => {
|
||||
selectElement(null);
|
||||
$doc.find('[data-studio-hero-content], .page-photo-credit').prop('hidden', $heroInput.val() === '0');
|
||||
});
|
||||
for (const [area, fallback] of Object.entries({header: '.masthead', footer: '.site-footer'})) {
|
||||
const $input = pageInput(area + '_choice');
|
||||
const selector = '[data-site-area="' + area + '"], ' + fallback;
|
||||
let rendered = $input.val();
|
||||
let pending;
|
||||
$input.on('change.canvas', () => {
|
||||
selectElement(null);
|
||||
$target.prop('hidden', $input.val() === '0');
|
||||
pending?.abort();
|
||||
const choice = $input.val();
|
||||
const $target = $body.children(selector);
|
||||
$target.prop('hidden', choice === 'hidden');
|
||||
if (choice === 'hidden' || choice === rendered) return;
|
||||
pending = $.get($frame.attr('src'), {area, choice}, undefined, 'text').done((html) => {
|
||||
if ($input.val() !== choice) return;
|
||||
const preview = new DOMParser().parseFromString(html, 'text/html');
|
||||
const replacement = $(preview.body).children(selector).get(0);
|
||||
if (!replacement) return;
|
||||
$target.replaceWith(doc.importNode(replacement, true));
|
||||
rendered = choice;
|
||||
});
|
||||
});
|
||||
}
|
||||
const labels = {name: '页面名称', heading: '首屏标题', accent: '标题第二行', lead: '首屏简介'};
|
||||
@@ -983,7 +1013,7 @@ jQuery(function ($) {
|
||||
this.classList.remove(...alignmentClasses);
|
||||
if (values[this.dataset.studioAlignField]) this.classList.add('studio-align-' + values[this.dataset.studioAlignField]);
|
||||
});
|
||||
Object.keys(visibilityTargets).forEach((area) => pageInput('show_' + area).triggerHandler('change.canvas'));
|
||||
visibilityInputs.forEach((field) => pageInput(field).triggerHandler('change.canvas'));
|
||||
pageInput('palette_id').triggerHandler('change.canvas');
|
||||
actions = readActions();
|
||||
syncActions();
|
||||
@@ -995,6 +1025,11 @@ jQuery(function ($) {
|
||||
|
||||
function editResource(node) {
|
||||
const tag = node.localName;
|
||||
if (node.matches('a.studio-member-slot') && $settings.find('[data-shared-auth]').length) {
|
||||
syncMemberSettings();
|
||||
$settings.find('[data-shared-auth]').prop('open', true).find('[name=provider_mode]').trigger('focus');
|
||||
return;
|
||||
}
|
||||
if (tag === 'progress') {
|
||||
openProperties('进度条', {value: node.getAttribute('value') || '0', max: node.getAttribute('max') || '100'}, ({value, max}) => {
|
||||
if (!/^\d+$/.test(value) || !/^\d+$/.test(max) || Number(max) < 1 || Number(value) > Number(max)) {
|
||||
@@ -1411,6 +1446,7 @@ jQuery(function ($) {
|
||||
}
|
||||
}
|
||||
$layout.find('[data-layers-empty]').prop('hidden', heroVisible || sections.length > 0);
|
||||
$(doc).find('[data-studio-empty-layout]').prop('hidden', heroVisible || sections.length > 0);
|
||||
$pending.prop('hidden', !$pending.children().length);
|
||||
}
|
||||
|
||||
@@ -1611,8 +1647,8 @@ jQuery(function ($) {
|
||||
const template = this.dataset.canvasTemplate;
|
||||
const feed = this.dataset.templateFeed;
|
||||
if ($presets.find('[data-template-inline]').prop('checked')) {
|
||||
if (feed) {
|
||||
$templateStatus.text('动态模块需要作为独立区块添加。');
|
||||
if (feed || this.dataset.templateStyle === 'layout') {
|
||||
$templateStatus.text('此组件需要作为独立区块添加。');
|
||||
return;
|
||||
}
|
||||
if (!activeBody) {
|
||||
@@ -1629,7 +1665,8 @@ jQuery(function ($) {
|
||||
return;
|
||||
}
|
||||
const end = doc.querySelector('[data-studio-section-end]');
|
||||
const section = end.content.firstElementChild.cloneNode(true);
|
||||
const skeleton = this.dataset.templateStyle === 'layout' ? doc.querySelector('[data-studio-section-layout]') : end;
|
||||
const section = skeleton.content.firstElementChild.cloneNode(true);
|
||||
const id = newSectionId();
|
||||
section.id = id;
|
||||
section.classList.replace('section-plain', 'section-' + this.dataset.templateStyle);
|
||||
@@ -1669,6 +1706,7 @@ jQuery(function ($) {
|
||||
|
||||
function captureHistory(group = null) {
|
||||
if (initialOrder === undefined) return;
|
||||
syncMemberSettings();
|
||||
syncPagePresentation();
|
||||
const state = {
|
||||
settings: settingsSnapshot(),
|
||||
@@ -1748,6 +1786,7 @@ jQuery(function ($) {
|
||||
pageInput(name).val(value);
|
||||
}
|
||||
syncPageFromInputs();
|
||||
syncMemberSettings();
|
||||
renderLayers();
|
||||
historyObserver?.takeRecords();
|
||||
syncHistoryButtons();
|
||||
@@ -1788,6 +1827,7 @@ jQuery(function ($) {
|
||||
$doc.find('[data-studio-section]').each((_, section) => registerSection(section));
|
||||
renderLayers();
|
||||
initialOrder = canvasOrder();
|
||||
syncMemberSettings();
|
||||
syncPagePresentation();
|
||||
savedSettings = JSON.stringify(settingsSnapshot());
|
||||
history.length = 0;
|
||||
|
||||
Reference in New Issue
Block a user