fix some errors in typescript

This commit is contained in:
Matteo Manzinello 2020-07-24 10:40:46 +02:00
parent 749ebdd628
commit 4237137107
7 changed files with 48 additions and 39 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

2
dist/mailgo.min.js vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -977,18 +977,18 @@ var setModalDisplay = function setModalDisplay() {
var modal = getModalHTMLElement(ref); var modal = getModalHTMLElement(ref);
modal.style.display = value; modal.style.display = value;
if (value === 'flex') { if (value === "flex") {
// "save" the activated link. // "save" the activated link.
activatedLink = document.activeElement; activatedLink = document.activeElement;
modal.setAttribute('aria-hidden', false); // Focus on the modal container. modal.setAttribute("aria-hidden", "false"); // Focus on the modal container.
modal.setAttribute('tabindex', "0"); modal.setAttribute("tabindex", "0");
modal.focus(); modal.focus();
setFocusLoop(modal); setFocusLoop(modal);
} else { } else {
modal.setAttribute('aria-hidden', true); // focus back the activated link for getting back to the context. modal.setAttribute("aria-hidden", "true"); // focus back the activated link for getting back to the context.
modal.setAttribute('tabindex', '-1'); modal.setAttribute("tabindex", "-1");
activatedLink.focus(); activatedLink.focus();
} }
}; // set focus loop within modal }; // set focus loop within modal
@ -996,23 +996,23 @@ var setModalDisplay = function setModalDisplay() {
var setFocusLoop = function setFocusLoop(ref) { var setFocusLoop = function setFocusLoop(ref) {
var modal = ref; var modal = ref;
modal.querySelector('.m-modal-content a:last-of-type').addEventListener('keydown', leaveLastLink); modal.querySelector(".m-modal-content a:last-of-type").addEventListener("keydown", leaveLastLink);
modal.querySelector('.m-modal-content a:first-of-type').addEventListener('keydown', leaveFirstLink); modal.querySelector(".m-modal-content a:first-of-type").addEventListener("keydown", leaveFirstLink);
}; };
var leaveLastLink = function leaveLastLink(e) { var leaveLastLink = function leaveLastLink(e) {
// going back to the first link to force looping // going back to the first link to force looping
if (e.code === 'Tab' && e.shiftKey === false) { if (e.code === "Tab" && e.shiftKey === false) {
e.preventDefault(); e.preventDefault();
e.target.closest('div').querySelector('a:first-of-type').focus(); e.target.closest("div").querySelector("a:first-of-type").focus();
} }
}; };
var leaveFirstLink = function leaveFirstLink(e) { var leaveFirstLink = function leaveFirstLink(e) {
// going back to the first link to force looping // going back to the first link to force looping
if (e.code === 'Tab' && e.shiftKey === true) { if (e.code === "Tab" && e.shiftKey === true) {
e.preventDefault(); e.preventDefault();
e.target.closest('div').querySelector('a:last-of-type').focus(); e.target.closest("div").querySelector("a:last-of-type").focus();
} }
}; // enable dark mode }; // enable dark mode

File diff suppressed because one or more lines are too long

View File

@ -890,50 +890,59 @@ const getModalDisplay = (ref: string = MAIL_TYPE): string =>
getModalHTMLElement(ref).style.display; getModalHTMLElement(ref).style.display;
// set display value // set display value
const setModalDisplay = (ref: string = MAIL_TYPE, value: string): string => { const setModalDisplay = (ref: string = MAIL_TYPE, value: string): void => {
let modal = getModalHTMLElement(ref); let modal = getModalHTMLElement(ref);
modal.style.display = value; modal.style.display = value;
if ( value === 'flex' ) { if (value === "flex") {
// "save" the activated link. // "save" the activated link.
activatedLink = document.activeElement; activatedLink = document.activeElement as HTMLElement;
modal.setAttribute('aria-hidden', false); modal.setAttribute("aria-hidden", "false");
// Focus on the modal container. // Focus on the modal container.
modal.setAttribute('tabindex', "0"); modal.setAttribute("tabindex", "0");
modal.focus(); modal.focus();
setFocusLoop(modal); setFocusLoop(modal);
} else { } else {
modal.setAttribute('aria-hidden', true); modal.setAttribute("aria-hidden", "true");
// focus back the activated link for getting back to the context. // focus back the activated link for getting back to the context.
modal.setAttribute('tabindex', '-1'); modal.setAttribute("tabindex", "-1");
activatedLink.focus(); activatedLink.focus();
} }
} };
// set focus loop within modal // set focus loop within modal
const setFocusLoop = (ref: HTMLElement): string => { const setFocusLoop = (ref: HTMLElement): void => {
let modal = ref; let modal = ref;
modal.querySelector('.m-modal-content a:last-of-type').addEventListener('keydown', leaveLastLink); modal
modal.querySelector('.m-modal-content a:first-of-type').addEventListener('keydown', leaveFirstLink); .querySelector(".m-modal-content a:last-of-type")
} .addEventListener("keydown", leaveLastLink);
modal
.querySelector(".m-modal-content a:first-of-type")
.addEventListener("keydown", leaveFirstLink);
};
const leaveLastLink = (e): void => { const leaveLastLink = (e: KeyboardEvent): void => {
// going back to the first link to force looping // going back to the first link to force looping
if ( e.code === 'Tab' && e.shiftKey === false ) { if (e.code === "Tab" && e.shiftKey === false) {
e.preventDefault(); e.preventDefault();
e.target.closest('div').querySelector('a:first-of-type').focus();
}
}
const leaveFirstLink = (e): void => { ((e.target as HTMLElement)
.closest("div")
.querySelector("a:first-of-type") as HTMLElement).focus();
}
};
const leaveFirstLink = (e: KeyboardEvent): void => {
// going back to the first link to force looping // going back to the first link to force looping
if ( e.code === 'Tab' && e.shiftKey === true ) { if (e.code === "Tab" && e.shiftKey === true) {
e.preventDefault(); e.preventDefault();
e.target.closest('div').querySelector('a:last-of-type').focus(); ((e.target as HTMLElement)
} .closest("div")
.querySelector("a:last-of-type") as HTMLElement).focus();
} }
};
// enable dark mode // enable dark mode
const enableDarkMode = (type: string = MAIL_TYPE) => const enableDarkMode = (type: string = MAIL_TYPE) =>