mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
Merge pull request #5190 from overleaf/jpa-sso-oauth-de-ng
[web] de-ng sso/oauth/institutional account linking pages GitOrigin-RevId: 50718cefff68142431aa411cb4f8644a3d8ab93f
This commit is contained in:
parent
7bdd5c8e98
commit
c9e22f7ddf
5 changed files with 61 additions and 23 deletions
|
@ -2,6 +2,7 @@ import classNames from 'classnames'
|
|||
import { FetchError, postJSON } from '../../infrastructure/fetch-json'
|
||||
import { validateCaptchaV2 } from './captcha'
|
||||
import inputValidator from './input-validator'
|
||||
import { disableElement, enableElement } from '../utils/disableElement'
|
||||
|
||||
// Form helper(s) to handle:
|
||||
// - Attaching to the relevant form elements
|
||||
|
@ -122,16 +123,12 @@ export function inflightHelper(el) {
|
|||
const showWhenInflight = el.querySelectorAll('[data-ol-inflight="pending"]')
|
||||
|
||||
el.addEventListener('pending', () => {
|
||||
disabledInflight.forEach(el => {
|
||||
el.disabled = true
|
||||
})
|
||||
disabledInflight.forEach(disableElement)
|
||||
toggleDisplay(showWhenNotInflight, showWhenInflight)
|
||||
})
|
||||
|
||||
el.addEventListener('idle', () => {
|
||||
disabledInflight.forEach(el => {
|
||||
el.disabled = false
|
||||
})
|
||||
disabledInflight.forEach(enableElement)
|
||||
toggleDisplay(showWhenInflight, showWhenNotInflight)
|
||||
})
|
||||
}
|
||||
|
@ -146,20 +143,7 @@ function formSentHelper(el) {
|
|||
})
|
||||
}
|
||||
|
||||
export function toggleDisplay(hide, show) {
|
||||
hide.forEach(el => {
|
||||
el.hidden = true
|
||||
})
|
||||
show.forEach(el => {
|
||||
el.hidden = false
|
||||
})
|
||||
}
|
||||
|
||||
export function hydrateForm(el) {
|
||||
formSubmitHelper(el)
|
||||
inflightHelper(el)
|
||||
formSentHelper(el)
|
||||
|
||||
function formValidationHelper(el) {
|
||||
el.querySelectorAll('input').forEach(inputEl => {
|
||||
if (
|
||||
inputEl.willValidate &&
|
||||
|
@ -170,6 +154,31 @@ export function hydrateForm(el) {
|
|||
})
|
||||
}
|
||||
|
||||
document
|
||||
.querySelectorAll(`[data-ol-async-form]`)
|
||||
.forEach(form => hydrateForm(form))
|
||||
export function toggleDisplay(hide, show) {
|
||||
hide.forEach(el => {
|
||||
el.hidden = true
|
||||
})
|
||||
show.forEach(el => {
|
||||
el.hidden = false
|
||||
})
|
||||
}
|
||||
|
||||
function hydrateAsyncForm(el) {
|
||||
formSubmitHelper(el)
|
||||
inflightHelper(el)
|
||||
formSentHelper(el)
|
||||
formValidationHelper(el)
|
||||
}
|
||||
|
||||
function hydrateRegularForm(el) {
|
||||
inflightHelper(el)
|
||||
formValidationHelper(el)
|
||||
|
||||
el.addEventListener('submit', () => {
|
||||
el.dispatchEvent(new Event('pending'))
|
||||
})
|
||||
}
|
||||
|
||||
document.querySelectorAll(`[data-ol-async-form]`).forEach(hydrateAsyncForm)
|
||||
|
||||
document.querySelectorAll(`[data-ol-regular-form]`).forEach(hydrateRegularForm)
|
||||
|
|
|
@ -1,8 +1,13 @@
|
|||
import { inflightHelper } from '../form-helpers/hydrate-form'
|
||||
import { disableElement } from '../utils/disableElement'
|
||||
|
||||
function setup(el) {
|
||||
// Make the element discoverable for multi-submit.
|
||||
el.setAttribute('data-ol-disabled-inflight', '')
|
||||
|
||||
inflightHelper(el)
|
||||
el.addEventListener('click', function () {
|
||||
disableElement(el)
|
||||
el.dispatchEvent(new Event('pending'))
|
||||
})
|
||||
}
|
||||
|
|
14
services/web/frontend/js/features/multi-submit/index.js
Normal file
14
services/web/frontend/js/features/multi-submit/index.js
Normal file
|
@ -0,0 +1,14 @@
|
|||
import { disableElement } from '../utils/disableElement'
|
||||
|
||||
document.querySelectorAll('[data-ol-multi-submit]').forEach(el => {
|
||||
function onSubmit() {
|
||||
el.querySelectorAll('[data-ol-disabled-inflight]').forEach(disableElement)
|
||||
}
|
||||
function setup(childEl) {
|
||||
childEl.addEventListener('pending', onSubmit)
|
||||
}
|
||||
el.querySelectorAll('[data-ol-regular-form]').forEach(setup)
|
||||
el.querySelectorAll('[data-ol-slow-link]').forEach(setup)
|
||||
// NOTE: data-ol-async-form is not added explicitly as of now.
|
||||
// Managing the return to idle is tricky and we can look into that later.
|
||||
})
|
|
@ -0,0 +1,9 @@
|
|||
export function disableElement(el) {
|
||||
el.setAttribute('disabled', '')
|
||||
el.setAttribute('aria-disabled', 'true')
|
||||
}
|
||||
|
||||
export function enableElement(el) {
|
||||
el.removeAttribute('disabled')
|
||||
el.removeAttribute('aria-disabled')
|
||||
}
|
|
@ -5,5 +5,6 @@ import './features/form-helpers/hydrate-form'
|
|||
import './features/link-helpers/slow-link'
|
||||
import './features/contact-form'
|
||||
import './features/event-tracking'
|
||||
import './features/multi-submit'
|
||||
|
||||
$('[data-ol-lang-selector-tooltip]').tooltip({ trigger: 'hover' })
|
||||
|
|
Loading…
Reference in a new issue