Updated word filtering to allow as many parts of speech as the user wants.

This commit is contained in:
Robbie Antenesse 2016-05-26 17:37:37 -06:00
parent bdf9327fa3
commit 2a9fecae89
7 changed files with 70 additions and 36 deletions

View File

@ -1,2 +1 @@
You can now use Keyboard Shortcuts! Check About Lexiconga (Ctrl+H) to find out what they are!<br> The Filter system has been updated—you can now filter on as many parts of speech as you want!
Check the <a href="https://github.com/Alamantus/DictionaryBuilder/releases" target="_blank">update log</a> for other changes.

View File

@ -189,6 +189,12 @@ input[type=checkbox] {
cursor: pointer; cursor: pointer;
} }
.searchOption, .filterOption {
font-size:12px;
display: inline-block;
margin: 0 8px 0 0;
}
#wordFilter { #wordFilter {
margin: 10px 0; margin: 10px 0;
} }

View File

@ -104,21 +104,22 @@ require_once(SITE_LOCATION . '/php/notificationconditiontree.php');
<input type="text" id="searchBox" onclick="this.select();" onchange="ShowDictionary()" style="display:inline;" />&nbsp; <input type="text" id="searchBox" onclick="this.select();" onchange="ShowDictionary()" style="display:inline;" />&nbsp;
<span style="display:inline;cursor:pointer;font-size:10px;font-weight:bold;" onclick="document.getElementById('searchBox').value='';ShowDictionary();">Clear Search</span> <span style="display:inline;cursor:pointer;font-size:10px;font-weight:bold;" onclick="document.getElementById('searchBox').value='';ShowDictionary();">Clear Search</span>
</div> </div>
<div id="searchOptions" style="font-size:12px;"> <div id="searchOptions">
<label style="display:inline;margin:0;">Word <input type="checkbox" id="searchOptionWord" checked="checked" onchange="ShowDictionary()" /></label>&nbsp;&nbsp; <label class="searchOption">Word <input type="checkbox" id="searchOptionWord" checked="checked" onchange="ShowDictionary()" /></label>
<label style="display:inline;margin:0;">Equivalent <input type="checkbox" id="searchOptionSimple" checked="checked" onchange="ShowDictionary()" /></label>&nbsp;&nbsp; <label class="searchOption">Equivalent <input type="checkbox" id="searchOptionSimple" checked="checked" onchange="ShowDictionary()" /></label>
<label style="display:inline;margin:0;">Explanation <input type="checkbox" id="searchOptionLong" checked="checked" onchange="ShowDictionary()" /></label> <label class="searchOption">Explanation <input type="checkbox" id="searchOptionLong" checked="checked" onchange="ShowDictionary()" /></label>
<br /> <br />
<label style="display:inline;margin:0;">Search Case-Sensitive <input type="checkbox" id="searchCaseSensitive" onchange="ShowDictionary()" /></label> <label class="searchOption">Search Case-Sensitive <input type="checkbox" id="searchCaseSensitive" onchange="ShowDictionary()" /></label>
<label style="display:inline;margin:0;" title="Note: Matching diacritics will appear but may not highlight.">Ignore Diacritics/Accents <input type="checkbox" id="searchIgnoreDiacritics" onchange="ShowDictionary()" /></label> <label class="searchOption" title="Note: Matching diacritics will appear but may not highlight.">Ignore Diacritics/Accents <input type="checkbox" id="searchIgnoreDiacritics" onchange="ShowDictionary()" /></label>
</div> </div>
</label> </label>
</div> </div>
<label style="display:block;"><b>Filter Words </b><select id="wordFilter" onchange="ShowDictionary()"> <label style="display:block;margin-bottom:0;"><b>Filter Words</b></label>
<option value="">All</option> <div id="filterOptions" style="display:block"></div>
</select> <div style="display:block;">
</label> <span style="display:inline;cursor:pointer;font-size:12px;font-weight:bold;" onclick="ToggleAllFilters(true)">Check All</span>&nbsp;/&nbsp;<span style="display:inline;cursor:pointer;font-size:12px;font-weight:bold;" onclick="ToggleAllFilters(false)">Uncheck All</span>
</div>
</div> </div>
<div id="filterWordCount"></div> <div id="filterWordCount"></div>

View File

