-
-
Notifications
You must be signed in to change notification settings - Fork 156
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch '5.x' into feature/edit-image-sizes
- Loading branch information
Showing
560 changed files
with
6,611 additions
and
12,454 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
window.addEventListener('DOMContentLoaded', () => { | ||
document.querySelectorAll('[data-ajax-form]').forEach(el => { | ||
function request(form, body, callback) { | ||
const xhr = new XMLHttpRequest(); | ||
|
||
xhr.open('POST', form.action, true); | ||
xhr.setRequestHeader('Accept', 'text/html'); | ||
xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest'); | ||
xhr.setRequestHeader('X-Contao-Ajax-Form', form.querySelector('[name="FORM_SUBMIT"]').value); | ||
|
||
form.ariaBusy = 'true'; | ||
form.dataset.ajaxForm = 'loading'; | ||
|
||
xhr.onload = () => { | ||
form.dispatchEvent(new CustomEvent('ajax-form-onload', { | ||
bubbles: true, | ||
detail: { body, form, xhr }, | ||
})); | ||
|
||
form.ariaBusy = 'false'; | ||
form.dataset.ajaxForm = ''; | ||
|
||
callback(xhr); | ||
}; | ||
|
||
xhr.send(body || null) | ||
} | ||
|
||
function initForm(form) { | ||
form.addEventListener('submit', e => { | ||
e.preventDefault(); | ||
|
||
const formData = new FormData(form); | ||
|
||
// Send the triggered button data as well | ||
if (e.submitter) { | ||
formData.append(e.submitter.name, e.submitter.value); | ||
} | ||
|
||
request(form, formData, xhr => { | ||
const location = xhr.getResponseHeader('X-Ajax-Location'); | ||
|
||
// Handle the redirect header | ||
if (location) { | ||
window.location.href = location; | ||
return; | ||
} | ||
|
||
const template = document.createElement('template'); | ||
template.innerHTML = xhr.responseText.trim(); | ||
|
||
const newForm = template.content.firstElementChild; | ||
form.replaceWith(newForm); | ||
initForm(newForm); | ||
}); | ||
}); | ||
} | ||
|
||
initForm(el); | ||
}); | ||
}); |
Oops, something went wrong.