diff --git a/index.html b/index.html index 2256c92..5f8038e 100644 --- a/index.html +++ b/index.html @@ -372,30 +372,25 @@ \ No newline at end of file diff --git a/src/index.js b/src/index.js index 48f5350..aa62245 100644 --- a/src/index.js +++ b/src/index.js @@ -20,12 +20,11 @@ function initialize() { }); } - setupAds().then(() => renderAll()); + setupAds(); + renderAll(); } window.onload = (function (oldLoad) { - return function () { - oldLoad && oldLoad(); - initialize(); - } + oldLoad && oldLoad(); + initialize(); })(window.onload); \ No newline at end of file diff --git a/src/js/account/passwordReset.js b/src/js/account/passwordReset.js index 2d7eb4c..488563c 100644 --- a/src/js/account/passwordReset.js +++ b/src/js/account/passwordReset.js @@ -1,4 +1,3 @@ -import { setupInfoModal } from "../setupListeners"; import { request } from "./helpers"; export function renderForgotPasswordForm() { @@ -24,6 +23,15 @@ export function renderForgotPasswordForm() { setupInfoModal(modal); } +function setupInfoModal(modal) { + const closeElements = modal.querySelectorAll('.modal-background, .close-button'); + Array.from(closeElements).forEach(close => { + close.addEventListener('click', () => { + modal.parentElement.removeChild(modal); + }); + }); +} + function setupStartResetForm() { document.getElementById('forgotPasswordSubmit').addEventListener('click', startPasswordReset); } @@ -59,7 +67,10 @@ function startPasswordReset() { } function setupPasswordResetForm() { - document.getElementById('newPasswordSubmit').addEventListener('click', submitPasswordReset); + const submitButton = document.getElementById('newPasswordSubmit'); + if (submitButton) { + submitButton.addEventListener('click', submitPasswordReset); + } } function submitPasswordReset() { @@ -97,8 +108,6 @@ function submitPasswordReset() { } window.onload = (function (oldLoad) { - return function () { - oldLoad && oldLoad(); - setupPasswordResetForm(); - } + oldLoad && oldLoad(); + setupPasswordResetForm(); })(window.onload); \ No newline at end of file diff --git a/src/js/ads.js b/src/js/ads.js index 66de56a..8ad52cc 100644 --- a/src/js/ads.js +++ b/src/js/ads.js @@ -1,12 +1,11 @@ import { DISPLAY_AD_EVERY } from '../constants.js'; +import ads from '../../ads.json'; export function setupAds() { - return import('../../ads.json').then(ads => { - const shuffle = (a, b) => Math.random() > 0.5 ? 1 : -1; - const priority = ads.filter(ad => isActive(ad) && ad.isPriority).sort(shuffle); - const regular = ads.filter(ad => isActive(ad) && !ad.isPriority).sort(shuffle); - window.ads = [...priority, ...regular]; - }); + const shuffle = (a, b) => Math.random() > 0.5 ? 1 : -1; + const priority = ads.filter(ad => isActive(ad) && ad.isPriority).sort(shuffle); + const regular = ads.filter(ad => isActive(ad) && !ad.isPriority).sort(shuffle); + window.ads = [...priority, ...regular]; } function isActive(ad) { diff --git a/src/js/dictionaryManagement.js b/src/js/dictionaryManagement.js index 0890537..a6d1c91 100644 --- a/src/js/dictionaryManagement.js +++ b/src/js/dictionaryManagement.js @@ -1,3 +1,4 @@ +import papa from 'papaparse'; import { renderDictionaryDetails, renderPartsOfSpeech, renderAll, renderTheme } from "./render"; import { removeTags, cloneObject, getTimestampInSeconds, download, slugify } from "../helpers"; import { LOCAL_STORAGE_KEY, DEFAULT_DICTIONARY, MIGRATE_VERSION } from "../constants"; @@ -203,50 +204,48 @@ export function importWords() { if (importWordsField.files.length === 1) { if (confirm('Importing a CSV file with words will add all of the words in the file to your dictionary regardless of duplication!\nDo you want to continue?')) { addMessage('Importing words...'); - import('papaparse').then(papa => { - const importedWords = []; - papa.parse(importWordsField.files[0], { - header: true, - encoding: "utf-8", - step: results => { - if (results.errors.length > 0) { - results.errors.forEach(err => { - addMessage('Error Importing Word: ' + err, undefined, 'error'); - console.error('Error Importing Word: ', err) - }); - } else { - const row = results.data[0]; - const importedWord = addWord({ - name: removeTags(row.word).trim(), - pronunciation: removeTags(row.pronunciation).trim(), - partOfSpeech: removeTags(row['part of speech']).trim(), - definition: removeTags(row.definition).trim(), - details: removeTags(row.explanation).trim(), - wordId: getNextId(), - }, false, false, false); + const importedWords = []; + papa.parse(importWordsField.files[0], { + header: true, + encoding: "utf-8", + step: results => { + if (results.errors.length > 0) { + results.errors.forEach(err => { + addMessage('Error Importing Word: ' + err, undefined, 'error'); + console.error('Error Importing Word: ', err) + }); + } else { + const row = results.data[0]; + const importedWord = addWord({ + name: removeTags(row.word).trim(), + pronunciation: removeTags(row.pronunciation).trim(), + partOfSpeech: removeTags(row['part of speech']).trim(), + definition: removeTags(row.definition).trim(), + details: removeTags(row.explanation).trim(), + wordId: getNextId(), + }, false, false, false); - importedWords.push(importedWord); - } - }, - complete: () => { - saveDictionary(false); - renderAll(); - importWordsField.value = ''; - document.getElementById('editModal').style.display = 'none'; - addMessage(`Done Importing ${importedWords.length} Words`); + importedWords.push(importedWord); + } + }, + complete: () => { + saveDictionary(false); + renderAll(); + importWordsField.value = ''; + document.getElementById('editModal').style.display = 'none'; + addMessage(`Done Importing ${importedWords.length} Words`); - if (hasToken()) { - import('./account/index.js').then(account => { - account.syncImportedWords(importedWords); - }); - } - }, - error: err => { - addMessage('Error Importing Words: ' + err, undefined, 'error'); - console.error('Error Importing Words: ', err); - }, - skipEmptyLines: true, - }); + if (hasToken()) { + import('./account/index.js').then(account => { + account.syncImportedWords(importedWords); + }); + } + }, + error: err => { + addMessage('Error Importing Words: ' + err, undefined, 'error'); + console.error('Error Importing Words: ', err); + }, + skipEmptyLines: true, }); } } @@ -269,23 +268,21 @@ export function exportWords() { addMessage('Exporting Words...'); setTimeout(() => { - import('papaparse').then(papa => { - const { name, specification } = window.currentDictionary; - - const fileName = slugify(name + '_' + specification) + '_words.csv'; - - const words = window.currentDictionary.words.map(word => { - return { - word: word.name, - pronunciation: word.pronunciation, - 'part of speech': word.partOfSpeech, - definition: word.definition, - explanation: word.details, - } - }); - const csv = papa.unparse(words, { quotes: true }); - download(csv, fileName, 'text/csv;charset=utf-8'); + const { name, specification } = window.currentDictionary; + + const fileName = slugify(name + '_' + specification) + '_words.csv'; + + const words = window.currentDictionary.words.map(word => { + return { + word: word.name, + pronunciation: word.pronunciation, + 'part of speech': word.partOfSpeech, + definition: word.definition, + explanation: word.details, + } }); + const csv = papa.unparse(words, { quotes: true }); + download(csv, fileName, 'text/csv;charset=utf-8'); }, 1); } diff --git a/src/js/hotkeys.js b/src/js/hotkeys.js index 8e39441..8fc2966 100644 --- a/src/js/hotkeys.js +++ b/src/js/hotkeys.js @@ -5,6 +5,7 @@ import { showSearchModal, clearSearchText } from "./search"; import { saveAndCloseSettingsModal, openSettingsModal, saveSettings } from "./settings"; import { saveAndCloseEditModal, openEditModal } from "./dictionaryManagement"; import { addMessage, hideAllModals } from "./utilities"; +import helpFile from '../markdown/help.md'; export function enableHotKeys() { document.addEventListener('keydown', hotKeyActions); @@ -102,9 +103,7 @@ function submitWord() { } function showHelpModal() { - import('../markdown/help.md').then(html => { - renderInfoModal(html); - }); + renderInfoModal(helpFile); } function maximizeTextarea() { diff --git a/src/js/render.js b/src/js/render.js index 5395ca2..a818cb5 100644 --- a/src/js/render.js +++ b/src/js/render.js @@ -17,6 +17,7 @@ import { import { getPaginationData } from './pagination'; import { getOpenEditForms, parseReferences } from './wordManagement'; import { renderAd } from './ads'; +import ipaTableFile from './KeyboardFire/phondue/ipa-table.html'; export function renderAll() { renderTheme(); @@ -311,24 +312,22 @@ export function renderIPATable(ipaTableButton) { ipaTableButton = typeof ipaTableButton.target === 'undefined' || ipaTableButton.target === '' ? ipaTableButton : ipaTableButton.target; const label = ipaTableButton.parentElement.innerText.replace(/(Field Help|IPA Chart)/g, '').trim(); const textBox = ipaTableButton.parentElement.querySelector('input'); - import('./KeyboardFire/phondue/ipa-table.html').then(html => { - const modalElement = document.createElement('section'); - modalElement.classList.add('modal', 'ipa-table-modal'); - modalElement.innerHTML = ` - `; + const modalElement = document.createElement('section'); + modalElement.classList.add('modal', 'ipa-table-modal'); + modalElement.innerHTML = ` + `; + + document.body.appendChild(modalElement); - document.body.appendChild(modalElement); - - setupIPAFields(); - setupIPATable(modalElement, textBox); - }); + setupIPAFields(); + setupIPATable(modalElement, textBox); } export function renderMaximizedTextbox(maximizeButton) { diff --git a/src/js/setupListeners.js b/src/js/setupListeners.js index be6e0bc..31be8dc 100644 --- a/src/js/setupListeners.js +++ b/src/js/setupListeners.js @@ -8,6 +8,9 @@ import { usePhondueDigraphs } from './KeyboardFire/phondue/ipaField'; import { openSettingsModal, saveSettingsModal, saveAndCloseSettingsModal } from './settings'; import { enableHotKeys } from './hotkeys'; import { showSearchModal, clearSearchText, checkAllPartsOfSpeechFilters, uncheckAllPartsOfSpeechFilters } from './search'; +import helpFile from '../markdown/help.md'; +import termsFile from '../markdown/terms.md'; +import privacyFile from '../markdown/privacy.md'; export default function setupListeners() { setupDetailsTabs(); @@ -357,19 +360,13 @@ export function setupMaximizeModal(modal, textBox) { export function setupInfoButtons() { document.getElementById('helpInfoButton').addEventListener('click', () => { - import('../markdown/help.md').then(html => { - renderInfoModal(html); - }); + renderInfoModal(helpFile); }); document.getElementById('termsInfoButton').addEventListener('click', () => { - import('../markdown/terms.md').then(html => { - renderInfoModal(html); - }); + renderInfoModal(termsFile); }); document.getElementById('privacyInfoButton').addEventListener('click', () => { - import('../markdown/privacy.md').then(html => { - renderInfoModal(html); - }); + renderInfoModal(privacyFile); }); } diff --git a/src/js/view/index.js b/src/js/view/index.js index b588b6f..a3826e8 100644 --- a/src/js/view/index.js +++ b/src/js/view/index.js @@ -3,7 +3,8 @@ import setupListeners from './setupListeners'; import { setupAds } from '../ads'; function initialize() { - setupAds().then(() => renderAll()); + setupAds(); + renderAll(); setupListeners(); } diff --git a/src/js/view/setupListeners.js b/src/js/view/setupListeners.js index 8ba46bb..dae5a0e 100644 --- a/src/js/view/setupListeners.js +++ b/src/js/view/setupListeners.js @@ -1,6 +1,9 @@ import {showSection, hideDetailsPanel} from './displayToggles'; import { showSearchModal, clearSearchText, checkAllPartsOfSpeechFilters, uncheckAllPartsOfSpeechFilters } from './search'; import { renderWords, renderInfoModal } from './render'; +import helpFile from '../../markdown/help.md'; +import termsFile from '../../markdown/terms.md'; +import privacyFile from '../../markdown/privacy.md'; export default function setupListeners() { setupDetailsTabs(); @@ -79,19 +82,13 @@ export function setupSearchFilters() { export function setupInfoButtons() { document.getElementById('helpInfoButton').addEventListener('click', () => { - import('../../markdown/help.md').then(html => { - renderInfoModal(html); - }); + renderInfoModal(helpFile); }); document.getElementById('termsInfoButton').addEventListener('click', () => { - import('../../markdown/terms.md').then(html => { - renderInfoModal(html); - }); + renderInfoModal(termsFile); }); document.getElementById('privacyInfoButton').addEventListener('click', () => { - import('../../markdown/privacy.md').then(html => { - renderInfoModal(html); - }); + renderInfoModal(privacyFile); }); }