fix(frontend): align reward modal with shared runtime
This commit is contained in:
@@ -5232,248 +5232,6 @@ body.aksrt-body-scroll .aksrt-show-on-scroll {
|
||||
.aksrt-cursor-zoom-in {
|
||||
cursor: zoom-in;
|
||||
}
|
||||
/* ============================================================
|
||||
* 8. 打赏弹窗
|
||||
* ============================================================ */
|
||||
.reward-modal {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
z-index: 99999;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
opacity: 0;
|
||||
visibility: hidden;
|
||||
transition: opacity 0.3s, visibility 0.3s;
|
||||
}
|
||||
|
||||
.reward-modal.is-open {
|
||||
opacity: 1;
|
||||
visibility: visible;
|
||||
}
|
||||
|
||||
.reward-modal__overlay {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
background: rgba(0,0,0,0.5);
|
||||
}
|
||||
|
||||
.reward-modal__card {
|
||||
position: relative;
|
||||
background: var(--surface-1, #fff);
|
||||
border-radius: var(--radius-lg, 8px);
|
||||
padding: 32px;
|
||||
max-width: 360px;
|
||||
width: 90%;
|
||||
text-align: center;
|
||||
box-shadow: 0 8px 32px rgba(0,0,0,0.15);
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
.reward-modal__title {
|
||||
margin: 0 0 8px;
|
||||
font-size: 18px;
|
||||
font-weight: 600;
|
||||
color: var(--color-ink);
|
||||
}
|
||||
|
||||
.reward-modal__desc {
|
||||
margin: 0 0 20px;
|
||||
font-size: 14px;
|
||||
color: var(--color-ink-3);
|
||||
}
|
||||
|
||||
.reward-modal__qr {
|
||||
width: 200px;
|
||||
height: 200px;
|
||||
margin: 0 auto 16px;
|
||||
border-radius: var(--radius, 10px);
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.reward-modal__qr img {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: contain;
|
||||
}
|
||||
|
||||
.reward-modal__close {
|
||||
position: absolute;
|
||||
top: 12px;
|
||||
right: 12px;
|
||||
width: 32px;
|
||||
height: 32px;
|
||||
border: none;
|
||||
border-radius: 50%;
|
||||
background: var(--surface-2, #F4F5F7);
|
||||
color: var(--color-ink-3);
|
||||
cursor: pointer;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
transition: background 0.2s;
|
||||
}
|
||||
|
||||
.reward-modal__close:hover {
|
||||
background: var(--surface-3, #ECEEF1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
.reward-modal__content > p {
|
||||
margin: -4px 0 18px;
|
||||
}
|
||||
|
||||
.reward-amounts {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(3, minmax(0, 1fr));
|
||||
gap: 10px;
|
||||
margin: 18px 0;
|
||||
}
|
||||
|
||||
.reward-amount {
|
||||
min-height: 42px;
|
||||
border: 1px solid var(--color-line-soft, rgba(15, 23, 42, 0.1));
|
||||
border-radius: 10px;
|
||||
background: var(--surface-2);
|
||||
color: var(--color-ink-2);
|
||||
cursor: pointer;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.reward-amount.is-active {
|
||||
border-color: var(--color-primary);
|
||||
background: var(--color-primary-soft);
|
||||
color: var(--color-primary);
|
||||
}
|
||||
|
||||
.reward-custom {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
margin-bottom: 16px;
|
||||
color: var(--color-ink-3);
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.reward-custom input {
|
||||
width: 140px;
|
||||
min-height: 40px;
|
||||
border: 1px solid var(--color-line-soft, rgba(15, 23, 42, 0.1));
|
||||
border-radius: 9px;
|
||||
background: var(--surface-1);
|
||||
color: var(--color-ink);
|
||||
padding: 0 12px;
|
||||
}
|
||||
|
||||
.reward-modal__submit {
|
||||
width: 100%;
|
||||
min-height: 42px;
|
||||
}
|
||||
|
||||
.reward-modal__message {
|
||||
min-height: 20px;
|
||||
margin-top: 10px;
|
||||
color: var(--color-primary);
|
||||
font-size: 12px;
|
||||
text-align: center;
|
||||
}
|
||||
/* ---- reward amounts ---- */
|
||||
.reward-amounts {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 8px;
|
||||
justify-content: center;
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
.reward-amounts__btn {
|
||||
display: inline-flex;
|
||||
align-items: baseline;
|
||||
gap: 2px;
|
||||
padding: 8px 16px;
|
||||
border: 1px solid var(--color-line, #e5e7eb);
|
||||
border-radius: var(--radius, 10px);
|
||||
background: var(--surface-2, #F4F5F7);
|
||||
color: var(--color-ink);
|
||||
font-size: 15px;
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
transition: all 0.2s ease;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
.reward-amounts__btn:hover {
|
||||
border-color: var(--color-primary, #f04494);
|
||||
background: rgba(240, 68, 148, 0.06);
|
||||
}
|
||||
|
||||
.reward-amounts__btn.is-active {
|
||||
border-color: var(--color-primary, #f04494);
|
||||
background: var(--color-primary, #f04494);
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.reward-amounts__currency {
|
||||
font-size: 13px;
|
||||
font-weight: 400;
|
||||
}
|
||||
|
||||
.reward-amounts__value {
|
||||
font-size: 15px;
|
||||
}
|
||||
/* ---- custom amount ---- */
|
||||
.reward-custom {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
.reward-custom__input {
|
||||
flex: 1;
|
||||
height: 40px;
|
||||
padding: 0 12px;
|
||||
border: 1px solid var(--color-line, #e5e7eb);
|
||||
border-radius: var(--radius, 10px);
|
||||
background: var(--surface-2, #F4F5F7);
|
||||
color: var(--color-ink);
|
||||
font-size: 14px;
|
||||
text-align: center;
|
||||
outline: none;
|
||||
transition: border-color 0.2s;
|
||||
-moz-appearance: textfield;
|
||||
}
|
||||
|
||||
.reward-custom__input::-webkit-inner-spin-button,
|
||||
.reward-custom__input::-webkit-outer-spin-button {
|
||||
-webkit-appearance: none;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.reward-custom__input:focus {
|
||||
border-color: var(--color-primary, #f04494);
|
||||
}
|
||||
|
||||
.reward-custom__confirm {
|
||||
flex-shrink: 0;
|
||||
height: 40px;
|
||||
padding: 0 20px;
|
||||
border: none;
|
||||
border-radius: var(--radius, 10px);
|
||||
background: var(--color-primary, #f04494);
|
||||
color: #fff;
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
cursor: pointer;
|
||||
transition: opacity 0.2s;
|
||||
}
|
||||
|
||||
.reward-custom__confirm:hover {
|
||||
opacity: 0.85;
|
||||
}
|
||||
|
||||
/* ============================================================
|
||||
* 9. 公告跑马灯 Widget
|
||||
* ============================================================ */
|
||||
|
||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
@@ -1,3 +1 @@
|
||||
@import url("components/base.css");
|
||||
@import url("components/reward-amounts.css");
|
||||
@import url("components/custom-amount.css");
|
||||
|
||||
@@ -1,147 +0,0 @@
|
||||
/* ============================================================
|
||||
* 8. 打赏弹窗
|
||||
* ============================================================ */
|
||||
.reward-modal {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
z-index: 99999;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
opacity: 0;
|
||||
visibility: hidden;
|
||||
transition: opacity 0.3s, visibility 0.3s;
|
||||
}
|
||||
|
||||
.reward-modal.is-open {
|
||||
opacity: 1;
|
||||
visibility: visible;
|
||||
}
|
||||
|
||||
.reward-modal__overlay {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
background: rgba(0,0,0,0.5);
|
||||
}
|
||||
|
||||
.reward-modal__card {
|
||||
position: relative;
|
||||
background: var(--surface-1, #fff);
|
||||
border-radius: var(--radius-lg, 8px);
|
||||
padding: 32px;
|
||||
max-width: 360px;
|
||||
width: 90%;
|
||||
text-align: center;
|
||||
box-shadow: 0 8px 32px rgba(0,0,0,0.15);
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
.reward-modal__title {
|
||||
margin: 0 0 8px;
|
||||
font-size: 18px;
|
||||
font-weight: 600;
|
||||
color: var(--color-ink);
|
||||
}
|
||||
|
||||
.reward-modal__desc {
|
||||
margin: 0 0 20px;
|
||||
font-size: 14px;
|
||||
color: var(--color-ink-3);
|
||||
}
|
||||
|
||||
.reward-modal__qr {
|
||||
width: 200px;
|
||||
height: 200px;
|
||||
margin: 0 auto 16px;
|
||||
border-radius: var(--radius, 10px);
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.reward-modal__qr img {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: contain;
|
||||
}
|
||||
|
||||
.reward-modal__close {
|
||||
position: absolute;
|
||||
top: 12px;
|
||||
right: 12px;
|
||||
width: 32px;
|
||||
height: 32px;
|
||||
border: none;
|
||||
border-radius: 50%;
|
||||
background: var(--surface-2, #F4F5F7);
|
||||
color: var(--color-ink-3);
|
||||
cursor: pointer;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
transition: background 0.2s;
|
||||
}
|
||||
|
||||
.reward-modal__close:hover {
|
||||
background: var(--surface-3, #ECEEF1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
.reward-modal__content > p {
|
||||
margin: -4px 0 18px;
|
||||
}
|
||||
|
||||
.reward-amounts {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(3, minmax(0, 1fr));
|
||||
gap: 10px;
|
||||
margin: 18px 0;
|
||||
}
|
||||
|
||||
.reward-amount {
|
||||
min-height: 42px;
|
||||
border: 1px solid var(--color-line-soft, rgba(15, 23, 42, 0.1));
|
||||
border-radius: 10px;
|
||||
background: var(--surface-2);
|
||||
color: var(--color-ink-2);
|
||||
cursor: pointer;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.reward-amount.is-active {
|
||||
border-color: var(--color-primary);
|
||||
background: var(--color-primary-soft);
|
||||
color: var(--color-primary);
|
||||
}
|
||||
|
||||
.reward-custom {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
margin-bottom: 16px;
|
||||
color: var(--color-ink-3);
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.reward-custom input {
|
||||
width: 140px;
|
||||
min-height: 40px;
|
||||
border: 1px solid var(--color-line-soft, rgba(15, 23, 42, 0.1));
|
||||
border-radius: 9px;
|
||||
background: var(--surface-1);
|
||||
color: var(--color-ink);
|
||||
padding: 0 12px;
|
||||
}
|
||||
|
||||
.reward-modal__submit {
|
||||
width: 100%;
|
||||
min-height: 42px;
|
||||
}
|
||||
|
||||
.reward-modal__message {
|
||||
min-height: 20px;
|
||||
margin-top: 10px;
|
||||
color: var(--color-primary);
|
||||
font-size: 12px;
|
||||
text-align: center;
|
||||
}
|
||||
@@ -1,54 +1,3 @@
|
||||
/* ---- custom amount ---- */
|
||||
.reward-custom {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
.reward-custom__input {
|
||||
flex: 1;
|
||||
height: 40px;
|
||||
padding: 0 12px;
|
||||
border: 1px solid var(--color-line, #e5e7eb);
|
||||
border-radius: var(--radius, 10px);
|
||||
background: var(--surface-2, #F4F5F7);
|
||||
color: var(--color-ink);
|
||||
font-size: 14px;
|
||||
text-align: center;
|
||||
outline: none;
|
||||
transition: border-color 0.2s;
|
||||
-moz-appearance: textfield;
|
||||
}
|
||||
|
||||
.reward-custom__input::-webkit-inner-spin-button,
|
||||
.reward-custom__input::-webkit-outer-spin-button {
|
||||
-webkit-appearance: none;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.reward-custom__input:focus {
|
||||
border-color: var(--color-primary, #f04494);
|
||||
}
|
||||
|
||||
.reward-custom__confirm {
|
||||
flex-shrink: 0;
|
||||
height: 40px;
|
||||
padding: 0 20px;
|
||||
border: none;
|
||||
border-radius: var(--radius, 10px);
|
||||
background: var(--color-primary, #f04494);
|
||||
color: #fff;
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
cursor: pointer;
|
||||
transition: opacity 0.2s;
|
||||
}
|
||||
|
||||
.reward-custom__confirm:hover {
|
||||
opacity: 0.85;
|
||||
}
|
||||
|
||||
/* ============================================================
|
||||
* 9. 公告跑马灯 Widget
|
||||
* ============================================================ */
|
||||
|
||||
@@ -1,45 +0,0 @@
|
||||
/* ---- reward amounts ---- */
|
||||
.reward-amounts {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 8px;
|
||||
justify-content: center;
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
.reward-amounts__btn {
|
||||
display: inline-flex;
|
||||
align-items: baseline;
|
||||
gap: 2px;
|
||||
padding: 8px 16px;
|
||||
border: 1px solid var(--color-line, #e5e7eb);
|
||||
border-radius: var(--radius, 10px);
|
||||
background: var(--surface-2, #F4F5F7);
|
||||
color: var(--color-ink);
|
||||
font-size: 15px;
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
transition: all 0.2s ease;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
.reward-amounts__btn:hover {
|
||||
border-color: var(--color-primary, #f04494);
|
||||
background: rgba(240, 68, 148, 0.06);
|
||||
}
|
||||
|
||||
.reward-amounts__btn.is-active {
|
||||
border-color: var(--color-primary, #f04494);
|
||||
background: var(--color-primary, #f04494);
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.reward-amounts__currency {
|
||||
font-size: 13px;
|
||||
font-weight: 400;
|
||||
}
|
||||
|
||||
.reward-amounts__value {
|
||||
font-size: 15px;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,120 @@
|
||||
/* ---- 文章打赏:内容使用 AksrtModalRuntime,几何对齐参考主题 modal-mini ---- */
|
||||
.aksrt-modal-runtime.aksrt-reward-modal:not(.aksrt-modal-runtime--bottom) .aksrt-modal-runtime__dialog {
|
||||
width: min(400px, calc(100vw - 32px));
|
||||
border-radius: var(--main-radius, 8px);
|
||||
background: var(--main-bg-color, #fff);
|
||||
}
|
||||
|
||||
.aksrt-modal-runtime.aksrt-reward-modal .aksrt-modal-runtime__content {
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.aksrt-reward-modal .modal-colorful-header + .aksrt-reward__body {
|
||||
margin-top: 0;
|
||||
padding: 135px 15px 15px;
|
||||
color: var(--main-color, var(--color-ink, #333));
|
||||
}
|
||||
|
||||
.aksrt-reward__desc {
|
||||
margin: 0 0 16px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.aksrt-reward__amounts {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(3, minmax(0, 1fr));
|
||||
gap: 8px;
|
||||
margin: 16px 0;
|
||||
}
|
||||
|
||||
.aksrt-reward__amount {
|
||||
display: inline-flex;
|
||||
min-width: 0;
|
||||
min-height: 42px;
|
||||
align-items: baseline;
|
||||
justify-content: center;
|
||||
gap: 2px;
|
||||
padding: 8px 10px;
|
||||
border: 1px solid var(--muted-border-color, var(--color-line-stronger, rgba(50, 50, 50, 0.12)));
|
||||
border-radius: var(--main-radius, 8px);
|
||||
background: var(--body-bg-color, var(--surface-2, #eee));
|
||||
color: var(--main-color, var(--color-ink, #333));
|
||||
cursor: pointer;
|
||||
font-size: 15px;
|
||||
font-weight: 600;
|
||||
transition: border-color 0.2s ease, background-color 0.2s ease, color 0.2s ease;
|
||||
}
|
||||
|
||||
.aksrt-reward__amount:hover,
|
||||
.aksrt-reward__amount.is-active {
|
||||
border-color: var(--focus-color, var(--color-primary, #f04494));
|
||||
background: var(--focus-color, var(--color-primary, #f04494));
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.aksrt-reward__currency {
|
||||
font-size: 13px;
|
||||
font-weight: 400;
|
||||
}
|
||||
|
||||
.aksrt-reward__value {
|
||||
font-size: 15px;
|
||||
}
|
||||
|
||||
.aksrt-reward__custom {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
margin: 0 0 16px;
|
||||
color: var(--muted-color, var(--color-ink-3, #777));
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.aksrt-reward__input {
|
||||
width: min(180px, 58%);
|
||||
min-height: 40px;
|
||||
padding: 0 12px;
|
||||
border: 1px solid var(--muted-border-color, var(--color-line-stronger, rgba(50, 50, 50, 0.12)));
|
||||
border-radius: var(--main-radius, 8px);
|
||||
background: var(--main-bg-color, #fff);
|
||||
color: var(--main-color, var(--color-ink, #333));
|
||||
text-align: right;
|
||||
-moz-appearance: textfield;
|
||||
}
|
||||
|
||||
.aksrt-reward__input::-webkit-inner-spin-button,
|
||||
.aksrt-reward__input::-webkit-outer-spin-button {
|
||||
margin: 0;
|
||||
-webkit-appearance: none;
|
||||
}
|
||||
|
||||
.aksrt-reward__input:focus {
|
||||
border-color: var(--focus-color, var(--color-primary, #f04494));
|
||||
outline: 0;
|
||||
}
|
||||
|
||||
.aksrt-reward__submit {
|
||||
min-height: 42px;
|
||||
}
|
||||
|
||||
.aksrt-reward__submit:disabled {
|
||||
cursor: wait;
|
||||
opacity: 0.7;
|
||||
}
|
||||
|
||||
.aksrt-reward__message {
|
||||
min-height: 20px;
|
||||
margin-top: 8px;
|
||||
color: var(--focus-color, var(--color-primary, #f04494));
|
||||
font-size: 12px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.aksrt-modal-runtime--bottom.aksrt-reward-modal .aksrt-modal-runtime__dialog {
|
||||
border-radius: 16px 16px 0 0;
|
||||
}
|
||||
|
||||
.aksrt-modal-runtime--bottom.aksrt-reward-modal .modal-colorful-header {
|
||||
border-radius: 16px 16px 0 0;
|
||||
}
|
||||
+155
-117
@@ -1,127 +1,165 @@
|
||||
/**
|
||||
* On-site wallet tipping modal.
|
||||
* On-site wallet tipping content for the shared modal runtime.
|
||||
*
|
||||
* @package AKSRT
|
||||
*/
|
||||
;(function () {
|
||||
;(function (window, document) {
|
||||
'use strict';
|
||||
|
||||
var cfg = window.aksrtData || {};
|
||||
var titleSequence = 0;
|
||||
|
||||
function initReward() {
|
||||
var activeTrigger = null;
|
||||
|
||||
function operationKey(modal) {
|
||||
if (!modal.dataset.aksrtOperationKey) {
|
||||
modal.dataset.aksrtOperationKey = window.AksrtRequest.createIdempotencyKey();
|
||||
}
|
||||
return modal.dataset.aksrtOperationKey;
|
||||
}
|
||||
|
||||
function closeAll() {
|
||||
document.querySelectorAll('.reward-modal.is-open').forEach(function (modal) {
|
||||
modal.classList.remove('is-open');
|
||||
modal.setAttribute('aria-hidden', 'true');
|
||||
});
|
||||
document.body.style.overflow = '';
|
||||
if (activeTrigger) activeTrigger.focus();
|
||||
activeTrigger = null;
|
||||
}
|
||||
|
||||
function open(trigger) {
|
||||
var userId = trigger.getAttribute('data-user-id') || '';
|
||||
var modal = document.getElementById('reward-modal-' + userId);
|
||||
if (!modal) return;
|
||||
closeAll();
|
||||
activeTrigger = trigger;
|
||||
modal.dataset.postId = trigger.getAttribute('data-post-id') || modal.dataset.postId || '0';
|
||||
modal.classList.add('is-open');
|
||||
modal.setAttribute('aria-hidden', 'false');
|
||||
document.body.style.overflow = 'hidden';
|
||||
var first = modal.querySelector('[data-reward-amount], [data-aksrt-reward-custom]');
|
||||
if (first) first.focus();
|
||||
}
|
||||
|
||||
document.addEventListener('click', function (event) {
|
||||
var opener = event.target.closest('[data-aksrt-reward-open]');
|
||||
if (opener) {
|
||||
event.preventDefault();
|
||||
open(opener);
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.target.closest('[data-aksrt-reward-close]')) {
|
||||
event.preventDefault();
|
||||
closeAll();
|
||||
return;
|
||||
}
|
||||
|
||||
var amountButton = event.target.closest('[data-reward-amount]');
|
||||
if (amountButton) {
|
||||
var modal = amountButton.closest('.reward-modal');
|
||||
delete modal.dataset.aksrtOperationKey;
|
||||
modal.querySelectorAll('[data-reward-amount]').forEach(function (button) {
|
||||
button.classList.toggle('is-active', button === amountButton);
|
||||
});
|
||||
var custom = modal.querySelector('[data-aksrt-reward-custom]');
|
||||
if (custom) custom.value = '';
|
||||
return;
|
||||
}
|
||||
|
||||
var submit = event.target.closest('[data-aksrt-reward-submit]');
|
||||
if (!submit || submit.disabled) return;
|
||||
var tipModal = submit.closest('.reward-modal');
|
||||
var message = tipModal.querySelector('[data-aksrt-reward-message]');
|
||||
var customInput = tipModal.querySelector('[data-aksrt-reward-custom]');
|
||||
var selected = tipModal.querySelector('[data-reward-amount].is-active');
|
||||
var amount = customInput && customInput.value ? customInput.value : (selected ? selected.dataset.rewardAmount : '');
|
||||
if (customInput && customInput.dataset.aksrtIdempotencyBound !== '1') {
|
||||
customInput.dataset.aksrtIdempotencyBound = '1';
|
||||
customInput.addEventListener('input', function () { delete tipModal.dataset.aksrtOperationKey; });
|
||||
}
|
||||
|
||||
submit.disabled = true;
|
||||
submit.textContent = '赞赏中…';
|
||||
if (message) message.textContent = '';
|
||||
|
||||
var body = new URLSearchParams();
|
||||
body.set('action', 'aksrt_submit_tip');
|
||||
body.set('nonce', cfg.nonce || '');
|
||||
body.set('recipient_id', tipModal.dataset.userId || '');
|
||||
body.set('post_id', tipModal.dataset.postId || '0');
|
||||
body.set('amount', amount);
|
||||
|
||||
fetch(cfg.ajaxUrl || '/wp-admin/admin-ajax.php', {
|
||||
method: 'POST',
|
||||
credentials: 'same-origin',
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
|
||||
'Idempotency-Key': operationKey(tipModal)
|
||||
},
|
||||
body: body.toString()
|
||||
}).then(function (response) {
|
||||
return response.json();
|
||||
}).then(function (response) {
|
||||
var text = response && response.data && response.data.message ? response.data.message : '赞赏失败';
|
||||
if (response && response.success) {
|
||||
delete tipModal.dataset.aksrtOperationKey;
|
||||
if (message) message.textContent = text;
|
||||
setTimeout(closeAll, 900);
|
||||
} else if (message) {
|
||||
message.textContent = text;
|
||||
}
|
||||
}).catch(function () {
|
||||
if (message) message.textContent = '网络错误,请稍后重试';
|
||||
}).finally(function () {
|
||||
submit.disabled = false;
|
||||
submit.textContent = '余额赞赏';
|
||||
});
|
||||
});
|
||||
|
||||
document.addEventListener('keydown', function (event) {
|
||||
if (event.key === 'Escape') closeAll();
|
||||
});
|
||||
function rewardModal(target) {
|
||||
return target.closest('.aksrt-modal-runtime.aksrt-reward-modal');
|
||||
}
|
||||
|
||||
jQuery(document).off('auto_fun.aksrt-reward').on('auto_fun.aksrt-reward', initReward);
|
||||
})();
|
||||
function rewardTemplate(modal) {
|
||||
return modal ? document.getElementById(modal.dataset.templateId || '') : null;
|
||||
}
|
||||
|
||||
function operationKey(template) {
|
||||
if (!template.dataset.aksrtOperationKey) {
|
||||
template.dataset.aksrtOperationKey = window.AksrtRequest.createIdempotencyKey();
|
||||
}
|
||||
return template.dataset.aksrtOperationKey;
|
||||
}
|
||||
|
||||
function openReward(trigger) {
|
||||
var runtime = window.AksrtModalRuntime;
|
||||
if (!runtime || !window.AksrtRequest) {
|
||||
if (trigger.dataset.aksrtRewardWaiting !== '1') {
|
||||
trigger.dataset.aksrtRewardWaiting = '1';
|
||||
document.addEventListener('aksrt:modal-runtime:ready', function () {
|
||||
delete trigger.dataset.aksrtRewardWaiting;
|
||||
if (document.contains(trigger)) openReward(trigger);
|
||||
}, { once: true });
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
var templateId = trigger.getAttribute('data-template-id') || '';
|
||||
var template = document.getElementById(templateId);
|
||||
if (!template || !template.content) return;
|
||||
|
||||
var shell = runtime.open({
|
||||
html: template.innerHTML,
|
||||
className: 'aksrt-reward-modal modal-mini full-sm',
|
||||
mobileBottom: true,
|
||||
kind: 'generic',
|
||||
});
|
||||
shell.dataset.templateId = template.id;
|
||||
shell.dataset.userId = trigger.getAttribute('data-user-id') || template.dataset.userId || '';
|
||||
shell.dataset.postId = trigger.getAttribute('data-post-id') || template.dataset.postId || '0';
|
||||
var title = shell.querySelector('.aksrt-reward__title');
|
||||
if (title) {
|
||||
title.id = 'aksrt-reward-title-' + (++titleSequence);
|
||||
shell.setAttribute('aria-labelledby', title.id);
|
||||
}
|
||||
|
||||
var initialFocus = shell.querySelector('[data-reward-amount].is-active, [data-aksrt-reward-custom]');
|
||||
if (initialFocus) initialFocus.focus();
|
||||
}
|
||||
|
||||
document.addEventListener('click', function (event) {
|
||||
var opener = event.target.closest('[data-aksrt-reward-open]');
|
||||
if (opener) {
|
||||
event.preventDefault();
|
||||
openReward(opener);
|
||||
return;
|
||||
}
|
||||
|
||||
var amountButton = event.target.closest('[data-reward-amount]');
|
||||
if (amountButton) {
|
||||
var amountModal = rewardModal(amountButton);
|
||||
if (!amountModal) return;
|
||||
var amountTemplate = rewardTemplate(amountModal);
|
||||
if (amountTemplate) delete amountTemplate.dataset.aksrtOperationKey;
|
||||
amountModal.querySelectorAll('[data-reward-amount]').forEach(function (button) {
|
||||
var isActive = button === amountButton;
|
||||
button.classList.toggle('is-active', isActive);
|
||||
button.setAttribute('aria-pressed', isActive ? 'true' : 'false');
|
||||
});
|
||||
var customInput = amountModal.querySelector('[data-aksrt-reward-custom]');
|
||||
if (customInput) customInput.value = '';
|
||||
return;
|
||||
}
|
||||
|
||||
var submit = event.target.closest('[data-aksrt-reward-submit]');
|
||||
if (!submit || submit.disabled) return;
|
||||
|
||||
var modal = rewardModal(submit);
|
||||
var template = rewardTemplate(modal);
|
||||
var runtime = window.AksrtModalRuntime;
|
||||
if (!modal || !template || !runtime) return;
|
||||
|
||||
var message = modal.querySelector('[data-aksrt-reward-message]');
|
||||
var custom = modal.querySelector('[data-aksrt-reward-custom]');
|
||||
var selected = modal.querySelector('[data-reward-amount].is-active');
|
||||
var amount = custom && custom.value ? custom.value : (selected ? selected.dataset.rewardAmount : '');
|
||||
var key;
|
||||
try {
|
||||
key = operationKey(template);
|
||||
} catch (error) {
|
||||
if (message) message.textContent = error.message || '无法创建安全请求,请稍后重试';
|
||||
return;
|
||||
}
|
||||
|
||||
submit.disabled = true;
|
||||
submit.textContent = '赞赏中…';
|
||||
if (message) message.textContent = '';
|
||||
|
||||
var body = new URLSearchParams();
|
||||
body.set('action', 'aksrt_submit_tip');
|
||||
body.set('nonce', cfg.nonce || '');
|
||||
body.set('recipient_id', modal.dataset.userId || '');
|
||||
body.set('post_id', modal.dataset.postId || '0');
|
||||
body.set('amount', amount);
|
||||
var succeeded = false;
|
||||
|
||||
window.fetch(cfg.ajaxUrl || '/wp-admin/admin-ajax.php', {
|
||||
method: 'POST',
|
||||
credentials: 'same-origin',
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
|
||||
'Idempotency-Key': key,
|
||||
},
|
||||
body: body.toString(),
|
||||
}).then(function (response) {
|
||||
return response.json();
|
||||
}).then(function (response) {
|
||||
if (runtime.getActive() !== modal) return;
|
||||
var text = response && response.data && response.data.message ? response.data.message : '赞赏失败';
|
||||
if (response && response.success) {
|
||||
succeeded = true;
|
||||
delete template.dataset.aksrtOperationKey;
|
||||
if (message) message.textContent = text;
|
||||
window.setTimeout(function () {
|
||||
if (runtime.getActive() === modal) runtime.close('success');
|
||||
}, 900);
|
||||
} else if (message) {
|
||||
message.textContent = text;
|
||||
}
|
||||
}).catch(function () {
|
||||
if (runtime.getActive() === modal && message) message.textContent = '网络错误,请稍后重试';
|
||||
}).finally(function () {
|
||||
submit.disabled = succeeded;
|
||||
submit.textContent = '余额赞赏';
|
||||
});
|
||||
});
|
||||
|
||||
document.addEventListener('input', function (event) {
|
||||
if (!event.target.matches('[data-aksrt-reward-custom]')) return;
|
||||
var modal = rewardModal(event.target);
|
||||
var template = rewardTemplate(modal);
|
||||
if (template) delete template.dataset.aksrtOperationKey;
|
||||
if (!modal) return;
|
||||
|
||||
var hasCustomAmount = event.target.value !== '';
|
||||
var firstAmount = modal.querySelector('[data-reward-amount]');
|
||||
modal.querySelectorAll('[data-reward-amount]').forEach(function (button) {
|
||||
var isActive = hasCustomAmount ? false : button === firstAmount;
|
||||
button.classList.toggle('is-active', isActive);
|
||||
button.setAttribute('aria-pressed', isActive ? 'true' : 'false');
|
||||
});
|
||||
});
|
||||
})(window, document);
|
||||
|
||||
@@ -25,9 +25,11 @@ if (!function_exists('aksrt_get_rewards_button')) {
|
||||
$settings = \AKSRT\Settings\Settings::get_post_page_settings();
|
||||
$label = (string) ($settings['rewards_btn_text'] ?? __('赞赏', 'aksrt'));
|
||||
$icon = function_exists('aksrt_icon_markup') ? aksrt_icon_markup('zibsvg-money') : '';
|
||||
$template_id = 'aksrt-reward-template-' . $user_id . '-' . $post_id;
|
||||
return sprintf(
|
||||
'<button type="button" class="%1$s aksrt-reward-open" data-aksrt-reward-open data-user-id="%2$d" data-post-id="%3$d">%4$s<text>%5$s</text></button>',
|
||||
'<button type="button" class="%1$s aksrt-reward-open" data-aksrt-reward-open data-template-id="%2$s" data-user-id="%3$d" data-post-id="%4$d">%5$s<text>%6$s</text></button>',
|
||||
esc_attr($class),
|
||||
esc_attr($template_id),
|
||||
$user_id,
|
||||
$post_id,
|
||||
$icon, // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- fixed sprite markup.
|
||||
@@ -36,8 +38,8 @@ if (!function_exists('aksrt_get_rewards_button')) {
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('aksrt_render_rewards_modal_for_user')) {
|
||||
function aksrt_render_rewards_modal_for_user(int $user_id, int $post_id = 0): void {
|
||||
if (!function_exists('aksrt_render_rewards_template_for_user')) {
|
||||
function aksrt_render_rewards_template_for_user(int $user_id, int $post_id = 0): void {
|
||||
static $done = [];
|
||||
$key = $user_id . ':' . $post_id;
|
||||
if ($user_id <= 0 || isset($done[$key]) || !aksrt_rewards_enabled()) {
|
||||
@@ -58,27 +60,34 @@ if (!function_exists('aksrt_render_rewards_modal_for_user')) {
|
||||
}
|
||||
}
|
||||
$recipient = get_userdata($user_id);
|
||||
$template_id = 'aksrt-reward-template-' . $user_id . '-' . $post_id;
|
||||
$title = (string) ($settings['rewards_text'] ?? __('赞赏', 'aksrt'));
|
||||
$money_icon = function_exists('aksrt_icon_markup') ? aksrt_icon_markup('zibsvg-money') : '<i class="fa fas fa-money-bill-wave" aria-hidden="true"></i>';
|
||||
$close_icon = function_exists('aksrt_icon_markup') ? aksrt_icon_markup('zibsvg-close', 'ic-close') : '<i class="fa fas fa-times" aria-hidden="true"></i>';
|
||||
?>
|
||||
<div class="reward-modal" id="reward-modal-<?php echo (int) $user_id; ?>" data-user-id="<?php echo (int) $user_id; ?>" data-post-id="<?php echo (int) $post_id; ?>" aria-hidden="true">
|
||||
<div class="reward-modal__overlay" data-aksrt-reward-close></div>
|
||||
<div class="reward-modal__dialog" role="dialog" aria-modal="true" aria-labelledby="reward-title-<?php echo (int) $user_id; ?>">
|
||||
<button type="button" class="reward-modal__close" data-aksrt-reward-close aria-label="<?php esc_attr_e('关闭', 'aksrt'); ?>"><i class="fa fas fa-times" aria-hidden="true"></i></button>
|
||||
<div class="reward-modal__content">
|
||||
<h3 id="reward-title-<?php echo (int) $user_id; ?>"><?php echo esc_html((string) ($settings['rewards_text'] ?? __('赞赏', 'aksrt'))); ?></h3>
|
||||
<p class="muted-2-color em09"><?php printf(esc_html__('赞赏将直接进入 %s 的站内余额', 'aksrt'), esc_html($recipient ? $recipient->display_name : __('作者', 'aksrt'))); ?></p>
|
||||
<div class="reward-amounts" data-aksrt-reward-amounts>
|
||||
<?php foreach ($render_amounts as $index => $amount) : ?>
|
||||
<button type="button" class="reward-amount<?php echo $index === 0 ? ' is-active' : ''; ?>" data-reward-amount="<?php echo esc_attr($amount); ?>">¥<?php echo esc_html($amount); ?></button>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<?php if (!empty($settings['rewards_custom'])) : ?>
|
||||
<label class="reward-custom"><span><?php esc_html_e('自定义金额', 'aksrt'); ?></span><input type="number" min="<?php echo esc_attr((string) ($settings['rewards_min'] ?? 1)); ?>" max="<?php echo esc_attr((string) ($settings['rewards_max'] ?? 1000)); ?>" step="0.01" data-aksrt-reward-custom placeholder="<?php esc_attr_e('输入金额', 'aksrt'); ?>"></label>
|
||||
<?php endif; ?>
|
||||
<button type="button" class="btn-primary reward-modal__submit" data-aksrt-reward-submit><?php esc_html_e('余额赞赏', 'aksrt'); ?></button>
|
||||
<div class="reward-modal__message" data-aksrt-reward-message role="status"></div>
|
||||
<template id="<?php echo esc_attr($template_id); ?>" data-user-id="<?php echo (int) $user_id; ?>" data-post-id="<?php echo (int) $post_id; ?>">
|
||||
<div class="modal-colorful-header colorful-bg jb-blue">
|
||||
<button type="button" class="close" data-aksrt-modal-close aria-label="<?php esc_attr_e('关闭', 'aksrt'); ?>"><?php echo $close_icon; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- fixed theme icon markup. ?></button>
|
||||
<div class="colorful-make"></div>
|
||||
<div class="text-center">
|
||||
<div class="em2x"><?php echo $money_icon; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- fixed theme icon markup. ?></div>
|
||||
<div class="mt10 em12 padding-w10 aksrt-reward__title" role="heading" aria-level="2"><?php echo esc_html($title); ?></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-body aksrt-reward__body">
|
||||
<p class="aksrt-reward__desc muted-2-color em09"><?php printf(esc_html__('赞赏将直接进入 %s 的站内余额', 'aksrt'), esc_html($recipient ? $recipient->display_name : __('作者', 'aksrt'))); ?></p>
|
||||
<div class="aksrt-reward__amounts">
|
||||
<?php foreach ($render_amounts as $index => $amount) : ?>
|
||||
<button type="button" class="aksrt-reward__amount<?php echo $index === 0 ? ' is-active' : ''; ?>" data-reward-amount="<?php echo esc_attr($amount); ?>" aria-pressed="<?php echo $index === 0 ? 'true' : 'false'; ?>"><span class="aksrt-reward__currency">¥</span><span class="aksrt-reward__value"><?php echo esc_html($amount); ?></span></button>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<?php if (!empty($settings['rewards_custom'])) : ?>
|
||||
<label class="aksrt-reward__custom"><span><?php esc_html_e('自定义金额', 'aksrt'); ?></span><input class="aksrt-reward__input" type="number" min="<?php echo esc_attr((string) ($settings['rewards_min'] ?? 1)); ?>" max="<?php echo esc_attr((string) ($settings['rewards_max'] ?? 1000)); ?>" step="0.01" data-aksrt-reward-custom placeholder="<?php esc_attr_e('输入金额', 'aksrt'); ?>"></label>
|
||||
<?php endif; ?>
|
||||
<button type="button" class="but jb-blue btn-block aksrt-reward__submit" data-aksrt-reward-submit><?php esc_html_e('余额赞赏', 'aksrt'); ?></button>
|
||||
<div class="aksrt-reward__message" data-aksrt-reward-message role="status" aria-live="polite"></div>
|
||||
</div>
|
||||
</template>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
|
||||
@@ -211,7 +211,7 @@ if (!function_exists('aksrt_single_render_actions')) :
|
||||
: '';
|
||||
if ($reward_btn !== '') {
|
||||
echo $reward_btn; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
aksrt_render_rewards_modal_for_user($reward_author, $post_id);
|
||||
aksrt_render_rewards_template_for_user($reward_author, $post_id);
|
||||
}
|
||||
?>
|
||||
|
||||
|
||||
@@ -210,6 +210,7 @@ trait ScriptsPart1b {
|
||||
'needs_navigation' => 'single-post/navigation',
|
||||
'needs_cover' => 'single-post/cover',
|
||||
'needs_related_toc' => 'single-post/related-toc',
|
||||
'needs_reward' => 'single-post/rewards',
|
||||
'has_hidden_content' => 'single-post/hidden-content',
|
||||
'needs_pay_box' => 'pay-box',
|
||||
];
|
||||
|
||||
@@ -80,7 +80,7 @@ $reward_button = get_current_user_id() !== $author_id && function_exists('aksrt_
|
||||
<?php echo $follow_html; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
|
||||
<?php if ($reward_button !== '') : ?>
|
||||
<?php echo $reward_button; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
|
||||
<?php aksrt_render_rewards_modal_for_user($author_id, get_the_ID()); ?>
|
||||
<?php aksrt_render_rewards_template_for_user($author_id, get_the_ID()); ?>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -26,7 +26,6 @@ const routed = [
|
||||
'assets/js/author.js',
|
||||
'assets/js/credits.js',
|
||||
'assets/js/order-center.js',
|
||||
'assets/js/reward.js',
|
||||
'assets/js/routes/user-center.js',
|
||||
'assets/js/signin.js',
|
||||
'assets/js/section-navs.js',
|
||||
@@ -99,6 +98,34 @@ test('routed modules use one namespaced auto_fun owner and no registry', () => {
|
||||
}
|
||||
});
|
||||
|
||||
test('wallet reward content opens in the shared modal runtime once', () => {
|
||||
const reward = read('assets/js/reward.js');
|
||||
const helper = read('inc/helpers/aksrt-rewards.php');
|
||||
const authorBar = read('templates/parts/single-author-bar.php');
|
||||
const singleActions = read('inc/helpers/aksrt-single-render.php');
|
||||
const scripts = read('src/Core/ScriptsPart1b.php');
|
||||
|
||||
assert.match(reward, /runtime\.open\(\{/);
|
||||
assert.match(reward, /className: 'aksrt-reward-modal modal-mini full-sm'/);
|
||||
assert.match(reward, /mobileBottom: true/);
|
||||
assert.match(reward, /shell\.setAttribute\('aria-labelledby', title\.id\)/);
|
||||
assert.match(reward, /'Idempotency-Key': key/);
|
||||
assert.equal((reward.match(/document\.addEventListener\('click'/g) || []).length, 1);
|
||||
assert.doesNotMatch(reward, /auto_fun|reward-modal\.is-open/);
|
||||
|
||||
assert.equal((helper.match(/<template\b/g) || []).length, 1);
|
||||
assert.match(helper, /data-template-id="%2\$s"/);
|
||||
assert.match(helper, /static \$done = \[\]/);
|
||||
assert.match(helper, /isset\(\$done\[\$key\]\)/);
|
||||
assert.match(helper, /modal-colorful-header colorful-bg jb-blue/);
|
||||
assert.match(helper, /data-aksrt-modal-close/);
|
||||
assert.match(helper, /data-aksrt-reward-submit/);
|
||||
assert.match(authorBar, /aksrt_render_rewards_template_for_user/);
|
||||
assert.match(singleActions, /aksrt_render_rewards_template_for_user/);
|
||||
assert.match(scripts, /'needs_reward'\s*=>\s*'single-post\/rewards'/);
|
||||
assert.doesNotMatch(helper + authorBar + singleActions, /aksrt_render_rewards_modal_for_user|reward-modal__qr/);
|
||||
});
|
||||
|
||||
test('user center navigation initializes once across auto_fun rescans', () => {
|
||||
const source = read('assets/js/routes/user-center.js');
|
||||
const initAt = source.indexOf('function initDashboardNavigation()');
|
||||
|
||||
@@ -220,7 +220,6 @@ test('dead cover css is removed from every stylesheet surface', () => {
|
||||
'assets/css/main.min.css',
|
||||
'assets/css/build/public.css',
|
||||
'assets/css/build/public.min.css',
|
||||
'assets/css/frontend/enhancements/components/base.css',
|
||||
]) {
|
||||
const css = read(file);
|
||||
assert.doesNotMatch(css, /\.single-cover-slide[,{ ]/, `${file} 不得再包含死的 .single-cover-slide 规则`);
|
||||
|
||||
Reference in New Issue
Block a user