From b418afafcbe58f95b1a9410f7a88e589ea6826e3 Mon Sep 17 00:00:00 2001 From: Robbie Antenesse Date: Fri, 30 Oct 2015 16:56:29 -0600 Subject: [PATCH] Conditional and case-insensitive search highlighting --- css/styles.css | 2 +- js/dictionaryBuilder.js | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/css/styles.css b/css/styles.css index 92be1f1..fe972d9 100644 --- a/css/styles.css +++ b/css/styles.css @@ -77,7 +77,7 @@ input[type=checkbox] { } #dictionaryContainer { - margin: 15px 0 36px; /* bottom margin must clear footer */ + margin: 15px 0 36px 15px; /* bottom margin must clear footer */ width: 50%; min-width: 350px; float: left; diff --git a/js/dictionaryBuilder.js b/js/dictionaryBuilder.js index 5e6f4f9..781e7be 100644 --- a/js/dictionaryBuilder.js +++ b/js/dictionaryBuilder.js @@ -269,9 +269,9 @@ function DictionaryEntry(itemIndex) { var entryText = ""; var searchTerm = htmlEntities(document.getElementById("searchBox").value); - var searchRegEx = new RegExp(searchTerm, "g"); + var searchRegEx = new RegExp(searchTerm, "gi"); - entryText += "" + ((searchTerm != "") ? currentDictionary.words[itemIndex].name.replace(searchRegEx, "" + searchTerm + "") : currentDictionary.words[itemIndex].name) + ""; + entryText += "" + ((searchTerm != "" && document.getElementById("searchOptionWord").checked) ? currentDictionary.words[itemIndex].name.replace(searchRegEx, "" + searchTerm + "") : currentDictionary.words[itemIndex].name) + ""; if (currentDictionary.words[itemIndex].partOfSpeech != "") { entryText += " " + currentDictionary.words[itemIndex].partOfSpeech + ""; @@ -280,11 +280,11 @@ function DictionaryEntry(itemIndex) { entryText += "
"; if (currentDictionary.words[itemIndex].simpleDefinition != "") { - entryText += "" + ((searchTerm != "") ? currentDictionary.words[itemIndex].simpleDefinition.replace(searchRegEx, "" + searchTerm + "") : currentDictionary.words[itemIndex].simpleDefinition) + ""; + entryText += "" + ((searchTerm != "" && document.getElementById("searchOptionSimple").checked) ? currentDictionary.words[itemIndex].simpleDefinition.replace(searchRegEx, "" + searchTerm + "") : currentDictionary.words[itemIndex].simpleDefinition) + ""; } if (currentDictionary.words[itemIndex].longDefinition != "") { - entryText += "" + ((searchTerm != "") ? markdown.toHTML(htmlEntitiesParse(currentDictionary.words[itemIndex].longDefinition)).replace(searchRegEx, "" + searchTerm + "") : markdown.toHTML(htmlEntitiesParse(currentDictionary.words[itemIndex].longDefinition))) + ""; + entryText += "" + ((searchTerm != "" && document.getElementById("searchOptionLong").checked) ? markdown.toHTML(htmlEntitiesParse(currentDictionary.words[itemIndex].longDefinition)).replace(searchRegEx, "" + searchTerm + "") : markdown.toHTML(htmlEntitiesParse(currentDictionary.words[itemIndex].longDefinition))) + ""; } if (!currentDictionary.settings.isComplete) {