Added Search through Defiant.js
Altered when Allow Duplicates is considered Added Entry Count in settings screen.
This commit is contained in:
parent
d8b3ab00c5
commit
8f6a3e3a99
|
@ -8,11 +8,13 @@
|
|||
footer {
|
||||
width: 100%;
|
||||
text-align: center;
|
||||
vertical-align: middle;
|
||||
position:fixed;
|
||||
bottom: 0px;
|
||||
left: 0px;
|
||||
background: #aaaaaa;
|
||||
padding: 3px;
|
||||
padding: 6px;
|
||||
max-height: 32px; /* Update Dictionary Container's bottom margin to account for footer */
|
||||
}
|
||||
|
||||
#leftColumn {
|
||||
|
@ -69,12 +71,13 @@ input[type=checkbox] {
|
|||
font-weight: bold;
|
||||
}
|
||||
|
||||
#aboutPanel {
|
||||
padding: 10px;
|
||||
#aboutButton {
|
||||
display: inline;
|
||||
margin: 0 10px 0 0;
|
||||
}
|
||||
|
||||
#dictionaryContainer {
|
||||
margin: 15px;
|
||||
margin: 15px 0 36px; /* bottom margin must clear footer */
|
||||
width: 50%;
|
||||
min-width: 350px;
|
||||
float: left;
|
||||
|
|
29
index.html
29
index.html
|
@ -11,6 +11,9 @@
|
|||
<!-- Markdown Parser -->
|
||||
<script src="js/markdown-js/markdown.min.js"></script>
|
||||
|
||||
<!-- JSON Search -->
|
||||
<script src="js/defiant-js/defiant-latest.min.js"></script>
|
||||
|
||||
<script src="js/dictionaryBuilder.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
|
@ -48,9 +51,7 @@
|
|||
</div>
|
||||
<div id="updateConflict" style="display: none;"></div>
|
||||
</form>
|
||||
<div id="aboutPanel">
|
||||
<span id="aboutButton" class="clickable" onclick="ShowAbout()">About Dictionary Builder</span>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div id="dictionaryContainer">
|
||||
|
@ -61,7 +62,19 @@
|
|||
<span id="descriptionToggle" onclick="ToggleDescription();">Show Description</span>
|
||||
<div id="dictionaryDescription" style="display:none;"></div>
|
||||
|
||||
<label><b>Filter Words </b><select id="wordFilter" onchange="UpdateFilter()">
|
||||
<div id="searchArea" style="display:block;">
|
||||
<label style="margin-top:10px;">
|
||||
<span>Search</span>
|
||||
<input type="text" id="searchBox" onclick="this.select();" onchange="UpdateFilter()" style="display:block;" />
|
||||
<div id="searchOptions" style="font-size:12px;">
|
||||
<label style="display:inline;margin:0;">Word <input type="checkbox" id="searchOptionWord" checked="checked" /></label>
|
||||
<label style="display:inline;margin:0;">Equivalent <input type="checkbox" id="searchOptionSimple" checked="checked" /></label>
|
||||
<label style="display:inline;margin:0;">Explanation <input type="checkbox" id="searchOptionLong" checked="checked" /></label>
|
||||
</div>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<label style="display:block;"><b>Filter Words </b><select id="wordFilter" onchange="UpdateFilter()">
|
||||
<option value="">All</option>
|
||||
</select>
|
||||
</label>
|
||||
|
@ -103,6 +116,9 @@
|
|||
</label>
|
||||
</div>
|
||||
<div class="settingsCol">
|
||||
<label>
|
||||
<b>Total Entries:</b> <i id="numberOfWordsInDictionary"></i>
|
||||
</label>
|
||||
<label><button type="button" onclick="ExportDictionary()" style="cursor:pointer;">Export Current Dictionary</button></label>
|
||||
<label>
|
||||
<span>Import Dictionary</span>
|
||||
|
@ -169,6 +185,9 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<footer>Version <script>document.write(currentVersion);</script>. Dictionary Builder only guaranteed to work with most up-to-date HTML5 browsers.</footer>
|
||||
<footer>
|
||||
<span id="aboutButton" class="clickable" onclick="ShowAbout()">About Dictionary Builder</span>
|
||||
Version <script>document.write(currentVersion);</script>. Dictionary Builder only guaranteed to work with most up-to-date HTML5 browsers.
|
||||
</footer>
|
||||
</body>
|
||||
</html>
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -16,6 +16,10 @@ var currentDictionary = {
|
|||
|
||||
var defaultDictionaryJSON = JSON.stringify(currentDictionary); //Saves a stringifyed default dictionary.
|
||||
|
||||
var dictionarySearchSnapshot;
|
||||
|
||||
var searchResults = [];
|
||||
|
||||
var savedScroll = {
|
||||
x: 0,
|
||||
y: 0
|
||||
|
@ -45,7 +49,7 @@ function AddWord() {
|
|||
var updateConflictArea = document.getElementById("updateConflict");
|
||||
|
||||
if (word != "" && (simpleDefinition != "" || longDefinition != "")) {
|
||||
var wordIndex = WordIndex(word);
|
||||
var wordIndex = (!currentDictionary.settings.allowDuplicates) ? WordIndex(word) : -1;
|
||||
|
||||
if (editIndex != "") {
|
||||
if (WordAtIndexWasChanged(editIndex, word, simpleDefinition, longDefinition, partOfSpeech)) {
|
||||
|
@ -195,6 +199,31 @@ function UpdateFilter() {
|
|||
function ShowDictionary(filter) {
|
||||
filter = (typeof filter !== 'undefined') ? filter : "";
|
||||
|
||||
searchResults = [];
|
||||
var search = document.getElementById("searchBox").value;
|
||||
if (search != "") {
|
||||
if (document.getElementById("searchOptionWord").checked) {
|
||||
var wordSearch = JSON.search(dictionarySearchSnapshot, '//words[contains(name, "' + search + '")]/name');
|
||||
searchResults.push(wordSearch);
|
||||
}
|
||||
if (document.getElementById("searchOptionSimple").checked) {
|
||||
var simpleDefinitionSearch = JSON.search(dictionarySearchSnapshot, '//words[contains(simpleDefinition, "' + search + '")]/name');
|
||||
for (var i = 0; i < simpleDefinitionSearch.length; i++) {
|
||||
if (searchResults.indexOf(simpleDefinitionSearch[i]) < 0) {
|
||||
searchResults.push(simpleDefinitionSearch[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (document.getElementById("searchOptionLong").checked) {
|
||||
var longDefinitionSearch = JSON.search(dictionarySearchSnapshot, '//words[contains(longDefinition, "' + search + '")]/name');
|
||||
for (var i = 0; i < longDefinitionSearch.length; i++) {
|
||||
if (searchResults.indexOf(longDefinitionSearch[i]) < 0) {
|
||||
searchResults.push(longDefinitionSearch[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var dictionaryNameArea = document.getElementById("dictionaryName");
|
||||
dictionaryNameArea.innerHTML = htmlEntitiesParse(currentDictionary.name) + " Dictionary";
|
||||
|
||||
|
@ -207,9 +236,11 @@ function ShowDictionary(filter) {
|
|||
if (currentDictionary.words.length > 0) {
|
||||
for (var i = 0; i < currentDictionary.words.length; i++) {
|
||||
if (filter == "" || (filter != "" && currentDictionary.words[i].partOfSpeech == filter)) {
|
||||
if (search == "" || (search != "" && searchResults.indexOf(currentDictionary.words[i].name) >= 0)) {
|
||||
dictionaryText += DictionaryEntry(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
dictionaryText = "There are no entries in the dictionary."
|
||||
}
|
||||
|
@ -298,6 +329,7 @@ function ShowSettings() {
|
|||
document.getElementById("dictionaryAllowDuplicates").checked = currentDictionary.settings.allowDuplicates;
|
||||
document.getElementById("dictionaryCaseSensitive").checked = currentDictionary.settings.caseSensitive;
|
||||
document.getElementById("dictionaryIsComplete").checked = currentDictionary.settings.isComplete;
|
||||
document.getElementById("numberOfWordsInDictionary").innerHTML = currentDictionary.words.length.toString();
|
||||
}
|
||||
|
||||
function SaveSettings() {
|
||||
|
@ -377,6 +409,9 @@ function EmptyWholeDictionary() {
|
|||
|
||||
function SaveDictionary() {
|
||||
localStorage.setItem('dictionary', JSON.stringify(currentDictionary));
|
||||
|
||||
// Update search snapshot
|
||||
dictionarySearchSnapshot = Defiant.getSnapshot(currentDictionary);
|
||||
}
|
||||
|
||||
function LoadDictionary() {
|
||||
|
@ -397,6 +432,9 @@ function LoadDictionary() {
|
|||
if (currentDictionary.settings.isComplete) {
|
||||
document.getElementById("wordEntryForm").style.display = "none";
|
||||
}
|
||||
|
||||
// Update search snapshot
|
||||
dictionarySearchSnapshot = Defiant.getSnapshot(currentDictionary);
|
||||
}
|
||||
|
||||
function ExportDictionary() {
|
||||
|
@ -440,7 +478,6 @@ function ImportDictionary() {
|
|||
}
|
||||
|
||||
function WordIndex(word) {
|
||||
if (!currentDictionary.settings.allowDuplicates) {
|
||||
for (var i = 0; i < currentDictionary.words.length; i++)
|
||||
{
|
||||
if ((!currentDictionary.settings.caseSensitive && currentDictionary.words[i].name.toLowerCase() == word.toLowerCase()) ||
|
||||
|
@ -448,7 +485,6 @@ function WordIndex(word) {
|
|||
return i;
|
||||
}
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue