Fix CMS login and restore PAGEPAN feature icons
@@ -49,3 +49,7 @@
|
||||
.form-grid { grid-template-columns: 1fr; }
|
||||
.admin-bar nav { gap: .3rem .85rem; }
|
||||
}
|
||||
|
||||
.password-form { max-width: 37rem; }
|
||||
.admin-form button:disabled, .admin-bar button:disabled { cursor: progress; opacity: .65; }
|
||||
.admin-form .ajax-feedback { margin: 0; }
|
||||
|
||||
@@ -1,30 +1,95 @@
|
||||
'use strict';
|
||||
|
||||
const formats = {
|
||||
markdown: {
|
||||
heading: ['## ', '', '小标题'],
|
||||
bold: ['**', '**', '粗体文字'],
|
||||
list: ['- ', '', '列表项'],
|
||||
link: ['[', '](https://)', '链接文字']
|
||||
},
|
||||
html: {
|
||||
heading: ['<h3>', '</h3>', '小标题'],
|
||||
bold: ['<strong>', '</strong>', '粗体文字'],
|
||||
list: ['<ul>\n <li>', '</li>\n</ul>', '列表项'],
|
||||
link: ['<a href="https://">', '</a>', '链接文字']
|
||||
jQuery(function ($) {
|
||||
const formats = {
|
||||
markdown: {
|
||||
heading: ['## ', '', '小标题'],
|
||||
bold: ['**', '**', '粗体文字'],
|
||||
list: ['- ', '', '列表项'],
|
||||
link: ['[', '](https://)', '链接文字']
|
||||
},
|
||||
html: {
|
||||
heading: ['<h3>', '</h3>', '小标题'],
|
||||
bold: ['<strong>', '</strong>', '粗体文字'],
|
||||
list: ['<ul>\n <li>', '</li>\n</ul>', '列表项'],
|
||||
link: ['<a href="https://">', '</a>', '链接文字']
|
||||
}
|
||||
};
|
||||
|
||||
function refreshToken(response) {
|
||||
if (response?.csrf) {
|
||||
$('input[name="csrf"]').val(response.csrf);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
for (const editor of document.querySelectorAll('[data-editor]')) {
|
||||
const area = editor.querySelector('textarea');
|
||||
const format = editor.dataset.format;
|
||||
const preview = editor.querySelector('.editor-preview');
|
||||
const previewButton = editor.querySelector('[data-preview-button]');
|
||||
const form = editor.closest('form');
|
||||
function formError($form, message, status) {
|
||||
let $feedback = $form.children('.ajax-feedback');
|
||||
if (!$feedback.length) {
|
||||
$feedback = $('<p>', {class: 'ajax-feedback feedback error', role: 'alert', tabindex: -1})
|
||||
.prependTo($form);
|
||||
}
|
||||
$feedback.text(message);
|
||||
if (status === 401) {
|
||||
$feedback.append(' ', $('<a>', {
|
||||
href: '/admin/login', target: '_blank', rel: 'noopener', text: '打开登录页'
|
||||
}));
|
||||
}
|
||||
$feedback.prop('hidden', false).trigger('focus');
|
||||
}
|
||||
|
||||
for (const button of editor.querySelectorAll('[data-insert]')) {
|
||||
button.addEventListener('click', () => {
|
||||
const [before, after, example] = formats[format][button.dataset.insert];
|
||||
$('form[method="post"]').on('submit', function (event) {
|
||||
event.preventDefault();
|
||||
const $form = $(this);
|
||||
if ($form.attr('aria-busy') === 'true') return;
|
||||
const action = $form.attr('action');
|
||||
const isLogin = action === '/admin/login';
|
||||
const $submit = $form.find(':submit');
|
||||
$form.attr('aria-busy', 'true').children('.ajax-feedback').prop('hidden', true);
|
||||
$submit.prop('disabled', true);
|
||||
|
||||
function finish() {
|
||||
$form.removeAttr('aria-busy');
|
||||
$submit.prop('disabled', false);
|
||||
}
|
||||
|
||||
function submit(canRetryLogin) {
|
||||
$.ajax({
|
||||
url: action,
|
||||
method: 'POST',
|
||||
data: $form.serialize(),
|
||||
dataType: 'json'
|
||||
}).done(function (response) {
|
||||
if (response.redirect) {
|
||||
window.location.assign(response.redirect);
|
||||
return;
|
||||
}
|
||||
formError($form, '未收到保存结果,请刷新页面确认。');
|
||||
finish();
|
||||
}).fail(function (request) {
|
||||
const response = request.responseJSON;
|
||||
refreshToken(response);
|
||||
if (canRetryLogin && request.status === 403 && response?.csrf) {
|
||||
submit(false);
|
||||
return;
|
||||
}
|
||||
formError($form, response?.message || '请求未完成,请稍后重试。', request.status);
|
||||
finish();
|
||||
});
|
||||
}
|
||||
|
||||
submit(isLogin);
|
||||
});
|
||||
|
||||
$('[data-editor]').each(function () {
|
||||
const $editor = $(this);
|
||||
const area = $editor.find('textarea').get(0);
|
||||
const format = $editor.data('format');
|
||||
const $preview = $editor.find('.editor-preview');
|
||||
const $form = $editor.closest('form');
|
||||
let pendingPreview;
|
||||
|
||||
$editor.on('click', '[data-insert]', function () {
|
||||
const [before, after, example] = formats[format][$(this).data('insert')];
|
||||
const start = area.selectionStart;
|
||||
const end = area.selectionEnd;
|
||||
const selection = area.value.slice(start, end) || example;
|
||||
@@ -32,24 +97,30 @@ for (const editor of document.querySelectorAll('[data-editor]')) {
|
||||
area.focus();
|
||||
area.setSelectionRange(start + before.length, start + before.length + selection.length);
|
||||
});
|
||||
}
|
||||
|
||||
previewButton.addEventListener('click', async () => {
|
||||
const show = preview.hidden;
|
||||
preview.hidden = !show;
|
||||
previewButton.textContent = show ? '收起预览' : '预览正文';
|
||||
previewButton.setAttribute('aria-expanded', String(show));
|
||||
if (!show) return;
|
||||
$editor.on('click', '[data-preview-button]', function () {
|
||||
const $button = $(this);
|
||||
const show = $preview.prop('hidden');
|
||||
$preview.prop('hidden', !show);
|
||||
$button.text(show ? '收起预览' : '预览正文').attr('aria-expanded', String(show));
|
||||
pendingPreview?.abort();
|
||||
if (!show) return;
|
||||
|
||||
preview.textContent = '正在加载预览…';
|
||||
try {
|
||||
const body = new URLSearchParams({body: area.value, format, csrf: form.elements.csrf.value});
|
||||
const response = await fetch('/admin/preview', {method: 'POST', body, redirect: 'error'});
|
||||
if (!response.ok) throw new Error('Preview could not be loaded');
|
||||
const markup = await response.text();
|
||||
preview.innerHTML = markup;
|
||||
} catch {
|
||||
preview.textContent = '预览无法加载,请刷新后重试。';
|
||||
}
|
||||
$preview.text('正在加载预览…');
|
||||
pendingPreview = $.ajax({
|
||||
url: '/admin/preview',
|
||||
method: 'POST',
|
||||
data: {body: area.value, format, csrf: $form.find('input[name="csrf"]').val()},
|
||||
dataType: 'text'
|
||||
}).done((markup) => $preview.html(markup)).fail((request, status) => {
|
||||
if (status === 'abort') return;
|
||||
let feedback = request.responseJSON;
|
||||
if (!feedback && request.getResponseHeader('Content-Type')?.startsWith('application/json')) {
|
||||
feedback = JSON.parse(request.responseText);
|
||||
}
|
||||
refreshToken(feedback);
|
||||
$preview.text(feedback?.message || '预览无法加载,请重试。');
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
Copyright OpenJS Foundation and other contributors, https://openjsf.org/
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
"Software"), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
@@ -0,0 +1 @@
|
||||
<svg height="50" viewBox="0 0 1033 1024" width="50" xmlns="http://www.w3.org/2000/svg"><path d="M512 512m-499.2 0a499.2 499.2 0 1 0 998.4 0 499.2 499.2 0 1 0-998.4 0Z" fill="#1989FA" fill-opacity=".3"></path><path d="M13.4144 536.8832A507.4816 507.4816 0 0 1 12.8 512C12.8 236.288 236.288 12.8 512 12.8c134.464 0 256.512 53.1584 346.2656 139.6096-7.1936 13.1328-18.2528 22.8992-28.5696 31.7056-17.1392 14.656-21.12-14.6432-34.3808-62.9888s-113.792-20.736-113.792 0 90.2272 29.6064-2.5984 79.296c-27.84 14.8992-65.1136 16.2176-87.8464 27.648-12.1344 6.0928-6.528 44.1856-14.6176 59.3152-6.272 11.776-26.8288 2.4064-31.68 0-24.8192-12.288-7.8336-80.9472-27.1104-86.9632-26.3168-8.2304-50.2784 27.4304-50.2784 40.64 0 15.0656 22.464 94.72 0 151.0784-24.8832 62.4256-104.5504 120.7936-156.2624 110.2976-98.4064-19.968-122.4448-48.4608-143.7184-19.968-21.2864 28.4928 12.9664 94.976 37.5552 135.6544 24.576 40.6656 2.56 92.2624-24.5888 92.2624-36.544 0-79.7824-46.6816-102.8096-92.2624-11.4048-22.5664-32.7936-49.664-64.1536-81.2416z m466.3936 246.7456c55.8336-38.3232 121.7664-60.6976 185.28-38.3232 63.488 22.3616 85.376 158.2976 31.616 200.0256-53.76 41.728-106.112 14.1696-128.7296 0-22.6176-14.1824-155.9936 14.1696-177.984 0-21.9904-14.1824-45.824-44.0832-45.824-99.776 0-55.68 79.808-23.616 135.6416-61.9264z m-171.392-146.7136c12.288-25.4208 40.64 7.168 57.3056-39.68 16.6656-46.8736 31.616-56.6784 49.344-26.5984 17.7408 30.08 13.376 62.7968 0 82.5344-13.376 19.7248-12.7872 15.5008-48.768 15.5008-35.968 0-70.1952-6.336-57.8944-31.7568zM473.0112 435.2c13.0176 1.3824 19.52 5.824 19.52 13.3504 0 11.2768-9.7536 26.9056-9.7536 26.9056s-27.1616 15.2576-33.28 8.704c-6.0928-6.528 8.1664-22.272 8.1664-35.6096 0-8.896 5.12-13.3504 15.36-13.3504z m24.6016 206.3488c28.9536-16.0512 51.7632-18.6368 68.4032-7.744 24.96 16.3456 87.2448 28.9024 87.2448 36.4928v25.0368c-51.9296-2.9824-85.248-11.328-99.9424-25.0368-22.0416-20.5568-66.9312 9.0368-66.9312 0 0-6.016 3.7376-15.6032 11.2256-28.7488z" fill="#1989FA"></path></svg>
|
||||
|
After Width: | Height: | Size: 2.0 KiB |
|
After Width: | Height: | Size: 5.8 KiB |
@@ -0,0 +1 @@
|
||||
<svg height="50" viewBox="0 0 1024 1024" width="50" xmlns="http://www.w3.org/2000/svg"><path d="M109.312 228.736H765.44c30.208 0 54.72 24.512 54.72 54.656v468.16H54.656V283.392c0-30.144 24.512-54.656 54.656-54.656z" fill="#A4ADC5"></path><path d="M0 809.6m27.328 0l820.096 0q27.328 0 27.328 27.328l0 61.504q0 27.328-27.328 27.328l-820.096 0q-27.328 0-27.328-27.328l0-61.504q0-27.328 27.328-27.328Z" fill="#A4ADC5"></path><path d="M328 83.52m54.656 0l546.752 0q54.656 0 54.656 54.656l0 413.504q0 54.656-54.656 54.656l-546.752 0q-54.656 0-54.656-54.656l0-413.504q0-54.656 54.656-54.656Z" fill="#08153A"></path><path d="M536.96 244.16a25.6 25.6 0 0 1 4.224 32l-3.2 4.16-60.8 64.576 60.8 64.64a25.6 25.6 0 0 1 2.304 32.256l-3.392 3.904A25.6 25.6 0 0 1 504.64 448l-3.904-3.392-69.12-73.344a38.4 38.4 0 0 1-3.712-48l3.776-4.672 69.056-73.344a25.6 25.6 0 0 1 36.16-1.088zM775.168 244.16a25.6 25.6 0 0 0-4.224 32l3.2 4.16 60.8 64.576-60.8 64.64a25.6 25.6 0 0 0-2.368 32.256l3.392 3.904a25.6 25.6 0 0 0 32.256 2.304l3.968-3.392 69.056-73.344a38.4 38.4 0 0 0 3.712-48l-3.712-4.672-69.12-73.344a25.6 25.6 0 0 0-36.16-1.088zM677.952 243.712a25.6 25.6 0 0 1 47.04 19.648l-2.048 4.8-88.832 163.456a25.6 25.6 0 0 1-46.976-19.648l1.984-4.8 88.832-163.456z" fill="#FFFFFF"></path></svg>
|
||||
|
After Width: | Height: | Size: 1.2 KiB |
@@ -0,0 +1 @@
|
||||
<svg height="50" viewBox="0 0 1048 1024" width="50" xmlns="http://www.w3.org/2000/svg"><path d="M387.121951 636.878049m-387.121951 0a387.121951 387.121951 0 1 0 774.243902 0 387.121951 387.121951 0 1 0-774.243902 0Z" fill="#FFEFDB"></path><path d="M899.121951 574.439024v224.780488H249.756098V274.731707h212.292682l87.414635 69.931708V0h499.512195v574.439024H899.121951zM437.073171 324.682927H299.707317v424.585366h549.463415V424.585366H561.95122zM999.02439 49.95122H599.414634v324.682926h299.707317v149.853659h99.902439V49.95122z" fill="#040405"></path><path d="M674.341463 299.707317v-49.951219h249.756098v49.951219H674.341463z m0-149.853658h249.756098v49.951219H674.341463v-49.951219z" fill="#FF9E1F"></path></svg>
|
||||
|
After Width: | Height: | Size: 718 B |
@@ -0,0 +1 @@
|
||||
<svg height="50" viewBox="0 0 1024 1024" width="50" xmlns="http://www.w3.org/2000/svg"><path d="M572.4 584.1m-159.4 0a159.4 159.4 0 1 0 318.8 0 159.4 159.4 0 1 0-318.8 0Z" fill="#FF4C4D"></path><path d="M223.3 743.5l54.5-145.4h199.7l51.9 145.4h61.9L408.6 231.8l-6.8-19.7-41.5-0.6-199.3 532h62.3zM380 325l76.6 214.8h-157L380 325zM869.1 474.2c17 19.2 25.4 45.2 25.4 78v183.6H853v-48.1c-11.4 15.9-26.2 28.8-44.2 38.7-21.8 11.4-45.4 17.1-70.8 17.1-28.8 0-51.6-7.4-68.6-22.1-17.7-15.1-26.6-35.2-26.6-60.3 0-36.5 14.6-63.1 43.7-79.6 23.6-14 55.3-21 95.1-21l68.6-0.6v-9.4c0-47.9-24.9-71.9-74.7-71.9-23.2 0-41.3 4.8-54.2 14.4-14.4 10-23.2 24.7-26.5 44.2h-43.7c4.4-32.8 18.4-57.1 42-73 20.6-14.7 49-22.1 85.2-22.1 40.7 0 70.9 10.7 90.8 32.1z m-18.8 120.5l-65.8 0.6c-64.1 0-96.2 21.8-96.2 65.3 0 14 5.2 25.4 15.5 34.3 10.7 8.5 25.2 12.7 43.7 12.7 28.8 0 53.3-8.9 73.6-26.6 19.5-17.7 29.3-38.2 29.3-61.4v-24.9z"></path></svg>
|
||||
|
After Width: | Height: | Size: 915 B |
@@ -0,0 +1 @@
|
||||
<svg height="50" viewBox="0 0 1024 1024" width="50" xmlns="http://www.w3.org/2000/svg"><path d="M311.224 428.616V40.96C186.696 93.99 87.406 195.29 36.936 321.096l274.286 274.286 0.002-166.766z" fill="#AFE164"></path><path d="M428.616 311.22L702.904 36.936C643.84 13.164 579.474 0 512 0c-71.314 0-139.154 14.628-200.776 40.96v387.656L428.616 311.22z" fill="#D7E664"></path><path d="M983.04 311.22H595.384l117.394 117.396 274.286 274.286C1010.836 643.84 1024 579.474 1024 512c0-71.314-14.628-139.154-40.96-200.78z" fill="#FFAA64"></path><path d="M712.776 595.384V983.04c124.526-53.03 223.816-154.33 274.286-280.136L712.776 428.616v166.768z" fill="#FF6469"></path><path d="M595.384 712.776L321.096 987.064C380.16 1010.834 444.526 1024 512 1024c71.316 0 139.154-14.628 200.776-40.96V595.384L595.384 712.776z" fill="#C3B4FA"></path><path d="M428.616 712.776H40.96c53.03 124.526 154.33 223.816 280.136 274.286l274.286-274.286H428.616z" fill="#7DD2F0"></path><path d="M311.224 595.384L36.936 321.096C13.164 380.16 0 444.526 0 512c0 71.314 14.628 139.154 40.96 200.776h387.656L311.224 595.384z" fill="#7DE6C3"></path><path d="M595.384 311.22H983.04C930.01 186.696 828.71 87.404 702.904 36.936L428.616 311.22h166.768z" fill="#FFE669"></path></svg>
|
||||
|
After Width: | Height: | Size: 1.2 KiB |
@@ -0,0 +1 @@
|
||||
<svg height="50" viewBox="0 0 1024 1024" width="50" xmlns="http://www.w3.org/2000/svg"><path d="M891.2 948.8l-33.6-96H699.2l-33.6 96H564.8l153.6-403.2h115.2l153.6 403.2h-96zM780.8 632l-57.6 148.8h115.2L780.8 632zM526.4 780.8L569.6 680c-14.4-9.6-28.8-19.2-38.4-28.8 72-81.6 129.6-182.4 172.8-302.4h129.6v-96H468.8l72-24c-9.6-33.6-33.6-86.4-57.6-129.6l-105.6 33.6c19.2 38.4 38.4 86.4 48 120H70.4v96h134.4c43.2 120 105.6 220.8 177.6 302.4C296 718.4 185.6 766.4 56 800c19.2 24 48 72 62.4 96 134.4-38.4 249.6-96 340.8-172.8 19.2 19.2 43.2 38.4 67.2 57.6z m-220.8-432h288C560 440 512 516.8 454.4 584 392 516.8 339.2 440 305.6 348.8z"></path></svg>
|
||||
|
After Width: | Height: | Size: 642 B |
|
After Width: | Height: | Size: 6.0 KiB |
|
After Width: | Height: | Size: 5.0 KiB |
@@ -1,44 +1,39 @@
|
||||
'use strict';
|
||||
|
||||
const toggle = document.querySelector('.menu-toggle');
|
||||
const nav = document.querySelector('.primary-nav');
|
||||
if (toggle && nav) {
|
||||
toggle.hidden = false;
|
||||
nav.classList.add('has-toggle');
|
||||
jQuery(function ($) {
|
||||
const $toggle = $('.menu-toggle');
|
||||
const $nav = $('.primary-nav');
|
||||
if ($toggle.length && $nav.length) {
|
||||
$toggle.prop('hidden', false);
|
||||
$nav.addClass('has-toggle');
|
||||
|
||||
const closeMenu = () => {
|
||||
toggle.setAttribute('aria-expanded', 'false');
|
||||
nav.classList.remove('is-open');
|
||||
};
|
||||
const setMenu = (open) => {
|
||||
$toggle.attr('aria-expanded', String(open));
|
||||
$nav.toggleClass('is-open', open);
|
||||
};
|
||||
|
||||
toggle.addEventListener('click', () => {
|
||||
const open = toggle.getAttribute('aria-expanded') === 'true';
|
||||
if (open) {
|
||||
closeMenu();
|
||||
} else {
|
||||
toggle.setAttribute('aria-expanded', 'true');
|
||||
nav.classList.add('is-open');
|
||||
}
|
||||
});
|
||||
|
||||
nav.addEventListener('click', closeMenu);
|
||||
document.addEventListener('keydown', (event) => {
|
||||
if (event.key === 'Escape' && toggle.getAttribute('aria-expanded') === 'true') {
|
||||
closeMenu();
|
||||
toggle.focus();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if ('IntersectionObserver' in window && !matchMedia('(prefers-reduced-motion: reduce)').matches) {
|
||||
const observer = new IntersectionObserver((entries) => {
|
||||
for (const entry of entries) {
|
||||
if (entry.isIntersecting) {
|
||||
entry.target.classList.add('moment-active');
|
||||
observer.unobserve(entry.target);
|
||||
$toggle.on('click', () => setMenu($toggle.attr('aria-expanded') !== 'true'));
|
||||
$nav.on('click', 'a', () => setMenu(false));
|
||||
$(document).on('keydown', (event) => {
|
||||
if (event.key === 'Escape' && $toggle.attr('aria-expanded') === 'true') {
|
||||
setMenu(false);
|
||||
$toggle.trigger('focus');
|
||||
}
|
||||
}
|
||||
}, {threshold: 0.35});
|
||||
});
|
||||
}
|
||||
|
||||
document.querySelectorAll('[data-moment]').forEach((section) => observer.observe(section));
|
||||
}
|
||||
if ('IntersectionObserver' in window && !matchMedia('(prefers-reduced-motion: reduce)').matches) {
|
||||
const observer = new IntersectionObserver((entries) => {
|
||||
for (const entry of entries) {
|
||||
if (entry.isIntersecting) {
|
||||
$(entry.target).addClass('moment-active');
|
||||
observer.unobserve(entry.target);
|
||||
}
|
||||
}
|
||||
}, {threshold: 0.35});
|
||||
|
||||
$('[data-moment]').each(function () {
|
||||
observer.observe(this);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||