Add ability to search for orthographic translations
This commit is contained in:
parent
56ce6c30a6
commit
10d2159262
|
@ -1,6 +1,7 @@
|
||||||
import { cloneObject, getIndicesOf } from "../helpers";
|
import { cloneObject, getIndicesOf } from "../helpers";
|
||||||
import removeDiacritics from "./StackOverflow/removeDiacritics";
|
import removeDiacritics from "./StackOverflow/removeDiacritics";
|
||||||
import { renderWords } from "./render/words";
|
import { renderWords } from "./render/words";
|
||||||
|
import { translateOrthography, parseReferences } from "./wordManagement";
|
||||||
|
|
||||||
export function showSearchModal() {
|
export function showSearchModal() {
|
||||||
document.getElementById('searchModal').style.display = 'block';
|
document.getElementById('searchModal').style.display = 'block';
|
||||||
|
@ -22,6 +23,7 @@ export function getSearchFilters() {
|
||||||
caseSensitive: document.getElementById('searchCaseSensitive').checked,
|
caseSensitive: document.getElementById('searchCaseSensitive').checked,
|
||||||
ignoreDiacritics: document.getElementById('searchIgnoreDiacritics').checked,
|
ignoreDiacritics: document.getElementById('searchIgnoreDiacritics').checked,
|
||||||
exact: document.getElementById('searchExactWords').checked,
|
exact: document.getElementById('searchExactWords').checked,
|
||||||
|
orthography: document.getElementById('searchOrthography').checked,
|
||||||
name: document.getElementById('searchIncludeName').checked,
|
name: document.getElementById('searchIncludeName').checked,
|
||||||
definition: document.getElementById('searchIncludeDefinition').checked,
|
definition: document.getElementById('searchIncludeDefinition').checked,
|
||||||
details: document.getElementById('searchIncludeDetails').checked,
|
details: document.getElementById('searchIncludeDetails').checked,
|
||||||
|
@ -53,11 +55,13 @@ export function getMatchingSearchWords() {
|
||||||
}).filter(word => {
|
}).filter(word => {
|
||||||
searchTerm = filters.ignoreDiacritics ? removeDiacritics(searchTerm) : searchTerm;
|
searchTerm = filters.ignoreDiacritics ? removeDiacritics(searchTerm) : searchTerm;
|
||||||
searchTerm = filters.caseSensitive ? searchTerm : searchTerm.toLowerCase();
|
searchTerm = filters.caseSensitive ? searchTerm : searchTerm.toLowerCase();
|
||||||
let name = filters.ignoreDiacritics ? removeDiacritics(word.name) : word.name;
|
let name = filters.orthography ? translateOrthography(word.name) : word.name;
|
||||||
|
name = filters.ignoreDiacritics ? removeDiacritics(name) : name;
|
||||||
name = filters.caseSensitive ? name : name.toLowerCase();
|
name = filters.caseSensitive ? name : name.toLowerCase();
|
||||||
let definition = filters.ignoreDiacritics ? removeDiacritics(word.definition) : word.definition;
|
let definition = filters.ignoreDiacritics ? removeDiacritics(word.definition) : word.definition;
|
||||||
definition = filters.caseSensitive ? definition : definition.toLowerCase();
|
definition = filters.caseSensitive ? definition : definition.toLowerCase();
|
||||||
let details = filters.ignoreDiacritics ? removeDiacritics(word.details) : word.details;
|
let details = filters.orthography ? parseReferences(word.details) : word.details;
|
||||||
|
details = filters.ignoreDiacritics ? removeDiacritics(details) : details;
|
||||||
details = filters.caseSensitive ? details : details.toLowerCase();
|
details = filters.caseSensitive ? details : details.toLowerCase();
|
||||||
|
|
||||||
const isInName = filters.name && (filters.exact
|
const isInName = filters.name && (filters.exact
|
||||||
|
@ -80,6 +84,10 @@ export function highlightSearchTerm(word) {
|
||||||
if (searchTerm) {
|
if (searchTerm) {
|
||||||
const filters = getSearchFilters();
|
const filters = getSearchFilters();
|
||||||
const markedUpWord = cloneObject(word);
|
const markedUpWord = cloneObject(word);
|
||||||
|
if (filters.orthography) {
|
||||||
|
markedUpWord.name = translateOrthography(markedUpWord.name);
|
||||||
|
markedUpWord.details = parseReferences(markedUpWord.details);
|
||||||
|
}
|
||||||
if (filters.ignoreDiacritics) {
|
if (filters.ignoreDiacritics) {
|
||||||
const searchTermLength = searchTerm.length;
|
const searchTermLength = searchTerm.length;
|
||||||
searchTerm = removeDiacritics(searchTerm);
|
searchTerm = removeDiacritics(searchTerm);
|
||||||
|
|
|
@ -81,6 +81,9 @@
|
||||||
<label>Exact Words
|
<label>Exact Words
|
||||||
<input type="checkbox" id="searchExactWords">
|
<input type="checkbox" id="searchExactWords">
|
||||||
</label>
|
</label>
|
||||||
|
<label>Translations
|
||||||
|
<input type="checkbox" id="searchOrthography">
|
||||||
|
</label>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="split">
|
<div class="split">
|
||||||
|
|
Loading…
Reference in New Issue