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 {
|
footer {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
|
vertical-align: middle;
|
||||||
position:fixed;
|
position:fixed;
|
||||||
bottom: 0px;
|
bottom: 0px;
|
||||||
left: 0px;
|
left: 0px;
|
||||||
background: #aaaaaa;
|
background: #aaaaaa;
|
||||||
padding: 3px;
|
padding: 6px;
|
||||||
|
max-height: 32px; /* Update Dictionary Container's bottom margin to account for footer */
|
||||||
}
|
}
|
||||||
|
|
||||||
#leftColumn {
|
#leftColumn {
|
||||||
|
@ -69,12 +71,13 @@ input[type=checkbox] {
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
}
|
}
|
||||||
|
|
||||||
#aboutPanel {
|
#aboutButton {
|
||||||
padding: 10px;
|
display: inline;
|
||||||
|
margin: 0 10px 0 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#dictionaryContainer {
|
#dictionaryContainer {
|
||||||
margin: 15px;
|
margin: 15px 0 36px; /* bottom margin must clear footer */
|
||||||
width: 50%;
|
width: 50%;
|
||||||
min-width: 350px;
|
min-width: 350px;
|
||||||
float: left;
|
float: left;
|
||||||
|
|
29
index.html
29
index.html
|
@ -11,6 +11,9 @@
|
||||||
<!-- Markdown Parser -->
|
<!-- Markdown Parser -->
|
||||||
<script src="js/markdown-js/markdown.min.js"></script>
|
<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>
|
<script src="js/dictionaryBuilder.js"></script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
@ -48,9 +51,7 @@
|
||||||
</div>
|
</div>
|
||||||
<div id="updateConflict" style="display: none;"></div>
|
<div id="updateConflict" style="display: none;"></div>
|
||||||
</form>
|
</form>
|
||||||
<div id="aboutPanel">
|
|
||||||
<span id="aboutButton" class="clickable" onclick="ShowAbout()">About Dictionary Builder</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="dictionaryContainer">
|
<div id="dictionaryContainer">
|
||||||
|
@ -61,7 +62,19 @@
|
||||||
<span id="descriptionToggle" onclick="ToggleDescription();">Show Description</span>
|
<span id="descriptionToggle" onclick="ToggleDescription();">Show Description</span>
|
||||||
<div id="dictionaryDescription" style="display:none;"></div>
|
<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>
|
<option value="">All</option>
|
||||||
</select>
|
</select>
|
||||||
</label>
|
</label>
|
||||||
|
@ -103,6 +116,9 @@
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
<div class="settingsCol">
|
<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><button type="button" onclick="ExportDictionary()" style="cursor:pointer;">Export Current Dictionary</button></label>
|
||||||
<label>
|
<label>
|
||||||
<span>Import Dictionary</span>
|
<span>Import Dictionary</span>
|
||||||
|
@ -169,6 +185,9 @@
|
||||||
</div>
|
</div>
|
||||||
</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>
|
</body>
|
||||||
</html>
|
</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 defaultDictionaryJSON = JSON.stringify(currentDictionary); //Saves a stringifyed default dictionary.
|
||||||
|
|
||||||
|
var dictionarySearchSnapshot;
|
||||||
|
|
||||||
|
var searchResults = [];
|
||||||
|
|
||||||
var savedScroll = {
|
var savedScroll = {
|
||||||
x: 0,
|
x: 0,
|
||||||
y: 0
|
y: 0
|
||||||
|
@ -45,7 +49,7 @@ function AddWord() {
|
||||||
var updateConflictArea = document.getElementById("updateConflict");
|
var updateConflictArea = document.getElementById("updateConflict");
|
||||||
|
|
||||||
if (word != "" && (simpleDefinition != "" || longDefinition != "")) {
|
if (word != "" && (simpleDefinition != "" || longDefinition != "")) {
|
||||||
var wordIndex = WordIndex(word);
|
var wordIndex = (!currentDictionary.settings.allowDuplicates) ? WordIndex(word) : -1;
|
||||||
|
|
||||||
if (editIndex != "") {
|
if (editIndex != "") {
|
||||||
if (WordAtIndexWasChanged(editIndex, word, simpleDefinition, longDefinition, partOfSpeech)) {
|
if (WordAtIndexWasChanged(editIndex, word, simpleDefinition, longDefinition, partOfSpeech)) {
|
||||||
|
@ -195,6 +199,31 @@ function UpdateFilter() {
|
||||||
function ShowDictionary(filter) {
|
function ShowDictionary(filter) {
|
||||||
filter = (typeof filter !== 'undefined') ? 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");
|
var dictionaryNameArea = document.getElementById("dictionaryName");
|
||||||
dictionaryNameArea.innerHTML = htmlEntitiesParse(currentDictionary.name) + " Dictionary";
|
dictionaryNameArea.innerHTML = htmlEntitiesParse(currentDictionary.name) + " Dictionary";
|
||||||
|
|
||||||
|
@ -207,7 +236,9 @@ function ShowDictionary(filter) {
|
||||||
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 (filter == "" || (filter != "" && currentDictionary.words[i].partOfSpeech == filter)) {
|
||||||
dictionaryText += DictionaryEntry(i);
|
if (search == "" || (search != "" && searchResults.indexOf(currentDictionary.words[i].name) >= 0)) {
|
||||||
|
dictionaryText += DictionaryEntry(i);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -298,6 +329,7 @@ function ShowSettings() {
|
||||||
document.getElementById("dictionaryAllowDuplicates").checked = currentDictionary.settings.allowDuplicates;
|
document.getElementById("dictionaryAllowDuplicates").checked = currentDictionary.settings.allowDuplicates;
|
||||||
document.getElementById("dictionaryCaseSensitive").checked = currentDictionary.settings.caseSensitive;
|
document.getElementById("dictionaryCaseSensitive").checked = currentDictionary.settings.caseSensitive;
|
||||||
document.getElementById("dictionaryIsComplete").checked = currentDictionary.settings.isComplete;
|
document.getElementById("dictionaryIsComplete").checked = currentDictionary.settings.isComplete;
|
||||||
|
document.getElementById("numberOfWordsInDictionary").innerHTML = currentDictionary.words.length.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
function SaveSettings() {
|
function SaveSettings() {
|
||||||
|
@ -377,6 +409,9 @@ function EmptyWholeDictionary() {
|
||||||
|
|
||||||
function SaveDictionary() {
|
function SaveDictionary() {
|
||||||
localStorage.setItem('dictionary', JSON.stringify(currentDictionary));
|
localStorage.setItem('dictionary', JSON.stringify(currentDictionary));
|
||||||
|
|
||||||
|
// Update search snapshot
|
||||||
|
dictionarySearchSnapshot = Defiant.getSnapshot(currentDictionary);
|
||||||
}
|
}
|
||||||
|
|
||||||
function LoadDictionary() {
|
function LoadDictionary() {
|
||||||
|
@ -397,6 +432,9 @@ function LoadDictionary() {
|
||||||
if (currentDictionary.settings.isComplete) {
|
if (currentDictionary.settings.isComplete) {
|
||||||
document.getElementById("wordEntryForm").style.display = "none";
|
document.getElementById("wordEntryForm").style.display = "none";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Update search snapshot
|
||||||
|
dictionarySearchSnapshot = Defiant.getSnapshot(currentDictionary);
|
||||||
}
|
}
|
||||||
|
|
||||||
function ExportDictionary() {
|
function ExportDictionary() {
|
||||||
|
@ -440,13 +478,11 @@ function ImportDictionary() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function WordIndex(word) {
|
function WordIndex(word) {
|
||||||
if (!currentDictionary.settings.allowDuplicates) {
|
for (var i = 0; i < currentDictionary.words.length; i++)
|
||||||
for (var i = 0; i < currentDictionary.words.length; i++)
|
{
|
||||||
{
|
if ((!currentDictionary.settings.caseSensitive && currentDictionary.words[i].name.toLowerCase() == word.toLowerCase()) ||
|
||||||
if ((!currentDictionary.settings.caseSensitive && currentDictionary.words[i].name.toLowerCase() == word.toLowerCase()) ||
|
(currentDictionary.settings.caseSensitive && currentDictionary.words[i].name == word)) {
|
||||||
(currentDictionary.settings.caseSensitive && currentDictionary.words[i].name == word)) {
|
return i;
|
||||||
return i;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
|
|
Loading…
Reference in New Issue