Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delay submit in Desktop Safari #4137

Merged
merged 1 commit into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 14 additions & 2 deletions web/js/src/formSubmit.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
import { enableUnlimitedInputs } from './unlimitedInput';
import { updateAdvancedTextarea } from './toggleAdvanced';
import { showSpinner } from './helpers';
import { isDesktopSafari, showSpinner } from './helpers';

export default function handleFormSubmit() {
const mainForm = document.querySelector('#main-form');
if (mainForm) {
mainForm.addEventListener('submit', () => {
mainForm.addEventListener('submit', (event) => {
// Show loading spinner
showSpinner();

// Wait a bit if Desktop Safari to ensure spinner is shown
if (isDesktopSafari()) {
const submitButton = document.querySelector('button[type="submit"]');
if (!submitButton.dataset.clicked) {
event.preventDefault();
submitButton.dataset.clicked = 'true';
setTimeout(() => {
mainForm.submit();
}, 500);
}
}

// Enable any disabled inputs to ensure all fields are submitted
if (mainForm.classList.contains('js-enable-inputs-on-submit')) {
document.querySelectorAll('input[disabled]').forEach((input) => {
Expand Down
8 changes: 8 additions & 0 deletions web/js/src/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ export function parseAndSortIpLists(ipListsData) {
return ipLists.sort((a, b) => a.name.localeCompare(b.name));
}

// Determines if the current browser is Desktop Safari
export function isDesktopSafari() {
const userAgent = window.navigator.userAgent;
const isSafari = /^((?!chrome|android).)*safari/i.test(userAgent);
const isMobile = /iPhone|iPad|iPod|Android/i.test(userAgent);
return isSafari && !isMobile;
}

// Posts data to the given URL and returns the response
export async function post(url, data, headers = {}) {
const requestOptions = {
Expand Down