Only split out html/md files;Fix page load problem

This commit is contained in:
Robbie Antenesse 2019-06-06 11:25:08 -06:00 committed by Robbie Antenesse
parent 46b579d73f
commit 87b7bbff89
10 changed files with 128 additions and 136 deletions

View File

@ -372,30 +372,25 @@
<script src="//cdnjs.cloudflare.com/ajax/libs/UpUp/1.1.0/upup.min.js"></script> <script src="//cdnjs.cloudflare.com/ajax/libs/UpUp/1.1.0/upup.min.js"></script>
<script> <script>
window.onload = (function (oldLoad) { window.onload = (function (oldLoad) {
return function () { oldLoad && oldLoad();
oldLoad && oldLoad(); if (UpUp) {
if (UpUp) { UpUp.start({
UpUp.start({ 'cache-version': '2.0.0',
'cache-version': '2.0.0', 'content-url': 'offline.html',
'content-url': 'offline.html', 'assets': [
'assets': [ 'src.c95c2dcd.js',
'src.8d47de22.js', 'main.3381ca43.css',
'main.3381ca43.css', 'help.ecc721dc.html',
'help.ecc721dc.html', 'privacy.5cbf7ea0.html',
'privacy.5cbf7ea0.html', 'terms.bcb4cecc.html',
'terms.bcb4cecc.html', 'usage.4a51122f.html',
'usage.4a51122f.html', 'ipa-table.6c5cf939.html',
'ads.f4e0c99c.js', 'favicon.5d013634.png',
'favicon.5d013634.png', ],
'ipa-table.6c5cf939.html', 'service-worker-url': 'upup.sw.min.js',
'papaparse.min.dab93fe4.js', });
],
'service-worker-url': 'upup.sw.min.js',
});
}
} }
})(window.onload); })(window.onload);
</script> </script>
</body> </body>
</html> </html>

View File

@ -20,12 +20,11 @@ function initialize() {
}); });
} }
setupAds().then(() => renderAll()); setupAds();
renderAll();
} }
window.onload = (function (oldLoad) { window.onload = (function (oldLoad) {
return function () { oldLoad && oldLoad();
oldLoad && oldLoad(); initialize();
initialize();
}
})(window.onload); })(window.onload);

View File

