forked from laysense/laysense.cn
Add visual CMS, media library and product directory
This commit is contained in:
@@ -53,3 +53,40 @@
|
||||
.password-form { max-width: 37rem; }
|
||||
.admin-form button:disabled, .admin-bar button:disabled { cursor: progress; opacity: .65; }
|
||||
.admin-form .ajax-feedback { margin: 0; }
|
||||
|
||||
.studio-layout { display: grid; grid-template-columns: minmax(0, 1.7fr) minmax(16rem, 1fr); gap: 1rem; align-items: start; }
|
||||
.studio-frame-window { position: relative; height: min(67vh, 39rem); overflow: hidden; margin-bottom: .8rem; border: 1px solid var(--line); border-radius: .55rem; background: var(--paper); }
|
||||
.studio-frame-window iframe { display: block; width: 100%; height: 100%; border: 0; background: white; }
|
||||
.studio-frame-window.has-scaled-preview iframe { position: absolute; top: 0; transform-origin: 0 0; }
|
||||
.preview-selector { display: flex; gap: .35rem; flex-wrap: wrap; }
|
||||
.preview-selector [aria-pressed="true"] { background: var(--accent-light); color: var(--accent-deep); }
|
||||
.studio-inspector details label { margin-top: .7rem; }
|
||||
.studio-blocks form, .studio-block-actions { display: flex; align-items: center; flex-wrap: wrap; gap: .32rem; }
|
||||
.studio-blocks .button { padding-inline: .65rem; }
|
||||
.studio-block-add { margin-top: 1.25rem; }
|
||||
.studio-rich { min-height: 15rem; max-width: 100%; overflow-x: auto; padding: 1rem; background: #fff; border: 1px solid var(--line); border-radius: .55rem; }
|
||||
.studio-rich:focus { outline: 2px solid var(--accent); outline-offset: 2px; }
|
||||
.studio-rich details { margin-bottom: .5rem; }
|
||||
.studio-rich img, .studio-rich video { max-width: 100%; height: auto; }
|
||||
.asset-field { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: end; gap: .55rem; }
|
||||
.settings-form { max-width: 54rem; }
|
||||
.media-grid, .picker-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(10rem, 1fr)); gap: .8rem; }
|
||||
.media-card, .picker-item { min-width: 0; border: 1px solid var(--line); border-radius: .65rem; background: white; padding: .75rem; overflow-wrap: anywhere; }
|
||||
.media-card > img, .picker-item img, .media-file-type { height: 6rem; width: 100%; object-fit: contain; background: var(--paper); border-radius: .45rem; margin-bottom: .7rem; }
|
||||
.media-card .media-file-type { display: grid; place-items: center; font-size: 1.1rem; text-transform: uppercase; }
|
||||
.media-card h3 { font-size: 1rem; margin-bottom: 0; }
|
||||
.media-card small { color: var(--muted); }
|
||||
.media-card .actions { margin: .45rem 0; }
|
||||
.media-card .button { padding-inline: .55rem; }
|
||||
.media-card .media-archive { display: flex; align-items: center; }
|
||||
.media-card .media-archive input { width: auto; min-height: 0; }
|
||||
.media-picker { max-width: min(92vw, 52rem); max-height: 86vh; width: 100%; padding: 1.25rem; border: 1px solid var(--line); border-radius: var(--radius); color: var(--ink); }
|
||||
.media-picker::backdrop { background: #101c3488; }
|
||||
.media-picker label { display: grid; gap: .35rem; }
|
||||
.media-picker input { padding: .55rem .75rem; border: 1px solid var(--line); border-radius: .4rem; }
|
||||
.picker-grid { max-height: 50vh; overflow: auto; padding: .25rem; }
|
||||
.picker-item { text-align: left; min-height: 44px; }
|
||||
.picker-item:hover { border-color: var(--accent); }
|
||||
@media (max-width: 65rem) {
|
||||
.studio-layout { grid-template-columns: minmax(0, 1fr); }
|
||||
}
|
||||
|
||||
+15
-3
@@ -41,9 +41,12 @@ jQuery(function ($) {
|
||||
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;
|
||||
const action = $form.attr('action');
|
||||
const isLogin = action === '/admin/login';
|
||||
const $submit = $form.find(':submit');
|
||||
const $submit = $form.find(':submit:enabled');
|
||||
const multipart = $form.attr('enctype') === 'multipart/form-data';
|
||||
$form.attr('aria-busy', 'true').children('.ajax-feedback').prop('hidden', true);
|
||||
$submit.prop('disabled', true);
|
||||
|
||||
@@ -53,10 +56,18 @@ jQuery(function ($) {
|
||||
}
|
||||
|
||||
function submit(canRetryLogin) {
|
||||
$form.triggerHandler('studio:sync');
|
||||
const fields = multipart ? new FormData($form.get(0)) : $form.serializeArray();
|
||||
if (submitter?.name) {
|
||||
if (multipart) fields.append(submitter.name, submitter.value);
|
||||
else fields.push({name: submitter.name, value: submitter.value});
|
||||
}
|
||||
$.ajax({
|
||||
url: action,
|
||||
method: 'POST',
|
||||
data: $form.serialize(),
|
||||
data: fields,
|
||||
processData: !multipart,
|
||||
contentType: multipart ? false : 'application/x-www-form-urlencoded; charset=UTF-8',
|
||||
dataType: 'json'
|
||||
}).done(function (response) {
|
||||
if (response.redirect) {
|
||||
@@ -82,6 +93,7 @@ jQuery(function ($) {
|
||||
|
||||
$('[data-editor]').each(function () {
|
||||
const $editor = $(this);
|
||||
if ($editor.find('[data-rich-canvas]').length) return;
|
||||
const area = $editor.find('textarea').get(0);
|
||||
const format = $editor.data('format');
|
||||
const $preview = $editor.find('.editor-preview');
|
||||
@@ -116,7 +128,7 @@ jQuery(function ($) {
|
||||
if (status === 'abort') return;
|
||||
let feedback = request.responseJSON;
|
||||
if (!feedback && request.getResponseHeader('Content-Type')?.startsWith('application/json')) {
|
||||
feedback = JSON.parse(request.responseText);
|
||||
try { feedback = JSON.parse(request.responseText); } catch { /* Use the fallback feedback. */ }
|
||||
}
|
||||
refreshToken(feedback);
|
||||
$preview.text(feedback?.message || '预览无法加载,请重试。');
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 72 72" width="72" height="72">
|
||||
<rect width="72" height="72" rx="19" fill="#e6f5f1"/>
|
||||
<rect x="16.5" y="20.5" width="39" height="31" rx="5" fill="#bfe4da" stroke="#0c775f" stroke-width="2.5"/>
|
||||
<path d="m30 31-6 5 6 5m12-10 6 5-6 5m-4-12-4 14" fill="none" stroke="#0c775f" stroke-linecap="round" stroke-linejoin="round" stroke-width="2.5"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 405 B |
@@ -0,0 +1,5 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 72 72" width="72" height="72">
|
||||
<rect width="72" height="72" rx="19" fill="#e8efff"/>
|
||||
<path d="M18 26a4 4 0 0 1 4-4h12l5 5h12a4 4 0 0 1 4 4v16a5 5 0 0 1-5 5H23a5 5 0 0 1-5-5Z" fill="#c5d7ff" stroke="#214ed7" stroke-width="2.5" stroke-linejoin="round"/>
|
||||
<path d="m29 39 5 5 10-10" fill="none" stroke="#214ed7" stroke-linecap="round" stroke-linejoin="round" stroke-width="3"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 440 B |
@@ -0,0 +1,5 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 72 72" width="72" height="72">
|
||||
<rect width="72" height="72" rx="19" fill="#fff1e0"/>
|
||||
<path d="M36 18c5 5 12 7 17 8v10c0 9-8 15-17 19-9-4-17-10-17-19V26c5-1 12-3 17-8Z" fill="#ffdab0" stroke="#a85410" stroke-linejoin="round" stroke-width="2.5"/>
|
||||
<path d="m29 36 5 5 9-10" fill="none" stroke="#a85410" stroke-linecap="round" stroke-linejoin="round" stroke-width="3"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 432 B |
@@ -371,3 +371,74 @@ progress { width: 100%; height: .8rem; accent-color: var(--accent); }
|
||||
|
||||
.payment-methods { display: flex; gap: .65rem; align-items: center; margin-block: .5rem; }
|
||||
.payment-methods img { width: 1.625rem; height: 1.625rem; object-fit: contain; }
|
||||
|
||||
.hero-inner.hero-text-only { grid-template-columns: minmax(0, 1fr); min-height: 28rem; }
|
||||
.hero-directory > .directory-label { border-inline-start: 0; }
|
||||
.catalog-hero { background: var(--paper); padding-block: clamp(3rem, 6vw, 6rem); }
|
||||
.catalog-hero h1 { margin-bottom: .85rem; }
|
||||
.catalog-hero p { margin: 0; font-size: 1.15rem; }
|
||||
.catalog-listing { padding-block: clamp(3rem, 6vw, 6rem); }
|
||||
.catalog-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: clamp(1rem, 3vw, 2rem); }
|
||||
.catalog-card { min-width: 0; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; display: flex; flex-direction: column; }
|
||||
.catalog-image { aspect-ratio: 16 / 8; padding: clamp(.8rem, 3vw, 1.8rem); background: var(--paper); display: grid; place-items: center; }
|
||||
.catalog-image img { max-height: 100%; width: 100%; height: 100%; object-fit: contain; }
|
||||
.catalog-content { padding: clamp(1.25rem, 3vw, 2rem); flex: 1; display: flex; flex-direction: column; }
|
||||
.catalog-content h2 { font-size: clamp(1.45rem, 3vw, 2.6rem); margin-bottom: .7rem; }
|
||||
.catalog-content .overline { margin-bottom: .4rem; }
|
||||
.catalog-content .actions { margin-top: auto; padding-top: 1rem; }
|
||||
|
||||
.copyright-service #materials .feature-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
|
||||
.copyright-service #why .choice-card { background: #e9f0ff; border-color: #7599ec; box-shadow: inset 0 3px var(--accent); }
|
||||
.copyright-service #why .choice-card h3 { color: var(--accent-deep); }
|
||||
.copyright-service #options .feature-card { display: flex; flex-direction: column; align-items: flex-start; }
|
||||
.copyright-service #options .feature-card > img { width: 3.6rem; height: 3.6rem; margin-bottom: .95rem; }
|
||||
.copyright-service #options .feature-card > a { margin-top: auto; }
|
||||
.copyright-service #faq .faq { max-width: none; }
|
||||
.copyright-service #faq summary { font-size: clamp(1.05rem, 1.35vw, 1.2rem); min-height: 3.75rem; }
|
||||
.copyright-service #faq details > div { max-width: 75ch; }
|
||||
.copyright-service #go { padding-block: clamp(2rem, 5vw, 4rem); background: var(--white); }
|
||||
.copyright-service #go > .wrap {
|
||||
position: relative;
|
||||
padding: clamp(1.5rem, 5vw, 4.5rem);
|
||||
padding-right: clamp(11rem, 29vw, 23rem);
|
||||
border-radius: var(--radius);
|
||||
background: radial-gradient(ellipse at 88% 110%, #264b9a 0, transparent 59%), #132443;
|
||||
color: var(--white);
|
||||
min-height: 16rem;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
}
|
||||
.copyright-service #go .section-heading { margin-bottom: .8rem; }
|
||||
.copyright-service #go h2 { font-size: clamp(1.8rem, 4vw, 3.5rem); }
|
||||
.copyright-service #go .contact-panel { display: block; }
|
||||
.copyright-service #go .contact-panel p { color: #d9e8ff; max-width: 40ch; }
|
||||
.copyright-service #go .contact-panel img {
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
right: clamp(1.5rem, 6vw, 6rem);
|
||||
transform: translateY(-50%);
|
||||
width: clamp(8rem, 13vw, 12rem);
|
||||
padding: .5rem;
|
||||
border: 0;
|
||||
border-radius: .85rem;
|
||||
background: white;
|
||||
}
|
||||
.copyright-service #go .button { color: #142956; background: #eef4ff; border-color: #eef4ff; }
|
||||
.copyright-service #terms { padding-block: 1.4rem 2.5rem; border-top: 0; }
|
||||
.copyright-service #terms .section-heading { margin-bottom: .35rem; }
|
||||
.copyright-service #terms h2 { font-size: .95rem; letter-spacing: 0; }
|
||||
.copyright-service #terms .rich { font-size: .875rem; color: var(--muted); }
|
||||
|
||||
@media (max-width: 62rem) {
|
||||
.copyright-service #materials .feature-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
|
||||
}
|
||||
@media (max-width: 44rem) {
|
||||
.catalog-grid, .copyright-service #materials .feature-grid { grid-template-columns: 1fr; }
|
||||
.hero-directory > .directory-label { grid-column: 1 / -1; border-top: 0; }
|
||||
.copyright-service #go > .wrap { padding: 1.55rem; min-height: 0; }
|
||||
.copyright-service #go .contact-panel { display: flex; gap: 1rem; }
|
||||
.copyright-service #go .contact-panel img { position: static; transform: none; width: 7rem; }
|
||||
}
|
||||
.hero h1 .hero-heading-primary { color: inherit; }
|
||||
[data-studio-field][contenteditable] { min-height: 1em; outline: 1px dashed #7896d5; outline-offset: 3px; }
|
||||
|
||||
@@ -0,0 +1,259 @@
|
||||
'use strict';
|
||||
|
||||
jQuery(function ($) {
|
||||
const $picker = $('#media-picker');
|
||||
const $pickerItems = $picker.find('[data-picker-items]');
|
||||
const $pickerStatus = $picker.find('[data-picker-status]');
|
||||
let pick = null;
|
||||
let files = [];
|
||||
let mediaType = '';
|
||||
let pickerRequest;
|
||||
|
||||
function renderPicker() {
|
||||
const query = String($picker.find('[data-media-query]').val() || '').trim().toLowerCase();
|
||||
const results = files.filter((file) => file.mime.startsWith(mediaType)
|
||||
&& (file.label + ' ' + file.url).toLowerCase().includes(query));
|
||||
$pickerStatus.text(results.length ? results.length + ' 个资源' : '没有匹配资源。');
|
||||
$pickerItems.empty();
|
||||
for (const file of results) {
|
||||
const $item = $('<button>', {type: 'button', class: 'picker-item'}).data('file', file);
|
||||
if (file.mime.startsWith('image/')) {
|
||||
$item.append($('<img>', {src: file.url, alt: '', loading: 'lazy'}));
|
||||
}
|
||||
$item.append($('<span>').text(file.label));
|
||||
$pickerItems.append($item);
|
||||
}
|
||||
}
|
||||
|
||||
function openPicker(type, callback) {
|
||||
if (!$picker.length || typeof $picker.get(0).showModal !== 'function') return;
|
||||
pick = callback;
|
||||
mediaType = type;
|
||||
$picker.find('[data-media-query]').val('');
|
||||
$pickerItems.empty();
|
||||
$pickerStatus.text('加载资源…');
|
||||
$picker.get(0).showModal();
|
||||
pickerRequest?.abort();
|
||||
pickerRequest = $.getJSON('/admin/media/options').done(function (response) {
|
||||
files = response.files;
|
||||
renderPicker();
|
||||
}).fail(function (_request, status) {
|
||||
if (status !== 'abort') $pickerStatus.text('媒体库暂时无法打开。');
|
||||
});
|
||||
}
|
||||
|
||||
$picker.on('input', '[data-media-query]', renderPicker);
|
||||
$picker.on('click', '[data-close-picker]', () => $picker.get(0).close());
|
||||
$picker.on('click', '.picker-item', function () {
|
||||
const file = $(this).data('file');
|
||||
$picker.get(0).close();
|
||||
pick?.(file);
|
||||
});
|
||||
|
||||
$('[data-asset-pick]').on('click', function () {
|
||||
const $button = $(this);
|
||||
const name = $button.data('asset-pick');
|
||||
const $input = $button.closest('form').find('input').filter((_, field) => field.name === name);
|
||||
openPicker($button.data('asset-type') || '', (file) => $input.val(file.url).trigger('input').trigger('focus'));
|
||||
});
|
||||
|
||||
$('[data-copy-asset]').on('click', function () {
|
||||
const $button = $(this);
|
||||
const url = $button.data('copy-asset');
|
||||
if (!navigator.clipboard) {
|
||||
window.prompt('复制资源路径', url);
|
||||
return;
|
||||
}
|
||||
navigator.clipboard.writeText(url).then(() => $button.text('已复制')).catch(() => window.prompt('复制资源路径', url));
|
||||
});
|
||||
|
||||
$('[data-media-library]').each(function () {
|
||||
const $library = $(this);
|
||||
const $cards = $library.find('[data-library-card]');
|
||||
function filter() {
|
||||
const query = String($library.find('[data-library-query]').val()).trim().toLowerCase();
|
||||
const category = $library.find('[data-library-type]').val();
|
||||
let count = 0;
|
||||
$cards.each(function () {
|
||||
const $card = $(this);
|
||||
const mime = $card.data('mime');
|
||||
const matchesType = category === 'other' ? !/^(image|audio|video)\//.test(mime) : mime.startsWith(category);
|
||||
const visible = matchesType && $card.data('search').toLowerCase().includes(query);
|
||||
$card.prop('hidden', !visible);
|
||||
if (visible) count++;
|
||||
});
|
||||
$library.find('[data-library-count]').text(count + ' 个资源');
|
||||
}
|
||||
$library.on('input change', '[data-library-query], [data-library-type]', filter);
|
||||
filter();
|
||||
});
|
||||
|
||||
$('[data-preview-studio]').each(function () {
|
||||
const $studio = $(this);
|
||||
const $frame = $studio.find('iframe');
|
||||
const $window = $studio.find('.studio-frame-window');
|
||||
function fitPreview() {
|
||||
const width = $window.width();
|
||||
const height = $window.height();
|
||||
if (!width || !height) return;
|
||||
const viewport = $studio.hasClass('studio-phone') ? 390 : 1280;
|
||||
const scale = Math.min(1, width / viewport);
|
||||
$window.addClass('has-scaled-preview');
|
||||
$frame.css({
|
||||
width: viewport,
|
||||
height: height / scale,
|
||||
left: (width - viewport * scale) / 2,
|
||||
transform: 'scale(' + scale + ')'
|
||||
});
|
||||
}
|
||||
if ('ResizeObserver' in window) {
|
||||
new ResizeObserver(fitPreview).observe($window.get(0));
|
||||
} else {
|
||||
$(window).on('resize', fitPreview);
|
||||
}
|
||||
fitPreview();
|
||||
const $settings = $studio.closest('.studio-layout').find('.studio-inspector');
|
||||
$studio.on('click', '[data-preview-size]', function () {
|
||||
const $button = $(this);
|
||||
$studio.toggleClass('studio-phone', $button.data('preview-size') === 'phone');
|
||||
$studio.find('[data-preview-size]').attr('aria-pressed', 'false');
|
||||
$button.attr('aria-pressed', 'true');
|
||||
fitPreview();
|
||||
});
|
||||
function attachCanvas() {
|
||||
const $doc = $frame.contents();
|
||||
for (const field of ['heading', 'lead']) {
|
||||
const $target = $doc.find('[data-studio-field="' + field + '"]');
|
||||
const $input = $settings.find('[name="' + field + '"]');
|
||||
$target.text($input.val());
|
||||
$target.attr({contenteditable: 'plaintext-only', spellcheck: 'false', 'aria-label': field === 'heading' ? '编辑首屏标题' : '编辑首屏简介'});
|
||||
$target.on('input.studio', () => $input.val($target.text()));
|
||||
$input.off('input.studio').on('input.studio', () => $target.text($input.val()));
|
||||
}
|
||||
$doc.on('click.studio', 'a', (event) => event.preventDefault());
|
||||
}
|
||||
$frame.on('load', attachCanvas);
|
||||
if ($frame.contents().find('[data-studio-field]').length) attachCanvas();
|
||||
});
|
||||
|
||||
$('[data-rich-canvas]').each(function () {
|
||||
const $canvas = $(this);
|
||||
const $editor = $canvas.closest('[data-editor]');
|
||||
const $area = $editor.find('textarea');
|
||||
const $form = $editor.closest('form');
|
||||
const $status = $editor.find('[data-rich-status]');
|
||||
const $visualButtons = $editor.find('[data-insert], [data-rich-media]');
|
||||
let savedRange;
|
||||
let source = false;
|
||||
$area.prop('hidden', true);
|
||||
$canvas.prop('hidden', false);
|
||||
$form.on('studio:sync', () => {
|
||||
if (!source) $area.val($canvas.html());
|
||||
});
|
||||
|
||||
function restoreRange() {
|
||||
const selection = window.getSelection();
|
||||
const root = $canvas.get(0);
|
||||
$canvas.trigger('focus');
|
||||
if (!savedRange || !root.contains(savedRange.commonAncestorContainer)) {
|
||||
savedRange = document.createRange();
|
||||
savedRange.selectNodeContents(root);
|
||||
savedRange.collapse(false);
|
||||
}
|
||||
selection.removeAllRanges();
|
||||
selection.addRange(savedRange);
|
||||
}
|
||||
|
||||
function edit(command, value) {
|
||||
restoreRange();
|
||||
document.execCommand(command, false, value);
|
||||
}
|
||||
|
||||
function safeLink(value) {
|
||||
return value && !/[\u0000-\u0020\\]/.test(value)
|
||||
&& (/^(https?:\/\/|mailto:|tel:|#\S)/i.test(value) || /^\/(?!\/)/.test(value));
|
||||
}
|
||||
|
||||
$canvas.on('click', 'a', (event) => event.preventDefault());
|
||||
$canvas.on('keyup mouseup focusout input', function () {
|
||||
const selection = window.getSelection();
|
||||
if (selection.rangeCount && this.contains(selection.anchorNode) && this.contains(selection.focusNode)) {
|
||||
savedRange = selection.getRangeAt(0).cloneRange();
|
||||
}
|
||||
});
|
||||
$canvas.on('paste', function (event) {
|
||||
event.preventDefault();
|
||||
document.execCommand('insertText', false, event.originalEvent.clipboardData.getData('text/plain'));
|
||||
});
|
||||
|
||||
$editor.on('mousedown', '[data-insert], [data-rich-media]', (event) => event.preventDefault());
|
||||
$editor.on('click', '[data-insert]', function () {
|
||||
const command = $(this).data('insert');
|
||||
if (command === 'link') {
|
||||
const href = window.prompt('输入链接地址', 'https://')?.trim();
|
||||
if (!href) return;
|
||||
if (!safeLink(href)) {
|
||||
$status.prop('hidden', false).text('请输入站内地址或有效的链接。');
|
||||
return;
|
||||
}
|
||||
restoreRange();
|
||||
const selection = window.getSelection();
|
||||
if (selection.isCollapsed) {
|
||||
edit('insertHTML', $('<a>', {href}).text(href).prop('outerHTML'));
|
||||
} else {
|
||||
edit('createLink', href);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (command === 'heading') edit('formatBlock', 'h3');
|
||||
if (command === 'bold') edit('bold');
|
||||
if (command === 'list') edit('insertUnorderedList');
|
||||
});
|
||||
|
||||
$editor.on('click', '[data-rich-media]', function () {
|
||||
openPicker('', (file) => {
|
||||
const mime = file.mime;
|
||||
let $node;
|
||||
if (mime.startsWith('image/')) {
|
||||
const alt = window.prompt('图片替代文本(装饰图可留空)', file.label);
|
||||
if (alt === null) return;
|
||||
$node = $('<img>', {src: file.url, alt, loading: 'lazy'});
|
||||
} else if (mime.startsWith('video/') || mime.startsWith('audio/')) {
|
||||
const tag = mime.startsWith('video/') ? '<video>' : '<audio>';
|
||||
$node = $(tag, {src: file.url, controls: true, preload: 'metadata'});
|
||||
} else {
|
||||
$node = $('<a>', {href: file.url}).text(file.label);
|
||||
}
|
||||
edit('insertHTML', $node.prop('outerHTML'));
|
||||
});
|
||||
});
|
||||
|
||||
$editor.on('click', '[data-source-toggle]', function () {
|
||||
const $button = $(this);
|
||||
if (!source) {
|
||||
$area.val($canvas.html()).prop('hidden', false).trigger('focus');
|
||||
$canvas.prop('hidden', true);
|
||||
$visualButtons.prop('disabled', true);
|
||||
$button.text('返回可视化').attr('aria-pressed', 'true');
|
||||
source = true;
|
||||
return;
|
||||
}
|
||||
$button.prop('disabled', true);
|
||||
$.ajax({
|
||||
url: '/admin/preview',
|
||||
method: 'POST',
|
||||
dataType: 'text',
|
||||
data: {csrf: $form.find('[name="csrf"]').val(), format: 'html', body: $area.val()}
|
||||
}).done(function (html) {
|
||||
$canvas.html(html).prop('hidden', false);
|
||||
$area.prop('hidden', true);
|
||||
$visualButtons.prop('disabled', false);
|
||||
$button.text('HTML 源码').attr('aria-pressed', 'false');
|
||||
$status.prop('hidden', true);
|
||||
savedRange = null;
|
||||
source = false;
|
||||
}).fail(() => $status.prop('hidden', false).text('源码暂时无法转换,当前编辑内容已保留。'))
|
||||
.always(() => $button.prop('disabled', false));
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user