Skip to content

Commit 689114e

Browse files
authored
Delay submit in Desktop Safari (hestiacp#4137)
To ensure spinner is shown.
1 parent afe73c8 commit 689114e

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

web/js/src/formSubmit.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,26 @@
11
import { enableUnlimitedInputs } from './unlimitedInput';
22
import { updateAdvancedTextarea } from './toggleAdvanced';
3-
import { showSpinner } from './helpers';
3+
import { isDesktopSafari, showSpinner } from './helpers';
44

55
export default function handleFormSubmit() {
66
const mainForm = document.querySelector('#main-form');
77
if (mainForm) {
8-
mainForm.addEventListener('submit', () => {
8+
mainForm.addEventListener('submit', (event) => {
99
// Show loading spinner
1010
showSpinner();
1111

12+
// Wait a bit if Desktop Safari to ensure spinner is shown
13+
if (isDesktopSafari()) {
14+
const submitButton = document.querySelector('button[type="submit"]');
15+
if (!submitButton.dataset.clicked) {
16+
event.preventDefault();
17+
submitButton.dataset.clicked = 'true';
18+
setTimeout(() => {
19+
mainForm.submit();
20+
}, 500);
21+
}
22+
}
23+
1224
// Enable any disabled inputs to ensure all fields are submitted
1325
if (mainForm.classList.contains('js-enable-inputs-on-submit')) {
1426
document.querySelectorAll('input[disabled]').forEach((input) => {

web/js/src/helpers.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,14 @@ export function parseAndSortIpLists(ipListsData) {
4343
return ipLists.sort((a, b) => a.name.localeCompare(b.name));
4444
}
4545

46+
// Determines if the current browser is Desktop Safari
47+
export function isDesktopSafari() {
48+
const userAgent = window.navigator.userAgent;
49+
const isSafari = /^((?!chrome|android).)*safari/i.test(userAgent);
50+
const isMobile = /iPhone|iPad|iPod|Android/i.test(userAgent);
51+
return isSafari && !isMobile;
52+
}
53+
4654
// Posts data to the given URL and returns the response
4755
export async function post(url, data, headers = {}) {
4856
const requestOptions = {

0 commit comments

Comments
 (0)