mirror of
https://github.com/glitch-soc/mastodon.git
synced 2025-12-14 00:08:46 +00:00
[Glitch] Add UJS to buttons
Port 100b20f290 to glitch-soc
Signed-off-by: Claire <claire.github-309c@sitedethib.com>
This commit is contained in:
@@ -5,20 +5,26 @@ export function setupLinkListeners() {
|
|||||||
|
|
||||||
// We don't want to target links with data-confirm here, as those are handled already.
|
// We don't want to target links with data-confirm here, as those are handled already.
|
||||||
on('click', 'a[data-method]:not([data-confirm])', handleMethodLink);
|
on('click', 'a[data-method]:not([data-confirm])', handleMethodLink);
|
||||||
|
|
||||||
|
// We also want to target buttons with data-confirm that are not inside forms.
|
||||||
|
on('click', ':not(form) button[data-confirm]:not([form])', handleConfirmLink);
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleConfirmLink(event: MouseEvent) {
|
function handleConfirmLink(event: MouseEvent) {
|
||||||
const anchor = event.currentTarget;
|
const target = event.currentTarget;
|
||||||
if (!(anchor instanceof HTMLAnchorElement)) {
|
if (
|
||||||
|
!(target instanceof HTMLAnchorElement) &&
|
||||||
|
!(target instanceof HTMLButtonElement)
|
||||||
|
) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const message = anchor.dataset.confirm;
|
const message = target.dataset.confirm;
|
||||||
if (!message || !window.confirm(message)) {
|
if (!message || !window.confirm(message)) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (anchor.dataset.method) {
|
if (target.dataset.method) {
|
||||||
handleMethodLink(event);
|
handleMethodLink(event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user