Skip to content

Commit

Permalink
move tempAlert code to step.util.js. Alert user if they entered a sto…
Browse files Browse the repository at this point in the history
…p word for search
  • Loading branch information
patricksptang committed Oct 30, 2023
1 parent 817aa1b commit 703317b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 19 deletions.
21 changes: 3 additions & 18 deletions step-web/src/main/webapp/js/backbone/views/view_menu_passage.js
Original file line number Diff line number Diff line change
Expand Up @@ -765,21 +765,21 @@ var PassageMenuView = Backbone.View.extend({
if ((typeof lastChapter === "boolean") && (!lastChapter)) {
if ((nextChapter === "Matt.1") &&
(step.passageSelect.translationsWithPopularOTBooksChapters.indexOf(version.toLowerCase()) > -1)) {
this.tempAlert("You are at the last chapter of the " + version + ".", 3);
step.util.tempAlert("You are at the last chapter of the " + version + ".", 3);
return false;
}
this.showDots(activePassage);
}
else if (nextChapter === "Rev.22") {
this.tempAlert("You are at the last chapter of " + version + ".", 3);
step.util.tempAlert("You are at the last chapter of " + version + ".", 3);
return false;
}
}
else {
if ((previousChapter === "Gen.1") ||
((previousChapter === "Mal.4") &&
(step.passageSelect.translationsWithPopularNTBooksChapters.indexOf(version.toLowerCase()) > -1))) {
this.tempAlert("You are at the first chapter of " + version + ".", 3);
step.util.tempAlert("You are at the first chapter of " + version + ".", 3);
return false;
}
this.showDots(activePassage);
Expand Down Expand Up @@ -810,21 +810,6 @@ var PassageMenuView = Backbone.View.extend({
var randomDots = "..... .... .... ....... ... .... ... ........ .... ...<br> .... .. .... ... .... ........ .... ... .... ........<br>... ..... .. .... ..... .... ..... ........ .... ...<br>.... .. .... ... .... ........ .... ... .... ......<br> ...... .... ... ..... .... ..... ..... ..... ....<br>...... .... ... ..... .... ..... ..... ..... ... .<br> .... .. .... ... .... ........ .... ... .... ......<br>... ..... .... .... ..... .... ..... ........ .... ...<br>.... .. .... ... .... ........ .... ... .... ... ...<br> ...... .... ... ..... .... ..... ..... ..... ..<br";
$(verseElements[0]).html(randomDots + "<br>" + randomDots + "<br>" + randomDots);
},
tempAlert: function(msg, duration) {
var el = document.createElement("div");
el.setAttribute("style","text-align:center;position:absolute;top:15%;left:10%;right:10%;background-color:#ffffcc;color:black;font-size:20px;");
el.innerHTML = msg + "<div style='font-size:12px'>This message will go away in " + duration + " seconds.</div>";
setTimeout(function(){
el.innerHTML = msg + "<div style='font-size:12px'>This message will go away in " + Math.ceil(duration * .666) + " seconds.</div>";
setTimeout(function(){
el.innerHTML = msg + "<div style='font-size:12px'>This message will go away in " + Math.ceil(duration * .333) + " second.</div>";
setTimeout(function(){
el.parentNode.removeChild(el);
},duration * 333);
},duration * 333);
},duration * 333);
document.body.appendChild(el);
},
removeSearchArgs: function(args) {
return args.replace(new RegExp('\\|?' + STRONG_NUMBER + '[^|]+', "ig"), "")
.replace(new RegExp('\\|?' + SYNTAX + '[^|]+', "ig"), "")
Expand Down
7 changes: 6 additions & 1 deletion step-web/src/main/webapp/js/search_selection.js
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ step.searchSelect = {
if (userInput.replace(/\s\s+/, ' ').search(/^\s?[\da-z][a-z]+[\s.]?\d/i) > -1) step.searchSelect._handleEnteredSearchWord(null, null, true); // probably a passage
var sleep = 50;
if (step.searchSelect.searchUserInput !== userInput) {
step.searchSelect._handleEnteredSearchWord();
step.searchSelect._handleEnteredSearchWord();
sleep = 250;
}
setTimeout(function() { // Need to give time for the input to the sent to the server and also time for the response to come back to the browser.
Expand Down Expand Up @@ -1196,6 +1196,11 @@ step.searchSelect = {
}
userInput = userInput.replace(/[\n\r]/g, ' ').replace(/\t/g, ' ').replace(/\s\s/g, ' ').replace(/,,/g, ',').replace(/^\s+/g, '');
if ((userInput.length > 1) || ((step.searchSelect.userLang.toLowerCase().indexOf("zh") == 0) && (userInput.length > 0))) {
// If user enter a Lucene standard stop word, let the user know.
if (" a an and are as at be but by for if in into is it no not of on or such that the their then there these they this to was will with ".indexOf(" " + userInput.toLowerCase() + " ") > -1)
step.util.tempAlert("The word your entered is an extremely common word. That exact word will not be found in Fuzzy (meaning), Greek and Hebrew searches.", 3);
else
$('#tmpStepAlert').remove();
$('#updateButton').hide();
var url;
if ((limitType === "") && (step.searchSelect.searchOnSpecificType === ""))
Expand Down
16 changes: 16 additions & 0 deletions step-web/src/main/webapp/js/step.util.js
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,22 @@ step.util = {
if (model) {
model.trigger("squashErrors");
}
},
tempAlert: function(msg, duration) {
var el = document.createElement("div");
el.setAttribute("id","tmpStepAlert");
el.setAttribute("style","z-index:99999;text-align:center;position:absolute;top:15%;left:10%;right:10%;background-color:#ffffcc;color:black;font-size:20px;");
el.innerHTML = msg + "<div style='font-size:12px'>This message will go away in " + duration + " seconds.</div>";
setTimeout(function(){
el.innerHTML = msg + "<div style='font-size:12px'>This message will go away in " + Math.ceil(duration * .666) + " seconds.</div>";
setTimeout(function(){
el.innerHTML = msg + "<div style='font-size:12px'>This message will go away in " + Math.ceil(duration * .333) + " second.</div>";
setTimeout(function(){
el.parentNode.removeChild(el);
},duration * 333);
},duration * 333);
},duration * 333);
document.body.appendChild(el);
},
getErrorPopup: function (message, level) {
var errorPopup = $(_.template('<div class="alert alert-error fade in alert-<%= level %>" id="errorContainer">' +
Expand Down

0 comments on commit 703317b

Please sign in to comment.