import md from 'marked'; import { removeTags, slugify } from '../../helpers'; import { getWordsStats, hasToken } from '../utilities'; import { showSection } from '../displayToggles'; import { setupSearchFilters } from '../setupListeners/search'; import { parseReferences } from '../wordManagement'; import { getPublicLink } from '../account/utilities'; export function renderDictionaryDetails() { renderName(); const tabs = document.querySelectorAll('#detailsSection nav li'); const shownTab = Array.from(tabs).find(tab => tab.classList.contains('active')); if (shownTab) { const tabName = shownTab.innerText.toLowerCase(); showSection(tabName); } } export function renderName() { const dictionaryName = removeTags(window.currentDictionary.name) + ' ' + removeTags(window.currentDictionary.specification); const name = document.getElementById('dictionaryName'); name.innerHTML = dictionaryName; const isPublic = hasToken() && window.currentDictionary.settings.isPublic; const shareLinkElement = document.getElementById('dictionaryShare'); if (isPublic && !shareLinkElement) { const shareLink = document.createElement('a'); shareLink.id = 'dictionaryShare'; shareLink.classList.add('button'); shareLink.style.float = 'right'; shareLink.href = getPublicLink(); shareLink.target = '_blank'; shareLink.title = 'Public Link to Dictionary'; shareLink.innerHTML = '➦'; name.parentElement.insertBefore(shareLink, name); } else if (isPublic && shareLinkElement) { shareLinkElement.href = getPublicLink(); } else if (!isPublic && shareLinkElement) { shareLinkElement.parentElement.removeChild(shareLinkElement); } } export function renderDescription() { const descriptionHTML = md(parseReferences(removeTags(window.currentDictionary.description))); document.getElementById('detailsPanel').innerHTML = '
Parts of Speech
${partsOfSpeech.map(partOfSpeech => '' + partOfSpeech + '').join(' ')}`;
const alphabeticalOrderHTML = `
Alphabetical Order
${
(alphabeticalOrder.length > 0 ? alphabeticalOrder : ['English Alphabet']).map(letter => `${letter}`).join(' ')
}`;
const generalHTML = `
Consonants
${consonants.map(letter => `${letter}`).join(' ')}
Vowels
${vowels.map(letter => `${letter}`).join(' ')}
Polyphthongs / Blends
${blends.map(letter => `${letter}`).join(' ')}
Notes
Onset
${onset.map(letter => `${letter}`).join(' ')}
Nucleus
${nucleus.map(letter => `${letter}`).join(' ')}
Coda
${coda.map(letter => `${letter}`).join(' ')}
Notes
Translations
${translations.map(translation => {
translation = translation.split('=').map(value => value.trim());
if (translation.length > 1 && translation[0] !== '' && translation[1] !== '') {
return `${translation[0]}${translation[1]}`;
}
return false;
}).filter(html => html !== false).join(' ')}
Notes
' + md(parseReferences(removeTags(orthography.notes))) + '' : '';
const orthographyHTML = translations.length + orthographyNotesHTML.length > 0
? `
Number of Words
${wordStats.numberOfWords.map(stat => `${stat.name}${stat.value}`).join(' ')}
Word Length
Shortest${wordStats.wordLength.shortest}
Longest${wordStats.wordLength.longest}
Average${wordStats.wordLength.average}
Letter Distribution
${wordStats.letterDistribution.map(stat => `${stat.letter}${stat.percentage.toFixed(2)}`).join(' ')}
${wordStats.totalLetters} Total Letters
`; detailsPanel.innerHTML = numberOfWordsHTML + wordLengthHTML + letterDistributionHTML + totalLettersHTML; } export function renderPartsOfSpeech(onlyOptions = false) { let optionsHTML = '', searchHTML = ''; window.currentDictionary.partsOfSpeech.forEach(partOfSpeech => { partOfSpeech = removeTags(partOfSpeech); optionsHTML += ``; searchHTML += ``; }); searchHTML += `Check All Uncheck All`; Array.from(document.getElementsByClassName('part-of-speech-select')).forEach(select => { const selectedValue = select.value; select.innerHTML = optionsHTML; select.value = selectedValue; }); if (!onlyOptions) { document.getElementById('searchPartsOfSpeech').innerHTML = searchHTML; } setupSearchFilters(); }