@ -1,4 +1,3 @@
import { setupInfoModal } from "../setupListeners";
import { request } from "./helpers"; import { request } from "./helpers";
export function renderForgotPasswordForm() { export function renderForgotPasswordForm() {
@ -24,6 +23,15 @@ export function renderForgotPasswordForm() {
setupInfoModal(modal); 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() { function setupStartResetForm() {
document.getElementById('forgotPasswordSubmit').addEventListener('click', startPasswordReset); document.getElementById('forgotPasswordSubmit').addEventListener('click', startPasswordReset);
} }
@ -59,7 +67,10 @@ function startPasswordReset() {
} }
function setupPasswordResetForm() { function setupPasswordResetForm() {
document.getElementById('newPasswordSubmit').addEventListener('click', submitPasswordReset); const submitButton = document.getElementById('newPasswordSubmit');
if (submitButton) {
submitButton.addEventListener('click', submitPasswordReset);
}
} }
function submitPasswordReset() { function submitPasswordReset() {
@ -97,8 +108,6 @@ function submitPasswordReset() {
} }
window.onload = (function (oldLoad) { window.onload = (function (oldLoad) {
return function () { oldLoad && oldLoad();
oldLoad && oldLoad(); setupPasswordResetForm();
setupPasswordResetForm();
}
})(window.onload); })(window.onload);

View File

@ -1,12 +1,11 @@
import { DISPLAY_AD_EVERY } from '../constants.js'; import { DISPLAY_AD_EVERY } from '../constants.js';
import ads from '../../ads.json';
export function setupAds() { export function setupAds() {
return import('../../ads.json').then(ads => { const shuffle = (a, b) => Math.random() > 0.5 ? 1 : -1;
const shuffle = (a, b) => Math.random() > 0.5 ? 1 : -1; const priority = ads.filter(ad => isActive(ad) && ad.isPriority).sort(shuffle);
const priority = ads.filter(ad => isActive(ad) && ad.isPriority).sort(shuffle); const regular = ads.filter(ad => isActive(ad) && !ad.isPriority).sort(shuffle);
const regular = ads.filter(ad => isActive(ad) && !ad.isPriority).sort(shuffle); window.ads = [...priority, ...regular];
window.ads = [...priority, ...regular];
});
} }
function isActive(ad) { function isActive(ad) {

View File

@ -1,3 +1,4 @@
import papa from 'papaparse';
import { renderDictionaryDetails, renderPartsOfSpeech, renderAll, renderTheme } from "./render"; import { renderDictionaryDetails, renderPartsOfSpeech, renderAll, renderTheme } from "./render";
import { removeTags, cloneObject, getTimestampInSeconds, download, slugify } from "../helpers"; import { removeTags, cloneObject, getTimestampInSeconds, download, slugify } from "../helpers";
import { LOCAL_STORAGE_KEY, DEFAULT_DICTIONARY, MIGRATE_VERSION } from "../constants"; import { LOCAL_STORAGE_KEY, DEFAULT_DICTIONARY, MIGRATE_VERSION } from "../constants";
@ -203,50 +204,48 @@ export function importWords() {
if (importWordsField.files.length === 1) { 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?')) { 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...'); addMessage('Importing words...');
import('papaparse').then(papa => { const importedWords = [];
const importedWords = []; papa.parse(importWordsField.files[0], {
papa.parse(importWordsField.files[0], { header: true,
header: true, encoding: "utf-8",
encoding: "utf-8", step: results => {
step: results => { if (results.errors.length > 0) {
if (results.errors.length > 0) { results.errors.forEach(err => {
results.errors.forEach(err => { addMessage('Error Importing Word: ' + err, undefined, 'error');
addMessage('Error Importing Word: ' + err, undefined, 'error'); console.error('Error Importing Word: ', err)
console.error('Error Importing Word: ', err) });
}); } else {
} else { const row = results.data[0];
const row = results.data[0]; const importedWord = addWord({
const importedWord = addWord({ name: removeTags(row.word).trim(),
name: removeTags(row.word).trim(), pronunciation: removeTags(row.pronunciation).trim(),
pronunciation: removeTags(row.pronunciation).trim(), partOfSpeech: removeTags(row['part of speech']).trim(),
partOfSpeech: removeTags(row['part of speech']).trim(), definition: removeTags(row.definition).trim(),
definition: removeTags(row.definition).trim(), details: removeTags(row.explanation).trim(),
details: removeTags(row.explanation).trim(), wordId: getNextId(),
wordId: getNextId(), }, false, false, false);
}, false, false, false);
importedWords.push(importedWord); importedWords.push(importedWord);
} }
}, },
complete: () => { complete: () => {
saveDictionary(false); saveDictionary(false);
renderAll(); renderAll();
importWordsField.value = ''; importWordsField.value = '';
document.getElementById('editModal').style.display = 'none'; document.getElementById('editModal').style.display = 'none';
addMessage(`Done Importing ${importedWords.length} Words`); addMessage(`Done Importing ${importedWords.length} Words`);
if (hasToken()) { if (hasToken()) {
import('./account/index.js').then(account => { import('./account/index.js').then(account => {
account.syncImportedWords(importedWords); account.syncImportedWords(importedWords);
}); });
} }
}, },
error: err => { error: err => {
addMessage('Error Importing Words: ' + err, undefined, 'error'); addMessage('Error Importing Words: ' + err, undefined, 'error');
console.error('Error Importing Words: ', err); console.error('Error Importing Words: ', err);
}, },
skipEmptyLines: true, skipEmptyLines: true,
});
}); });
} }
} }
@ -269,23 +268,21 @@ export function exportWords() {
addMessage('Exporting Words...'); addMessage('Exporting Words...');
setTimeout(() => { setTimeout(() => {
import('papaparse').then(papa => { const { name, specification } = window.currentDictionary;
const { name, specification } = window.currentDictionary;
const fileName = slugify(name + '_' + specification) + '_words.csv';
const fileName = slugify(name + '_' + specification) + '_words.csv';
const words = window.currentDictionary.words.map(word => {
const words = window.currentDictionary.words.map(word => { return {
return { word: word.name,
word: word.name, pronunciation: word.pronunciation,
pronunciation: word.pronunciation, 'part of speech': word.partOfSpeech,
'part of speech': word.partOfSpeech, definition: word.definition,
definition: word.definition, explanation: word.details,
explanation: word.details, }
}
});
const csv = papa.unparse(words, { quotes: true });
download(csv, fileName, 'text/csv;charset=utf-8');
}); });
const csv = papa.unparse(words, { quotes: true });
download(csv, fileName, 'text/csv;charset=utf-8');
}, 1); }, 1);
} }

View File

@ -5,6 +5,7 @@ import { showSearchModal, clearSearchText } from "./search";
import { saveAndCloseSettingsModal, openSettingsModal, saveSettings } from "./settings"; import { saveAndCloseSettingsModal, openSettingsModal, saveSettings } from "./settings";
import { saveAndCloseEditModal, openEditModal } from "./dictionaryManagement"; import { saveAndCloseEditModal, openEditModal } from "./dictionaryManagement";
import { addMessage, hideAllModals } from "./utilities"; import { addMessage, hideAllModals } from "./utilities";
import helpFile from '../markdown/help.md';
export function enableHotKeys() { export function enableHotKeys() {
document.addEventListener('keydown', hotKeyActions); document.addEventListener('keydown', hotKeyActions);
@ -102,9 +103,7 @@ function submitWord() {
} }
function showHelpModal() { function showHelpModal() {
import('../markdown/help.md').then(html => { renderInfoModal(helpFile);
renderInfoModal(html);
});
} }
function maximizeTextarea() { function maximizeTextarea() {

View File

@ -17,6 +17,7 @@ import {
import { getPaginationData } from './pagination'; import { getPaginationData } from './pagination';
import { getOpenEditForms, parseReferences } from './wordManagement'; import { getOpenEditForms, parseReferences } from './wordManagement';
import { renderAd } from './ads'; import { renderAd } from './ads';
import ipaTableFile from './KeyboardFire/phondue/ipa-table.html';
export function renderAll() { export function renderAll() {
renderTheme(); renderTheme();
@ -311,24 +312,22 @@ export function renderIPATable(ipaTableButton) {
ipaTableButton = typeof ipaTableButton.target === 'undefined' || ipaTableButton.target === '' ? ipaTableButton : ipaTableButton.target; ipaTableButton = typeof ipaTableButton.target === 'undefined' || ipaTableButton.target === '' ? ipaTableButton : ipaTableButton.target;
const label = ipaTableButton.parentElement.innerText.replace(/(Field Help|IPA Chart)/g, '').trim(); const label = ipaTableButton.parentElement.innerText.replace(/(Field Help|IPA Chart)/g, '').trim();
const textBox = ipaTableButton.parentElement.querySelector('input'); const textBox = ipaTableButton.parentElement.querySelector('input');
import('./KeyboardFire/phondue/ipa-table.html').then(html => { const modalElement = document.createElement('section');
const modalElement = document.createElement('section'); modalElement.classList.add('modal', 'ipa-table-modal');
modalElement.classList.add('modal', 'ipa-table-modal'); modalElement.innerHTML = `<div class="modal-background"></div>
modalElement.innerHTML = `<div class="modal-background"></div> <div class="modal-content">
<div class="modal-content"> <a class="close-button">&times;&#xFE0E;</a>
<a class="close-button">&times;&#xFE0E;</a> <header><label>${label} <input value="${textBox.value}" class="ipa-field"></label></header>
<header><label>${label} <input value="${textBox.value}" class="ipa-field"></label></header> <section>
<section> ${ipaTableFile}
${html} </section>
</section> <footer><a class="button done-button">Done</a></footer>
<footer><a class="button done-button">Done</a></footer> </div>`;
</div>`;
document.body.appendChild(modalElement);
document.body.appendChild(modalElement); setupIPAFields();
setupIPATable(modalElement, textBox);
setupIPAFields();
setupIPATable(modalElement, textBox);
});
} }
export function renderMaximizedTextbox(maximizeButton) { export function renderMaximizedTextbox(maximizeButton) {

View File

@ -8,6 +8,9 @@ import { usePhondueDigraphs } from './KeyboardFire/phondue/ipaField';
import { openSettingsModal, saveSettingsModal, saveAndCloseSettingsModal } from './settings'; import { openSettingsModal, saveSettingsModal, saveAndCloseSettingsModal } from './settings';
import { enableHotKeys } from './hotkeys'; import { enableHotKeys } from './hotkeys';
import { showSearchModal, clearSearchText, checkAllPartsOfSpeechFilters, uncheckAllPartsOfSpeechFilters } from './search'; 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() { export default function setupListeners() {
setupDetailsTabs(); setupDetailsTabs();
@ -357,19 +360,13 @@ export function setupMaximizeModal(modal, textBox) {
export function setupInfoButtons() { export function setupInfoButtons() {
document.getElementById('helpInfoButton').addEventListener('click', () => { document.getElementById('helpInfoButton').addEventListener('click', () => {
import('../markdown/help.md').then(html => { renderInfoModal(helpFile);
renderInfoModal(html);
});
}); });
document.getElementById('termsInfoButton').addEventListener('click', () => { document.getElementById('termsInfoButton').addEventListener('click', () => {
import('../markdown/terms.md').then(html => { renderInfoModal(termsFile);
renderInfoModal(html);
});
}); });
document.getElementById('privacyInfoButton').addEventListener('click', () => { document.getElementById('privacyInfoButton').addEventListener('click', () => {
import('../markdown/privacy.md').then(html => { renderInfoModal(privacyFile);
renderInfoModal(html);
});
}); });
} }

View File

@ -3,7 +3,8 @@ import setupListeners from './setupListeners';
import { setupAds } from '../ads'; import { setupAds } from '../ads';
function initialize() { function initialize() {
setupAds().then(() => renderAll()); setupAds();
renderAll();
setupListeners(); setupListeners();
} }

View File

@ -1,6 +1,9 @@
import {showSection, hideDetailsPanel} from './displayToggles'; import {showSection, hideDetailsPanel} from './displayToggles';
import { showSearchModal, clearSearchText, checkAllPartsOfSpeechFilters, uncheckAllPartsOfSpeechFilters } from './search'; import { showSearchModal, clearSearchText, checkAllPartsOfSpeechFilters, uncheckAllPartsOfSpeechFilters } from './search';
import { renderWords, renderInfoModal } from './render'; 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() { export default function setupListeners() {
setupDetailsTabs(); setupDetailsTabs();
@ -79,19 +82,13 @@ export function setupSearchFilters() {
export function setupInfoButtons() { export function setupInfoButtons() {
document.getElementById('helpInfoButton').addEventListener('click', () => { document.getElementById('helpInfoButton').addEventListener('click', () => {
import('../../markdown/help.md').then(html => { renderInfoModal(helpFile);
renderInfoModal(html);
});
}); });
document.getElementById('termsInfoButton').addEventListener('click', () => { document.getElementById('termsInfoButton').addEventListener('click', () => {
import('../../markdown/terms.md').then(html => { renderInfoModal(termsFile);
renderInfoModal(html);
});
}); });
document.getElementById('privacyInfoButton').addEventListener('click', () => { document.getElementById('privacyInfoButton').addEventListener('click', () => {
import('../../markdown/privacy.md').then(html => { renderInfoModal(privacyFile);
renderInfoModal(html);
});
}); });
} }