forked from laysense/laysite
Edit shared headers and footers as page types
This commit is contained in:
+19
-1
@@ -341,8 +341,26 @@
|
||||
.canvas-module-settings .category-checks { max-height: min(15rem, 27dvh); overflow-y: auto; }
|
||||
.canvas-module-settings .actions { position: sticky; bottom: 0; padding-block: .35rem; margin: 0; background: var(--white); }
|
||||
|
||||
.design-overview, .palette-fields { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(min(100%, 14rem), 1fr)); }
|
||||
.palette-fields { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(min(100%, 14rem), 1fr)); }
|
||||
.palette-fields input[type=color] { padding: .25rem; }
|
||||
|
||||
.admin-bar .wordmark { display: inline-flex; gap: .5rem; align-items: center; font-size: 1.26rem; font-weight: 700; color: var(--ink); text-decoration: none; }
|
||||
.admin-bar .laysite-mark { width: 2.6rem; height: 2.6rem; max-width: 2.6rem; max-height: 2.6rem; object-fit: contain; }
|
||||
|
||||
.studio-layout-card-preview {
|
||||
position: relative;
|
||||
height: 5.25rem;
|
||||
overflow: hidden;
|
||||
background: var(--paper);
|
||||
border-bottom: 1px solid var(--line);
|
||||
}
|
||||
.studio-layout-card-preview iframe {
|
||||
position: absolute;
|
||||
inset: 0 auto auto 0;
|
||||
width: calc(100% / .34);
|
||||
height: calc(100% / .34);
|
||||
transform: scale(.34);
|
||||
transform-origin: top left;
|
||||
border: 0;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
+12
-19
@@ -1,37 +1,31 @@
|
||||
'use strict';
|
||||
|
||||
jQuery(function ($) {
|
||||
$('[data-layout-components]').on('click', '[data-component-move]', function () {
|
||||
const $item = $(this).closest('li');
|
||||
if (this.dataset.componentMove === '-1') $item.prevAll(':visible').first().before($item);
|
||||
else $item.nextAll(':visible').first().after($item);
|
||||
$(this).closest('[data-layout-components]').trigger('layout:order');
|
||||
$(this).trigger('focus');
|
||||
});
|
||||
$('[data-page-layout-editor]').each(function () {
|
||||
const {pageLayoutEditor: kind, defaultId} = this.dataset;
|
||||
const $link = $(this);
|
||||
$('#studio-page-settings').on('change', '[name="' + kind + '_id"]', function () {
|
||||
$link.attr('href', '/admin/design/' + kind + '/' + (this.value || defaultId || 'new?default=1'));
|
||||
$('#studio-page-settings').on('change', '[name="' + kind + '_choice"]', function () {
|
||||
const id = this.value || defaultId;
|
||||
$link.prop('hidden', this.value === 'hidden')
|
||||
.attr('href', id && this.value !== 'hidden' ? '/admin/pages/layout--' + kind + '-' + id : '/admin/new-page?type=' + kind);
|
||||
});
|
||||
});
|
||||
$('[data-new-page-type]').on('change', function () {
|
||||
const ordinary = this.value === 'page';
|
||||
$(this.form).find('[data-new-page-slug]').prop('hidden', !ordinary)
|
||||
.find('input').prop({required: ordinary, disabled: !ordinary});
|
||||
$('[data-open-page-templates]').prop('disabled', !ordinary);
|
||||
}).trigger('change');
|
||||
$('[data-provider-settings]').each(function () {
|
||||
const $settings = $(this);
|
||||
const $form = $settings.closest('form');
|
||||
const $preset = $form.find('[data-layout-preset]');
|
||||
const $account = $form.find('[name="components[]"][value=account]');
|
||||
const $mode = $settings.find('[name=provider_mode]');
|
||||
const sync = () => {
|
||||
$mode.on('change.layoutProvider', () => {
|
||||
const mode = $mode.val();
|
||||
const active = $preset.filter(':checked').val() === 'member' && $account.is(':checked');
|
||||
$settings.prop({hidden: !active, disabled: !active});
|
||||
$settings.find('[data-provider-field]').prop('hidden', !mode);
|
||||
$settings.find('[data-provider-mode]').each(function () {
|
||||
$(this).prop('hidden', this.dataset.providerMode !== mode);
|
||||
});
|
||||
};
|
||||
$preset.add($mode).add($account).on('change', sync);
|
||||
sync();
|
||||
}).triggerHandler('change.layoutProvider');
|
||||
});
|
||||
|
||||
$('[data-page-list]').each(function () {
|
||||
@@ -173,7 +167,6 @@ jQuery(function ($) {
|
||||
return;
|
||||
}
|
||||
finish();
|
||||
if (response?.field) $form.triggerHandler('studio:invalid', [response.field]);
|
||||
if (!designFieldError($form, response)) {
|
||||
formError($form, response?.message || '请求未完成,请稍后重试。', request.status);
|
||||
}
|
||||
|
||||
@@ -1,167 +0,0 @@
|
||||
.design-editor-bar {
|
||||
display: grid;
|
||||
grid-template-columns: minmax(12rem, 1fr) auto auto;
|
||||
align-items: end;
|
||||
gap: .85rem 1.25rem;
|
||||
margin: 0;
|
||||
}
|
||||
.design-editor-bar > label:has(input[type=checkbox]) { min-height: 46px; }
|
||||
.design-editor-grid {
|
||||
display: grid;
|
||||
grid-template-columns: minmax(0, 1fr) minmax(18.5rem, 23rem);
|
||||
align-items: start;
|
||||
gap: 1.1rem;
|
||||
}
|
||||
.design-editor-grid > * { min-width: 0; }
|
||||
.design-editor .admin-panel { padding: clamp(.85rem, 2vw, 1.5rem); }
|
||||
.design-canvas-stage {
|
||||
display: grid;
|
||||
justify-items: center;
|
||||
align-content: center;
|
||||
min-height: 15.5rem;
|
||||
padding: clamp(.4rem, 2.3vw, 1.45rem);
|
||||
border: 1px solid var(--line);
|
||||
border-radius: .65rem;
|
||||
background-color: var(--paper);
|
||||
background-image: radial-gradient(var(--line) 1px, transparent 1px);
|
||||
background-size: 13px 13px;
|
||||
}
|
||||
.design-canvas-viewport {
|
||||
position: relative;
|
||||
max-width: 100%;
|
||||
}
|
||||
.design-canvas-viewport iframe {
|
||||
display: block;
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
border: 1px solid var(--line);
|
||||
border-radius: .45rem;
|
||||
background: var(--white);
|
||||
box-shadow: 0 8px 28px rgb(20 36 70 / 9%);
|
||||
transform-origin: top left;
|
||||
}
|
||||
.design-canvas-stage > p { margin: 0; }
|
||||
.design-canvas-stage:has([data-layout-empty]:not([hidden])) .design-canvas-viewport { display: none; }
|
||||
.design-canvas > .field-note { margin-top: .65rem; }
|
||||
|
||||
.design-templates { min-inline-size: 0; }
|
||||
.design-templates legend, .design-component-panel legend, .design-properties legend {
|
||||
padding-inline: .35rem;
|
||||
color: var(--ink);
|
||||
font-weight: 660;
|
||||
}
|
||||
.design-template-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 12rem), 1fr)); gap: .75rem; }
|
||||
.design-editor label.design-template-choice {
|
||||
gap: 0;
|
||||
min-width: 0;
|
||||
overflow: hidden;
|
||||
border: 1px solid var(--line);
|
||||
border-radius: .6rem;
|
||||
cursor: pointer;
|
||||
transition: border-color .16s, transform .16s, box-shadow .16s;
|
||||
}
|
||||
.design-template-choice:hover { transform: translateY(-2px); border-color: var(--accent); }
|
||||
.design-template-choice:has(input:checked) { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
|
||||
.design-template-choice:focus-within { outline: 2px solid var(--accent); outline-offset: 3px; }
|
||||
.design-template-image {
|
||||
position: relative;
|
||||
height: 6rem;
|
||||
overflow: hidden;
|
||||
background: var(--paper);
|
||||
border-bottom: 1px solid var(--line);
|
||||
}
|
||||
.design-template-image iframe {
|
||||
position: absolute;
|
||||
inset: 0 auto auto 0;
|
||||
width: calc(100% / .42);
|
||||
height: calc(100% / .42);
|
||||
border: 0;
|
||||
transform: scale(.42);
|
||||
transform-origin: top left;
|
||||
pointer-events: none;
|
||||
}
|
||||
.design-template-caption {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: .55rem;
|
||||
min-height: 2.8rem;
|
||||
padding: .45rem .65rem;
|
||||
font-size: .92rem;
|
||||
}
|
||||
.design-editor-inspector { display: grid; gap: 1rem; }
|
||||
.design-component-panel { min-inline-size: 0; padding: .25rem .65rem .55rem; }
|
||||
.design-component-panel .layout-components li {
|
||||
min-height: 2.7rem;
|
||||
border: 0;
|
||||
border-radius: .4rem;
|
||||
padding: .35rem .45rem;
|
||||
gap: .35rem;
|
||||
}
|
||||
.design-component-panel .layout-components li + li { margin-block-start: .2rem; }
|
||||
.design-component-panel .layout-components li.is-selected { background: var(--accent-light); }
|
||||
.design-component-panel .layout-components .actions { gap: .22rem; }
|
||||
.design-component-panel .button, .design-link-row .button {
|
||||
min-height: 2rem;
|
||||
width: 2rem;
|
||||
padding: 0;
|
||||
background: var(--white);
|
||||
}
|
||||
.design-component-panel .button svg, .design-link-row .button svg { width: 1rem; height: 1rem; }
|
||||
.design-component-panel .button:disabled, .design-link-row .button:disabled { opacity: .45; cursor: default; transform: none; }
|
||||
.design-properties {
|
||||
display: grid;
|
||||
gap: .8rem;
|
||||
min-inline-size: 0;
|
||||
margin: 0;
|
||||
padding: .5rem .7rem .8rem;
|
||||
}
|
||||
.design-properties .asset-field { grid-template-columns: minmax(0, 1fr); }
|
||||
.design-properties .asset-field button { justify-self: start; }
|
||||
.design-link-rows { display: grid; gap: .5rem; margin-bottom: .65rem; }
|
||||
.design-link-row {
|
||||
display: grid;
|
||||
grid-template-columns: minmax(0, 1fr) auto;
|
||||
gap: .4rem .55rem;
|
||||
padding: .55rem;
|
||||
border: 1px solid var(--line);
|
||||
border-radius: .45rem;
|
||||
}
|
||||
.design-link-row label { grid-column: 1; }
|
||||
.design-link-controls { display: grid; grid-column: 2; grid-row: 1 / span 2; align-content: center; gap: .25rem; }
|
||||
.design-link-row input { min-height: 2.2rem; padding: .3rem .45rem; }
|
||||
|
||||
.design-frame { display: flow-root; margin: 0; background: transparent; }
|
||||
.design-frame-sample { display: grid; align-content: center; min-height: 100vh; background: var(--paper); }
|
||||
.design-frame .masthead { position: static; }
|
||||
.design-frame-sample .masthead .primary-nav { width: auto; order: 0; }
|
||||
.design-frame-editing :is([data-layout-component], [data-layout-text], [data-layout-link-text]) {
|
||||
outline: 1px dashed transparent;
|
||||
outline-offset: 3px;
|
||||
}
|
||||
.design-frame-editing :is([data-layout-component]:hover, [data-layout-component].is-selected) { outline-color: var(--accent); }
|
||||
.design-frame-editing [contenteditable] { cursor: text; overflow-wrap: anywhere; min-inline-size: .4em; }
|
||||
.design-frame-editing [contenteditable]:focus { outline: 2px solid var(--accent); }
|
||||
.design-frame-editing [contenteditable]:empty::before {
|
||||
content: attr(data-layout-placeholder);
|
||||
opacity: .72;
|
||||
pointer-events: none;
|
||||
}
|
||||
.design-frame-editing .site-footer-text { white-space: pre-wrap; }
|
||||
.design-frame-editing .primary-nav { align-items: center; }
|
||||
|
||||
@media (max-width: 55rem) {
|
||||
.design-editor-grid { grid-template-columns: minmax(0, 1fr); }
|
||||
.design-editor-main { display: contents; }
|
||||
.design-editor-inspector { grid-row: 2; }
|
||||
}
|
||||
@media (max-width: 39rem) {
|
||||
.design-editor-bar { grid-template-columns: 1fr auto; align-items: center; }
|
||||
.design-editor-bar > label:first-child { grid-column: 1 / -1; }
|
||||
.design-editor-bar > button { justify-self: end; }
|
||||
.design-canvas-stage { min-height: 12rem; }
|
||||
}
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.design-template-choice { transition: none; }
|
||||
.design-template-choice:hover { transform: none; }
|
||||
}
|
||||
@@ -1,277 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
jQuery(function ($) {
|
||||
$('[data-layout-editor]').each(function () {
|
||||
const $form = $(this);
|
||||
const $frame = $form.find('[data-layout-frame]');
|
||||
const $viewport = $frame.parent();
|
||||
const $stage = $viewport.parent();
|
||||
const $list = $form.find('[data-layout-components]');
|
||||
const $rows = $form.find('[data-layout-link-rows]');
|
||||
const $linkInput = $form.find('[name=canvas_links]');
|
||||
const kind = this.dataset.layoutEditor;
|
||||
const siteName = this.dataset.siteName;
|
||||
const $presets = $form.find('[name=preset]');
|
||||
const field = (name) => $form.find('[name="' + name + '"]');
|
||||
const placeholder = {
|
||||
brand: siteName, action_label: '按钮文案', text: '添加说明文字', legal: '添加版权文字'
|
||||
};
|
||||
const buttonStyles = {solid: 'button-primary', outline: 'button-outline', underline: 'button-underline', plain: 'button-plain'};
|
||||
let links = JSON.parse($linkInput.val()).filter((link) =>
|
||||
Array.isArray(link) && typeof link[0] === 'string' && typeof link[1] === 'string');
|
||||
let selected = '';
|
||||
let doc;
|
||||
let parts;
|
||||
let host;
|
||||
let observer;
|
||||
let phone = window.matchMedia('(max-width: 44rem)').matches;
|
||||
|
||||
function part(name) {
|
||||
return parts.get(name);
|
||||
}
|
||||
|
||||
function selectComponent(name) {
|
||||
selected = name;
|
||||
$form.find('[data-layout-panel]').each(function () {
|
||||
this.hidden = this.dataset.layoutPanel !== name;
|
||||
});
|
||||
$list.children().each(function () {
|
||||
const active = this.dataset.layoutLayer === name;
|
||||
$(this).toggleClass('is-selected', active).find('[data-layout-select]').attr('aria-pressed', String(active));
|
||||
});
|
||||
for (const [key, node] of parts) {
|
||||
node.classList.toggle('is-selected', key === name);
|
||||
}
|
||||
}
|
||||
|
||||
function syncLayers() {
|
||||
const preset = $presets.filter(':checked').val();
|
||||
const base = kind === 'header' ? 'masthead' : 'site-footer';
|
||||
const root = host.parentElement;
|
||||
root.className = base + ' ' + base + '-' + preset;
|
||||
const $available = $list.children().each(function () {
|
||||
this.hidden = this.dataset.layoutLayer === 'account' && preset !== 'member';
|
||||
}).filter(function () { return !this.hidden; });
|
||||
$available.each(function (index) {
|
||||
const $item = $(this);
|
||||
$item.find('[data-component-move="-1"]').prop('disabled', index === 0);
|
||||
$item.find('[data-component-move="1"]').prop('disabled', index === $available.length - 1);
|
||||
});
|
||||
|
||||
const ordered = $available.find('input:checked').map((_, input) => input.value).get();
|
||||
for (const [name, node] of parts) {
|
||||
node.hidden = !ordered.includes(name);
|
||||
}
|
||||
for (const name of ordered) host.append(part(name));
|
||||
root.hidden = ordered.length === 0;
|
||||
$form.find('[data-layout-empty]').prop('hidden', ordered.length > 0);
|
||||
if (!$available.filter(function () { return this.dataset.layoutLayer === selected; }).length) {
|
||||
selectComponent(ordered[0] || $available.first().attr('data-layout-layer') || '');
|
||||
}
|
||||
syncFrameSize();
|
||||
}
|
||||
|
||||
function setInlineText(node, label, fallback) {
|
||||
node.contentEditable = 'plaintext-only';
|
||||
node.setAttribute('aria-label', label);
|
||||
node.dataset.layoutPlaceholder = fallback;
|
||||
}
|
||||
|
||||
function syncBrand() {
|
||||
const image = part('brand').querySelector('img');
|
||||
const label = part('brand').querySelector('[data-layout-text]');
|
||||
const url = field('logo').val().trim();
|
||||
const safeImage = /^(?:\/(?!\/)|https:\/\/)[^\s\\]+$/i.test(url);
|
||||
if (safeImage) image.setAttribute('src', url);
|
||||
else image.removeAttribute('src');
|
||||
image.alt = field('brand').val() || siteName;
|
||||
image.hidden = !safeImage;
|
||||
label.hidden = safeImage;
|
||||
}
|
||||
|
||||
function renderLinks() {
|
||||
const nav = part('links');
|
||||
nav.replaceChildren();
|
||||
if (links.length === 0) {
|
||||
$('<button>', {type: 'button', class: 'button button-outline', 'data-layout-add-in-canvas': '', text: '添加链接'}).appendTo(nav);
|
||||
return;
|
||||
}
|
||||
links.forEach((link, index) => {
|
||||
const item = doc.createElement('a');
|
||||
item.href = '#';
|
||||
item.dataset.layoutLinkText = index;
|
||||
item.textContent = link[1];
|
||||
setInlineText(item, '链接文案', '链接文案');
|
||||
nav.append(item);
|
||||
});
|
||||
}
|
||||
|
||||
function renderLinkRows() {
|
||||
const template = $form.find('[data-layout-link-template]').get(0);
|
||||
$rows.empty();
|
||||
links.forEach((link, index) => {
|
||||
const $row = $(template.content.firstElementChild.cloneNode(true));
|
||||
$row.attr('data-layout-link-index', index).find('[data-layout-link-field]').each(function () {
|
||||
this.value = link[Number(this.dataset.layoutLinkField)];
|
||||
});
|
||||
$row.find('[data-layout-link-move="-1"]').prop('disabled', index === 0);
|
||||
$row.find('[data-layout-link-move="1"]').prop('disabled', index === links.length - 1);
|
||||
$rows.append($row);
|
||||
});
|
||||
$form.find('[data-layout-link-add]').prop('disabled', links.length >= 20);
|
||||
}
|
||||
|
||||
function updateLinkInput() {
|
||||
$linkInput.val(JSON.stringify(links));
|
||||
}
|
||||
|
||||
function rebuildLinks() {
|
||||
updateLinkInput();
|
||||
renderLinks();
|
||||
renderLinkRows();
|
||||
}
|
||||
|
||||
function addLink() {
|
||||
if (links.length >= 20) return;
|
||||
links.push(['', '']);
|
||||
rebuildLinks();
|
||||
$rows.children().last().find('[data-layout-link-field="1"]').trigger('focus');
|
||||
}
|
||||
|
||||
function syncFrameSize() {
|
||||
if (!doc) return;
|
||||
const available = $stage.width();
|
||||
if (!available) return;
|
||||
const width = phone ? 390 : Math.max(960, available);
|
||||
const scale = Math.min(1, available / width);
|
||||
$frame.css({width, transform: 'scale(' + scale + ')'});
|
||||
const height = Math.ceil(doc.body.getBoundingClientRect().height) + 2;
|
||||
$frame.css('height', height);
|
||||
$viewport.css({width: width * scale, height: height * scale});
|
||||
}
|
||||
|
||||
function mount() {
|
||||
const next = $frame.get(0).contentDocument;
|
||||
if (!next?.body?.classList.contains('design-frame-editing') || next === doc) return;
|
||||
doc = next;
|
||||
parts = new Map($(doc).find('[data-layout-component]').map((_, node) => [[node.dataset.layoutComponent, node]]).get());
|
||||
host = part('brand').parentElement;
|
||||
const $doc = $(doc);
|
||||
|
||||
$doc.find('[data-layout-text]').each(function () {
|
||||
const name = this.dataset.layoutText;
|
||||
const input = field(name).get(0);
|
||||
this.textContent = input.value;
|
||||
setInlineText(this, input.closest('label').firstChild.textContent.trim(), placeholder[name]);
|
||||
});
|
||||
$doc.on('click auxclick', 'a', (event) => event.preventDefault());
|
||||
$doc.on('click focusin', '[data-layout-component]', function () {
|
||||
selectComponent(this.dataset.layoutComponent);
|
||||
});
|
||||
$doc.on('click', '[data-layout-add-in-canvas]', () => {
|
||||
selectComponent('links');
|
||||
addLink();
|
||||
});
|
||||
$doc.on('beforeinput', '[data-layout-text], [data-layout-link-text]', function (event) {
|
||||
if (this.dataset.layoutText !== 'text' && ['insertParagraph', 'insertLineBreak'].includes(event.originalEvent?.inputType)) {
|
||||
event.preventDefault();
|
||||
}
|
||||
});
|
||||
$doc.on('paste drop', '[data-layout-text], [data-layout-link-text]', function (event) {
|
||||
event.preventDefault();
|
||||
if (event.type !== 'paste') return;
|
||||
const text = event.originalEvent.clipboardData.getData('text/plain');
|
||||
doc.execCommand('insertText', false, this.dataset.layoutText === 'text' ? text : text.replace(/\s*\r?\n\s*/g, ' '));
|
||||
});
|
||||
$doc.on('input', '[data-layout-text]', function () {
|
||||
field(this.dataset.layoutText).val(this.innerText);
|
||||
if (this.dataset.layoutText === 'brand') syncBrand();
|
||||
});
|
||||
$doc.on('input', '[data-layout-link-text]', function () {
|
||||
const index = Number(this.dataset.layoutLinkText);
|
||||
links[index][1] = this.innerText;
|
||||
$rows.children().eq(index).find('[data-layout-link-field="1"]').val(this.innerText);
|
||||
updateLinkInput();
|
||||
});
|
||||
|
||||
$form.find('[data-layout-workspace], [data-layout-link-editor], [data-layout-select]').prop('hidden', false);
|
||||
$form.find('[data-layout-viewport]').attr('aria-pressed', 'false')
|
||||
.filter('[data-layout-viewport="' + (phone ? 'phone' : 'desktop') + '"]').attr('aria-pressed', 'true');
|
||||
$form.find('[data-layout-legacy-links]').prop('hidden', true).find(':input').prop('disabled', true);
|
||||
$linkInput.prop('disabled', false);
|
||||
const initialField = $form.find('[data-field-error]:not([hidden])').closest('[data-layout-panel]').attr('data-layout-panel');
|
||||
selectComponent(initialField || 'brand');
|
||||
syncLayers();
|
||||
syncBrand();
|
||||
syncButton();
|
||||
syncAccount();
|
||||
rebuildLinks();
|
||||
observer?.disconnect();
|
||||
if ('ResizeObserver' in window) {
|
||||
observer = new ResizeObserver(syncFrameSize);
|
||||
observer.observe(doc.body);
|
||||
observer.observe($stage.get(0));
|
||||
}
|
||||
}
|
||||
|
||||
function syncButton() {
|
||||
const button = part('action');
|
||||
if (!button) return;
|
||||
button.classList.remove(...Object.values(buttonStyles));
|
||||
button.classList.add(buttonStyles[field('action_style').val()] || buttonStyles.outline);
|
||||
}
|
||||
|
||||
function syncAccount() {
|
||||
const account = part('account');
|
||||
if (account) account.textContent = field('provider_mode').val() ? '登录' : '配置登录';
|
||||
}
|
||||
|
||||
$frame.on('load', mount);
|
||||
$presets.on('change', () => { if (doc) syncLayers(); });
|
||||
$list.on('change', 'input', function () {
|
||||
if (!doc) return;
|
||||
syncLayers();
|
||||
if (this.checked) selectComponent(this.value);
|
||||
}).on('layout:order', () => { if (doc) syncLayers(); })
|
||||
.on('click', '[data-layout-select]', function () { selectComponent(this.dataset.layoutSelect); });
|
||||
$form.on('click', '[data-layout-viewport]', function () {
|
||||
$form.find('[data-layout-viewport]').attr('aria-pressed', 'false');
|
||||
$(this).attr('aria-pressed', 'true');
|
||||
phone = this.dataset.layoutViewport === 'phone';
|
||||
syncFrameSize();
|
||||
}).on('input', '[name=brand], [name=action_label], [name=text], [name=legal]', function () {
|
||||
if (!doc) return;
|
||||
$(doc).find('[data-layout-text="' + this.name + '"]').text(this.value);
|
||||
if (this.name === 'brand') syncBrand();
|
||||
}).on('input', '[name=logo]', () => { if (doc) syncBrand(); })
|
||||
.on('change', '[name=action_style]', () => { if (doc) syncButton(); })
|
||||
.on('change', '[name=provider_mode]', () => { if (doc) syncAccount(); })
|
||||
.on('click', '[data-layout-link-add]', addLink)
|
||||
.on('studio:invalid', (_event, name) => {
|
||||
if (!doc) return;
|
||||
const $panel = $form.find('[data-field-error]').filter((_, node) => node.dataset.fieldError === name)
|
||||
.closest('[data-layout-panel]');
|
||||
if ($panel.length) selectComponent($panel.attr('data-layout-panel'));
|
||||
});
|
||||
|
||||
$rows.on('input', '[data-layout-link-field]', function () {
|
||||
const index = Number(this.closest('[data-layout-link-index]').dataset.layoutLinkIndex);
|
||||
const column = Number(this.dataset.layoutLinkField);
|
||||
links[index][column] = this.value;
|
||||
if (column === 1) part('links').children[index].textContent = this.value;
|
||||
updateLinkInput();
|
||||
}).on('click', '[data-layout-link-remove]', function () {
|
||||
links.splice(Number(this.closest('[data-layout-link-index]').dataset.layoutLinkIndex), 1);
|
||||
rebuildLinks();
|
||||
$form.find('[data-layout-link-add]').trigger('focus');
|
||||
}).on('click', '[data-layout-link-move]', function () {
|
||||
const index = Number(this.closest('[data-layout-link-index]').dataset.layoutLinkIndex);
|
||||
const next = index + Number(this.dataset.layoutLinkMove);
|
||||
if (next < 0 || next >= links.length) return;
|
||||
[links[index], links[next]] = [links[next], links[index]];
|
||||
rebuildLinks();
|
||||
$rows.children().eq(next).find('[data-layout-link-field="1"]').trigger('focus');
|
||||
});
|
||||
mount();
|
||||
});
|
||||
});
|
||||
@@ -643,3 +643,9 @@ progress { width: 100%; height: .8rem; accent-color: var(--accent); }
|
||||
.masthead .masthead-action { display: inline-flex; min-height: 40px; padding: .45rem .7rem; }
|
||||
.masthead .site-account { margin-inline-start: 0; }
|
||||
}
|
||||
|
||||
.layout-thumbnail { display: grid; align-content: center; min-height: 100vh; background: var(--paper); }
|
||||
.layout-thumbnail .masthead { position: static; }
|
||||
.layout-thumbnail .masthead .primary-nav { width: auto; order: 0; }
|
||||
.studio-layout-block { margin: 0; }
|
||||
.studio-layout-empty { padding-block: 3rem; text-align: center; }
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
'use strict';
|
||||
|
||||
jQuery(function ($) {
|
||||
const $toggle = $('.menu-toggle');
|
||||
const $nav = $('.primary-nav');
|
||||
if ($toggle.length && $nav.length) {
|
||||
$('.menu-toggle[aria-controls]').each(function () {
|
||||
const $toggle = $(this);
|
||||
const $nav = $(document.getElementById(this.getAttribute('aria-controls')));
|
||||
if (!$nav.hasClass('primary-nav')) return;
|
||||
$toggle.prop('hidden', false);
|
||||
$nav.addClass('has-toggle');
|
||||
|
||||
@@ -20,7 +21,7 @@ jQuery(function ($) {
|
||||
$toggle.trigger('focus');
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
$('[data-article-tabs]').each(function () {
|
||||
const $feed = $(this);
|
||||
|
||||
+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