Files
notifications-admin/app/assets/javascripts/fileUpload.js
T

78 lines
2.1 KiB
JavaScript
Raw Normal View History

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);
}
}
2025-04-01 13:03:12 -04:00
// Exported for use in tests
function initUploadStatusAnnouncer() {
document.addEventListener('DOMContentLoaded', () => {
announceUploadStatusFromElement();
});
}
2025-10-06 09:38:54 -04:00
(function(window) {
2016-02-02 17:28:30 +00:00
"use strict";
2025-10-06 09:38:54 -04:00
window.NotifyModules['file-upload'] = function() {
2025-10-21 09:35:41 -04:00
this.submit = () => this.form.submit();
2016-02-02 17:28:30 +00:00
this.showCancelButton = () => {
2025-10-21 09:35:41 -04:00
const uploadButton = this.form.querySelector('.file-upload-button');
if (uploadButton) {
uploadButton.outerHTML = `
<button class='usa-button uploading-button' aria-disabled="true" tabindex="0">
Uploading<span class="loading-spinner" role="status" aria-label="Uploading"></span>
</button>
`;
}
};
2016-02-02 17:28:30 +00:00
this.start = function(component) {
2025-10-21 09:35:41 -04:00
this.form = component;
2016-02-02 17:28:30 +00:00
2025-10-21 09:35:41 -04:00
this.form.addEventListener('click', (event) => {
const trigger = event.target.closest('[data-module="upload-trigger"]');
if (trigger) {
const inputId = trigger.dataset.fileInputId;
const fileInput = document.getElementById(inputId);
if (fileInput) fileInput.click();
}
2025-03-28 10:36:17 -04:00
});
2025-10-21 09:35:41 -04:00
window.addEventListener("pageshow", () => this.form.reset());
2025-10-21 09:35:41 -04:00
this.form.addEventListener('change', (event) => {
if (event.target.closest('.file-upload-field')) {
this.submit();
this.showCancelButton();
}
2025-03-28 10:36:17 -04:00
});
2016-02-02 17:28:30 +00:00
};
};
2025-10-06 09:38:54 -04:00
})(window);
2025-04-01 13:03:12 -04:00
if (typeof module !== 'undefined' && module.exports) {
module.exports = {
announceUploadStatusFromElement,
initUploadStatusAnnouncer
};
}
2025-04-01 16:22:46 -04:00
if (typeof window !== 'undefined') {
initUploadStatusAnnouncer();
}