Feature/#48 migrate to typescript #151

Merged
Serraniel merged 30 commits from feature/#48-migrate-to-typescript into develop 2020-12-30 17:24:49 +01:00
Showing only changes of commit b0d0f66369 - Show all commits

View file

@ -5,7 +5,7 @@ import * as helper from '../utils/helpers';
const quickSearchID = 'ea-quickSearch'; const quickSearchID = 'ea-quickSearch';
const quickSearchLink = 'ea-quickSearchLink'; const quickSearchLink = 'ea-quickSearchLink';
export function init() { export function init(): void {
getGlobalConfiguration().getProperty(SETTINGS_websiteDisplayQuickSearch, value => { getGlobalConfiguration().getProperty(SETTINGS_websiteDisplayQuickSearch, value => {
if (value) { if (value) {
core.runAfterLoad(() => { core.runAfterLoad(() => {
@ -15,7 +15,7 @@ export function init() {
}); });
} }
function initSearch() { function initSearch(): void {
let entry = document.createElement('li'); let entry = document.createElement('li');
entry.setAttribute('ng-repeat', 'item in navbar'); entry.setAttribute('ng-repeat', 'item in navbar');
entry.setAttribute('ng-class', '{\'anime-indicator\': item[\'@attributes\'].title==\'Anime\'}'); entry.setAttribute('ng-class', '{\'anime-indicator\': item[\'@attributes\'].title==\'Anime\'}');
@ -45,13 +45,13 @@ function initSearch() {
document.addEventListener('keypress', event => handleSearchForShiftF(event)); document.addEventListener('keypress', event => handleSearchForShiftF(event));
// additionally, the last dropdown ul has a "right: 0px" style, which has to be fixed with auto, otherwhise it will pop up in the wrong position // additionally, the last dropdown ul has a "right: 0px" style, which has to be fixed with auto, otherwhise it will pop up in the wrong position
Array.from(menu.querySelectorAll('ul.dropdown')).slice(-1)[0].style.right = 'auto'; (Array.from(menu.querySelectorAll('ul.dropdown')).slice(-1)[0] as HTMLElement).style.right = 'auto';
} }
function handleQuickSearch(event) { function handleQuickSearch(event: KeyboardEvent): void {
if (event.key === 'Enter') { if (event.key === 'Enter') {
let quickSearchElement = document.getElementById(quickSearchID); let quickSearchElement = document.getElementById(quickSearchID) as HTMLInputElement;
let linkElement = document.getElementById(quickSearchLink); let linkElement = document.getElementById(quickSearchLink) as HTMLAnchorElement;
let url = new URL(window.location.origin) let url = new URL(window.location.origin)
url.pathname = '/search'; url.pathname = '/search';
@ -67,10 +67,10 @@ function handleQuickSearch(event) {
} }
} }
function handleSearchForShiftF(event) { function handleSearchForShiftF(event: KeyboardEvent): void {
if (helper.isShiftPressed) { if (helper.isShiftPressed) {
// check if some kind of input is focused already; we then prevent our hotkey // check if some kind of input is focused already; we then prevent our hotkey
if (document.activeElement instanceof HTMLInputElement || document.activeElement instanceof HTMLTextAreaElement || document.activeElement.isContentEditable) { if (document.activeElement instanceof HTMLInputElement || document.activeElement instanceof HTMLTextAreaElement || ((document.activeElement as HTMLElement)?.isContentEditable ?? false)) {
return; return;
} }