refactor(modal): remove legacy compatibility paths

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
kate522andClaude Fable 5 committed 2026-08-05 00:06:37 +08:00
1 parent bdfe3a461d
commit 34150f3358
18 files changed
+188 -380

No files matched your search

@@ -1,17 +1,17 @@
/**
* Remote modal + ajax list primitives (shared).
* Modal runtime + ajax list primitives (shared).
*
* @package AKSRT
*/
/* ---- scroll lock ---- */
html.aksrt-remote-modal-open,
body.aksrt-remote-modal-open {
html.aksrt-modal-runtime-open,
body.aksrt-modal-runtime-open {
overflow: hidden;
}
/* ---- remote modal shell ---- */
.aksrt-remote-modal {
/* ---- modal runtime shell ---- */
.aksrt-modal-runtime {
position: fixed;
inset: 0;
z-index: 100050;
@@ -24,20 +24,20 @@ body.aksrt-remote-modal-open {
pointer-events: none;
}
.aksrt-remote-modal.is-open {
.aksrt-modal-runtime.is-open {
opacity: 1;
visibility: visible;
pointer-events: auto;
}
.aksrt-remote-modal__overlay {
.aksrt-modal-runtime__overlay {
position: absolute;
inset: 0;
background: rgba(15, 18, 28, 0.48);
backdrop-filter: blur(2px);
}
.aksrt-remote-modal__dialog {
.aksrt-modal-runtime__dialog {
position: relative;
z-index: 1;
width: min(440px, calc(100vw - 32px));
@@ -51,15 +51,15 @@ body.aksrt-remote-modal-open {
color: var(--color-ink, #1f2937);
}
.aksrt-remote-modal.is-open .aksrt-remote-modal__dialog {
.aksrt-modal-runtime.is-open .aksrt-modal-runtime__dialog {
transform: translateY(0) scale(1);
}
.aksrt-remote-modal--bottom {
.aksrt-modal-runtime--bottom {
align-items: flex-end;
}
.aksrt-remote-modal--bottom .aksrt-remote-modal__dialog {
.aksrt-modal-runtime--bottom .aksrt-modal-runtime__dialog {
width: 100%;
max-width: 100%;
border-radius: 16px 16px 0 0;
@@ -67,11 +67,11 @@ body.aksrt-remote-modal-open {
transform: translateY(24px);
}
.aksrt-remote-modal--bottom.is-open .aksrt-remote-modal__dialog {
.aksrt-modal-runtime--bottom.is-open .aksrt-modal-runtime__dialog {
transform: translateY(0);
}
.aksrt-remote-modal__header {
.aksrt-modal-runtime__header {
display: flex;
align-items: center;
justify-content: space-between;
@@ -79,32 +79,32 @@ body.aksrt-remote-modal-open {
padding: 16px 18px 0;
}
.aksrt-remote-modal__title {
.aksrt-modal-runtime__title {
margin: 0;
font-size: 17px;
line-height: 1.35;
}
.aksrt-remote-modal__content {
.aksrt-modal-runtime__content {
padding: 18px 18px 16px;
}
.aksrt-remote-modal__loading,
.aksrt-remote-modal__error-body {
.aksrt-modal-runtime__loading,
.aksrt-modal-runtime__error-body {
padding: 28px 8px;
text-align: center;
color: var(--color-ink-2, #6b7280);
font-size: 14px;
}
.aksrt-remote-modal__skeleton {
.aksrt-modal-runtime__skeleton {
display: grid;
gap: 12px;
padding: 8px 2px;
}
.aksrt-remote-modal__skeleton-line,
.aksrt-remote-modal__skeleton-block {
.aksrt-modal-runtime__skeleton-line,
.aksrt-modal-runtime__skeleton-block {
display: block;
border-radius: 8px;
background: linear-gradient(90deg, rgba(148, 163, 184, 0.16), rgba(148, 163, 184, 0.3), rgba(148, 163, 184, 0.16));
@@ -112,26 +112,26 @@ body.aksrt-remote-modal-open {
animation: aksrt-modal-skeleton 1.2s ease-in-out infinite;
}
.aksrt-remote-modal__skeleton-line {
.aksrt-modal-runtime__skeleton-line {
width: 72%;
height: 12px;
}
.aksrt-remote-modal__skeleton-line.is-wide {
.aksrt-modal-runtime__skeleton-line.is-wide {
width: 92%;
height: 18px;
}
.aksrt-remote-modal__skeleton-line.is-short {
.aksrt-modal-runtime__skeleton-line.is-short {
width: 44%;
}
.aksrt-remote-modal__skeleton-block {
.aksrt-modal-runtime__skeleton-block {
width: 100%;
min-height: 84px;
}
.aksrt-remote-modal__retry {
.aksrt-modal-runtime__retry {
cursor: pointer;
}
@@ -140,8 +140,8 @@ body.aksrt-remote-modal-open {
100% { background-position: -100% 0; }
}
.aksrt-remote-modal .touch.border-title,
.aksrt-remote-modal .border-title {
.aksrt-modal-runtime .touch.border-title,
.aksrt-modal-runtime .border-title {
font-size: 16px;
font-weight: 700;
margin: 0 0 14px;
@@ -151,8 +151,7 @@ body.aksrt-remote-modal-open {
gap: 6px;
}
.aksrt-remote-modal .abs-close,
.aksrt-remote-modal .aksrt-remote-modal__close {
.aksrt-modal-runtime .aksrt-modal-runtime__close {
position: absolute;
top: 10px;
right: 10px;
@@ -167,17 +166,17 @@ body.aksrt-remote-modal-open {
line-height: 1;
}
.aksrt-remote-modal .but-average.modal-buts,
.aksrt-remote-modal .modal-buts {
.aksrt-modal-runtime .but-average.modal-buts,
.aksrt-modal-runtime .modal-buts {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 10px;
margin-top: 16px;
}
.aksrt-remote-modal .but-average.modal-buts .but,
.aksrt-remote-modal .modal-buts .but,
.aksrt-remote-modal .modal-buts button {
.aksrt-modal-runtime .but-average.modal-buts .but,
.aksrt-modal-runtime .modal-buts .but,
.aksrt-modal-runtime .modal-buts button {
min-height: 40px;
border-radius: 10px;
border: 1px solid var(--color-line, #e5e7eb);
@@ -187,9 +186,9 @@ body.aksrt-remote-modal-open {
cursor: pointer;
}
.aksrt-remote-modal .modal-buts .but.c-blue,
.aksrt-remote-modal .modal-buts button.c-blue,
.aksrt-remote-modal .modal-buts .btn-primary {
.aksrt-modal-runtime .modal-buts .but.c-blue,
.aksrt-modal-runtime .modal-buts button.c-blue,
.aksrt-modal-runtime .modal-buts .btn-primary {
background: var(--color-primary, #f04494);
border-color: color-mix(in srgb, var(--color-primary, #f04494) 70%, #000 0%);
color: var(--color-on-primary, #fff);
@@ -351,7 +350,7 @@ body.aksrt-remote-modal-open {
}
@media (max-width: 768px) {
.aksrt-remote-modal:not(.aksrt-remote-modal--bottom) .aksrt-remote-modal__dialog {
.aksrt-modal-runtime:not(.aksrt-modal-runtime--bottom) .aksrt-modal-runtime__dialog {
width: calc(100vw - 20px);
}
}
+9 -29
View File
@@ -2,26 +2,7 @@
* VIP pay modal + hover cards (zibll payvip-modal / vip-card).
*/
.aksrt-vip-modal-open {
overflow: hidden;
}
.aksrt-vip-modal-overlay {
position: fixed;
inset: 0;
z-index: 1200;
display: none;
align-items: center;
justify-content: center;
padding: 16px;
background: rgba(0, 0, 0, 0.5);
}
.aksrt-vip-modal-overlay.is-open {
display: flex;
}
.aksrt-vip-modal-dialog {
.aksrt-vip-modal-panel {
width: min(560px, 100%);
max-height: min(90vh, 760px);
overflow: auto;
@@ -31,11 +12,11 @@
}
/* VIP now uses the shared modal runtime host. */
.aksrt-remote-modal.aksrt-vip-modal-shell {
.aksrt-modal-runtime.aksrt-vip-modal-shell {
z-index: 1200;
}
.aksrt-remote-modal.aksrt-vip-modal-shell .aksrt-remote-modal__dialog {
.aksrt-modal-runtime.aksrt-vip-modal-shell .aksrt-modal-runtime__dialog {
width: min(560px, 100%);
max-height: min(90vh, 760px);
background: var(--main-bg-color, #fff);
@@ -43,7 +24,7 @@
box-shadow: 0 16px 48px rgba(0, 0, 0, 0.22);
}
.aksrt-remote-modal.aksrt-vip-modal-shell .aksrt-remote-modal__content {
.aksrt-modal-runtime.aksrt-vip-modal-shell .aksrt-modal-runtime__content {
padding: 0;
}
@@ -52,8 +33,7 @@
padding: 18px 16px 16px;
}
.payvip-modal .close,
.aksrt-vip-modal-close {
.aksrt-modal-close {
position: absolute;
top: 8px;
right: 12px;
@@ -121,7 +101,7 @@
/* Modal-only equity (admin HTML; no forced bullets) */
.payvip-modal .v-equity,
.aksrt-vip-modal-dialog .v-equity {
.aksrt-vip-modal-panel .v-equity {
display: block;
list-style: none;
margin: 8px 0 0;
@@ -130,7 +110,7 @@
line-height: 1.6;
}
.payvip-modal .v-equity > li,
.aksrt-vip-modal-dialog .v-equity > li {
.aksrt-vip-modal-panel .v-equity > li {
display: block;
margin: 0 0 6px;
padding: 0;
@@ -138,8 +118,8 @@
}
.payvip-modal .v-equity > li::before,
.payvip-modal .v-equity > li::after,
.aksrt-vip-modal-dialog .v-equity > li::before,
.aksrt-vip-modal-dialog .v-equity > li::after {
.aksrt-vip-modal-panel .v-equity > li::before,
.aksrt-vip-modal-panel .v-equity > li::after {
content: none !important;
display: none !important;
}
+1 -1
View File
@@ -166,7 +166,7 @@
font-size: 16px;
margin-bottom: 14px;
}
.aksrt-checkin-modal__head .aksrt-remote-modal__close {
.aksrt-checkin-modal__head .aksrt-modal-runtime__close {
margin-left: auto;
border: 0;
background: transparent;
+6 -64
View File
@@ -5,7 +5,6 @@
* aksrt.tbquire(deps, cb) — lazy script/CSS loader
* aksrt.notyf(msg, opts) — unified toast (same-ID update)
* aksrt.confirm(msg, opts) — i18n confirm dialog
* aksrt.refreshModal(opts) — remote content modal
* aksrt.scrollTopTo(target, off) — smart scroll with header offset
* aksrt.loading(el, show) — element-level loading overlay
* aksrt.Drawer(opts) — mobile fullscreen drawer + route
@@ -313,68 +312,6 @@
el.appendChild(mask);
};
// ══════════════════════════════════════════════════════════════
// §10.10 — refreshModal: remote content modal
// ══════════════════════════════════════════════════════════════
function closeRefreshModal() {
if (window.AksrtModalRuntime && typeof window.AksrtModalRuntime.close === 'function') {
window.AksrtModalRuntime.close('refresh-modal');
}
}
aksrt.refreshModal = function (opts) {
opts = opts || {};
var runtime = window.AksrtModalRuntime;
if (!runtime || typeof runtime.open !== 'function' || typeof runtime.openRemote !== 'function') {
return Promise.reject(new Error('modal runtime unavailable'));
}
var base = {
title: opts.title || '',
className: opts.class || '',
bottom: opts.mobile_from_bottom === true,
mobileBottom: opts.mobile_from_bottom === true,
cache: opts.cache !== false,
cacheTtl: opts.cacheTtl || 15000,
cacheTags: opts.cacheTags || opts.tags || [],
kind: opts.kind || 'generic',
};
if (opts.content !== undefined) {
return Promise.resolve(runtime.open(Object.assign({}, base, { html: opts.content })))
.catch(function () { return null; });
}
if (opts.remote) {
return runtime.openRemote(Object.assign({}, base, {
url: opts.remote,
method: opts.method || 'GET',
}));
}
if (opts.action) {
var ajaxUrl = (window.aksrtData && window.aksrtData.ajaxUrl) || '/wp-admin/admin-ajax.php';
var params = new URLSearchParams();
params.set('action', opts.action);
if (window.aksrtData && window.aksrtData.nonce) params.set('nonce', window.aksrtData.nonce);
if (opts.data) {
Object.keys(opts.data).forEach(function (key) { params.set(key, opts.data[key]); });
}
return runtime.openRemote(Object.assign({}, base, {
url: ajaxUrl,
method: 'POST',
cache: false,
headers: { 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8' },
body: params.toString(),
}));
}
return Promise.resolve(runtime.open(base));
};
aksrt.refreshModal.close = closeRefreshModal;
// ══════════════════════════════════════════════════════════════
// §10.11 — Drawer: mobile fullscreen slide-in + route
// ══════════════════════════════════════════════════════════════
@@ -707,7 +644,12 @@
btn.classList.remove('is-loading');
if (json && json.success) {
if (json.data && json.data.show_modal) {
aksrt.refreshModal({ content: json.data.show_modal, mobile_from_bottom: true });
window.AksrtModalRuntime.open({
html: json.data.show_modal,
bottom: true,
mobileBottom: true,
kind: 'generic',
});
} else if (json.data && json.data.message) {
aksrt.notyf(json.data.message, 'success');
}
+37 -64
View File
@@ -1,7 +1,7 @@
/**
* Canonical frontend modal runtime.
*
* Keeps the existing remote-modal shell while adding cancellable loaders,
* Owns the modal shell while adding cancellable loaders,
* short in-memory caching, request deduplication, retryable errors, focus
* restoration, and modal-scoped rehydration.
*
@@ -10,7 +10,7 @@
(function (window, document) {
"use strict";
var ROOT_ID = "aksrt-remote-modal-root";
var ROOT_ID = "aksrt-modal-runtime-root";
var active = null;
var sequence = 0;
var loaders = Object.create(null);
@@ -24,7 +24,7 @@
if (root) return root;
root = document.createElement("div");
root.id = ROOT_ID;
root.className = "aksrt-remote-modal-host";
root.className = "aksrt-modal-runtime-host";
document.body.appendChild(root);
return root;
}
@@ -39,31 +39,28 @@
}
function lockScroll(lock) {
document.documentElement.classList.toggle("aksrt-remote-modal-open", !!lock);
document.body.classList.toggle("aksrt-remote-modal-open", !!lock);
document.documentElement.classList.toggle("aksrt-modal-runtime-open", !!lock);
document.body.classList.toggle("aksrt-modal-runtime-open", !!lock);
}
function skeleton(options) {
return (options && options.skeleton) ||
'<div class="aksrt-remote-modal__skeleton" aria-live="polite" aria-busy="true">' +
'<span class="aksrt-remote-modal__skeleton-line is-wide"></span>' +
'<span class="aksrt-remote-modal__skeleton-line"></span>' +
'<span class="aksrt-remote-modal__skeleton-line is-short"></span>' +
'<span class="aksrt-remote-modal__skeleton-block"></span>' +
'<div class="aksrt-modal-runtime__skeleton" aria-live="polite" aria-busy="true">' +
'<span class="aksrt-modal-runtime__skeleton-line is-wide"></span>' +
'<span class="aksrt-modal-runtime__skeleton-line"></span>' +
'<span class="aksrt-modal-runtime__skeleton-line is-short"></span>' +
'<span class="aksrt-modal-runtime__skeleton-block"></span>' +
'</div>';
}
function telemetryStart(kind) {
if (kind === false) return "";
var telemetry = window.AksrtModalTelemetry;
if (!telemetry || typeof telemetry.start !== "function") return "";
return telemetry.start(kind || "unknown");
return window.AksrtModalTelemetry.start(kind || "generic");
}
function telemetryMark(session, event) {
var telemetry = window.AksrtModalTelemetry;
if (!session || !session.telemetryId || !telemetry || typeof telemetry.mark !== "function") return;
telemetry.mark(session.telemetryId, event);
if (!session || !session.telemetryId) return;
window.AksrtModalTelemetry.mark(session.telemetryId, event);
}
function setState(session, status, error) {
@@ -81,7 +78,7 @@
}
function closeSelector() {
return "[data-aksrt-remote-modal-close], [data-aksrt-modal-close], [data-dismiss='modal'], .aksrt-remote-modal__close, .aksrt-vip-modal-close, .payvip-modal .close";
return "[data-aksrt-modal-close], .aksrt-modal-runtime__close";
}
function bindChrome(session) {
@@ -93,11 +90,11 @@
close("control");
return;
}
if (event.target === shell || event.target.classList.contains("aksrt-remote-modal__overlay")) {
if (event.target === shell || event.target.classList.contains("aksrt-modal-runtime__overlay")) {
close("overlay");
return;
}
var retry = event.target.closest("[data-aksrt-remote-modal-retry], [data-aksrt-modal-retry]");
var retry = event.target.closest("[data-aksrt-modal-retry]");
if (retry) {
event.preventDefault();
refresh();
@@ -138,31 +135,29 @@
var initialHtml = options.html !== undefined ? options.html : skeleton(options);
var titleId = "aksrt-modal-title-" + String(sequence + 1);
var titleHtml = options.title
? '<header class="aksrt-remote-modal__header"><h3 class="aksrt-remote-modal__title" id="' + titleId + '">' + escapeHtml(options.title) + '</h3><button type="button" class="aksrt-remote-modal__close" data-aksrt-modal-close aria-label="关闭">&times;</button></header>'
? '<header class="aksrt-modal-runtime__header"><h3 class="aksrt-modal-runtime__title" id="' + titleId + '">' + escapeHtml(options.title) + '</h3><button type="button" class="aksrt-modal-runtime__close" data-aksrt-modal-close aria-label="关闭">&times;</button></header>'
: "";
shell.className =
"aksrt-remote-modal" +
(bottom ? " aksrt-remote-modal--bottom" : "") +
"aksrt-modal-runtime" +
(bottom ? " aksrt-modal-runtime--bottom" : "") +
(options.className ? " " + options.className : "");
shell.setAttribute("role", "dialog");
shell.setAttribute("aria-modal", "true");
if (options.title) shell.setAttribute("aria-labelledby", titleId);
shell.setAttribute("tabindex", "-1");
shell.innerHTML =
'<div class="aksrt-remote-modal__overlay" data-aksrt-remote-modal-close></div>' +
'<div class="aksrt-remote-modal__dialog" style="' + heightStyle + '">' +
'<div class="aksrt-modal-runtime__overlay" data-aksrt-modal-close></div>' +
'<div class="aksrt-modal-runtime__dialog" style="' + heightStyle + '">' +
titleHtml +
'<div class="aksrt-remote-modal__content">' + initialHtml + "</div></div>";
'<div class="aksrt-modal-runtime__content">' + initialHtml + "</div></div>";
var session = {
id: String(++sequence),
shell: shell,
content: shell.querySelector(".aksrt-remote-modal__content"),
content: shell.querySelector(".aksrt-modal-runtime__content"),
options: options,
state: window.AksrtModalState && typeof window.AksrtModalState.create === "function"
? window.AksrtModalState.create(options.kind || "generic")
: { status: "idle", error: null },
state: window.AksrtModalState.create(options.kind || "generic"),
focusReturn: document.activeElement,
controller: null,
flight: null,
@@ -184,9 +179,6 @@
(nodes.length ? nodes[0] : shell).focus();
} catch (error) {}
document.dispatchEvent(new CustomEvent("aksrt:remote-modal:open", {
detail: { shell: shell, options: options, session: session },
}));
document.dispatchEvent(new CustomEvent("aksrt:modal:open", {
detail: { shell: shell, options: options, session: session },
}));
@@ -203,9 +195,7 @@
function rehydrate(session) {
if (!session || !session.content) return;
if (window.AksrtFrontend && typeof window.AksrtFrontend.rehydrate === "function") {
window.AksrtFrontend.rehydrate(session.content, "modal");
}
window.AksrtFrontend.rehydrate(session.content, "modal");
}
function abortSessionRequest(session) {
@@ -226,9 +216,6 @@
if (!preserveRequest) abortSessionRequest(session);
session.shell.classList.remove("is-open");
if (!preserveRequest) lockScroll(false);
document.dispatchEvent(new CustomEvent("aksrt:remote-modal:close", {
detail: { shell: session.shell, reason: reason || "close", session: session },
}));
document.dispatchEvent(new CustomEvent("aksrt:modal:close", {
detail: { shell: session.shell, reason: reason || "close", session: session },
}));
@@ -249,8 +236,6 @@
if (json) {
if (typeof json.html === "string") return json.html;
if (json.data && typeof json.data.html === "string") return json.data.html;
if (json.data && typeof json.data.show_modal === "string") return json.data.show_modal;
if (typeof json.data === "string") return json.data;
}
return typeof result.text === "string" ? result.text : "";
}
@@ -266,11 +251,11 @@
setState(session, unauthorized ? "unauthorized" : "error", error);
telemetryMark(session, unauthorized ? "unauthorized" : "error");
session.content.innerHTML =
'<div class="aksrt-remote-modal__error touch border-title"><b>提示</b></div>' +
'<div class="aksrt-remote-modal__error-body">' + escapeHtml(errorMessage(error)) +
'<div class="aksrt-modal-runtime__error touch border-title"><b>提示</b></div>' +
'<div class="aksrt-modal-runtime__error-body">' + escapeHtml(errorMessage(error)) +
'</div><div class="but-average modal-buts">' +
'<button type="button" class="but" data-aksrt-remote-modal-retry>重试</button>' +
'<button type="button" class="but" data-aksrt-remote-modal-close>关闭</button></div>';
'<button type="button" class="but" data-aksrt-modal-retry>重试</button>' +
'<button type="button" class="but" data-aksrt-modal-close>关闭</button></div>';
rehydrate(session);
if (typeof session.options.onError === "function") session.options.onError(error, session);
}
@@ -282,7 +267,7 @@
setState(session, "empty");
telemetryMark(session, "first-content");
telemetryMark(session, "ready");
session.content.innerHTML = '<div class="aksrt-remote-modal__error-body">暂无内容</div>';
session.content.innerHTML = '<div class="aksrt-modal-runtime__error-body">暂无内容</div>';
return;
}
session.content.innerHTML = html;
@@ -311,21 +296,14 @@
if (requestOptions.body === undefined) delete requestOptions.body;
if (!requestOptions.signal) delete requestOptions.signal;
var request = window.AksrtRequest && typeof window.AksrtRequest.request === "function"
? function () { return window.AksrtRequest.request(session.options.url, requestOptions); }
: function () {
return window.fetch(session.options.url, requestOptions).then(function (response) {
return response.text().then(function (text) { return { ok: response.ok, status: response.status, text: text, json: null }; });
});
};
var request = function () {
return window.AksrtRequest.request(session.options.url, requestOptions);
};
var method = String(session.options.method || "GET").toUpperCase();
var cacheable = method === "GET" && session.options.cache !== false;
var cacheKey = session.options.cacheKey ||
method + ":" +
(window.AksrtRequest && typeof window.AksrtRequest.url === "function"
? window.AksrtRequest.url(session.options.url, session.options.query)
: session.options.url);
method + ":" + window.AksrtRequest.url(session.options.url, session.options.query);
var cache = window.AksrtModalCache;
var acquireOptions = {
ttl: Number(session.options.cacheTtl || 15000),
@@ -339,7 +317,7 @@
},
};
session.flight = cacheable && cache && typeof cache.acquire === "function"
session.flight = cacheable
? cache.acquire(cacheKey, request, acquireOptions)
: { promise: request(), release: function () {} };
@@ -367,9 +345,7 @@
function sessionKey(options) {
if (!options || !options.url) return "";
var method = String(options.method || "GET").toUpperCase();
var requestUrl = window.AksrtRequest && typeof window.AksrtRequest.url === "function"
? window.AksrtRequest.url(options.url, options.query)
: String(options.url);
var requestUrl = window.AksrtRequest.url(options.url, options.query);
return method + ":" + requestUrl;
}
@@ -400,10 +376,7 @@
}
function invalidate(tags) {
if (window.AksrtModalCache && typeof window.AksrtModalCache.invalidate === "function") {
return window.AksrtModalCache.invalidate(tags);
}
return 0;
return window.AksrtModalCache.invalidate(tags);
}
window.AksrtModalRuntime = {
+42
View File
@@ -0,0 +1,42 @@
/**
* Declarative modal triggers.
*
* The only modal entry point is AksrtModalRuntime. Triggers carry an
* explicit URL and never create a second modal implementation.
*
* @package AKSRT
*/
(function (window, document) {
"use strict";
function openFromTrigger(element) {
var runtime = window.AksrtModalRuntime;
var url = element.getAttribute("data-aksrt-modal-url") || "";
if (!url || url === "#") return;
var ttl = parseInt(element.getAttribute("data-aksrt-modal-cache-ttl") || "15000", 10);
var tags = (element.getAttribute("data-aksrt-modal-cache-tags") || "").split(",").map(function (tag) {
return tag.trim();
}).filter(Boolean);
runtime.openRemote({
url: url,
method: element.getAttribute("data-aksrt-modal-method") || "GET",
className: element.getAttribute("data-aksrt-modal-class") || "modal-mini full-sm",
height: parseInt(element.getAttribute("data-aksrt-modal-height") || "0", 10) || 0,
mobileBottom: element.getAttribute("data-aksrt-modal-mobile-bottom") === "true",
bottom: element.getAttribute("data-aksrt-modal-bottom") === "true",
kind: element.getAttribute("data-aksrt-modal-kind") || "generic",
cacheKey: element.getAttribute("data-aksrt-modal-cache-key") || "",
cacheTtl: ttl > 0 ? ttl : 15000,
cacheTags: tags,
});
}
document.addEventListener("click", function (event) {
var trigger = event.target.closest('[data-aksrt-modal="remote"]');
if (!trigger) return;
event.preventDefault();
openFromTrigger(trigger);
});
})(window, document);
-77
View File
@@ -1,77 +0,0 @@
/**
* AKSRT Remote Modal compatibility bridge.
*
* The lifecycle implementation lives in AksrtModalRuntime. This file keeps
* the legacy trigger contract and the AksrtRemoteModal public alias stable.
*
* @package AKSRT
*/
(function (window, document) {
"use strict";
function runtime() {
return window.AksrtModalRuntime || null;
}
function fromTrigger(element) {
var modalRuntime = runtime();
if (!modalRuntime || !element) return Promise.reject(new Error("modal runtime unavailable"));
var url = element.getAttribute("data-remote") ||
element.getAttribute("data-aksrt-remote") ||
element.getAttribute("href") || "";
if (!url || url === "#") return Promise.resolve(null);
var ttl = parseInt(element.getAttribute("data-modal-cache-ttl") || "15000", 10);
var tags = (element.getAttribute("data-modal-cache-tags") || "").split(",").map(function (tag) {
return tag.trim();
}).filter(Boolean);
return modalRuntime.openRemote({
url: url,
method: element.getAttribute("data-method") || "GET",
className: element.getAttribute("data-class") || element.getAttribute("data-aksrt-class") || "modal-mini full-sm",
height: parseInt(element.getAttribute("data-height") || element.getAttribute("data-aksrt-height") || "0", 10) || 0,
mobileBottom: element.getAttribute("mobile-bottom") !== "false",
bottom: element.getAttribute("data-bottom") === "true",
kind: element.getAttribute("data-modal-kind") || "generic",
cacheKey: element.getAttribute("data-modal-cache-key") || "",
cacheTtl: ttl > 0 ? ttl : 15000,
cacheTags: tags,
});
}
function bind() {
if (window.__aksrtRemoteModalBound) return;
if (!runtime()) return;
window.__aksrtRemoteModalBound = true;
document.addEventListener("click", function (event) {
var trigger = event.target.closest(
'[data-toggle="AksrtRemoteModal"], [data-toggle="RefreshModal"], [data-aksrt-remote-modal], a.aksrt-remote-modal-link'
);
if (!trigger || trigger.getAttribute("data-aksrt-remote-modal") === "off") return;
event.preventDefault();
fromTrigger(trigger);
});
}
function expose() {
var modalRuntime = runtime();
if (!modalRuntime) return;
window.AksrtRemoteModal = {
open: modalRuntime.open,
openRemote: modalRuntime.openRemote,
close: modalRuntime.close,
refresh: modalRuntime.refresh,
fromTrigger: fromTrigger,
getActive: modalRuntime.getActive,
};
bind();
}
expose();
if (!window.AksrtModalRuntime) {
document.addEventListener("aksrt:modal-runtime:ready", expose, { once: true });
}
})(window, document);
+1 -1
View File
@@ -302,7 +302,7 @@
initParallax();
initFloatLabels();
initSigninCalendar();
document.addEventListener('aksrt:remote-modal:open', function () {
document.addEventListener('aksrt:modal:open', function () {
// Remote modal may inject calendar markup after open.
window.setTimeout(initSigninCalendar, 30);
});
+3 -18
View File
@@ -16,21 +16,10 @@
var detailOrderNumber = "";
function toast(message, type) {
if (typeof window.AksrtToast === "function") {
window.AksrtToast(message, type || "info");
return;
}
if (typeof window.aksrtNotify === "function") {
window.aksrtNotify(message, type || "info");
return;
}
window.alert(message);
window.AksrtToast(message, type || "info");
}
function request(path, body, method) {
if (!window.AksrtRequest || typeof window.AksrtRequest.request !== "function") {
return Promise.resolve({ success: false, message: "请求适配器未加载" });
}
var options = { method: method || "POST" };
if (body !== undefined) options.body = JSON.stringify(body || {});
return window.AksrtRequest.request(path, options).then(function (response) {
@@ -219,9 +208,7 @@
button.disabled = true;
request(orderPath(number, "/pay"), method ? { payment_method: method } : {}).then(function (result) {
if (!result.success) throw new Error(result.message || "支付失败");
if (window.AksrtModalRuntime && typeof window.AksrtModalRuntime.invalidate === "function") {
window.AksrtModalRuntime.invalidate(["orders", "vip"]);
}
window.AksrtModalRuntime.invalidate(["orders", "vip"]);
var data = result.data || {};
if (data.redirect && data.payment_url) {
window.location.assign(data.payment_url);
@@ -246,9 +233,7 @@
button.disabled = true;
request(orderPath(number, "/cancel")).then(function (result) {
if (!result.success) throw new Error(result.message || "关闭订单失败");
if (window.AksrtModalRuntime && typeof window.AksrtModalRuntime.invalidate === "function") {
window.AksrtModalRuntime.invalidate(["orders", "vip"]);
}
window.AksrtModalRuntime.invalidate(["orders", "vip"]);
toast("订单已关闭");
refreshView();
}).catch(function (error) {
+6 -29
View File
@@ -6,16 +6,7 @@
"use strict";
function api(path, options) {
var opts = Object.assign({}, options || {});
var request = window.AksrtRequest && typeof window.AksrtRequest.request === "function"
? window.AksrtRequest.request(path, opts)
: fetch(path, Object.assign({ credentials: "same-origin" }, opts)).then(function (response) {
return response.json().then(function (json) {
return { ok: response.ok, status: response.status, json: json };
});
});
return request.then(function (response) {
return window.AksrtRequest.request(path, Object.assign({}, options || {})).then(function (response) {
return {
ok: response.ok,
status: response.status,
@@ -34,11 +25,10 @@
var activeVipShell = null;
function openModal() {
if (!window.AksrtModalRuntime || typeof window.AksrtModalRuntime.open !== "function") return null;
activeVipShell = window.AksrtModalRuntime.open({
className: "aksrt-vip-modal-shell",
mobileBottom: false,
skeleton: '<div class="aksrt-vip-modal-dialog"><div class="aksrt-vip-modal-content" data-aksrt-vip-modal-body><div class="text-center padding-20 muted-2-color">加载中…</div></div></div>',
skeleton: '<div class="aksrt-vip-modal-panel"><div class="aksrt-vip-modal-content" data-aksrt-vip-modal-body><div class="text-center padding-20 muted-2-color">加载中…</div></div></div>',
telemetry: false,
kind: "vip",
});
@@ -46,9 +36,7 @@
}
function closeModal() {
if (window.AksrtModalRuntime && typeof window.AksrtModalRuntime.close === "function") {
window.AksrtModalRuntime.close("vip");
}
window.AksrtModalRuntime.close("vip");
activeVipShell = null;
}
@@ -151,17 +139,13 @@
}
var data = r.json && r.json.data ? r.json.data : r.json;
if (data && data.redirect && (data.payment_url || data.qr_content)) {
if (window.AksrtModalRuntime && typeof window.AksrtModalRuntime.invalidate === "function") {
window.AksrtModalRuntime.invalidate(["vip", "orders"]);
}
window.AksrtModalRuntime.invalidate(["vip", "orders"]);
if (data.payment_url) window.open(data.payment_url, "_blank");
setTip(pane, data.message || "请完成支付,支付成功后将自动刷新。");
if (data.order_number) pollOrder(data.order_number);
return;
}
if (window.AksrtModalRuntime && typeof window.AksrtModalRuntime.invalidate === "function") {
window.AksrtModalRuntime.invalidate(["vip", "orders"]);
}
window.AksrtModalRuntime.invalidate(["vip", "orders"]);
setTip(pane, (data && data.message) || "开通成功,正在刷新…");
setTimeout(function () {
window.location.reload();
@@ -189,11 +173,6 @@
if (telemetry && telemetryId && typeof telemetry.mark === "function") telemetry.mark(telemetryId, event);
}
var shell = openModal();
if (!shell) {
loading = false;
telemetryMark("error");
return;
}
var body = shell.querySelector("[data-aksrt-vip-modal-body]");
telemetryMark("shell");
@@ -220,9 +199,7 @@
if (body) {
body.innerHTML = r.json.html;
telemetryMark("first-content");
if (window.AksrtFrontend && typeof window.AksrtFrontend.rehydrate === "function") {
window.AksrtFrontend.rehydrate(body, "modal");
}
window.AksrtFrontend.rehydrate(body, "modal");
bindModalUi(body);
telemetryMark("ready");
}
+16 -29
View File
@@ -3,15 +3,12 @@
*
* User-center modal: category-grouped medal card grid + in-modal detail
* view (medal-background card, obtain time, wear action). Also provides the
* global wear handler used inside remote (AJAX HTML) badge modals.
* global wear handler used inside runtime-loaded badge modals.
*/
(function () {
'use strict';
function api(path, options) {
if (!window.AksrtRequest || typeof window.AksrtRequest.request !== 'function') {
return Promise.resolve({ ok: false, status: 0, json: { message: '请求适配器未加载' } });
}
return window.AksrtRequest.request(path, options || {}).then(function (response) {
return { ok: response.ok, status: response.status, json: response.json || {} };
}).catch(function (error) {
@@ -25,15 +22,7 @@
}
function toast(msg, type) {
if (typeof window.AksrtToast === 'function') {
window.AksrtToast(msg, type || 'info');
return;
}
if (typeof window.aksrtNotify === 'function') {
window.aksrtNotify(msg, type || 'info');
return;
}
try { console.log('[AKSRT badges]', msg); } catch (_) {}
window.AksrtToast(msg, type || 'info');
}
function escapeHtml(s) {
@@ -260,9 +249,7 @@
return;
}
toast((r.json && r.json.message) || '已佩戴徽章', 'success');
if (window.AksrtModalRuntime && typeof window.AksrtModalRuntime.invalidate === 'function') {
window.AksrtModalRuntime.invalidate(['badges', 'identity']);
}
window.AksrtModalRuntime.invalidate(['badges', 'identity']);
state.data = (r.json && r.json.data) || state.data;
renderHead();
renderGrid();
@@ -352,9 +339,7 @@
return;
}
toast((r.json && r.json.message) || '已佩戴徽章', 'success');
if (window.AksrtModalRuntime && typeof window.AksrtModalRuntime.invalidate === 'function') {
window.AksrtModalRuntime.invalidate(['badges', 'identity']);
}
window.AksrtModalRuntime.invalidate(['badges', 'identity']);
// Re-open the refreshed single-badge modal so state stays in sync.
var refreshed = null;
try {
@@ -362,19 +347,21 @@
var data = r.json && r.json.data;
var isSelf = data && data.is_self;
if (isSelf && data.wear) {
refreshed = (window.aksrtData && aksrtData.ajaxUrl)
? aksrtData.ajaxUrl + '?action=aksrt_single_badge_info_modal&name=' + encodeURIComponent(data.wear) + '&user_id=' + (uid || 0)
refreshed = (window.aksrtData && window.aksrtData.ajaxUrl)
? window.aksrtData.ajaxUrl + '?action=aksrt_single_badge_info_modal&name=' + encodeURIComponent(data.wear) + '&user_id=' + (uid || 0)
: null;
}
} catch (_) {}
try {
if (refreshed && window.AksrtRemoteModal && typeof window.AksrtRemoteModal.openRemote === 'function') {
window.AksrtRemoteModal.openRemote({ url: refreshed, className: 'modal-mini', mobileBottom: true });
} else {
document.dispatchEvent(new CustomEvent('aksrt:remote-modal:close'));
}
} catch (_) {
try { document.dispatchEvent(new CustomEvent('aksrt:remote-modal:close')); } catch (__) {}
if (refreshed) {
window.AksrtModalRuntime.openRemote({
url: refreshed,
className: 'modal-mini',
mobileBottom: true,
kind: 'badges',
cache: false,
});
} else {
window.AksrtModalRuntime.close('badge-wear');
}
}).catch(function () {
toast('网络错误', 'error');