Update simpleDefinition to definition and longDefinition to details
This commit is contained in:
parent
b8702a6716
commit
ac8d88f082
|
@ -37,8 +37,8 @@ export const DEFAULT_DICTIONARY = {
|
|||
name: '',
|
||||
pronunciation: '',
|
||||
partOfSpeech: '',
|
||||
simpleDefinition: '',
|
||||
longDefinition: '',
|
||||
definition: '',
|
||||
details: '',
|
||||
wordId: 0
|
||||
}, */
|
||||
],
|
||||
|
|
|
@ -99,7 +99,10 @@ export function migrateDictionary() {
|
|||
const fixStupidOldNonsense = string => string.replace(/"/g, '"').replace(/'/g, "'").replace(/\/g, '\\').replace(/<br>/g, '\n');
|
||||
window.currentDictionary.description = fixStupidOldNonsense(window.currentDictionary.description);
|
||||
window.currentDictionary.words = window.currentDictionary.words.map(word => {
|
||||
word.longDefinition = fixStupidOldNonsense(word.longDefinition);
|
||||
word.definition = word.simpleDefinition;
|
||||
delete word.simpleDefinition;
|
||||
word.details = fixStupidOldNonsense(word.longDefinition);
|
||||
delete word.longDefinition;
|
||||
return word;
|
||||
});
|
||||
window.currentDictionary = Object.assign({}, DEFAULT_DICTIONARY, window.currentDictionary);
|
||||
|
|
|
@ -154,7 +154,7 @@ export function renderWords() {
|
|||
|
||||
// words.slice(pageStart, pageEnd).forEach(originalWord => {
|
||||
words.forEach(originalWord => {
|
||||
let detailsMarkdown = removeTags(originalWord.longDefinition);
|
||||
let detailsMarkdown = removeTags(originalWord.details);
|
||||
const references = detailsMarkdown.match(/\{\{.+?\}\}/g);
|
||||
if (references && Array.isArray(references)) {
|
||||
new Set(references).forEach(reference => {
|
||||
|
@ -170,8 +170,8 @@ export function renderWords() {
|
|||
name: removeTags(originalWord.name),
|
||||
pronunciation: removeTags(originalWord.pronunciation),
|
||||
partOfSpeech: removeTags(originalWord.partOfSpeech),
|
||||
simpleDefinition: removeTags(originalWord.simpleDefinition),
|
||||
longDefinition: detailsMarkdown,
|
||||
definition: removeTags(originalWord.definition),
|
||||
details: detailsMarkdown,
|
||||
wordId: originalWord.wordId,
|
||||
});
|
||||
wordsHTML += `<article class="entry" id="${word.wordId}">
|
||||
|
@ -186,9 +186,9 @@ export function renderWords() {
|
|||
</div>
|
||||
</header>
|
||||
<dl>
|
||||
<dt class="definition">${word.simpleDefinition}</dt>
|
||||
<dt class="definition">${word.definition}</dt>
|
||||
<dd class="details">
|
||||
${md(word.longDefinition)}
|
||||
${md(word.details)}
|
||||
</dd>
|
||||
</dl>
|
||||
</article>`;
|
||||
|
@ -261,10 +261,10 @@ export function renderEditForm(wordId = false) {
|
|||
</select>
|
||||
</label>
|
||||
<label>Definition<span class="red">*</span><br>
|
||||
<input id="wordDefinition_${wordId}" value="${word.simpleDefinition}" placeholder="Equivalent words">
|
||||
<input id="wordDefinition_${wordId}" value="${word.definition}" placeholder="Equivalent words">
|
||||
</label>
|
||||
<label>Details<span class="red">*</span><a class="label-button maximize-button">Maximize</a><br>
|
||||
<textarea id="wordDetails_${wordId}" placeholder="Markdown formatting allowed">${word.longDefinition}</textarea>
|
||||
<textarea id="wordDetails_${wordId}" placeholder="Markdown formatting allowed">${word.details}</textarea>
|
||||
</label>
|
||||
<div id="wordErrorMessage_${wordId}"></div>
|
||||
<a class="button edit-save-changes" id="editWordButton_${wordId}">Save Changes</a>
|
||||
|
|
|
@ -44,18 +44,18 @@ export function getMatchingSearchWords() {
|
|||
searchTerm = filters.caseSensitive ? searchTerm : searchTerm.toLowerCase();
|
||||
let name = filters.ignoreDiacritics ? removeDiacritics(word.name) : word.name;
|
||||
name = filters.caseSensitive ? name : name.toLowerCase();
|
||||
let simpleDefinition = filters.ignoreDiacritics ? removeDiacritics(word.simpleDefinition) : word.simpleDefinition;
|
||||
simpleDefinition = filters.caseSensitive ? simpleDefinition : simpleDefinition.toLowerCase();
|
||||
let longDefinition = filters.ignoreDiacritics ? removeDiacritics(word.longDefinition) : word.longDefinition;
|
||||
longDefinition = filters.caseSensitive ? longDefinition : longDefinition.toLowerCase();
|
||||
let definition = filters.ignoreDiacritics ? removeDiacritics(word.definition) : word.definition;
|
||||
definition = filters.caseSensitive ? definition : definition.toLowerCase();
|
||||
let details = filters.ignoreDiacritics ? removeDiacritics(word.details) : word.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 == simpleDefinition
|
||||
: new RegExp(searchTerm, 'g').test(simpleDefinition));
|
||||
const isInDetails = filters.details && new RegExp(searchTerm, 'g').test(longDefinition);
|
||||
? searchTerm == definition
|
||||
: new RegExp(searchTerm, 'g').test(definition));
|
||||
const isInDetails = filters.details && new RegExp(searchTerm, 'g').test(details);
|
||||
return searchTerm === '' || isInName || isInDefinition || isInDetails;
|
||||
});
|
||||
return matchingWords;
|
||||
|
@ -82,21 +82,21 @@ export function highlightSearchTerm(word) {
|
|||
});
|
||||
}
|
||||
if (filters.definition) {
|
||||
const simpleDefinitionMatches = getIndicesOf(searchTerm, removeDiacritics(markedUpWord.simpleDefinition), filters.caseSensitive);
|
||||
simpleDefinitionMatches.forEach((wordIndex, i) => {
|
||||
const definitionMatches = getIndicesOf(searchTerm, removeDiacritics(markedUpWord.definition), filters.caseSensitive);
|
||||
definitionMatches.forEach((wordIndex, i) => {
|
||||
wordIndex += '<mark></mark>'.length * i;
|
||||
markedUpWord.simpleDefinition = markedUpWord.simpleDefinition.substring(0, wordIndex)
|
||||
+ '<mark>' + markedUpWord.simpleDefinition.substr(wordIndex, searchTermLength) + '</mark>'
|
||||
+ markedUpWord.simpleDefinition.substr(wordIndex + searchTermLength);
|
||||
markedUpWord.definition = markedUpWord.definition.substring(0, wordIndex)
|
||||
+ '<mark>' + markedUpWord.definition.substr(wordIndex, searchTermLength) + '</mark>'
|
||||
+ markedUpWord.definition.substr(wordIndex + searchTermLength);
|
||||
});
|
||||
}
|
||||
if (filters.details) {
|
||||
const longDefinitionMatches = getIndicesOf(searchTerm, removeDiacritics(markedUpWord.longDefinition), filters.caseSensitive);
|
||||
longDefinitionMatches.forEach((wordIndex, i) => {
|
||||
const detailsMatches = getIndicesOf(searchTerm, removeDiacritics(markedUpWord.details), filters.caseSensitive);
|
||||
detailsMatches.forEach((wordIndex, i) => {
|
||||
wordIndex += '<mark></mark>'.length * i;
|
||||
markedUpWord.longDefinition = markedUpWord.longDefinition.substring(0, wordIndex)
|
||||
+ '<mark>' + markedUpWord.longDefinition.substr(wordIndex, searchTermLength) + '</mark>'
|
||||
+ markedUpWord.longDefinition.substr(wordIndex + searchTermLength);
|
||||
markedUpWord.details = markedUpWord.details.substring(0, wordIndex)
|
||||
+ '<mark>' + markedUpWord.details.substr(wordIndex, searchTermLength) + '</mark>'
|
||||
+ markedUpWord.details.substr(wordIndex + searchTermLength);
|
||||
});
|
||||
}
|
||||
} else {
|
||||
|
@ -105,10 +105,10 @@ export function highlightSearchTerm(word) {
|
|||
markedUpWord.name = markedUpWord.name.replace(new RegExp(`(${searchTerm})`, regexMethod), `<mark>$1</mark>`);
|
||||
}
|
||||
if (filters.definition) {
|
||||
markedUpWord.simpleDefinition = markedUpWord.simpleDefinition.replace(new RegExp(`(${searchTerm})`, regexMethod), `<mark>$1</mark>`);
|
||||
markedUpWord.definition = markedUpWord.definition.replace(new RegExp(`(${searchTerm})`, regexMethod), `<mark>$1</mark>`);
|
||||
}
|
||||
if (filters.details) {
|
||||
markedUpWord.longDefinition = markedUpWord.longDefinition.replace(new RegExp(`(${searchTerm})`, regexMethod), `<mark>$1</mark>`);
|
||||
markedUpWord.details = markedUpWord.details.replace(new RegExp(`(${searchTerm})`, regexMethod), `<mark>$1</mark>`);
|
||||
}
|
||||
}
|
||||
return markedUpWord;
|
||||
|
|
|
@ -156,8 +156,8 @@ function setupWordForm() {
|
|||
name: removeTags(name).trim(),
|
||||
pronunciation: removeTags(pronunciation).trim(),
|
||||
partOfSpeech: removeTags(partOfSpeech).trim(),
|
||||
simpleDefinition: removeTags(definition).trim(),
|
||||
longDefinition: removeTags(details).trim(),
|
||||
definition: removeTags(definition).trim(),
|
||||
details: removeTags(details).trim(),
|
||||
wordId: getNextId(),
|
||||
};
|
||||
|
||||
|
|
|
@ -123,8 +123,8 @@ export function generateRandomWords(numberOfWords) {
|
|||
name: word,
|
||||
pronunciation: '/' + word + '/',
|
||||
partOfSpeech: Math.random() > 0.5 ? 'Noun' : 'Verb',
|
||||
simpleDefinition: word,
|
||||
longDefinition: word + (index > 0 ? '\n\nRef: {{' + words[index - 1] + '}}' : ''),
|
||||
definition: word,
|
||||
details: word + (index > 0 ? '\n\nRef: {{' + words[index - 1] + '}}' : ''),
|
||||
wordId: getNextId(),
|
||||
}, false);
|
||||
});
|
||||
|
|
|
@ -12,7 +12,7 @@ export function validateWord(word, wordId = false) {
|
|||
if (word.name === '') {
|
||||
errorMessage += '<p class="bold red">Word field must not be blank.</p>';
|
||||
}
|
||||
if (word.simpleDefinition === '' && word.longDefinition === '') {
|
||||
if (word.definition === '' && word.details === '') {
|
||||
errorMessage += '<p class="bold red">You must enter Definition or Details.</p>';
|
||||
}
|
||||
|
||||
|
@ -32,7 +32,7 @@ export function validateWord(word, wordId = false) {
|
|||
|
||||
export function sortWords(render) {
|
||||
const { sortByDefinition } = window.currentDictionary.settings;
|
||||
const sortBy = sortByDefinition ? 'simpleDefinition' : 'name';
|
||||
const sortBy = sortByDefinition ? 'definition' : 'name';
|
||||
|
||||
window.currentDictionary.words.sort((wordA, wordB) => {
|
||||
if (removeDiacritics(wordA[sortBy]).toLowerCase() === removeDiacritics(wordB[sortBy]).toLowerCase()) return 0;
|
||||
|
@ -87,8 +87,8 @@ export function confirmEditWord() {
|
|||
name: removeTags(name).trim(),
|
||||
pronunciation: removeTags(pronunciation).trim(),
|
||||
partOfSpeech: removeTags(partOfSpeech).trim(),
|
||||
simpleDefinition: removeTags(definition).trim(),
|
||||
longDefinition: removeTags(details).trim(),
|
||||
definition: removeTags(definition).trim(),
|
||||
details: removeTags(details).trim(),
|
||||
wordId,
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue