Replaced confirm pages with dynamic requests on the forum.
This commit is contained in:
parent
a8c777d725
commit
265e8f2d4b
18 changed files with 1159 additions and 437 deletions
|
@ -164,6 +164,9 @@
|
|||
transition: background-color .2s;
|
||||
border-radius: 3px;
|
||||
cursor: pointer;
|
||||
font-family: inherit;
|
||||
font-size: inherit;
|
||||
line-height: inherit;
|
||||
}
|
||||
.forum__post__action:hover,
|
||||
.forum__post__action:focus {
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
#include msgbox.jsx
|
||||
#include utility.js
|
||||
#include xhr.js
|
||||
#include embed/embed.js
|
||||
|
@ -64,12 +65,73 @@
|
|||
});
|
||||
};
|
||||
|
||||
const initXhrActions = () => {
|
||||
const targets = Array.from($qa('a[data-url], button[data-url]'));
|
||||
for(const target of targets) {
|
||||
target.onclick = async () => {
|
||||
if(target.disabled)
|
||||
return;
|
||||
|
||||
const url = target.dataset.url;
|
||||
if(typeof url !== 'string' || url.length < 1)
|
||||
return;
|
||||
|
||||
const disableWithTarget = typeof target.dataset.disableWithTarget === 'string'
|
||||
? (target.querySelector(target.dataset.disableWithTarget) ?? target)
|
||||
: target;
|
||||
const originalText = disableWithTarget.textContent;
|
||||
|
||||
try {
|
||||
target.disabled = true;
|
||||
if(target.dataset.disableWith)
|
||||
disableWithTarget.textContent = target.dataset.disableWith;
|
||||
|
||||
if(target.dataset.confirm && !await MszShowConfirmBox(target.dataset.confirm, 'Are you sure?'))
|
||||
return;
|
||||
|
||||
const { status, body } = await $x.send(
|
||||
target.dataset.method ?? 'GET',
|
||||
url,
|
||||
{
|
||||
type: 'json',
|
||||
authed: target.dataset.withAuth,
|
||||
csrf: target.dataset.withCsrf,
|
||||
}
|
||||
)
|
||||
|
||||
if(status >= 400)
|
||||
await MszShowMessageBox(
|
||||
body?.error?.text ?? `No additional information was provided. (HTTP ${status})`,
|
||||
'Failed to complete action'
|
||||
);
|
||||
else if(status >= 200 && status <= 299) {
|
||||
if(target.dataset.refreshOnSuccess)
|
||||
location.reload();
|
||||
else {
|
||||
const redirectUrl = target.dataset.redirectOnSuccess;
|
||||
if(typeof redirectUrl === 'string' && redirectUrl.startsWith('/') && !redirectUrl.startsWith('//'))
|
||||
location.assign(redirectUrl);
|
||||
}
|
||||
}
|
||||
} catch(ex) {
|
||||
console.error(ex);
|
||||
await MszShowMessageBox(ex, 'Failed to complete action');
|
||||
} finally {
|
||||
disableWithTarget.textContent = originalText;
|
||||
target.disabled = false;
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
try {
|
||||
MszSakuya.trackElements($qa('time'));
|
||||
hljs.highlightAll();
|
||||
|
||||
MszEmbed.init(`${location.protocol}//uiharu.${location.host}`);
|
||||
|
||||
initXhrActions();
|
||||
|
||||
// only used by the forum posting form
|
||||
initQuickSubmit();
|
||||
const forumPostingForm = $q('.js-forum-posting');
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue