Merge branch 'new-features-wave-2'
This commit is contained in:
commit
e3c4ce7666
11
offline.html
11
offline.html
|
@ -139,6 +139,17 @@
|
|||
<label>Details<span class="red">*</span><a class="label-button maximize-button">Maximize</a><br>
|
||||
<textarea id="wordDetails" placeholder="Markdown formatting allowed"></textarea>
|
||||
</label>
|
||||
<label>
|
||||
<a id="expandAdvancedForm" class="small button expand-advanced-form">Show Advanced Fields</a>
|
||||
</label>
|
||||
<div id="advancedForm" class="advanced-word-form" style="display:none;">
|
||||
<label>Etymology / Root Words<br>
|
||||
<input id="wordEtymology" maxlength="2500" placeholder="comma,separated,root,words">
|
||||
</label>
|
||||
<label>Related Words<br>
|
||||
<input id="wordRelated" maxlength="2500" placeholder="comma,separated,related,words">
|
||||
</label>
|
||||
</div>
|
||||
<div id="wordErrorMessage"></div>
|
||||
<a class="button" id="addWordButton">Add Word</a>
|
||||
</form>
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "lexiconga",
|
||||
"version": "2.1.7",
|
||||
"version": "2.2.0",
|
||||
"description": "The quick and easy dictionary builder for constructed languages.",
|
||||
"main": "template-index.html",
|
||||
"repository": "https://github.com/Alamantus/Lexiconga.git",
|
||||
|
|
|
@ -35,6 +35,9 @@ export const DEFAULT_DICTIONARY = {
|
|||
partOfSpeech: '',
|
||||
definition: '',
|
||||
details: '',
|
||||
etymology: [],
|
||||
related: [],
|
||||
principalParts: [],
|
||||
wordId: 0
|
||||
}, */
|
||||
],
|
||||
|
@ -54,7 +57,9 @@ export const DEFAULT_DICTIONARY = {
|
|||
export const DEFAULT_SETTINGS = {
|
||||
useIPAPronunciationField: true,
|
||||
useHotkeys: true,
|
||||
showAdvanced: false,
|
||||
defaultTheme: 'default',
|
||||
templates: [],
|
||||
};
|
||||
|
||||
export const DISPLAY_AD_EVERY = 10;
|
||||
|
|
|
@ -94,18 +94,22 @@ export function renderAccountActions() {
|
|||
const accountActionsHTML = `<h3>Account Actions</h3>
|
||||
<label>Change Dictionary<br><select id="accountSettingsChangeDictionary"></select></label>
|
||||
<p><a class="button" id="accountSettingsCreateNewDictionary">Create New Dictionary</a></p>
|
||||
<h4>Request Your Data</h4>
|
||||
<p>
|
||||
Per your <a href="https://www.eugdpr.org/" target="_blank">GDPR</a> rights in Articles 13–15 and 20, we allow you to request any and all data we have stored about you. The only data we have about you personally is your email address and your Public Name, if you decided to set one. All other data (your Dictionary data) is visible and accessible via the Export button under your Dictionary's Settings. Send an email to help@lexicon.ga to request your information.
|
||||
</p>
|
||||
<details>
|
||||
<summary><h4>Request Your Data</h4></summary>
|
||||
<p>
|
||||
Per your <a href="https://www.eugdpr.org/" target="_blank">GDPR</a> rights in Articles 13–15 and 20, we allow you to request any and all data we have stored about you. The only data we have about you personally is your email address and your Public Name, if you decided to set one. All other data (your Dictionary data) is visible and accessible via the Export button under your Dictionary's Settings. Send an email to help@lexicon.ga to request your information.
|
||||
</p>
|
||||
</details>
|
||||
|
||||
<h4>Delete Your Account</h4>
|
||||
<p>
|
||||
Per your <a href="https://www.eugdpr.org/" target="_blank">GDPR</a> rights in Articles 17, if you wish for your account to be deleted, please contact us at help@lexicon.ga, and we will delete your account and all associated dictionaries and words as quickly as possible. Note that you can delete dictionaries yourself via your Dictionary's Settings.
|
||||
</p>
|
||||
<p>
|
||||
Anything that is deleted from our system is permanently and irretrievably removed from our system and cannot be restored, though search engines or internet archives may retain a cached version of your content (there is nothing we can do about this, and you will need to seek out removal of that information by directly contacting the services that are caching your data).
|
||||
</p>
|
||||
<details>
|
||||
<summary><h4>Delete Your Account</h4></summary>
|
||||
<p>
|
||||
Per your <a href="https://www.eugdpr.org/" target="_blank">GDPR</a> rights in Articles 17, if you wish for your account to be deleted, please contact us at help@lexicon.ga, and we will delete your account and all associated dictionaries and words as quickly as possible. Note that you can delete dictionaries yourself via your Dictionary's Settings.
|
||||
</p>
|
||||
<p>
|
||||
Anything that is deleted from our system is permanently and irretrievably removed from our system and cannot be restored, though search engines or internet archives may retain a cached version of your content (there is nothing we can do about this, and you will need to seek out removal of that information by directly contacting the services that are caching your data).
|
||||
</p>
|
||||
</details>
|
||||
`;
|
||||
accountActionsColumn.innerHTML = accountActionsHTML;
|
||||
|
||||
|
|
|
@ -8,7 +8,6 @@ import { addWord, sortWords } from "./wordManagement";
|
|||
import { migrateDictionary } from './migration';
|
||||
|
||||
export function updateDictionary () {
|
||||
|
||||
renderDictionaryDetails();
|
||||
}
|
||||
|
||||
|
@ -49,6 +48,7 @@ export function openEditModal() {
|
|||
}
|
||||
|
||||
document.getElementById('editModal').style.display = '';
|
||||
Array.from(document.querySelectorAll('#editModal .modal-content section')).forEach(section => section.scrollTop = 0);
|
||||
}
|
||||
|
||||
export function saveEditModal() {
|
||||
|
@ -238,14 +238,51 @@ export function importWords() {
|
|||
});
|
||||
} else {
|
||||
const row = results.data;
|
||||
const importedWord = addWord({
|
||||
const wordToImport = {
|
||||
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);
|
||||
};
|
||||
if (typeof row['etymology'] !== 'undefined') {
|
||||
const etymology = removeTags(row['etymology']).trim().split(',').filter(etymology => etymology.trim() !== '');
|
||||
if (etymology.length > 0) {
|
||||
wordToImport.etymology = etymology;
|
||||
}
|
||||
}
|
||||
if (typeof row['etymology (comma-separated)'] !== 'undefined') {
|
||||
const etymology = removeTags(row['etymology (comma-separated)']).trim().split(',').filter(etymology => etymology.trim() !== '');
|
||||
if (etymology.length > 0) {
|
||||
wordToImport.etymology = etymology;
|
||||
}
|
||||
}
|
||||
if (typeof row['related words'] !== 'undefined') {
|
||||
const related = removeTags(row['related words']).trim().split(',').filter(related => related.trim() !== '');
|
||||
if (related.length > 0) {
|
||||
wordToImport.related = related;
|
||||
}
|
||||
}
|
||||
if (typeof row['related words (comma-separated)'] !== 'undefined') {
|
||||
const related = removeTags(row['related words (comma-separated)']).trim().split(',').filter(related => related.trim() !== '');
|
||||
if (related.length > 0) {
|
||||
wordToImport.related = related;
|
||||
}
|
||||
}
|
||||
if (typeof row['principal parts'] !== 'undefined') {
|
||||
const principalParts = removeTags(row['principal parts']).trim().split(',').filter(principalParts => principalParts.trim() !== '');
|
||||
if (principalParts.length > 0) {
|
||||
wordToImport.principalParts = principalParts;
|
||||
}
|
||||
}
|
||||
if (typeof row['principal parts (comma-separated)'] !== 'undefined') {
|
||||
const principalParts = removeTags(row['principal parts (comma-separated)']).trim().split(',').filter(principalParts => principalParts.trim() !== '');
|
||||
if (principalParts.length > 0) {
|
||||
wordToImport.principalParts = principalParts;
|
||||
}
|
||||
}
|
||||
const importedWord = addWord(wordToImport, false);
|
||||
|
||||
importedWords.push(importedWord);
|
||||
|
||||
|
@ -306,6 +343,9 @@ export function exportWords() {
|
|||
'part of speech': word.partOfSpeech,
|
||||
definition: word.definition,
|
||||
explanation: word.details,
|
||||
'etymology (comma-separated)': typeof word.etymology !== 'undefined' ? word.etymology.join(',') : '',
|
||||
'related words (comma-separated)': typeof word.related !== 'undefined' ? word.related.join(',') : '',
|
||||
'principal parts (comma-separated)': typeof word.principalParts !== 'undefined' ? word.principalParts.join(',') : '',
|
||||
}
|
||||
});
|
||||
const csv = papa.unparse(words, { quotes: true });
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
import { renderDictionaryDetails, renderPartsOfSpeech } from './details';
|
||||
import { renderWords } from './words';
|
||||
import { renderTemplateSelectOptions } from './settings';
|
||||
|
||||
export function renderAll() {
|
||||
renderTheme();
|
||||
renderCustomCSS();
|
||||
renderDictionaryDetails();
|
||||
renderPartsOfSpeech();
|
||||
renderTemplateSelectOptions();
|
||||
renderWords();
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
import { setupTemplateSelectOptions } from "../setupListeners/settings";
|
||||
|
||||
export function renderTemplateSelectOptions() {
|
||||
const { templates } = window.settings;
|
||||
|
||||
if (typeof templates !== 'undefined') {
|
||||
const templatesOptionsHTML = templates.map((template, index) => {
|
||||
return `<option value="${index.toString()}">${template.name}</options>`;
|
||||
}).join('');
|
||||
|
||||
Array.from(document.getElementsByClassName('template-select')).forEach(select => {
|
||||
if (select.id !== 'savedDetailsTemplates' && templates.length < 1) {
|
||||
return select.parentElement.style.display = 'none';
|
||||
} else {
|
||||
select.parentElement.style.display = '';
|
||||
}
|
||||
select.innerHTML = '<option value="" selected="selected">None Selected</option>' + templatesOptionsHTML;
|
||||
});
|
||||
|
||||
setupTemplateSelectOptions();
|
||||
}
|
||||
}
|
||||
|
||||
export function showTemplateEditor(show = true) {
|
||||
document.getElementById('templateFields').style.display = show ? '' : 'none';
|
||||
if (show) {
|
||||
document.getElementById('templateTextarea').focus();
|
||||
document.querySelector('#settingsModal .modal-content section').scrollTop = 9999;
|
||||
} else {
|
||||
clearTemplateEditor();
|
||||
}
|
||||
}
|
||||
|
||||
export function showSelectedTemplate(template, index) {
|
||||
const nameField = document.getElementById('templateNameField');
|
||||
nameField.value = template.name;
|
||||
nameField.setAttribute('template', index.toString());
|
||||
document.getElementById('templateTextarea').value = template.template;
|
||||
showTemplateEditor(true);
|
||||
}
|
||||
|
||||
export function clearTemplateEditor() {
|
||||
document.getElementById('savedDetailsTemplates').value = '';
|
||||
document.getElementById('templateNameField').value = '';
|
||||
document.getElementById('templateTextarea').value = '';
|
||||
}
|
|
@ -9,10 +9,62 @@ import {
|
|||
setupWordEditFormButtons,
|
||||
} from '../setupListeners/words';
|
||||
import { getPaginationData } from '../pagination';
|
||||
import { getOpenEditForms, translateOrthography, parseReferences } from '../wordManagement';
|
||||
import { getOpenEditForms, translateOrthography, parseReferences, getWordReferenceMarkdown } from '../wordManagement';
|
||||
import { renderAd } from '../ads';
|
||||
import { getPublicLink } from '../account/utilities';
|
||||
import { renderPartsOfSpeech } from './details';
|
||||
import { renderTemplateSelectOptions } from './settings';
|
||||
|
||||
export function renderWord(savedWord, isPublic) {
|
||||
const word = highlightSearchTerm({
|
||||
name: removeTags(savedWord.name),
|
||||
pronunciation: removeTags(savedWord.pronunciation),
|
||||
partOfSpeech: removeTags(savedWord.partOfSpeech),
|
||||
definition: removeTags(savedWord.definition),
|
||||
details: parseReferences(removeTags(savedWord.details)),
|
||||
etymology: typeof savedWord.etymology === 'undefined' || savedWord.etymology.length < 1 ? null
|
||||
: savedWord.etymology.map(root => getWordReferenceMarkdown(removeTags(root))).join(', '),
|
||||
related: typeof savedWord.related === 'undefined' || savedWord.related.length < 1 ? null
|
||||
: savedWord.related.map(relatedWord => getWordReferenceMarkdown(removeTags(relatedWord))).join(', '),
|
||||
principalParts: typeof savedWord.principalParts === 'undefined' || savedWord.principalParts.length < 1 ? null
|
||||
: savedWord.principalParts.join(', '),
|
||||
wordId: savedWord.wordId,
|
||||
});
|
||||
const homonymnNumber = getHomonymnNumber(savedWord);
|
||||
const shareLink = window.currentDictionary.hasOwnProperty('externalID') ? getPublicLink() + '/' + word.wordId : '';
|
||||
|
||||
let wordNameDisplay = translateOrthography(word.name);
|
||||
|
||||
return `<article class="entry" id="${word.wordId}">
|
||||
<header>
|
||||
<h4 class="word"><span class="orthographic-translation">${wordNameDisplay}</span>${homonymnNumber > 0 ? ' <sub>' + homonymnNumber.toString() + '</sub>' : ''}</h4>
|
||||
${word.principalParts === null ? '' : `<span class="principalParts">(${word.principalParts})</span>`}
|
||||
<span class="pronunciation">${word.pronunciation}</span>
|
||||
<span class="part-of-speech">${word.partOfSpeech}</span>
|
||||
${isPublic ? `<a class="small button share-link" href="${shareLink}" target="_blank" title="Public Link to Word">➦</a>` : ''}
|
||||
<span class="small button word-option-button">Options</span>
|
||||
<div class="word-option-list" style="display:none;">
|
||||
<div class="word-option" id="edit_${word.wordId}">Edit</div>
|
||||
<div class="word-option" id="delete_${word.wordId}">Delete</div>
|
||||
</div>
|
||||
</header>
|
||||
<dl>
|
||||
<dt class="definition">${word.definition}</dt>
|
||||
<dd class="details">
|
||||
${md(word.details)}
|
||||
</dd>
|
||||
${word.etymology === null && word.related === null ? '' : `<hr>`}
|
||||
${word.etymology === null ? '' : `<dt>Etymology <small>(Root Word${savedWord.etymology.length !== 1 ? 's' : ''})</small></dt>
|
||||
<dd class="etymology">
|
||||
${md(word.etymology).replace(/<\/?p>/g, '')}
|
||||
</dd>`}
|
||||
${word.related === null ? '' : `<dt>Related Word${savedWord.related.length !== 1 ? 's' : ''}</dt>
|
||||
<dd class="related">
|
||||
${md(word.related).replace(/<\/?p>/g, '')}
|
||||
</dd>`}
|
||||
</dl>
|
||||
</article>`;
|
||||
}
|
||||
|
||||
export function renderWords() {
|
||||
let wordsHTML = '';
|
||||
|
@ -52,42 +104,11 @@ export function renderWords() {
|
|||
|
||||
// const { pageStart, pageEnd } = getPaginationData(words);
|
||||
|
||||
// words.slice(pageStart, pageEnd).forEach(originalWord => {
|
||||
words.forEach((originalWord, displayIndex) => {
|
||||
const word = highlightSearchTerm({
|
||||
name: removeTags(originalWord.name),
|
||||
pronunciation: removeTags(originalWord.pronunciation),
|
||||
partOfSpeech: removeTags(originalWord.partOfSpeech),
|
||||
definition: removeTags(originalWord.definition),
|
||||
details: parseReferences(removeTags(originalWord.details)),
|
||||
wordId: originalWord.wordId,
|
||||
});
|
||||
const homonymnNumber = getHomonymnNumber(originalWord);
|
||||
const shareLink = window.currentDictionary.hasOwnProperty('externalID') ? getPublicLink() + '/' + word.wordId : '';
|
||||
|
||||
// words.slice(pageStart, pageEnd).forEach(savedWord => {
|
||||
words.forEach((savedWord, displayIndex) => {
|
||||
wordsHTML += renderAd(displayIndex);
|
||||
|
||||
let wordNameDisplay = translateOrthography(word.name);
|
||||
|
||||
wordsHTML += `<article class="entry" id="${word.wordId}">
|
||||
<header>
|
||||
<h4 class="word"><span class="orthographic-translation">${wordNameDisplay}</span>${homonymnNumber > 0 ? ' <sub>' + homonymnNumber.toString() + '</sub>' : ''}</h4>
|
||||
<span class="pronunciation">${word.pronunciation}</span>
|
||||
<span class="part-of-speech">${word.partOfSpeech}</span>
|
||||
${isPublic ? `<a class="small button share-link" href="${shareLink}" target="_blank" title="Public Link to Word">➦</a>` : ''}
|
||||
<span class="small button word-option-button">Options</span>
|
||||
<div class="word-option-list" style="display:none;">
|
||||
<div class="word-option" id="edit_${word.wordId}">Edit</div>
|
||||
<div class="word-option" id="delete_${word.wordId}">Delete</div>
|
||||
</div>
|
||||
</header>
|
||||
<dl>
|
||||
<dt class="definition">${word.definition}</dt>
|
||||
<dd class="details">
|
||||
${md(word.details)}
|
||||
</dd>
|
||||
</dl>
|
||||
</article>`;
|
||||
wordsHTML += renderWord(savedWord, isPublic);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -139,6 +160,8 @@ export function renderEditForm(wordId = false) {
|
|||
wordId = typeof wordId.target === 'undefined' ? wordId : parseInt(this.id.replace('edit_', ''));
|
||||
const word = window.currentDictionary.words.find(w => w.wordId === wordId);
|
||||
if (word) {
|
||||
const wordHasAdvancedFields = (word.hasOwnProperty('etymology') && word.etymology)
|
||||
|| (word.hasOwnProperty('related') && word.related) || (word.hasOwnProperty('principalParts') && word.principalParts);
|
||||
const ipaPronunciationField = `<input id="wordPronunciation_${wordId}" class="ipa-field" maxlength="200" value="${word.pronunciation}"><br>
|
||||
<a class="label-help-button ipa-field-help-button">Field Help</a>`;
|
||||
const plainPronunciationField = `<input id="wordPronunciation_${wordId}" maxlength="200" value="${word.pronunciation}">`;
|
||||
|
@ -160,6 +183,25 @@ export function renderEditForm(wordId = false) {
|
|||
<label>Details<span class="red">*</span><a class="label-button maximize-button">Maximize</a><br>
|
||||
<textarea id="wordDetails_${wordId}" placeholder="Markdown formatting allowed">${word.details}</textarea>
|
||||
</label>
|
||||
<label>
|
||||
<a id="expandAdvancedForm_${wordId}" class="small button expand-advanced-form">${wordHasAdvancedFields || window.settings.showAdvanced ? 'Hide' : 'Show'} Advanced Fields</a>
|
||||
</label>
|
||||
<div id="advancedForm_${wordId}" class="advanced-word-form" style="display:${wordHasAdvancedFields || window.settings.showAdvanced ? 'block' : 'none'};">
|
||||
<label>Details Field Templates
|
||||
<select id="templateSelect_${wordId}" class="template-select">
|
||||
</select>
|
||||
<small>Choose one to fill the details field. (Note: Will erase anything currently there.)</small>
|
||||
</label>
|
||||
<label>Etymology / Root Words<br>
|
||||
<input id="wordEtymology_${wordId}" maxlength="2500" placeholder="comma,separated,root,words" value="${word.hasOwnProperty('etymology') ? word.etymology : ''}">
|
||||
</label>
|
||||
<label>Related Words<br>
|
||||
<input id="wordRelated_${wordId}" maxlength="2500" placeholder="comma,separated,related,words" value="${word.hasOwnProperty('related') ? word.related : ''}">
|
||||
</label>
|
||||
<label>Principal Parts<a href="https://en.wikipedia.org/wiki/Principal_parts" target="_blank" class="label-button">What's This?</a><br>
|
||||
<input id="wordPrincipalParts_${wordId}" maxlength="2500" placeholder="comma,separated,principal,parts" value="${word.hasOwnProperty('principalParts') ? word.principalParts : ''}">
|
||||
</label>
|
||||
</div>
|
||||
<div id="wordErrorMessage_${wordId}"></div>
|
||||
<a class="button edit-save-changes" id="editWordButton_${wordId}">Save Changes</a>
|
||||
<a class="button edit-cancel">Cancel Edit</a>
|
||||
|
@ -168,5 +210,6 @@ export function renderEditForm(wordId = false) {
|
|||
document.getElementById(wordId.toString()).innerHTML = editForm;
|
||||
setupWordEditFormButtons();
|
||||
renderPartsOfSpeech(true);
|
||||
renderTemplateSelectOptions();
|
||||
}
|
||||
}
|
||||
|
|
103
src/js/search.js
103
src/js/search.js
|
@ -42,41 +42,72 @@ export function getSearchFilters() {
|
|||
return filters;
|
||||
}
|
||||
|
||||
function wordMatchesPartsOfSpeechFilter(word, filters) {
|
||||
if (!filters.allPartsOfSpeechChecked) {
|
||||
const partOfSpeech = word.partOfSpeech === '' ? 'Unclassified' : word.partOfSpeech;
|
||||
return filters.partsOfSpeech.hasOwnProperty(partOfSpeech) && filters.partsOfSpeech[partOfSpeech];
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function wordMatchesSearchTermAndOptions(word, searchTerm, filters) {
|
||||
if (searchTerm === '') return true; // If searchTerm is blank, don't process word.
|
||||
|
||||
searchTerm = filters.ignoreDiacritics ? removeDiacritics(searchTerm) : searchTerm;
|
||||
searchTerm = filters.caseSensitive ? searchTerm : searchTerm.toLowerCase();
|
||||
let name = filters.orthography ? translateOrthography(word.name) : word.name;
|
||||
name = filters.ignoreDiacritics ? removeDiacritics(name) : name;
|
||||
name = filters.caseSensitive ? name : name.toLowerCase();
|
||||
let definition = filters.ignoreDiacritics ? removeDiacritics(word.definition) : word.definition;
|
||||
definition = filters.caseSensitive ? definition : definition.toLowerCase();
|
||||
let details = filters.orthography ? parseReferences(word.details) : word.details;
|
||||
details = filters.ignoreDiacritics ? removeDiacritics(details) : details;
|
||||
details = filters.caseSensitive ? details : details.toLowerCase();
|
||||
let principalParts = typeof word.principalParts === 'undefined' ? [] : word.principalParts;
|
||||
principalParts = filters.orthography ? principalParts.map(part => translateOrthography(part)) : principalParts;
|
||||
principalParts = filters.ignoreDiacritics ? principalParts.map(part => removeDiacritics(part)) : principalParts;
|
||||
principalParts = filters.caseSensitive ? principalParts : principalParts.map(part => part.toLowerCase());
|
||||
|
||||
const isInName = filters.name && (filters.exact
|
||||
? searchTerm == name
|
||||
: new RegExp(searchTerm, 'g').test(name)
|
||||
);
|
||||
const isInDefinition = filters.definition && (filters.exact
|
||||
? searchTerm == definition
|
||||
: new RegExp(searchTerm, 'g').test(definition)
|
||||
);
|
||||
const isInDetails = filters.details && new RegExp(searchTerm, 'g').test(details);
|
||||
const isInPrincipalParts = filters.name && (filters.exact
|
||||
? principalParts.includes(searchTerm)
|
||||
: principalParts.some(part => new RegExp(searchTerm, 'g').test(part))
|
||||
);
|
||||
return isInName || isInDefinition || isInDetails || isInPrincipalParts;
|
||||
}
|
||||
|
||||
export function getMatchingSearchWords() {
|
||||
let searchTerm = getSearchTerm();
|
||||
const searchTerm = getSearchTerm();
|
||||
const filters = getSearchFilters();
|
||||
if (searchTerm !== '' || !filters.allPartsOfSpeechChecked) {
|
||||
const matchingWords = window.currentDictionary.words.slice().filter(word => {
|
||||
if (!filters.allPartsOfSpeechChecked) {
|
||||
const partOfSpeech = word.partOfSpeech === '' ? 'Unclassified' : word.partOfSpeech;
|
||||
return filters.partsOfSpeech.hasOwnProperty(partOfSpeech) && filters.partsOfSpeech[partOfSpeech];
|
||||
}
|
||||
return true;
|
||||
}).filter(word => {
|
||||
searchTerm = filters.ignoreDiacritics ? removeDiacritics(searchTerm) : searchTerm;
|
||||
searchTerm = filters.caseSensitive ? searchTerm : searchTerm.toLowerCase();
|
||||
let name = filters.orthography ? translateOrthography(word.name) : word.name;
|
||||
name = filters.ignoreDiacritics ? removeDiacritics(name) : name;
|
||||
name = filters.caseSensitive ? name : name.toLowerCase();
|
||||
let definition = filters.ignoreDiacritics ? removeDiacritics(word.definition) : word.definition;
|
||||
definition = filters.caseSensitive ? definition : definition.toLowerCase();
|
||||
let details = filters.orthography ? parseReferences(word.details) : word.details;
|
||||
details = filters.ignoreDiacritics ? removeDiacritics(details) : details;
|
||||
details = filters.caseSensitive ? details : details.toLowerCase();
|
||||
|
||||
const isInName = filters.name && (filters.exact
|
||||
? searchTerm == name
|
||||
: new RegExp(searchTerm, 'g').test(name));
|
||||
const isInDefinition = filters.definition && (filters.exact
|
||||
? searchTerm == definition
|
||||
: new RegExp(searchTerm, 'g').test(definition));
|
||||
const isInDetails = filters.details && new RegExp(searchTerm, 'g').test(details);
|
||||
return searchTerm === '' || isInName || isInDefinition || isInDetails;
|
||||
});
|
||||
const matchingWords = window.currentDictionary.words.slice()
|
||||
.filter(word => wordMatchesPartsOfSpeechFilter(word, filters))
|
||||
.filter(word => wordMatchesSearchTermAndOptions(word, searchTerm, filters));
|
||||
return matchingWords;
|
||||
}
|
||||
|
||||
return window.currentDictionary.words
|
||||
return window.currentDictionary.words;
|
||||
}
|
||||
|
||||
export function wordMatchesSearch(word) {
|
||||
const searchTerm = getSearchTerm();
|
||||
const filters = getSearchFilters();
|
||||
if (searchTerm !== '' || !filters.allPartsOfSpeechChecked) {
|
||||
if (searchTerm === '') {
|
||||
return wordMatchesPartsOfSpeechFilter(word, filters);
|
||||
}
|
||||
return wordMatchesPartsOfSpeechFilter(word, filters)
|
||||
&& wordMatchesSearchTermAndOptions(word, searchTerm, filters);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
export function highlightSearchTerm(word) {
|
||||
|
@ -99,6 +130,16 @@ export function highlightSearchTerm(word) {
|
|||
+ '<mark>' + markedUpWord.name.substr(wordIndex, searchTermLength) + '</mark>'
|
||||
+ markedUpWord.name.substr(wordIndex + searchTermLength);
|
||||
});
|
||||
|
||||
if (markedUpWord.principalParts !== null) {
|
||||
const part = getIndicesOf(searchTerm, removeDiacritics(markedUpWord.principalParts), filters.caseSensitive);
|
||||
part.forEach((wordIndex, i) => {
|
||||
wordIndex += '<mark></mark>'.length * i;
|
||||
markedUpWord.principalParts = markedUpWord.principalParts.substring(0, wordIndex)
|
||||
+ '<mark>' + markedUpWord.principalParts.substr(wordIndex, searchTermLength) + '</mark>'
|
||||
+ markedUpWord.principalParts.substr(wordIndex + searchTermLength);
|
||||
});
|
||||
}
|
||||
}
|
||||
if (filters.definition) {
|
||||
const definitionMatches = getIndicesOf(searchTerm, removeDiacritics(markedUpWord.definition), filters.caseSensitive);
|
||||
|
@ -122,6 +163,10 @@ export function highlightSearchTerm(word) {
|
|||
const regexMethod = 'g' + (filters.caseSensitive ? '' : 'i');
|
||||
if (filters.name) {
|
||||
markedUpWord.name = markedUpWord.name.replace(new RegExp(`(${searchTerm})`, regexMethod), `<mark>$1</mark>`);
|
||||
|
||||
if (markedUpWord.principalParts !== null) {
|
||||
markedUpWord.principalParts = markedUpWord.principalParts.replace(new RegExp(`(${searchTerm})`, regexMethod), `<mark>$1</mark>`);
|
||||
}
|
||||
}
|
||||
if (filters.definition) {
|
||||
markedUpWord.definition = markedUpWord.definition.replace(new RegExp(`(${searchTerm})`, regexMethod), `<mark>$1</mark>`);
|
||||
|
|
|
@ -4,11 +4,13 @@ import { usePhondueDigraphs } from "./KeyboardFire/phondue/ipaField";
|
|||
import { renderWords } from "./render/words";
|
||||
import { addMessage, hasToken, objectValuesAreDifferent } from "./utilities";
|
||||
import { enableHotKeys, disableHotKeys } from "./hotkeys";
|
||||
import { showTemplateEditor, renderTemplateSelectOptions, showSelectedTemplate } from "./render/settings";
|
||||
|
||||
export function loadSettings() {
|
||||
const storedSettings = window.localStorage.getItem(SETTINGS_KEY);
|
||||
window.settings = storedSettings ? JSON.parse(storedSettings) : cloneObject(DEFAULT_SETTINGS);
|
||||
toggleIPAPronunciationFields(false);
|
||||
toggleShowAdvancedFields();
|
||||
}
|
||||
|
||||
export function saveSettings() {
|
||||
|
@ -17,19 +19,98 @@ export function saveSettings() {
|
|||
}
|
||||
|
||||
export function openSettingsModal() {
|
||||
const { useIPAPronunciationField, useHotkeys, defaultTheme } = window.settings;
|
||||
const { useIPAPronunciationField, useHotkeys, showAdvanced, defaultTheme, templates } = window.settings;
|
||||
|
||||
document.getElementById('settingsUseIPA').checked = useIPAPronunciationField;
|
||||
document.getElementById('settingsUseHotkeys').checked = useHotkeys;
|
||||
document.getElementById('settingsShowAdvanced').checked = showAdvanced;
|
||||
document.getElementById('settingsDefaultTheme').value = defaultTheme;
|
||||
|
||||
renderTemplateSelectOptions();
|
||||
showTemplateEditor(false);
|
||||
|
||||
document.getElementById('settingsModal').style.display = '';
|
||||
document.querySelector('#settingsModal .modal-content section').scrollTop = 0;
|
||||
}
|
||||
|
||||
export function updateTemplateSelects() {
|
||||
const { templates } = window.settings;
|
||||
|
||||
if (typeof templates !== 'undefined') {
|
||||
const templatesOptionsHTML = templates.map((template, index) => {
|
||||
return `<option value="${index.toString()}">${template.name}</options>`;
|
||||
}).join('');
|
||||
document.getElementById('savedDetailsTemplates').innerHTML = templatesOptionsHTML;
|
||||
|
||||
const templateSelects = document.getElementsByClassName('template-select');
|
||||
Array.from(templateSelects).forEach(select => {
|
||||
select.removeEventListener('click', showWordOptions);
|
||||
select.innerHTML = templatesOptionsHTML;
|
||||
select.addEventListener('click', showWordOptions);
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
export function createTemplate() {
|
||||
window.settings.templates.push({ name: 'New Blank Template', template: '' });
|
||||
const newTemplateIndex = window.settings.templates.length - 1;
|
||||
|
||||
renderTemplateSelectOptions();
|
||||
document.getElementById('savedDetailsTemplates').value = (newTemplateIndex).toString();
|
||||
|
||||
editSavedTemplate(newTemplateIndex);
|
||||
}
|
||||
|
||||
export function saveTemplate() {
|
||||
const nameField = document.getElementById('templateNameField');
|
||||
const name = nameField.value.trim();
|
||||
const index = parseInt(nameField.getAttribute('template'));
|
||||
const template = document.getElementById('templateTextarea').value;
|
||||
window.settings.templates[index] = { name, template };
|
||||
|
||||
let storedSettings = window.localStorage.getItem(SETTINGS_KEY);
|
||||
storedSettings = storedSettings ? JSON.parse(storedSettings) : cloneObject(DEFAULT_SETTINGS);
|
||||
storedSettings.templates = window.settings.templates;
|
||||
window.localStorage.setItem(SETTINGS_KEY, JSON.stringify(storedSettings));
|
||||
addMessage('Templates Saved!');
|
||||
|
||||
showTemplateEditor(false);
|
||||
|
||||
renderTemplateSelectOptions();
|
||||
}
|
||||
|
||||
export function deleteSelectedTemplate() {
|
||||
const nameField = document.getElementById('templateNameField');
|
||||
const index = nameField.getAttribute('template');
|
||||
const name = window.settings.templates[index].name;
|
||||
if (confirm(`Are you sure you want to delete the "${name}" template? This cannot be undone!`)) {
|
||||
delete window.settings.templates[index];
|
||||
window.settings.templates = window.settings.templates.filter(template => template != null);
|
||||
|
||||
saveSettings();
|
||||
|
||||
showTemplateEditor(false);
|
||||
|
||||
renderTemplateSelectOptions();
|
||||
}
|
||||
}
|
||||
|
||||
export function editSavedTemplate(selectEvent) {
|
||||
const { templates } = window.settings;
|
||||
const selectedIndex = typeof selectEvent.target !== 'undefined' ? selectEvent.target.value : selectEvent;
|
||||
|
||||
if (selectedIndex !== '') {
|
||||
showSelectedTemplate(templates[selectedIndex], selectedIndex);
|
||||
} else {
|
||||
showTemplateEditor(false);
|
||||
}
|
||||
}
|
||||
|
||||
export function saveSettingsModal() {
|
||||
const updatedSettings = cloneObject(window.settings);
|
||||
updatedSettings.useIPAPronunciationField = document.getElementById('settingsUseIPA').checked;
|
||||
updatedSettings.useHotkeys = document.getElementById('settingsUseHotkeys').checked;
|
||||
updatedSettings.showAdvanced = document.getElementById('settingsShowAdvanced').checked;
|
||||
updatedSettings.defaultTheme = document.getElementById('settingsDefaultTheme').value;
|
||||
|
||||
if (hasToken()) {
|
||||
|
@ -62,6 +143,7 @@ export function saveSettingsModal() {
|
|||
saveSettings();
|
||||
toggleHotkeysEnabled();
|
||||
toggleIPAPronunciationFields();
|
||||
toggleShowAdvancedFields();
|
||||
} else {
|
||||
addMessage('No changes made to Settings.');
|
||||
}
|
||||
|
@ -101,3 +183,30 @@ export function toggleIPAPronunciationFields(render = true) {
|
|||
renderWords();
|
||||
}
|
||||
}
|
||||
|
||||
export function toggleShowAdvancedFields() {
|
||||
const buttons = document.getElementsByClassName('expand-advanced-form'),
|
||||
forms = document.getElementsByClassName('advanced-word-form');
|
||||
const formsWithFilledFields = [];
|
||||
|
||||
Array.from(forms).forEach(form => {
|
||||
const fields = form.querySelectorAll('input, textarea');
|
||||
const formHasFieldFilled = Array.from(fields).some(field => field.value.trim() !== '');
|
||||
if (window.settings.showAdvanced || formHasFieldFilled) {
|
||||
form.style.display = 'block';
|
||||
} else {
|
||||
form.style.display = 'none';
|
||||
}
|
||||
if (formHasFieldFilled) {
|
||||
formsWithFilledFields.push(form.id.replace('advancedForm', ''));
|
||||
}
|
||||
});
|
||||
Array.from(buttons).forEach(button => {
|
||||
const formHasFilledField = formsWithFilledFields.includes(button.id.replace('expandAdvancedForm', ''));
|
||||
if (window.settings.showAdvanced || formHasFilledField) {
|
||||
button.innerText = 'Hide Advanced Fields';
|
||||
} else {
|
||||
button.innerText = 'Show Advanced Fields';
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -35,7 +35,9 @@ function setupEditFormTabs() {
|
|||
document.getElementById('edit' + t.innerText + 'Tab').style.display = 'none';
|
||||
});
|
||||
tab.classList.add('active');
|
||||
document.getElementById('edit' + tab.innerText + 'Tab').style.display = '';
|
||||
const tabSection = document.getElementById('edit' + tab.innerText + 'Tab');
|
||||
tabSection.style.display = '';
|
||||
tabSection.scrollTop = 0;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -5,14 +5,17 @@ import { fadeOutElement } from '../utilities';
|
|||
import { setupDetailsTabs } from './details';
|
||||
import { setupWordForm, setupMobileWordFormButton } from './words';
|
||||
import { setupIPAButtons, setupHeaderButtons, setupInfoButtons } from './buttons';
|
||||
import { setupTemplateForm, setupTemplateSelectOptions } from './settings';
|
||||
|
||||
export default function setupListeners() {
|
||||
setupAnnouncements();
|
||||
setupDetailsTabs();
|
||||
setupTemplateForm();
|
||||
setupHeaderButtons();
|
||||
setupWordForm();
|
||||
setupMobileWordFormButton();
|
||||
setupInfoButtons();
|
||||
setupTemplateSelectOptions();
|
||||
if (window.settings.useHotkeys) {
|
||||
enableHotKeys();
|
||||
}
|
||||
|
|
|
@ -1,7 +1,16 @@
|
|||
import { insertAtCursor, getInputSelection, setSelectionRange } from '../StackOverflow/inputCursorManagement';
|
||||
import { openSettingsModal, saveSettingsModal, saveAndCloseSettingsModal } from '../settings';
|
||||
import {
|
||||
openSettingsModal,
|
||||
saveSettingsModal,
|
||||
saveAndCloseSettingsModal,
|
||||
createTemplate,
|
||||
saveTemplate
|
||||
} from '../settings';
|
||||
|
||||
export function setupSettingsModal() {
|
||||
document.getElementById('createTemplateButton').addEventListener('click', createTemplate);
|
||||
document.getElementById('saveTemplateButton').addEventListener('click', saveTemplate);
|
||||
|
||||
document.getElementById('settingsButton').addEventListener('click', openSettingsModal);
|
||||
document.getElementById('settingsSave').addEventListener('click', saveSettingsModal);
|
||||
document.getElementById('settingsSaveAndClose').addEventListener('click', saveAndCloseSettingsModal);
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
import { createTemplate, saveTemplate, editSavedTemplate, deleteSelectedTemplate } from "../settings";
|
||||
|
||||
export function setupTemplateForm() {
|
||||
document.getElementById('createTemplateButton').addEventListener('click', createTemplate);
|
||||
document.getElementById('saveTemplateButton').addEventListener('click', saveTemplate);
|
||||
document.getElementById('deleteTemplateButton').addEventListener('click', deleteSelectedTemplate);
|
||||
setupSavedTemplatesSelect();
|
||||
}
|
||||
|
||||
export function setupSavedTemplatesSelect() {
|
||||
const savedTemplatesSelect = document.getElementById('savedDetailsTemplates');
|
||||
|
||||
savedTemplatesSelect.removeEventListener('change', editSavedTemplate);
|
||||
savedTemplatesSelect.addEventListener('change', editSavedTemplate);
|
||||
}
|
||||
|
||||
export function setupTemplateSelectOptions() {
|
||||
const fillDetailsWithTemplate = function (e) {
|
||||
if (e.target.value !== '') {
|
||||
const template = window.settings.templates[parseInt(e.target.value)];
|
||||
let detailsId = 'wordDetails' + e.target.id.replace('templateSelect', '');
|
||||
document.getElementById(detailsId).value = template.template;
|
||||
}
|
||||
}
|
||||
Array.from(document.getElementsByClassName('template-select')).forEach(select => {
|
||||
if (select.id !== 'savedDetailsTemplates') {
|
||||
select.removeEventListener('change', fillDetailsWithTemplate);
|
||||
select.addEventListener('change', fillDetailsWithTemplate);
|
||||
}
|
||||
});
|
||||
}
|
|
@ -1,17 +1,19 @@
|
|||
import { renderEditForm } from '../render/words';
|
||||
import { confirmEditWord, cancelEditWord, confirmDeleteWord, submitWordForm } from '../wordManagement';
|
||||
import { confirmEditWord, cancelEditWord, confirmDeleteWord, expandAdvancedForm, submitWordForm } from '../wordManagement';
|
||||
import { goToNextPage, goToPreviousPage, goToPage } from '../pagination';
|
||||
import { setupMaximizeButtons } from './buttons';
|
||||
import { setupIPAFields } from '.';
|
||||
|
||||
export function setupWordForm() {
|
||||
const wordForm = document.getElementById('wordForm'),
|
||||
expandAdvancedFormButton = document.getElementById('expandAdvancedForm'),
|
||||
addWordButton = document.getElementById('addWordButton');
|
||||
wordForm.addEventListener('submit', event => {
|
||||
// Allow semantic form and prevent it from getting submitted
|
||||
event.preventDefault();
|
||||
return false;
|
||||
});
|
||||
expandAdvancedFormButton.addEventListener('click', expandAdvancedForm);
|
||||
addWordButton.addEventListener('click', submitWordForm);
|
||||
|
||||
setupIPAFields();
|
||||
|
@ -61,8 +63,13 @@ export function setupWordOptionSelections() {
|
|||
}
|
||||
|
||||
export function setupWordEditFormButtons() {
|
||||
const saveChangesButtons = document.getElementsByClassName('edit-save-changes'),
|
||||
const expandAdvancedFormButtons = document.getElementsByClassName('expand-advanced-form'),
|
||||
saveChangesButtons = document.getElementsByClassName('edit-save-changes'),
|
||||
cancelChangesButtons = document.getElementsByClassName('edit-cancel');
|
||||
Array.from(expandAdvancedFormButtons).forEach(button => {
|
||||
button.removeEventListener('click', expandAdvancedForm);
|
||||
button.addEventListener('click', expandAdvancedForm);
|
||||
});
|
||||
Array.from(saveChangesButtons).forEach(button => {
|
||||
button.removeEventListener('click', confirmEditWord);
|
||||
button.addEventListener('click', confirmEditWord);
|
||||
|
|
|
@ -182,6 +182,12 @@ export function renderWords() {
|
|||
partOfSpeech: removeTags(originalWord.partOfSpeech),
|
||||
definition: removeTags(originalWord.definition),
|
||||
details: originalWord.details,
|
||||
etymology: typeof originalWord.etymology === 'undefined' || originalWord.etymology.length < 1 ? null
|
||||
: originalWord.etymology.join(', '),
|
||||
related: typeof originalWord.related === 'undefined' || originalWord.related.length < 1 ? null
|
||||
: originalWord.related.join(', '),
|
||||
principalParts: typeof originalWord.principalParts === 'undefined' || originalWord.principalParts.length < 1 ? null
|
||||
: originalWord.principalParts.join(', '),
|
||||
wordId: originalWord.wordId,
|
||||
});
|
||||
|
||||
|
@ -193,6 +199,7 @@ export function renderWords() {
|
|||
wordsHTML += `<article class="entry" id="${word.wordId}">
|
||||
<header>
|
||||
<h4 class="word"><span class="orthographic-translation">${word.name}</span>${homonymnNumber > 0 ? ' <sub>' + homonymnNumber.toString() + '</sub>' : ''}</h4>
|
||||
${word.principalParts === null ? '' : `<span class="principalParts">(${word.principalParts})</span>`}
|
||||
<span class="pronunciation">${word.pronunciation}</span>
|
||||
<span class="part-of-speech">${word.partOfSpeech}</span>
|
||||
<a href="${shareLink}" target="_blank" class="small button word-option-button" title="Link to Word">➦</a>
|
||||
|
@ -202,6 +209,15 @@ export function renderWords() {
|
|||
<dd class="details">
|
||||
${md(word.details)}
|
||||
</dd>
|
||||
${word.etymology === null && word.related === null ? '' : `<hr>`}
|
||||
${word.etymology === null ? '' : `<dt>Etymology <small>(Root Word${originalWord.etymology.length !== 1 ? 's' : ''})</small></dt>
|
||||
<dd class="etymology">
|
||||
${md(word.etymology).replace(/<\/?p>/g, '')}
|
||||
</dd>`}
|
||||
${word.related === null ? '' : `<dt>Related Word${originalWord.related.length !== 1 ? 's' : ''}</dt>
|
||||
<dd class="related">
|
||||
${md(word.related).replace(/<\/?p>/g, '')}
|
||||
</dd>`}
|
||||
</dl>
|
||||
</article>`;
|
||||
});
|
||||
|
|
|
@ -22,7 +22,7 @@ export function getSearchFilters() {
|
|||
caseSensitive: document.getElementById('searchCaseSensitive').checked,
|
||||
ignoreDiacritics: document.getElementById('searchIgnoreDiacritics').checked,
|
||||
exact: document.getElementById('searchExactWords').checked,
|
||||
orthography: document.getElementById('searchOrthography').checked,
|
||||
// orthography is removed my default because it is already rendered on the backend.
|
||||
name: document.getElementById('searchIncludeName').checked,
|
||||
definition: document.getElementById('searchIncludeDefinition').checked,
|
||||
details: document.getElementById('searchIncludeDetails').checked,
|
||||
|
@ -54,23 +54,30 @@ export function getMatchingSearchWords() {
|
|||
}).filter(word => {
|
||||
searchTerm = filters.ignoreDiacritics ? removeDiacritics(searchTerm) : searchTerm;
|
||||
searchTerm = filters.caseSensitive ? searchTerm : searchTerm.toLowerCase();
|
||||
let name = filters.orthography ? translateOrthography(word.name) : word.name;
|
||||
name = filters.ignoreDiacritics ? removeDiacritics(name) : name;
|
||||
let name = filters.ignoreDiacritics ? removeDiacritics(word.name) : word.name;
|
||||
name = filters.caseSensitive ? name : name.toLowerCase();
|
||||
let definition = filters.ignoreDiacritics ? removeDiacritics(word.definition) : word.definition;
|
||||
definition = filters.caseSensitive ? definition : definition.toLowerCase();
|
||||
let details = filters.orthography ? parseReferences(word.details) : word.details;
|
||||
details = filters.ignoreDiacritics ? removeDiacritics(details) : details;
|
||||
let details = filters.ignoreDiacritics ? removeDiacritics(word.details) : word.details;
|
||||
details = filters.caseSensitive ? details : details.toLowerCase();
|
||||
let principalParts = typeof word.principalParts === 'undefined' ? [] : word.principalParts;
|
||||
principalParts = filters.ignoreDiacritics ? principalParts.map(part => removeDiacritics(part)) : principalParts;
|
||||
principalParts = filters.caseSensitive ? principalParts : principalParts.map(part => part.toLowerCase());
|
||||
|
||||
const isInName = filters.name && (filters.exact
|
||||
? searchTerm == name
|
||||
: new RegExp(searchTerm, 'g').test(name));
|
||||
? searchTerm == name
|
||||
: new RegExp(searchTerm, 'g').test(name)
|
||||
);
|
||||
const isInDefinition = filters.definition && (filters.exact
|
||||
? searchTerm == definition
|
||||
: new RegExp(searchTerm, 'g').test(definition));
|
||||
? searchTerm == definition
|
||||
: new RegExp(searchTerm, 'g').test(definition)
|
||||
);
|
||||
const isInDetails = filters.details && new RegExp(searchTerm, 'g').test(details);
|
||||
return searchTerm === '' || isInName || isInDefinition || isInDetails;
|
||||
const isInPrincipalParts = filters.name && (filters.exact
|
||||
? principalParts.includes(searchTerm)
|
||||
: principalParts.some(part => new RegExp(searchTerm, 'g').test(part))
|
||||
);
|
||||
return searchTerm === '' || isInName || isInDefinition || isInDetails || isInPrincipalParts;
|
||||
});
|
||||
return matchingWords;
|
||||
}
|
||||
|
@ -83,10 +90,6 @@ export function highlightSearchTerm(word) {
|
|||
if (searchTerm) {
|
||||
const filters = getSearchFilters();
|
||||
const markedUpWord = cloneObject(word);
|
||||
if (filters.orthography) {
|
||||
markedUpWord.name = translateOrthography(markedUpWord.name);
|
||||
markedUpWord.details = parseReferences(markedUpWord.details);
|
||||
}
|
||||
if (filters.ignoreDiacritics) {
|
||||
const searchTermLength = searchTerm.length;
|
||||
searchTerm = removeDiacritics(searchTerm);
|
||||
|
@ -98,6 +101,16 @@ export function highlightSearchTerm(word) {
|
|||
+ '<mark>' + markedUpWord.name.substr(wordIndex, searchTermLength) + '</mark>'
|
||||
+ markedUpWord.name.substr(wordIndex + searchTermLength);
|
||||
});
|
||||
|
||||
if (markedUpWord.principalParts !== null) {
|
||||
const part = getIndicesOf(searchTerm, removeDiacritics(markedUpWord.principalParts), filters.caseSensitive);
|
||||
part.forEach((wordIndex, i) => {
|
||||
wordIndex += '<mark></mark>'.length * i;
|
||||
markedUpWord.principalParts = markedUpWord.principalParts.substring(0, wordIndex)
|
||||
+ '<mark>' + markedUpWord.principalParts.substr(wordIndex, searchTermLength) + '</mark>'
|
||||
+ markedUpWord.principalParts.substr(wordIndex + searchTermLength);
|
||||
});
|
||||
}
|
||||
}
|
||||
if (filters.definition) {
|
||||
const definitionMatches = getIndicesOf(searchTerm, removeDiacritics(markedUpWord.definition), filters.caseSensitive);
|
||||
|
@ -121,6 +134,10 @@ export function highlightSearchTerm(word) {
|
|||
const regexMethod = 'g' + (filters.caseSensitive ? '' : 'i');
|
||||
if (filters.name) {
|
||||
markedUpWord.name = markedUpWord.name.replace(new RegExp(`(${searchTerm})`, regexMethod), `<mark>$1</mark>`);
|
||||
|
||||
if (markedUpWord.principalParts !== null) {
|
||||
markedUpWord.principalParts = markedUpWord.principalParts.replace(new RegExp(`(${searchTerm})`, regexMethod), `<mark>$1</mark>`);
|
||||
}
|
||||
}
|
||||
if (filters.definition) {
|
||||
markedUpWord.definition = markedUpWord.definition.replace(new RegExp(`(${searchTerm})`, regexMethod), `<mark>$1</mark>`);
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
import { wordExists, getHomonymnIndexes } from "./utilities";
|
||||
import removeDiacritics from "../StackOverflow/removeDiacritics";
|
||||
|
||||
export function sortWords() {
|
||||
|
@ -10,46 +9,3 @@ export function sortWords() {
|
|||
return removeDiacritics(wordA[sortBy]).toLowerCase() > removeDiacritics(wordB[sortBy]).toLowerCase() ? 1 : -1;
|
||||
});
|
||||
}
|
||||
|
||||
export function parseReferences(detailsMarkdown) {
|
||||
const references = detailsMarkdown.match(/\{\{.+?\}\}/g);
|
||||
if (references && Array.isArray(references)) {
|
||||
new Set(references).forEach(reference => {
|
||||
let wordToFind = reference.replace(/\{\{|\}\}/g, '');
|
||||
let homonymn = 0;
|
||||
|
||||
if (wordToFind.includes(':')) {
|
||||
const separator = wordToFind.indexOf(':');
|
||||
homonymn = wordToFind.substr(separator + 1);
|
||||
wordToFind = wordToFind.substring(0, separator);
|
||||
if (homonymn && homonymn.trim()
|
||||
&& !isNaN(parseInt(homonymn.trim())) && parseInt(homonymn.trim()) > 0) {
|
||||
homonymn = parseInt(homonymn.trim());
|
||||
} else {
|
||||
homonymn = false;
|
||||
}
|
||||
}
|
||||
|
||||
let existingWordId = false;
|
||||
const homonymnIndexes = getHomonymnIndexes({ name: wordToFind, wordId: -1 });
|
||||
|
||||
if (homonymn !== false && homonymn > 0) {
|
||||
if (typeof homonymnIndexes[homonymn - 1] !== 'undefined') {
|
||||
existingWordId = window.currentDictionary.words[homonymnIndexes[homonymn - 1]].wordId;
|
||||
}
|
||||
} else if (homonymn !== false) {
|
||||
existingWordId = wordExists(wordToFind, true);
|
||||
}
|
||||
|
||||
if (existingWordId !== false) {
|
||||
if (homonymn < 1 && homonymnIndexes.length > 0) {
|
||||
homonymn = 1;
|
||||
}
|
||||
const homonymnSubHTML = homonymn > 0 ? '<sub>' + homonymn.toString() + '</sub>' : '';
|
||||
const wordMarkdownLink = `[${wordToFind}${homonymnSubHTML}](#${existingWordId})`;
|
||||
detailsMarkdown = detailsMarkdown.replace(new RegExp(reference, 'g'), wordMarkdownLink);
|
||||
}
|
||||
});
|
||||
}
|
||||
return detailsMarkdown;
|
||||
}
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
import { renderWords } from "./render/words";
|
||||
import { renderWords, renderWord } from "./render/words";
|
||||
import { wordExists, addMessage, getNextId, hasToken, getHomonymnIndexes } from "./utilities";
|
||||
import removeDiacritics from "./StackOverflow/removeDiacritics";
|
||||
import { removeTags, getTimestampInSeconds } from "../helpers";
|
||||
import { saveDictionary } from "./dictionaryManagement";
|
||||
import { setupWordOptionButtons, setupWordOptionSelections } from "./setupListeners/words";
|
||||
import { wordMatchesSearch } from "./search";
|
||||
|
||||
export function validateWord(word, wordId = false) {
|
||||
const errorElementId = wordId === false ? 'wordErrorMessage' : 'wordErrorMessage_' + wordId,
|
||||
|
@ -116,38 +118,8 @@ export function parseReferences(detailsMarkdown) {
|
|||
const references = detailsMarkdown.match(/\{\{.+?\}\}/g);
|
||||
if (references && Array.isArray(references)) {
|
||||
new Set(references).forEach(reference => {
|
||||
let wordToFind = reference.replace(/\{\{|\}\}/g, '');
|
||||
let homonymn = 0;
|
||||
|
||||
if (wordToFind.includes(':')) {
|
||||
const separator = wordToFind.indexOf(':');
|
||||
homonymn = wordToFind.substr(separator + 1);
|
||||
wordToFind = wordToFind.substring(0, separator);
|
||||
if (homonymn && homonymn.trim()
|
||||
&& !isNaN(parseInt(homonymn.trim())) && parseInt(homonymn.trim()) > 0) {
|
||||
homonymn = parseInt(homonymn.trim());
|
||||
} else {
|
||||
homonymn = false;
|
||||
}
|
||||
}
|
||||
|
||||
let existingWordId = false;
|
||||
const homonymnIndexes = getHomonymnIndexes({ name: wordToFind, wordId: -1 });
|
||||
|
||||
if (homonymn !== false && homonymn > 0) {
|
||||
if (typeof homonymnIndexes[homonymn - 1] !== 'undefined') {
|
||||
existingWordId = window.currentDictionary.words[homonymnIndexes[homonymn - 1]].wordId;
|
||||
}
|
||||
} else if (homonymn !== false) {
|
||||
existingWordId = wordExists(wordToFind, true);
|
||||
}
|
||||
|
||||
if (existingWordId !== false) {
|
||||
if (homonymn < 1 && homonymnIndexes.length > 0) {
|
||||
homonymn = 1;
|
||||
}
|
||||
const homonymnSubHTML = homonymnIndexes.length > 1 && homonymn - 1 >= 0 ? '<sub>' + homonymn.toString() + '</sub>' : '';
|
||||
const wordMarkdownLink = `<span class="word-reference">[<span class="orthographic-translation">${translateOrthography(wordToFind)}</span>${homonymnSubHTML}](#${existingWordId})</span>`;
|
||||
const wordMarkdownLink = getWordReferenceMarkdown(reference);
|
||||
if (wordMarkdownLink !== reference) {
|
||||
detailsMarkdown = detailsMarkdown.replace(new RegExp(reference, 'g'), wordMarkdownLink);
|
||||
}
|
||||
});
|
||||
|
@ -155,12 +127,66 @@ export function parseReferences(detailsMarkdown) {
|
|||
return detailsMarkdown;
|
||||
}
|
||||
|
||||
export function getWordReferenceMarkdown(reference) {
|
||||
let wordToFind = reference.replace(/\{\{|\}\}/g, '');
|
||||
let homonymn = 0;
|
||||
|
||||
if (wordToFind.includes(':')) {
|
||||
const separator = wordToFind.indexOf(':');
|
||||
homonymn = wordToFind.substr(separator + 1);
|
||||
wordToFind = wordToFind.substring(0, separator);
|
||||
if (homonymn && homonymn.trim()
|
||||
&& !isNaN(parseInt(homonymn.trim())) && parseInt(homonymn.trim()) > 0) {
|
||||
homonymn = parseInt(homonymn.trim());
|
||||
} else {
|
||||
homonymn = false;
|
||||
}
|
||||
}
|
||||
|
||||
let existingWordId = false;
|
||||
const homonymnIndexes = getHomonymnIndexes({ name: wordToFind, wordId: -1 });
|
||||
|
||||
if (homonymn !== false && homonymn > 0) {
|
||||
if (typeof homonymnIndexes[homonymn - 1] !== 'undefined') {
|
||||
existingWordId = window.currentDictionary.words[homonymnIndexes[homonymn - 1]].wordId;
|
||||
}
|
||||
} else if (homonymn !== false) {
|
||||
existingWordId = wordExists(wordToFind, true);
|
||||
}
|
||||
|
||||
if (existingWordId !== false) {
|
||||
if (homonymn < 1 && homonymnIndexes.length > 0) {
|
||||
homonymn = 1;
|
||||
}
|
||||
const homonymnSubHTML = homonymnIndexes.length > 1 && homonymn - 1 >= 0 ? '<sub>' + homonymn.toString() + '</sub>' : '';
|
||||
return `<span class="word-reference">[<span class="orthographic-translation">${translateOrthography(wordToFind)}</span>${homonymnSubHTML}](#${existingWordId})</span>`;
|
||||
}
|
||||
|
||||
return reference;
|
||||
}
|
||||
|
||||
export function expandAdvancedForm(id = false) {
|
||||
const wordId = typeof id.target !== 'undefined' ? this.id.replace('expandAdvancedForm', '') : id;
|
||||
const button = typeof id.target !== 'undefined' ? this : document.getElementById('expandAdvancedForm' + (!wordId ? '' : wordId)),
|
||||
form = document.getElementById('advancedForm' + (!wordId ? '' : wordId));
|
||||
if (form.style.display !== 'block') {
|
||||
button.innerText = 'Hide Advanced Fields';
|
||||
form.style.display = 'block';
|
||||
} else {
|
||||
button.innerText = 'Show Advanced Fields';
|
||||
form.style.display = 'none';
|
||||
}
|
||||
}
|
||||
|
||||
export function submitWordForm() {
|
||||
const name = document.getElementById('wordName').value,
|
||||
pronunciation = document.getElementById('wordPronunciation').value,
|
||||
partOfSpeech = document.getElementById('wordPartOfSpeech').value,
|
||||
definition = document.getElementById('wordDefinition').value,
|
||||
details = document.getElementById('wordDetails').value;
|
||||
details = document.getElementById('wordDetails').value,
|
||||
etymology = document.getElementById('wordEtymology').value,
|
||||
related = document.getElementById('wordRelated').value,
|
||||
principalParts = document.getElementById('wordPrincipalParts').value;
|
||||
|
||||
const word = {
|
||||
name: removeTags(name).trim(),
|
||||
|
@ -171,6 +197,18 @@ export function submitWordForm() {
|
|||
wordId: getNextId(),
|
||||
};
|
||||
|
||||
if (removeTags(etymology).trim() !== '') {
|
||||
word.etymology = removeTags(etymology).split(',').map(w => w.trim()).filter(w => w.length > 0);
|
||||
}
|
||||
|
||||
if (removeTags(related).trim() !== '') {
|
||||
word.related = removeTags(related).split(',').map(w => w.trim()).filter(w => w.length > 0);
|
||||
}
|
||||
|
||||
if (removeTags(principalParts).trim() !== '') {
|
||||
word.principalParts = removeTags(principalParts).split(',').map(w => w.trim()).filter(w => w.length > 0);
|
||||
}
|
||||
|
||||
if (validateWord(word)) {
|
||||
addWord(word);
|
||||
sortWords(true);
|
||||
|
@ -192,6 +230,11 @@ export function clearWordForm() {
|
|||
document.getElementById('wordDefinition').value = '';
|
||||
document.getElementById('wordDetails').value = '';
|
||||
|
||||
document.getElementById('templateSelect').value = '';
|
||||
document.getElementById('wordEtymology').value = '';
|
||||
document.getElementById('wordRelated').value = '';
|
||||
document.getElementById('wordPrincipalParts').value = '';
|
||||
|
||||
document.getElementById('wordName').focus();
|
||||
}
|
||||
|
||||
|
@ -232,11 +275,30 @@ export function updateWord(word, wordId) {
|
|||
console.error('Could not find word to update');
|
||||
addMessage('Could not find word to update. Please refresh your browser and try again.', 10000, 'error');
|
||||
} else {
|
||||
const isPublic = hasToken() && window.currentDictionary.settings.isPublic;
|
||||
const { sortByDefinition } = window.currentDictionary.settings;
|
||||
const existingWord = window.currentDictionary.words[wordIndex];
|
||||
const needsReRender = (sortByDefinition && word.definition !== existingWord.definition)
|
||||
|| (!sortByDefinition && word.name !== existingWord.name);
|
||||
word.lastUpdated = getTimestampInSeconds();
|
||||
word.createdOn = window.currentDictionary.words[wordIndex].createdOn;
|
||||
word.createdOn = existingWord.createdOn;
|
||||
window.currentDictionary.words[wordIndex] = word;
|
||||
addMessage('Word Updated Successfully');
|
||||
sortWords(true);
|
||||
|
||||
if (needsReRender) {
|
||||
sortWords(true);
|
||||
} else {
|
||||
saveDictionary(false);
|
||||
const entry = document.getElementById(wordId.toString());
|
||||
if (!wordMatchesSearch(word)) {
|
||||
entry.parentElement.removeChild(entry);
|
||||
} else {
|
||||
console.log('matches search, updating in place');
|
||||
document.getElementById(wordId.toString()).outerHTML = renderWord(window.currentDictionary.words[wordIndex], isPublic);
|
||||
setupWordOptionButtons();
|
||||
setupWordOptionSelections();
|
||||
}
|
||||
}
|
||||
|
||||
if (hasToken()) {
|
||||
import('./account/index.js').then(account => {
|
||||
|
@ -252,7 +314,10 @@ export function confirmEditWord(id) {
|
|||
pronunciation = document.getElementById('wordPronunciation_' + wordId).value,
|
||||
partOfSpeech = document.getElementById('wordPartOfSpeech_' + wordId).value,
|
||||
definition = document.getElementById('wordDefinition_' + wordId).value,
|
||||
details = document.getElementById('wordDetails_' + wordId).value;
|
||||
details = document.getElementById('wordDetails_' + wordId).value,
|
||||
etymology = document.getElementById('wordEtymology_' + wordId).value,
|
||||
related = document.getElementById('wordRelated_' + wordId).value,
|
||||
principalParts = document.getElementById('wordPrincipalParts_' + wordId).value;
|
||||
|
||||
const word = {
|
||||
name: removeTags(name).trim(),
|
||||
|
@ -263,6 +328,18 @@ export function confirmEditWord(id) {
|
|||
wordId,
|
||||
};
|
||||
|
||||
if (removeTags(etymology).trim() !== '') {
|
||||
word.etymology = removeTags(etymology).split(',').map(w => w.trim()).filter(w => w.length > 0);
|
||||
}
|
||||
|
||||
if (removeTags(related).trim() !== '') {
|
||||
word.related = removeTags(related).split(',').map(w => w.trim()).filter(w => w.length > 0);
|
||||
}
|
||||
|
||||
if (removeTags(principalParts).trim() !== '') {
|
||||
word.principalParts = removeTags(principalParts).split(',').map(w => w.trim()).filter(w => w.length > 0);
|
||||
}
|
||||
|
||||
if (validateWord(word, wordId)) {
|
||||
if (confirm(`Are you sure you want to save changes to "${word.name}"?`)) {
|
||||
document.getElementById('editForm_' + wordId).classList.add('done');
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
* [Referencing Other Words](#referencing-other-words)
|
||||
* [Maximizing Large Text Boxes](#maximizing-large-text-boxes)
|
||||
* [IPA Auto-Fill Fields](#ipa-auto-fill-fields)
|
||||
* [Advanced Fields](#advanced-fields)
|
||||
* [Entry Management](#entry-management)
|
||||
* [Search/Filter](#searchfilter)
|
||||
* [The Settings Window](#the-settings-window)
|
||||
|
@ -62,13 +63,29 @@ If you have more than one word with the same spelling, the duplicate words will
|
|||
If you need more space to see what you are entering into a word's Details field or any other long text field with a "Maximize" button, clicking "Maximize" will give you a larger view of the text box to enter text in. When you're done writing, click either the "Done" or × button or any of the darker space outside of the larger view, and your text will be in the original text area. It will even preserve your cursor position or highlighted text so you don't lose your place moving from the larger view back to the small (and vice-versa)!
|
||||
|
||||
### IPA Auto-Fill Fields
|
||||
|
||||
You may notice some buttons around the Pronunciation field in the main word form and some other fields in the Details tab of your Dictionary Settings menu. This indicates that the field is using a special feature that generates [International Phonetic Alphabet](https://en.wikipedia.org/wiki/International_Phonetic_Alphabet) (IPA) characters when typing certain combinations of characters. Click the "Field Help" button below the field for instructions on how to use those fields.
|
||||
|
||||
You can also click the "IPA Table" button to display a maximized table that shows all of the characters in the IPA. Clicking them will add it to the pronunciation field wherever you position the cursor in the field. If you hover over the button for an IPA character that is not on a standard keyboard, you can what character combinations will produce that character when you type it in the field.
|
||||
|
||||
If you do not want to use the IPA field feaure, you can turn it off in the Settings. Click the "Settings" button in the top right side of the website, uncheck "Use IPA Auto-Fill", and click "Save" or "Save & Close". The "IPA Table" and "Field Help" buttons will be removed from all fields they were around, and you can use those fields as normal.
|
||||
|
||||
### Advanced Fields
|
||||
Clicking the button labeled "Show Advanced Fields" underneath the **Details** field on any word form will expand the "Advanced Fields" section for that word list. Clicking the button again when it says "Hide Advanced Fields" will hide the section again to make it so you don't have to scroll down to reach the "Add Word" button. The fields in the Advanced Fields section are detailed below:
|
||||
|
||||
- **Details Field Templates:** A dropdown box with any templates you have previously created (see [Templates for Details Fields](#templates-for-details-fields) in the Settings section below to learn how to create a template). Selecting one of the templates will put that template into the Details field for you, _overwriting **anything** that might have already been written there_.
|
||||
- If there are no templates created, this field will not be displayed.
|
||||
- Each time you select a different template (other than the "None Selected" option), it will overwrite anything in the Details field with the template without warning, so please be careful.
|
||||
- Selecting the "None Selected" option at the top of the list will _not_ change the Details field.
|
||||
- **Etymology / Root Words:** Any words that the current word might have stemmed from originally.
|
||||
- Words written here are treated as word references (see [Referencing Other Words](#referencing-other-words) for how to reference a word or a duplicate word) without requiring the \{\{double-curly-braces\}\} as in the Details field. The words referenced here will appear below the word's details in the list.
|
||||
- Separate each individual root word with a comma.
|
||||
- **Related Words:** Any words that might be related to the current word.
|
||||
- Words written here are treated as word references (see [Referencing Other Words](#referencing-other-words) for how to reference a word or a duplicate word) without requiring the \{\{double-curly-braces\}\} as in the Details field. The words referenced here will appear below the word's details in the list.
|
||||
- Separate each individual related word with a comma.
|
||||
- **Principal Parts:** Any words that someone must know in order to conjugate the current word (see the [Wikipedia entry](https://en.wikipedia.org/wiki/Principal_parts) for more details).
|
||||
- Words written here are treated as word references (see [Referencing Other Words](#referencing-other-words) for how to reference a word or a duplicate word) without requiring the \{\{double-curly-braces\}\} as in the Details field. The words referenced here will appear below the word's details in the list.
|
||||
- Separate each individual principal part with a comma.
|
||||
|
||||
### Entry Management
|
||||
After adding some words to your dictionary, you'll see an "Options" button on each entry. Clicking the button reveals Edit and Delete buttons.
|
||||
|
||||
|
@ -102,16 +119,25 @@ When you have a search term or filter applied, you can see the number of results
|
|||
To display _all_ of your words again, clear your search bar and ensure all the "Include Only" checkboxes are checked.
|
||||
|
||||
### The Settings Window
|
||||
|
||||
Clicking the "Settings" button in the top-right side of Lexiconga will show the Settings window with some options.
|
||||
|
||||
- **Use IPA Auto-Fill:** Check this to use character combinations to input International Phonetic Alphabet characters into Pronunciation fields. Use the "Field Help" button for instructions on how to use it and the "IPA Table" to display available characters. Uncheck it to disable the feature and hide the buttons.
|
||||
- **Use Hotkeys:** Check this to enable keyboard combinations to perform different helpful actions (see [Keyboard Shortcuts](#keyboard-shortcuts) below). Unchecking this disables the feature.
|
||||
- Note: If your browser does not support required features, this will be disabled automatically.
|
||||
- **Show Advanced Fields By Default:** Check this to make the advanced fields show on word forms without needing to click the "Show Advanced Fields" button (see [Advanced Fields](#advanced-fields) above). Unchecking this makes it so you need to click the "Show Advanced Fields" button to show the fields each time you edit a word.
|
||||
- **Default Theme:** Choose what color theme new dictionaries will use when they are created.
|
||||
|
||||
After making changes, click the "Save" or "Save & Close" button to save your changes.
|
||||
|
||||
#### Templates for Details Fields
|
||||
Below the "Default Theme" selector is the template editor. Either click "Create New Template" or choose one from the "Saved Templates" dropdown to begin editing the template. Once a new template is created or a saved template is selected, new fields will appear labeled "Template Name" and "Template," plus a "Save Template" and "Delete Template" button.
|
||||
|
||||
You can modify the template's name by editing the "Template Name" field, and whatever you set in the "Template" text area will be used as the template in the Details field of a word form if it is selected (see [Advanced Fields](#advanced-fields) above for more about how this is used).
|
||||
|
||||
After making any changes to a template, click the "Save Template" button below the "Template" field to save it to your browser. Templates are only stored in the browser they were created on and _do not_ get uploaded to your account (if you have one). If you create a template, it will _not be available on any other web browser_ unless you re-create it!
|
||||
|
||||
Clicking the "Delete Template" button will prompt you to confirm that you want to delete it, and if you confirm, it will permanently delete the currently selected template from your browser. There is no way to recover deleted templates!
|
||||
|
||||
### The Dictionary Settings Window
|
||||
|
||||
Clicking the "Edit" button under your dictionary's name will display a window with tabs that each contain different fields and options.
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
[
|
||||
{
|
||||
"header": "Minor Updates + 1 Important Fix",
|
||||
"body": "<p><em>March 4, 2020</em> – Lexiconga has been updated to fix a long-standing bug that prevented updated words from syncing between devices!</p><p>Check the <a href=\"https://github.com/Alamantus/Lexiconga/releases\" target=\"_blank\" rel=\"noopener\">Updates page</a> for the other minor updates.</p>",
|
||||
"expire": "April 4, 2020",
|
||||
"dismissId": "marchFixes1"
|
||||
"header": "New Features: Wave 2",
|
||||
"body": "<p><em>August 3, 2020</em> – Lexiconga has added new features in the form of advanced fields and templates!</p><p>Check the <a href=\"https://github.com/Alamantus/Lexiconga/releases\" target=\"_blank\" rel=\"noopener\">Updates page</a> to see all the new features, and please <a href=\"https://github.com/Alamantus/Lexiconga/issues\" target=\"_blank\" rel=\"noopener\">report any issues</a> you encounter so I can fix them.</p>",
|
||||
"expire": "October 31, 2020",
|
||||
"dismissId": "wave2"
|
||||
}
|
||||
]
|
|
@ -215,11 +215,14 @@ WHERE dictionary=$dictionary";
|
|||
}
|
||||
|
||||
public function getWords ($user, $dictionary) {
|
||||
$query = "SELECT words.* FROM words JOIN dictionaries ON id = dictionary WHERE dictionary=$dictionary AND user=$user";
|
||||
$query = "SELECT words.*, wa.etymology, wa.related, wa.principal_parts FROM words
|
||||
LEFT JOIN words_advanced wa ON wa.dictionary = words.dictionary AND wa.word_id = words.word_id
|
||||
JOIN dictionaries ON dictionaries.id = words.dictionary
|
||||
WHERE words.dictionary=$dictionary AND dictionaries.user=$user";
|
||||
$results = $this->db->query($query)->fetchAll();
|
||||
if ($results) {
|
||||
return array_map(function ($row) {
|
||||
return array(
|
||||
$word = array(
|
||||
'name' => $row['name'],
|
||||
'pronunciation' => $row['pronunciation'],
|
||||
'partOfSpeech' => $row['part_of_speech'],
|
||||
|
@ -229,6 +232,20 @@ WHERE dictionary=$dictionary";
|
|||
'createdOn' => intval($row['created_on']),
|
||||
'wordId' => intval($row['word_id']),
|
||||
);
|
||||
|
||||
if (!is_null($row['etymology']) && $row['etymology'] !== '') {
|
||||
$word['etymology'] = explode(',', $row['etymology']);
|
||||
}
|
||||
|
||||
if (!is_null($row['related']) && $row['related'] !== '') {
|
||||
$word['related'] = explode(',', $row['related']);
|
||||
}
|
||||
|
||||
if (!is_null($row['principal_parts']) && $row['principal_parts'] !== '') {
|
||||
$word['principalParts'] = explode(',', $row['principal_parts']);
|
||||
}
|
||||
|
||||
return $word;
|
||||
}, $results);
|
||||
}
|
||||
return array();
|
||||
|
@ -253,8 +270,10 @@ WHERE dictionary=$dictionary";
|
|||
return true;
|
||||
}
|
||||
|
||||
$query = 'INSERT INTO words (dictionary, word_id, name, pronunciation, part_of_speech, definition, details, last_updated, created_on) VALUES ';
|
||||
$params = array();
|
||||
$query1 = 'INSERT INTO words (dictionary, word_id, name, pronunciation, part_of_speech, definition, details, last_updated, created_on) VALUES ';
|
||||
$query2 = 'INSERT INTO words_advanced (dictionary, word_id, etymology, related, principal_parts) VALUES ';
|
||||
$params1 = array();
|
||||
$params2 = array();
|
||||
$word_ids = array();
|
||||
$most_recent_word_update = 0;
|
||||
foreach($words as $word) {
|
||||
|
@ -263,18 +282,25 @@ WHERE dictionary=$dictionary";
|
|||
$most_recent_word_update = $last_updated;
|
||||
}
|
||||
$word_ids[] = $word['wordId'];
|
||||
$query .= "(?, ?, ?, ?, ?, ?, ?, ?, ?), ";
|
||||
$params[] = $dictionary;
|
||||
$params[] = $word['wordId'];
|
||||
$params[] = $word['name'];
|
||||
$params[] = $word['pronunciation'];
|
||||
$params[] = $word['partOfSpeech'];
|
||||
$params[] = $word['definition'];
|
||||
$params[] = $word['details'];
|
||||
$params[] = $last_updated;
|
||||
$params[] = $word['createdOn'];
|
||||
$query1 .= "(?, ?, ?, ?, ?, ?, ?, ?, ?), ";
|
||||
$params1[] = $dictionary;
|
||||
$params1[] = $word['wordId'];
|
||||
$params1[] = $word['name'];
|
||||
$params1[] = $word['pronunciation'];
|
||||
$params1[] = $word['partOfSpeech'];
|
||||
$params1[] = $word['definition'];
|
||||
$params1[] = $word['details'];
|
||||
$params1[] = $last_updated;
|
||||
$params1[] = $word['createdOn'];
|
||||
|
||||
$query2 .= "(?, ?, ?, ?, ?), ";
|
||||
$params2[] = $dictionary;
|
||||
$params2[] = $word['wordId'];
|
||||
$params2[] = isset($word['etymology']) ? implode(',', $word['etymology']) : '';
|
||||
$params2[] = isset($word['related']) ? implode(',', $word['related']) : '';
|
||||
$params2[] = isset($word['principalParts']) ? implode(',', $word['principalParts']) : '';
|
||||
}
|
||||
$query = trim($query, ', ') . ' ON DUPLICATE KEY UPDATE
|
||||
$query1 = trim($query1, ', ') . ' ON DUPLICATE KEY UPDATE
|
||||
name=VALUES(name),
|
||||
pronunciation=VALUES(pronunciation),
|
||||
part_of_speech=VALUES(part_of_speech),
|
||||
|
@ -282,10 +308,14 @@ definition=VALUES(definition),
|
|||
details=VALUES(details),
|
||||
last_updated=VALUES(last_updated),
|
||||
created_on=VALUES(created_on)';
|
||||
$query2 = trim($query2, ', ') . ' ON DUPLICATE KEY UPDATE
|
||||
etymology=VALUES(etymology),
|
||||
related=VALUES(related),
|
||||
principal_parts=VALUES(principal_parts)';
|
||||
|
||||
$results = $this->db->execute($query, $params);
|
||||
$results1 = $this->db->execute($query1, $params1);
|
||||
|
||||
// if ($results) {
|
||||
// if ($results1) {
|
||||
// $database_words = $this->getWords($user, $dictionary);
|
||||
// $database_ids = array_map(function($database_word) { return $database_word['id']; }, $database_words);
|
||||
// $words_to_delete = array_filter($database_ids, function($database_id) use($word_ids) { return !in_array($database_id, $word_ids); });
|
||||
|
@ -295,8 +325,11 @@ created_on=VALUES(created_on)';
|
|||
// }
|
||||
// }
|
||||
|
||||
if ($results) {
|
||||
return $results;
|
||||
if ($results1 === true) {
|
||||
$results2 = $this->db->execute($query2, $params2);
|
||||
if ($results2 === true) {
|
||||
return $results1 && $results2;
|
||||
}
|
||||
}
|
||||
return array(
|
||||
'error' => $this->db->last_error_info,
|
||||
|
|
|
@ -81,16 +81,40 @@ class PublicDictionary {
|
|||
$words = $this->getWordsAsEntered();
|
||||
if ($words) {
|
||||
return array_map(function ($row) use ($dictionary) {
|
||||
return array(
|
||||
$word = array(
|
||||
'name' => $this->translateOrthography($row['name'], $dictionary),
|
||||
'pronunciation' => $row['pronunciation'],
|
||||
'partOfSpeech' => $row['part_of_speech'],
|
||||
'definition' => $row['definition'],
|
||||
'details' => $this->parseReferences(strip_tags($row['details']), $dictionary),
|
||||
'details' => $this->parseReferences(strip_tags($row['details']), $dictionary, false),
|
||||
'lastUpdated' => is_null($row['last_updated']) ? intval($row['created_on']) : intval($row['last_updated']),
|
||||
'createdOn' => intval($row['created_on']),
|
||||
'wordId' => intval($row['word_id']),
|
||||
);
|
||||
|
||||
if (!is_null($row['etymology'])) {
|
||||
if (strlen($row['etymology']) > 0) {
|
||||
$word['etymology'] = array_map(function ($root) use($dictionary) {
|
||||
return $this->getWordReferenceHTML(strip_tags($root), $dictionary, false);
|
||||
}, explode(',', $row['etymology']));
|
||||
}
|
||||
}
|
||||
|
||||
if (!is_null($row['related'])) {
|
||||
if (strlen($row['related']) > 0) {
|
||||
$word['related'] = array_map(function ($root) use($dictionary) {
|
||||
return $this->getWordReferenceHTML(strip_tags($root), $dictionary, false);
|
||||
}, explode(',', $row['related']));
|
||||
}
|
||||
}
|
||||
|
||||
if (!is_null($row['principal_parts'])) {
|
||||
if (strlen($row['principal_parts']) > 0) {
|
||||
$word['principalParts'] = explode(',', $row['principal_parts']);
|
||||
}
|
||||
}
|
||||
|
||||
return $word;
|
||||
}, $this->sortWords($words));
|
||||
}
|
||||
}
|
||||
|
@ -99,10 +123,13 @@ class PublicDictionary {
|
|||
|
||||
public function getSpecificPublicDictionaryWord ($dictionary, $word) {
|
||||
if (is_numeric($dictionary) && is_numeric($word)) {
|
||||
$query = "SELECT words.* FROM words JOIN dictionaries ON id = dictionary WHERE dictionary=? AND word_id=? AND is_public=1";
|
||||
$query = "SELECT words.*, wa.etymology, wa.related, wa.principal_parts FROM words
|
||||
LEFT JOIN words_advanced wa ON wa.dictionary = words.dictionary AND wa.word_id = words.word_id
|
||||
JOIN dictionaries ON dictionaries.id = words.dictionary
|
||||
WHERE words.dictionary=? AND words.word_id=? AND dictionaries.is_public=1";
|
||||
$result = $this->db->query($query, array($dictionary, $word))->fetch();
|
||||
if ($result) {
|
||||
return array(
|
||||
$word = array(
|
||||
'name' => $this->translateOrthography($result['name'], $dictionary),
|
||||
'pronunciation' => $result['pronunciation'],
|
||||
'partOfSpeech' => $result['part_of_speech'],
|
||||
|
@ -112,6 +139,30 @@ class PublicDictionary {
|
|||
'createdOn' => intval($result['created_on']),
|
||||
'wordId' => intval($result['word_id']),
|
||||
);
|
||||
|
||||
if (!is_null($result['etymology'])) {
|
||||
if (strlen($result['etymology']) > 0) {
|
||||
$word['etymology'] = array_map(function ($root) use($dictionary) {
|
||||
return $this->getWordReferenceHTML(strip_tags($root), $dictionary);
|
||||
}, explode(',', $result['etymology']));
|
||||
}
|
||||
}
|
||||
|
||||
if (!is_null($result['related'])) {
|
||||
if (strlen($result['related']) > 0) {
|
||||
$word['related'] = array_map(function ($root) use($dictionary) {
|
||||
return $this->getWordReferenceHTML(strip_tags($root), $dictionary);
|
||||
}, explode(',', $result['related']));
|
||||
}
|
||||
}
|
||||
|
||||
if (!is_null($result['principal_parts'])) {
|
||||
if (strlen($result['principal_parts']) > 0) {
|
||||
$word['principalParts'] = explode(',', $result['principal_parts']);
|
||||
}
|
||||
}
|
||||
|
||||
return $word;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
@ -119,7 +170,10 @@ class PublicDictionary {
|
|||
|
||||
private function getWordsAsEntered() {
|
||||
if (!isset($this->original_words)) {
|
||||
$query = "SELECT words.* FROM words JOIN dictionaries ON id = dictionary WHERE dictionary=? AND is_public=1";
|
||||
$query = "SELECT words.*, wa.etymology, wa.related, wa.principal_parts FROM words
|
||||
LEFT JOIN words_advanced wa ON wa.dictionary = words.dictionary AND wa.word_id = words.word_id
|
||||
JOIN dictionaries ON dictionaries.id = words.dictionary
|
||||
WHERE words.dictionary=? AND is_public=1";
|
||||
$this->original_words = $this->db->query($query, array($this->details['externalID']))->fetchAll();
|
||||
}
|
||||
return $this->original_words;
|
||||
|
@ -183,43 +237,9 @@ class PublicDictionary {
|
|||
if (preg_match_all('/\{\{.+?\}\}/', $details, $references) !== false) {
|
||||
$references = array_unique($references[0]);
|
||||
foreach($references as $reference) {
|
||||
$word_to_find = preg_replace('/\{\{|\}\}/', '', $reference);
|
||||
$homonymn = 0;
|
||||
|
||||
if (strpos($word_to_find, ':') !== false) {
|
||||
$separator = strpos($word_to_find, ':');
|
||||
$homonymn = substr($word_to_find, $separator + 1);
|
||||
$word_to_find = substr($word_to_find, 0, $separator);
|
||||
if ($homonymn && trim($homonymn) && intval(trim($homonymn)) > 0) {
|
||||
$homonymn = intval(trim($homonymn));
|
||||
} else {
|
||||
$homonymn = false;
|
||||
}
|
||||
}
|
||||
|
||||
$target_id = false;
|
||||
$reference_ids = $this->getWordIdsWithName($dictionary_id, $word_to_find);
|
||||
|
||||
if (count($reference_ids) > 0) {
|
||||
if ($homonymn !== false && $homonymn > 0) {
|
||||
if (isset($reference_ids[$homonymn - 1])) {
|
||||
$target_id = $reference_ids[$homonymn - 1];
|
||||
}
|
||||
} else if ($homonymn !== false) {
|
||||
$target_id = $reference_ids[0];
|
||||
}
|
||||
|
||||
if ($target_id !== false) {
|
||||
if ($homonymn < 1) {
|
||||
$homonymn = 1;
|
||||
}
|
||||
$homonymn_sub_html = count($reference_ids) > 1 && $homonymn - 1 >= 0 ? '<sub>' . $homonymn . '</sub>' : '';
|
||||
$site_root = substr($_SERVER['REQUEST_URI'], 0, strpos($_SERVER['REQUEST_URI'], $dictionary_id));
|
||||
$markdown_link = '<span class="word-reference"><a href="' . $site_root . $dictionary_id . '/' . $target_id .'" target="_blank" title="Link to Reference">'
|
||||
. '<span class="orthographic-translation">' . $this->translateOrthography($word_to_find, $dictionary_id) . '</span>' . $homonymn_sub_html
|
||||
. '</a></span>';
|
||||
$details = str_replace($reference, $markdown_link, $details);
|
||||
}
|
||||
$reference_link = $this->getWordReferenceHTML($reference, $dictionary_id);
|
||||
if ($reference_link !== $reference) {
|
||||
$details = str_replace($reference, $markdown_link, $details);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -227,6 +247,50 @@ class PublicDictionary {
|
|||
return $details;
|
||||
}
|
||||
|
||||
private function getWordReferenceHTML($reference, $dictionary_id, $direct_link = true) {
|
||||
$word_to_find = preg_replace('/\{\{|\}\}/', '', $reference);
|
||||
$homonymn = 0;
|
||||
|
||||
if (strpos($word_to_find, ':') !== false) {
|
||||
$separator = strpos($word_to_find, ':');
|
||||
$homonymn = substr($word_to_find, $separator + 1);
|
||||
$word_to_find = substr($word_to_find, 0, $separator);
|
||||
if ($homonymn && trim($homonymn) && intval(trim($homonymn)) > 0) {
|
||||
$homonymn = intval(trim($homonymn));
|
||||
} else {
|
||||
$homonymn = false;
|
||||
}
|
||||
}
|
||||
|
||||
$target_id = false;
|
||||
$reference_ids = $this->getWordIdsWithName($dictionary_id, $word_to_find);
|
||||
|
||||
if (count($reference_ids) > 0) {
|
||||
if ($homonymn !== false && $homonymn > 0) {
|
||||
if (isset($reference_ids[$homonymn - 1])) {
|
||||
$target_id = $reference_ids[$homonymn - 1];
|
||||
}
|
||||
} else if ($homonymn !== false) {
|
||||
$target_id = $reference_ids[0];
|
||||
}
|
||||
|
||||
if ($target_id !== false) {
|
||||
if ($homonymn < 1) {
|
||||
$homonymn = 1;
|
||||
}
|
||||
$homonymn_sub_html = count($reference_ids) > 1 && $homonymn - 1 >= 0 ? '<sub>' . $homonymn . '</sub>' : '';
|
||||
$site_root = substr($_SERVER['REQUEST_URI'], 0, strpos($_SERVER['REQUEST_URI'], $dictionary_id));
|
||||
return '<span class="word-reference"><a href="'
|
||||
. ($direct_link ? $site_root . $dictionary_id . '/' : '#') . $target_id .'" '
|
||||
. ($direct_link ? 'target="_blank" ' : '') . 'title="Link to Reference">'
|
||||
. '<span class="orthographic-translation">' . $this->translateOrthography($word_to_find, $dictionary_id) . '</span>' . $homonymn_sub_html
|
||||
. '</a></span>';
|
||||
}
|
||||
}
|
||||
|
||||
return $reference;
|
||||
}
|
||||
|
||||
private function getWordIdsWithName($dictionary, $word_name) {
|
||||
if (is_numeric($dictionary)) {
|
||||
$query = "SELECT word_id FROM words WHERE dictionary=? AND name=?";
|
||||
|
|
|
@ -134,7 +134,7 @@ switch ($view) {
|
|||
oldLoad && oldLoad();
|
||||
if (UpUp) {
|
||||
UpUp.start({
|
||||
'cache-version': '2.1.7',
|
||||
'cache-version': '2.2.0',
|
||||
'content-url': 'offline.html',
|
||||
'assets': [
|
||||
\"" . implode('","', $files) . "\"
|
||||
|
|
|
@ -15,6 +15,15 @@
|
|||
}
|
||||
}
|
||||
|
||||
details summary {
|
||||
cursor: pointer;
|
||||
|
||||
h4 {
|
||||
display: inline-block;
|
||||
margin: 5px 0;
|
||||
}
|
||||
}
|
||||
|
||||
.share-link {
|
||||
margin-left: $general-padding !important;
|
||||
line-height: 16px !important;
|
||||
|
|
|
@ -12,7 +12,7 @@ html, body {
|
|||
|
||||
header {
|
||||
display: block;
|
||||
padding: 5px $general-padding;
|
||||
padding: 5px ($general-padding / 2);
|
||||
margin: 0 0 5px;
|
||||
|
||||
&#top {
|
||||
|
|
|
@ -109,6 +109,7 @@
|
|||
border-radius: 5px;
|
||||
max-height: 80%;
|
||||
overflow-y: auto;
|
||||
z-index: 8;
|
||||
}
|
||||
|
||||
.edit-form {
|
||||
|
@ -196,6 +197,7 @@
|
|||
|
||||
header {
|
||||
position: relative;
|
||||
padding-right: 70px;
|
||||
|
||||
.word-option-button {
|
||||
position: absolute;
|
||||
|
|
|
@ -53,7 +53,6 @@ $mobile-word-form-size: 32px;
|
|||
top: $header-height + ($mobile-word-form-size / 2);
|
||||
left: 0;
|
||||
right: 3%;
|
||||
z-index: 1;
|
||||
|
||||
label:not(:last-child) {
|
||||
margin-bottom: 10px;
|
||||
|
|
|
@ -90,3 +90,16 @@ CREATE TABLE IF NOT EXISTS `words` (
|
|||
`created_on` int(11) NOT NULL,
|
||||
UNIQUE KEY `unique_index` (`dictionary`,`word_id`)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
|
||||
DELIMITER $$
|
||||
CREATE TRIGGER IF NOT EXISTS `delete_word_advanced` AFTER DELETE ON `words` FOR EACH ROW DELETE FROM words_advanced WHERE words_advanced.dictionary=old.dictionary AND words_advanced.word_id=old.word_id
|
||||
$$
|
||||
DELIMITER ;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `words_advanced` (
|
||||
`dictionary` int(11) NOT NULL,
|
||||
`word_id` int(11) NOT NULL,
|
||||
`etymology` text NOT NULL COMMENT 'Comma-separated',
|
||||
`related` text NOT NULL COMMENT 'Comma-separated',
|
||||
`principal_parts` text NOT NULL COMMENT 'Comma-separated',
|
||||
UNIQUE KEY `dictionary_word_id` (`dictionary`,`word_id`)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
|
||||
|
|
|
@ -139,6 +139,25 @@
|
|||
<label>Details<span class="red">*</span><a class="label-button maximize-button">Maximize</a><br>
|
||||
<textarea id="wordDetails" placeholder="Markdown formatting allowed"></textarea>
|
||||
</label>
|
||||
<label>
|
||||
<a id="expandAdvancedForm" class="small button expand-advanced-form">Show Advanced Fields</a>
|
||||
</label>
|
||||
<div id="advancedForm" class="advanced-word-form" style="display:none;">
|
||||
<label>Details Field Templates
|
||||
<select id="templateSelect" class="template-select">
|
||||
</select>
|
||||
<small>Choose one to fill the details field. (Note: Will erase anything currently there.)</small>
|
||||
</label>
|
||||
<label>Etymology / Root Words<br>
|
||||
<input id="wordEtymology" maxlength="2500" placeholder="comma,separated,root,words">
|
||||
</label>
|
||||
<label>Related Words<br>
|
||||
<input id="wordRelated" maxlength="2500" placeholder="comma,separated,related,words">
|
||||
</label>
|
||||
<label>Principal Parts<a href="https://en.wikipedia.org/wiki/Principal_parts" target="_blank" class="label-button">What's This?</a><br>
|
||||
<input id="wordPrincipalParts" maxlength="2500" placeholder="comma,separated,principal,parts">
|
||||
</label>
|
||||
</div>
|
||||
<div id="wordErrorMessage"></div>
|
||||
<a class="button" id="addWordButton">Add Word</a>
|
||||
</form>
|
||||
|
@ -205,6 +224,11 @@
|
|||
<input id="settingsUseHotkeys" type="checkbox" checked><br />
|
||||
<small>Check this to enable keyboard combinations to perform different helpful actions.</small>
|
||||
</label>
|
||||
|
||||
<label>Show Advanced Fields By Default
|
||||
<input id="settingsShowAdvanced" type="checkbox"><br />
|
||||
<small>Check this to make the advanced fields show on word forms without needing to click the "Show Advanced Fields" button.</small>
|
||||
</label>
|
||||
|
||||
<label>Default Theme <small>(the theme new dictionaries will use)</small>
|
||||
<select id="settingsDefaultTheme">
|
||||
|
@ -220,9 +244,33 @@
|
|||
<option value="grape">Grape</option>
|
||||
</select>
|
||||
</label>
|
||||
|
||||
<h4>Templates for Details Fields</h4>
|
||||
<p>Templates created here are saved only to your local browser.</p>
|
||||
<label>Saved Templates <a id="createTemplateButton" class="label-button">Create New Template</a>
|
||||
<select id="savedDetailsTemplates" class="template-select">
|
||||
</select>
|
||||
</label>
|
||||
<div id="templateFields" style="display:none;">
|
||||
<label>Template Name
|
||||
<input id="templateNameField"><br />
|
||||
<small>If you have chosen a template above, this will overwrite the chosen template.</small>
|
||||
</label>
|
||||
<label>Template<a class="label-button maximize-button">Maximize</a><br>
|
||||
<textarea id="templateTextarea" placeholder="**Era:**
|
||||
|
||||
**Dialect:**
|
||||
|
||||
etc."></textarea>
|
||||
</label>
|
||||
<a id="saveTemplateButton" class="button">Save Template</a>
|
||||
<a id="deleteTemplateButton" class="red button">Delete Template</a>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<div id="accountActions"></div>
|
||||
<div id="accountSettings"></div>
|
||||
</div>
|
||||
<div id="accountActions"></div>
|
||||
</form>
|
||||
</section>
|
||||
<footer>
|
||||
|
@ -383,7 +431,7 @@ ou=ow"></textarea>
|
|||
<label class="button">Import Words <input type="file" id="importWordsCSV" accept="text/csv, .csv"><br>
|
||||
<small>Import a CSV file of words.</small>
|
||||
</label>
|
||||
<a class="small button" download="Lexiconga_import-template.csv" href="data:text/csv;charset=utf-8,%22word%22,%22pronunciation%22,%22part of speech%22,%22definition%22,%22explanation%22%0A">Download an example file with the correct formatting</a>
|
||||
<a class="small button" download="Lexiconga_import-template.csv" href="data:text/csv;charset=utf-8,%22word%22,%22pronunciation%22,%22part of speech%22,%22definition%22,%22explanation%22,%22etymology %28comma-separated%29%22,%22related words %28comma-separated%29%22,%22principal parts %28comma-separated%29%22%0A">Download an example file with the correct formatting</a>
|
||||
</p>
|
||||
</div>
|
||||
<div>
|
||||
|
|
|
@ -81,9 +81,6 @@
|
|||
<label>Exact Words
|
||||
<input type="checkbox" id="searchExactWords">
|
||||
</label>
|
||||
<label style="display:none;">Translations
|
||||
<input type="checkbox" id="searchOrthography">
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="split">
|
||||
|
|
Loading…
Reference in New Issue