mirror of
https://github.com/GSA/notifications-admin.git
synced 2025-12-16 01:53:56 -05:00
70 lines
1.8 KiB
JavaScript
70 lines
1.8 KiB
JavaScript
function announceUploadStatusFromElement() {
|
|
const srRegion = document.getElementById('upload-status-live');
|
|
const success = document.getElementById('upload-success');
|
|
const error = document.getElementById('upload-error');
|
|
|
|
if (!srRegion) return;
|
|
|
|
const message = error?.textContent || success?.textContent;
|
|
|
|
if (message) {
|
|
srRegion.textContent = '';
|
|
setTimeout(() => {
|
|
srRegion.textContent = message + '\u00A0'; // add a non-breaking space
|
|
srRegion.focus(); // Optional
|
|
}, 300);
|
|
}
|
|
}
|
|
|
|
|
|
// Exported for use in tests
|
|
function initUploadStatusAnnouncer() {
|
|
document.addEventListener('DOMContentLoaded', () => {
|
|
announceUploadStatusFromElement();
|
|
});
|
|
}
|
|
|
|
(function(Modules) {
|
|
"use strict";
|
|
|
|
Modules.FileUpload = function() {
|
|
this.submit = () => this.$form.trigger('submit');
|
|
|
|
this.showCancelButton = () => {
|
|
$('.file-upload-button', this.$form).replaceWith(`
|
|
<button class='usa-button uploading-button' aria-disabled="true" tabindex="0">
|
|
Uploading<span class="dot-anim" aria-hidden="true"></span>
|
|
</button>
|
|
`);
|
|
};
|
|
|
|
this.start = function(component) {
|
|
this.$form = $(component);
|
|
|
|
this.$form.on('click', '[data-module="upload-trigger"]', function () {
|
|
const inputId = $(this).data('file-input-id');
|
|
const fileInput = document.getElementById(inputId);
|
|
if (fileInput) fileInput.click();
|
|
});
|
|
|
|
$(window).on("pageshow", () => this.$form[0].reset());
|
|
|
|
this.$form.on('change', '.file-upload-field', () => {
|
|
this.submit();
|
|
this.showCancelButton();
|
|
});
|
|
};
|
|
};
|
|
})(window.GOVUK.Modules);
|
|
|
|
if (typeof module !== 'undefined' && module.exports) {
|
|
module.exports = {
|
|
announceUploadStatusFromElement,
|
|
initUploadStatusAnnouncer
|
|
};
|
|
}
|
|
|
|
if (typeof window !== 'undefined') {
|
|
initUploadStatusAnnouncer();
|
|
}
|