@ -152,7 +152,7 @@ function DeleteWord(index) {
} }
function ShowDictionary() { function ShowDictionary() {
var filter = document.getElementById("wordFilter").value; var filters = GetSelectedFilters();
var searchResults = []; var searchResults = [];
var search = htmlEntitiesParseForSearchEntry(document.getElementById("searchBox").value); var search = htmlEntitiesParseForSearchEntry(document.getElementById("searchBox").value);
@ -196,7 +196,7 @@ function ShowDictionary() {
if (currentDictionary.words.length > 0) { if (currentDictionary.words.length > 0) {
for (var i = 0; i < currentDictionary.words.length; i++) { for (var i = 0; i < currentDictionary.words.length; i++) {
if (filter == "" || (filter != "" && currentDictionary.words[i].partOfSpeech == filter)) { if (filters.length == 0 || (filters.length > 0 && filters.indexOf(currentDictionary.words[i].partOfSpeech) > -1)) {
if (search == "" || (search != "" && (searchByWord || searchBySimple || searchByLong) && searchResults.indexOf(currentDictionary.words[i].wordId) >= 0)) { if (search == "" || (search != "" && (searchByWord || searchBySimple || searchByLong) && searchResults.indexOf(currentDictionary.words[i].wordId) >= 0)) {
if (!currentDictionary.words[i].hasOwnProperty("pronunciation")) { if (!currentDictionary.words[i].hasOwnProperty("pronunciation")) {
currentDictionary.words[i].pronunciation = ""; //Account for new property currentDictionary.words[i].pronunciation = ""; //Account for new property

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -581,43 +581,71 @@ function TogglePublicLink() {
function SetPartsOfSpeech () { function SetPartsOfSpeech () {
var partsOfSpeechSelect = document.getElementById("partOfSpeech"); var partsOfSpeechSelect = document.getElementById("partOfSpeech");
var wordFilterSelect = document.getElementById("wordFilter");
var selectedWordFilter = wordFilterSelect.value; var wordFilterOptions = document.getElementById("filterOptions");
var selectedWordStillExists = false; var wordFiltersSelected = GetSelectedFilters();
// Clear parts of speech.
if (partsOfSpeechSelect.options.length > 0) { if (partsOfSpeechSelect.options.length > 0) {
for (var i = partsOfSpeechSelect.options.length - 1; i >= 0; i--) { for (var i = partsOfSpeechSelect.options.length - 1; i >= 0; i--) {
partsOfSpeechSelect.removeChild(partsOfSpeechSelect.options[i]); partsOfSpeechSelect.removeChild(partsOfSpeechSelect.options[i]);
wordFilterSelect.removeChild(wordFilterSelect.options[i + 1]);
} }
wordFilterOptions.innerHTML = "";
} }
// Rebuild parts of speech
var newPartsOfSpeech = htmlEntitiesParse(currentDictionary.settings.partsOfSpeech).trim().split(","); var newPartsOfSpeech = htmlEntitiesParse(currentDictionary.settings.partsOfSpeech).trim().split(",");
for (var j = 0; j < newPartsOfSpeech.length; j++) { for (var j = 0; j < newPartsOfSpeech.length; j++) {
var thePartOfSpeech = newPartsOfSpeech[j].trim();
var partOfSpeechOption = document.createElement('option'); var partOfSpeechOption = document.createElement('option');
partOfSpeechOption.appendChild(document.createTextNode(newPartsOfSpeech[j].trim())); partOfSpeechOption.appendChild(document.createTextNode(thePartOfSpeech));
partOfSpeechOption.value = newPartsOfSpeech[j].trim(); partOfSpeechOption.value = thePartOfSpeech;
partsOfSpeechSelect.appendChild(partOfSpeechOption); partsOfSpeechSelect.appendChild(partOfSpeechOption);
var wordFilterOption = document.createElement('option'); var wordFilterLabel = document.createElement('label');
wordFilterOption.appendChild(document.createTextNode(newPartsOfSpeech[j].trim())); wordFilterLabel.appendChild(document.createTextNode(thePartOfSpeech + " "));
wordFilterOption.value = newPartsOfSpeech[j].trim(); wordFilterLabel['part-of-speech'] = thePartOfSpeech;
wordFilterSelect.appendChild(wordFilterOption); wordFilterLabel.className = 'filterOption';
var wordFilterCheckbox = document.createElement('input');
if (!selectedWordStillExists && newPartsOfSpeech[j].trim() == selectedWordFilter) { wordFilterCheckbox.type = 'checkbox';
selectedWordStillExists = true; wordFilterCheckbox.onchange = function(){ShowDictionary()};
} if (wordFiltersSelected.indexOf(thePartOfSpeech) > -1) wordFilterCheckbox.checked = true;
} wordFilterLabel.appendChild(wordFilterCheckbox);
wordFilterOptions.appendChild(wordFilterLabel);
if (selectedWordStillExists) {
wordFilterSelect.value = selectedWordFilter;
} }
} }
function GetSelectedFilters() {
var wordFilterOptions = document.getElementById("filterOptions");
var wordFiltersSelected = [];
for (var i = 0; i < wordFilterOptions.children.length; i++) {
var filterOption = wordFilterOptions.children[i];
if (filterOption.children[0].checked) {
wordFiltersSelected.push(filterOption['part-of-speech']);
}
}
return wordFiltersSelected;
}
function ToggleAllFilters(doCheck) {
var wordFilterOptions = document.getElementById("filterOptions");
for (var i = 0; i < wordFilterOptions.children.length; i++) {
wordFilterOptions.children[i].children[0].checked = doCheck;
}
ShowDictionary();
}
function ShowFilterWordCount(numberOfWords) { function ShowFilterWordCount(numberOfWords) {
var filter = document.getElementById("wordFilter").value; var filters = GetSelectedFilters();
var search = htmlEntitiesParseForSearchEntry(document.getElementById("searchBox").value); var search = htmlEntitiesParseForSearchEntry(document.getElementById("searchBox").value);
var wordCounter = document.getElementById("filterWordCount"); var wordCounter = document.getElementById("filterWordCount");
if (filter != "" || search != "") { if (filters.length > 0 || search != "") {
wordCounter.innerHTML = "Showing " + numberOfWords.toString() + " result" + ((numberOfWords != 1) ? "s" : ""); wordCounter.innerHTML = "Showing " + numberOfWords.toString() + " result" + ((numberOfWords != 1) ? "s" : "");
} else { } else {
wordCounter.innerHTML = ""; wordCounter.innerHTML = "";