Compare commits

...

4 Commits

6 changed files with 80 additions and 59 deletions

View File

@ -117,6 +117,9 @@ export function renderPartsOfSpeech() {
export function renderWords() { export function renderWords() {
let wordsHTML = ''; let wordsHTML = '';
let openEditForms = getOpenEditForms();
let words = false;
if (window.currentDictionary.words.length === 0) { if (window.currentDictionary.words.length === 0) {
wordsHTML = `<article class="entry"> wordsHTML = `<article class="entry">
<header> <header>
@ -126,62 +129,71 @@ export function renderWords() {
<dt class="definition">Use the Word Form to create words or click the Help button below!</dt> <dt class="definition">Use the Word Form to create words or click the Help button below!</dt>
</dl> </dl>
</article>`; </article>`;
} } else {
words = getMatchingSearchWords();
const words = getMatchingSearchWords(); if (words.length === 0) {
wordsHTML = `<article class="entry">
<header>
<h4 class="word">No Search Results</h4>
</header>
<dl>
<dt class="definition">Edit your search or filter to show words.</dt>
</dl>
</article>`;
}
const openEditForms = getOpenEditForms(); if (openEditForms.length > 0) {
// Clone the dom nodes
if (openEditForms.length > 0) { openEditForms.forEach((wordFormId, index) => {
// Clone the dom nodes openEditForms[index] = document.getElementById(wordFormId.toString()).cloneNode(true);
openEditForms.forEach((wordFormId, index) => {
openEditForms[index] = document.getElementById(wordFormId.toString()).cloneNode(true);
});
}
// const { pageStart, pageEnd } = getPaginationData(words);
// words.slice(pageStart, pageEnd).forEach(originalWord => {
words.forEach(originalWord => {
let detailsMarkdown = removeTags(originalWord.longDefinition);
const references = detailsMarkdown.match(/\{\{.+?\}\}/g);
if (references && Array.isArray(references)) {
new Set(references).forEach(reference => {
const wordToFind = reference.replace(/\{\{|\}\}/g, '');
const existingWordId = wordExists(wordToFind, true);
if (existingWordId !== false) {
const wordMarkdownLink = `[${wordToFind}](#${existingWordId})`;
detailsMarkdown = detailsMarkdown.replace(new RegExp(reference, 'g'), wordMarkdownLink);
}
}); });
} }
const word = highlightSearchTerm({
name: removeTags(originalWord.name), // const { pageStart, pageEnd } = getPaginationData(words);
pronunciation: removeTags(originalWord.pronunciation),
partOfSpeech: removeTags(originalWord.partOfSpeech), // words.slice(pageStart, pageEnd).forEach(originalWord => {
simpleDefinition: removeTags(originalWord.simpleDefinition), words.forEach(originalWord => {
longDefinition: detailsMarkdown, let detailsMarkdown = removeTags(originalWord.longDefinition);
wordId: originalWord.wordId, const references = detailsMarkdown.match(/\{\{.+?\}\}/g);
if (references && Array.isArray(references)) {
new Set(references).forEach(reference => {
const wordToFind = reference.replace(/\{\{|\}\}/g, '');
const existingWordId = wordExists(wordToFind, true);
if (existingWordId !== false) {
const wordMarkdownLink = `[${wordToFind}](#${existingWordId})`;
detailsMarkdown = detailsMarkdown.replace(new RegExp(reference, 'g'), wordMarkdownLink);
}
});
}
const word = highlightSearchTerm({
name: removeTags(originalWord.name),
pronunciation: removeTags(originalWord.pronunciation),
partOfSpeech: removeTags(originalWord.partOfSpeech),
simpleDefinition: removeTags(originalWord.simpleDefinition),
longDefinition: detailsMarkdown,
wordId: originalWord.wordId,
});
wordsHTML += `<article class="entry" id="${word.wordId}">
<header>
<h4 class="word">${word.name}</h4>
<span class="pronunciation">${word.pronunciation}</span>
<span class="part-of-speech">${word.partOfSpeech}</span>
<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.simpleDefinition}</dt>
<dd class="details">
${md(word.longDefinition)}
</dd>
</dl>
</article>`;
}); });
wordsHTML += `<article class="entry" id="${word.wordId}"> }
<header>
<h4 class="word">${word.name}</h4>
<span class="pronunciation">${word.pronunciation}</span>
<span class="part-of-speech">${word.partOfSpeech}</span>
<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.simpleDefinition}</dt>
<dd class="details">
${md(word.longDefinition)}
</dd>
</dl>
</article>`;
});
document.getElementById('entries').innerHTML = wordsHTML; document.getElementById('entries').innerHTML = wordsHTML;
@ -200,7 +212,7 @@ export function renderWords() {
// Show Search Results // Show Search Results
const searchTerm = getSearchTerm(); const searchTerm = getSearchTerm();
const filters = getSearchFilters(); const filters = getSearchFilters();
let resultsText = searchTerm !== '' || !filters.allPartsOfSpeechChecked ? words.length.toString() + ' Results' : ''; let resultsText = searchTerm !== '' || !filters.allPartsOfSpeechChecked ? (words ? words.length : 0).toString() + ' Results' : '';
resultsText += !filters.allPartsOfSpeechChecked ? ' (Filtered)' : ''; resultsText += !filters.allPartsOfSpeechChecked ? ' (Filtered)' : '';
document.getElementById('searchResults').innerHTML = resultsText; document.getElementById('searchResults').innerHTML = resultsText;

View File

@ -36,7 +36,6 @@ export function getMatchingSearchWords() {
const matchingWords = window.currentDictionary.words.slice().filter(word => { const matchingWords = window.currentDictionary.words.slice().filter(word => {
if (!filters.allPartsOfSpeechChecked) { if (!filters.allPartsOfSpeechChecked) {
const partOfSpeech = word.partOfSpeech === '' ? 'Unclassified' : word.partOfSpeech; const partOfSpeech = word.partOfSpeech === '' ? 'Unclassified' : word.partOfSpeech;
console.log('partOfSpeech', partOfSpeech);
return filters.partsOfSpeech.hasOwnProperty(partOfSpeech) && filters.partsOfSpeech[partOfSpeech]; return filters.partsOfSpeech.hasOwnProperty(partOfSpeech) && filters.partsOfSpeech[partOfSpeech];
} }
return true; return true;

View File

@ -5,7 +5,7 @@ import { removeTags } from '../helpers';
import { getNextId } from './utilities'; import { getNextId } from './utilities';
import { openEditModal, saveEditModal, saveAndCloseEditModal } from './dictionaryManagement'; import { openEditModal, saveEditModal, saveAndCloseEditModal } from './dictionaryManagement';
import { goToNextPage, goToPreviousPage, goToPage } from './pagination'; import { goToNextPage, goToPreviousPage, goToPage } from './pagination';
import { insertAtCursor } from './StackOverflow/inputCursorManagement'; import { insertAtCursor, getInputSelection, setSelectionRange } from './StackOverflow/inputCursorManagement';
import { usePhondueDigraphs } from './KeyboardFire/phondue/ipaField'; import { usePhondueDigraphs } from './KeyboardFire/phondue/ipaField';
import { openSettingsModal, saveSettingsModal, saveAndCloseSettingsModal } from './settings'; import { openSettingsModal, saveSettingsModal, saveAndCloseSettingsModal } from './settings';
@ -341,6 +341,9 @@ export function setupMaximizeModal(modal, textBox) {
maximizedTextBox = modal.querySelector('textarea'); maximizedTextBox = modal.querySelector('textarea');
Array.from(closeElements).forEach(close => { Array.from(closeElements).forEach(close => {
close.addEventListener('click', () => { close.addEventListener('click', () => {
const selection = getInputSelection(maximizedTextBox);
textBox.focus();
setSelectionRange(textBox, selection.start, selection.end);
modal.parentElement.removeChild(modal); modal.parentElement.removeChild(modal);
}); });
}); });
@ -350,7 +353,9 @@ export function setupMaximizeModal(modal, textBox) {
}) })
setTimeout(() => { setTimeout(() => {
modal.querySelector('textarea').focus(); const selection = getInputSelection(textBox);
maximizedTextBox.focus();
setSelectionRange(maximizedTextBox, selection.start, selection.end);
}, 1); }, 1);
} }

View File

@ -23,12 +23,12 @@ main {
} }
#sideColumn { #sideColumn {
width: 28%; width: 32%;
margin: 0 1%; margin: 0 1%;
} }
#mainColumn { #mainColumn {
width: 68%; width: 64%;
margin: 0; margin: 0;
} }

View File

@ -89,8 +89,8 @@
#wordForm { #wordForm {
position: fixed; position: fixed;
top: auto; top: auto;
width: 24%; width: 31%;
max-width: 275px; max-width: 320px;
padding: 10px; padding: 10px;
background-color: $light; background-color: $light;
border: $border; border: $border;

View File

@ -1,6 +1,11 @@
@media (max-width: 750px) { @media (max-width: 750px) {
#top { #top {
#title {
font-size: 13pt;
margin-right: 10px;
}
#openSearchModal { #openSearchModal {
width: 40%; width: 40%;
} }