dynamicbible/js/common.js
jason.wall f9dc9e5819 BUGFIXES: Fixes a variety of the remaining issues
* css formatting issues
 * upgraded to latest jquery
 * removed requirejs because of incompatibility with jquery mobile
 * multiple bug fixes relating to above
 * search now opens automatically when performing a search
2014-12-25 19:18:38 -05:00

1017 lines
37 KiB
JavaScript

var CurrentReferences = {};
function SortNumeric(x, y) {
return x - y;
}
var Util = {
HandleLink: function(e) {
Search($(e.target).text());
Settings.SaveResults();
},
HandleHiddenLink: function(e) {
Search($(e.target).find(".searchvalue").text());
Settings.SaveResults();
},
RemoveResult: function(e) {
var ref = $(e.target).parent().parent().children(".resultbody").children("h2").children("a").text();
delete CurrentReferences[ref];
$(e.target).parent().parent().remove();
Settings.SaveResults();
},
HandleError: function(e) {
// for now we're going to put the error in the main result div.
var t = $("<div class='strongsdef result'><a href='javascript:void();' class='removeresult' style='border: 0;'><img style='border: 0px;' src='images/delete.png' width='48' height='48' /></a><span class='resultbody'>" + e + "</span><br clear='all' /></div>");
$("#result").prepend(t);
t.find(".removeresult").click(function(e) {
Util.RemoveResult(e);
});
return false;
},
GetUrlVars: function() {
// Read a page's GET URL variables and return them as an associative array.
var vars = [], hash;
var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
for (var i = 0; i < hashes.length; i++)
{
hash = hashes[i].split('=');
vars.push(hash[0]);
vars[hash[0]] = hash[1];
}
return vars;
}
};
var Traverse = function(node, testament) {
try {
var treeText = "";
if (node != null) {
if (node.hasChildNodes()) {
if (node.nodeName == "s") {
// you need to test if this is the OT or NT and set the attribute accordingly.
var t = "";
if (testament == "old") {
t = "H";
}
if (testament == "new") {
t = "G";
}
treeText += "<a href='javascript:void();' class='hiddenlink' title='Strongs #: " + node.getAttribute("n") + "'><span class='searchvalue' style='display:none'>" + t + node.getAttribute("n") + "</span>" + Traverse(node.childNodes.item(0), testament) + "</a>";
} else {
treeText += '<' + node.nodeName + '>';
for (var i = 0; i < node.childNodes.length; i++) {
treeText += Traverse(node.childNodes.item(i), testament);
}
treeText += '</' + node.nodeName + '>';
}
} else {
if (node.nodeValue != null) {
if (node.nodeValue.search(/^(\,|\.|\:|\?|\;|\!)/) != -1) {
treeText += node.nodeValue;
} else {
treeText += " " + node.nodeValue;
}
}
}
}
return treeText;
}
catch (err) {
Util.HandleError(err);
}
return null;
};
var Search = function(sv) {
try {
var qs = sv.split(";");
for (var x in qs) {
var q = qs[x].trim();
if (q != "") {
// its a search term.
if (q.search(/[0-9]/i) == -1) {
// get new results.
Words.FindReferences(q);
$("#searchpanel").panel("open");
} else if (q.search(/(H|G)[0-9]/i) != -1) {
var original_q = q;
// its a strongs lookup
var dict = q.substring(0, 1);
if (dict.search(/h/i) != -1) {
dict = "heb";
} else {
dict = "grk";
}
q = q.substring(1, q.length);
var Ss = q.split(' ');
var results = [];
for (var s in Ss) {
results.push(Strongs.GetStrongs(Ss[s], dict));
}
for (var result in results) {
// display results.
//if ($("#display-strongs-as-dialog")[0].checked) {
// Strongs.DisplayStrongsDialog(results[result]);
//} else {
Strongs.DisplayStrongs(results[result]);
//}
}
CurrentReferences[original_q.toString()] = true;
} else {
// its a verse reference.
if (q.trim() != "") {
var myref = new Reference(q.trim());
var r = Bible.GetPassage(myref.book, myref.startchapter, myref.endchapter, myref.startverse, myref.endverse);
Bible.DisplayPassage(r.cs, myref, r.testament);
}
}
}
}
$("#result").sortable({
axis: "x",
handle: ".handle"
});
Settings.SaveResults();
}
catch (err) {
Util.HandleError(err);
}
//$("#searchpanel").removeClass("ui-panel-closed");
//$("#searchpanel").addClass("ui-panel-open");
//$("#searchpanel").trigger("updatelayout");
return false;
};
var Settings = {
Load: function(skipresults) {
if (typeof (Storage) !== undefined) {
// sometimes we want to load the settings, but not the results previously in the window.
if (skipresults == undefined || skipresults == false) {
if (localStorage.Panes !== undefined) {
$("#resultwrap").css("float", localStorage.Panes);
$("#searchresultswrap").css("float", localStorage.Panes);
}
}
if (localStorage.FontSize !== undefined) {
$("#result").css("font-size", localStorage.FontSize);
}
if (localStorage.Font !== undefined) {
$("#result").css("font-family", localStorage.Font);
$("#changefont").val(localStorage.Font);
}
//if (localStorage.StrongsAsDialog !== undefined && localStorage.StrongsAsDialog == "false") {
// $("#display-strongs-as-dialog")[0].checked = false;
//} else {
// $("#display-strongs-as-dialog")[0].checked = true;
//}
if (localStorage.Results !== undefined) {
$.each(
localStorage.Results.replace(/;$/, '').split(';'),
function(i, ref) {
if (ref != undefined && ref.trim() != "")
{
Search(ref);
//var myref = new Reference(ref);
//var r = Bible.GetPassage(myref.book, myref.startchapter, myref.endchapter, myref.startverse, myref.endverse);
//Bible.DisplayPassage(r.cs, myref, r.testament);
}
});
}
if (localStorage.SearchResults !== "undefined") {
$("#searchresultswrap").html(localStorage.SearchResults);
Words.AttachEvents($("#searchresultswrap"));
}
}
},
Save: function() {
if (typeof (Storage) !== "undefined")
{
localStorage.Panes = $("#resultwrap").css("float");
localStorage.Search = $("#searchresultswrap").css("display");
localStorage.FontSize = $("#result").css("font-size");
localStorage.Font = $("#result").css("font-family");
localStorage.StrongsAsDialog = $("#display-strongs-as-dialog")[0].checked;
}
},
IncreaseResultFontSize: function() {
var s = $("#result").css("font-size");
$("#result").css("font-size", parseInt(s) + 1);
this.Save();
},
DecreaseResultFontSize: function() {
var s = $("#result").css("font-size");
$("#result").css("font-size", parseInt(s) - 1);
this.Save();
},
ChangeResultFont: function(fontfamily) {
$("#result").css("font-family", fontfamily);
this.Save();
},
ChangeDisplayStrongsInDialog: function() {
this.Save();
},
SaveResults: function() {
if (typeof localStorage != 'undefined') {
var results = "";
for (var ref in CurrentReferences) {
results += ref + ';';
}
localStorage.Results = results;
localStorage.SearchResults = $("#searchresultswrap").html();
}
}
};
var Bible = {
DisplayPassage: function(cs, ref, testament) {
try {
var r = "";
for (var j = 0; j < cs.length; j++) {
if (Number(ref.startchapter) < Number(ref.endchapter)) {
r += "<b>Chapter: " + cs[j].ch + "</b><br />";
}
var vss = cs[j].vss;
for (var m = 0; m < vss.length; m++) {
var v = vss[m];
r += "<b>" + v.v + ".</b> ";
for (var w = 0; w < v.w.length; w++) {
if (v.w[w].s != undefined) {
var strongs_pre = "";
if (testament == "old") {
strongs_pre = "H";
}
if (testament == "new") {
strongs_pre = "G";
}
var sp = "";
if (v.w[w].t.substr(v.w[w].t.length - 1) == " ") {
sp = " ";
}
r += "<a href='javascript:void();' class='hiddenlink' title='Strongs #: " + v.w[w].s + "'><span class='searchvalue' style='display:none'>" + strongs_pre + v.w[w].s + "</span>" + v.w[w].t.trim() + "</a>" + sp;
} else {
r += v.w[w].t;
}
}
r += "<br />";
}
}
var t = $("<div class='passage result'><a href='javascript:void();' class='removeresult' style='border: 0;'><img style='border: 0px;' src='images/delete.png' width='48' height='48' /></a><a href='#' class='trigger left'>&nbsp;</a><div class='tags panel left'></div><span class='resultbody'>" + "<h2><a href='http://www.dynamicbible.com/?r=" + ref.toString() + "'>" + ref.toString() + "</a></h2>" + r + "</span><br clear='all' /></div>");
Bible.AttachEvents(t, ref);
$("#result").prepend(t);
CurrentReferences[ref.toString()] = true;
}
catch (err) {
Util.HandleError(err);
}
},
GetPassage: function(b, sch, ech, sv, ev) {
try {
var chapters = []; // the verses from the chapter.
var cs = []; // the verses requested.
var r = {};
for (var i = sch; i <= ech; i++) {
var url = "bibles/kjv_strongs/" + b + "-" + i + ".json";
$.ajax({
async: false,
type: "GET",
url: url,
dataType: "json",
success: function(d, t, x) {
chapters.push(d);
},
error: function(request, status, error) {
Util.HandleError(error, request);
}
});
}
for (var j = 0; j < chapters.length; j++) {
var vss = [];
var start;
var end;
// figure out the start verse.
if (j == 0) {
start = sv;
} else {
start = 1;
}
// figure out the end verse
if ((j + 1) == chapters.length) {
end = ev;
} else {
end = "*";
}
// get the verses requested.
var tvs = chapters[j].vss.length;
if (end == "*" || end > tvs) {
end = tvs;
}
for (i = start; i <= end; i++) {
// we're using c based indexes here, so the index is 1 less than the verse #.
vss.push(chapters[j].vss[i - 1]);
}
cs.push({
"ch": chapters[j].ch,
"vss": vss
});
}
r.cs = cs;
if (b >= 40) {
r.testament = "new";
} else {
r.testament = "old";
}
return r;
} catch (err) {
Util.HandleError(err);
}
return null;
},
AttachEvents: function(t, ref) {
t.find(".hiddenlink").click(function(e) {
Util.HandleHiddenLink(e);
});
t.find(".removeresult").click(function(e) {
Util.RemoveResult(e, ref);
});
// TODO(jwall): support longtouch events on mobile?
t.find(".resultbody h2").tooltip({
items: ".resultbody h2",
content: function(tt) {
}});
t.find('.btn-addtag').click(function(e) {
var tags = $(e.target).parent().find(".input-addtag").val().split(', ');
// TODO(jwall): add tags.
tagging.UpdateTags(
ref, tags, {success: function(req) {
console.log("Updated Reference");
}
});
});
t.find('.trigger').slidePanel({
triggerCss: 'margin-top: 60px; display: block; width: 48px; height: 48px;',
panelCss: 'margin-top: 55px; border: 2px solid #666;'
});
}
};
var Strongs = {
GetStrongs: function(sn, dict) {
try {
var self = this;
var results = {};
var url = dict + parseInt((sn - 1) / 100) + ".xml";
if (dict == "grk") {
results.prefix = "G";
} else {
results.prefix = "H";
}
results.sn = sn;
$.ajax({
async: false,
type: "GET",
url: "xml/" + url,
dataType: "xml",
success: function(d, t, x) {
results.strongs = d;
},
error: function(request, status, error) {
Util.HandleError(error, request);
}
});
$.ajax({
async: false,
type: "GET",
url: "xml/cr" + url,
dataType: "xml",
success: function(d, t, x) {
results.crossrefs = d;
},
error: function(request, status, error) {
Util.HandleError(error, request);
}
});
if (dict == "grk") {
url = "xml/rs" + parseInt((sn - 1) / 1000) + ".xml";
// rmac is a two get process.
$.ajax({
async: false,
type: "GET",
url: url,
dataType: "xml",
success: function(d, t, x) {
results.rmac = d;
},
error: function(request, status, error) {
Util.HandleError(error, request);
}
});
// deal with RMAC
results.rmaccode = $(results.rmac).find('s[id="' + sn + '"]').attr("r");
url = "xml/r-" + results.rmaccode.substring(0, 1) + ".xml";
$.ajax({
async: false,
type: "GET",
url: url,
dataType: "xml",
success: function(d, t, x) {
results.rmac = d;
},
error: function(request, status, error) {
Util.HandleError(error, request);
}
});
}
return results;
} catch (err) {
Util.HandleError(err);
}
return null;
},
BuildStrongs: function(r) {
try {
// first deal with strongs data.
var entry = $(r.strongs).find("i#" + r.prefix + r.sn);
var title = $(entry).find("t").text();
var trans = $(entry).find("tr").text();
var pron = $(entry).find("p").text();
var desc = Traverse($(entry).find("d")[0]);
var re = /([hg][0-9]{1,4})/gi;
desc = desc.replace(re, "<a href='javascript:void();' class='link'>$1</a>");
// now deal with cross references.
var cr = $(r.crossrefs).find("i#" + r.prefix + r.sn).find("rs");
var crtxt = "<div class='scr'><b>Cross References:</b> <a href='javascript:void()' class='showhide'>Show</a><br /><span class='contents'>";
cr.each(function(i) {
crtxt += "<b>" + $(this).find("t").text() + ":</b> ";
$(this).find("r").each(function(j) {
var ref = $(this).attr("r").split(";");
crtxt += "<a href='javascript:void();' class='link'>" + BookName(ref[0]) + " " + ref[1] + ":" + ref[2] + "</a>, ";
});
crtxt = crtxt.substr(0, crtxt.length - 2);
crtxt += "<br />";
});
crtxt += "</span></div>";
// ...processing statements go here...
var rtxt = "";
if (r.prefix == "G") {
rtxt += "<div class='rmac'><b>Robinsons Morphological Analysis Code: " + r.rmaccode + "</b> <a href='javascript:void()' class='showhide'>Show</a><br /><span class='contents'>";
;
$(r.rmac).find('i[id="' + r.rmaccode.toUpperCase() + '"]').find("d").each(function() {
rtxt += $(this).text() + "<br />";
});
rtxt += "</span></div>";
}
// put together the display.
// ok. we have to do this because click events seem to be cumulative with jquery.
var t = $("<div class='strongsdef result'><a href='javascript:void();' class='removeresult' style='border: 0;'><img style='border: 0px;' src='images/delete.png' width='48' height='48' /></a><span class='resultbody'><b>" + trans + " (" + r.sn + ")</b> - " + pron + " - " + title + " - " + desc + "<br />" + rtxt + crtxt + "</span><br clear='all' /></div>");
t.find(".link").click(function(e) {
Util.HandleLink(e);
});
t.find(".removeresult").click(function(e) {
Util.RemoveResult(e);
});
t.find(".showhide").click(function(e) {
Strongs.ShowHide(e);
});
return t;
} catch (err) {
Util.HandleError(err);
}
return null;
},
DisplayStrongs: function(r) {
try {
var t = Strongs.BuildStrongs(r);
$("#result").prepend(t);
return false;
} catch (err) {
Util.HandleError(err);
}
return null;
},
DisplayStrongsDialog: function(r) {
try {
var t = Strongs.BuildStrongs(r);
var d = $("<div></div>").append(t);
d.dialog({
draggable: true,
width: 600,
height: 500,
resizable: true,
title: "Strongs Definition",
buttons: {
"Close": function() {
$(this).dialog("close");
}
}
});
return false;
} catch (err) {
Util.HandleError(err);
}
return null;
},
ShowHide: function(e) {
var o = $(e.target);
var c = o.parent().find(".contents");
if (c.css("display") != "none") {
c.css("display", "none");
o.html("Show");
} else {
c.css("display", "inline");
o.html("Hide");
}
}
};
var Words = {
ConvertResultsToArray: function(r) {
try {
var results = new Array();
$(r).each(function() {
results.push([$(this).attr("b"), $(this).attr("ch"), $(this).attr("v")]);
});
return results;
} catch (err) {
Util.HandleError(err);
}
return null;
},
DisplayResults: function(results, q) {
try {
var txt = "<h4>Query: <a href='javascript:void();' class='link'>" + q + "</a></h4><ul>";
for (var i = 0; i < results.length; i++) {
var r = results[i].split(":");
txt += "<li /><a href='javascript:void();' class='link' alt='" + BookName(r[0]) + " " + r[1] + ":" + r[2] + "'>" + BookName(r[0]) + " " + r[1] + ":" + r[2] + "</a>";
}
txt += "</ul>";
var t = $(txt);
Words.AttachEvents(t);
$("#searchresults").html(t);
$("#searchTotal").html(results.length);
return false;
} catch (err) {
Util.HandleError(err);
}
return null;
},
FindReferences: function(qry) {
try {
qry = qry.toLowerCase();
var qs = qry.split(" ");
var words = this.BuildIndexArray().sort();
var results = new Array();
// Loop through each query term.
for (i = 0; i < qs.length; i++) {
var q = qs[i].replace("'", ""); // we don't included ticks in our words.
// For each query term, figure out which xml file it is in, and get it.
// getSearchRefs returns an array of references.
for (var w = 0; w < words.length; w++) {
// If we are at the end of the array, we want to use a different test.
if (w == 0) {
if (q <= words[w]) {
results.unshift(this.GetSearchReferences("index/" + words[w] + "idx.json", q));
break;
}
} else {
if (q <= words[w] && q > words[w - 1]) {
results.unshift(this.GetSearchReferences("index/" + words[w] + "idx.json", q));
break;
}
}
}
} // End of loop through query terms
// Now we need to test results. If there is more than one item in the array, we need to find the set
// that is shared by all of them. IF not, we can just return those refs.
if (results.length == 1) {
this.DisplayResults(results[0], qry);
} else {
var shared = this.FindSharedSet(results);
if (shared == null) {
shared = [];
}
this.DisplayResults(shared, qry);
}
return false;
} catch (err) {
Util.HandleError(err);
}
return null;
},
GetSearchReferences: function(url, query) {
try {
// getSearchRefs takes a url and uses ajax to retrieve the references and returns an array of references.
var r;
$.ajax({
async: false,
type: "GET",
url: url,
dataType: "json",
success: function(d, t, x) {
r = d;
},
error: function(request, status, error) {
Util.HandleError(error, request);
}
});
// find the right word
var refs = $.grep(r, function(o, i) {
return o.word == query;
});
if (refs.length > 0) {
return refs[0].refs;
} else {
return null;
}
} catch (err) {
Util.HandleError(err);
}
return null;
},
BuildIndexArray: function() {
var words = new Array();
words.unshift('abiram');
words.unshift('accepteth');
words.unshift('acquit');
words.unshift('adna');
words.unshift('affecteth');
words.unshift('aharhel');
words.unshift('aijeleth');
words.unshift('almug');
words.unshift('amiable');
words.unshift('ancients');
words.unshift('anything');
words.unshift('appointeth');
words.unshift('areopagus');
words.unshift('art');
words.unshift('ashteroth');
words.unshift('astaroth');
words.unshift('availeth');
words.unshift('azotus');
words.unshift('badness');
words.unshift('baptizing');
words.unshift('bat');
words.unshift('bechorath');
words.unshift('beguile');
words.unshift('bemoaning');
words.unshift('beside');
words.unshift('bezek');
words.unshift('bitterly');
words.unshift('bloodthirsty');
words.unshift('bolted');
words.unshift('bountifulness');
words.unshift('breastplates');
words.unshift('broth');
words.unshift('bunni');
words.unshift('cain');
words.unshift('cankered');
words.unshift('carry');
words.unshift('celebrate');
words.unshift('chapel');
words.unshift('cheese');
words.unshift('chilmad');
words.unshift('circumcision');
words.unshift('closer');
words.unshift('come');
words.unshift('communication');
words.unshift('concerning');
words.unshift('confusion');
words.unshift('consummation');
words.unshift('convince');
words.unshift('couch');
words.unshift('covers');
words.unshift('crisping');
words.unshift('curse');
words.unshift('damnable');
words.unshift('deacons');
words.unshift('decision');
words.unshift('defileth');
words.unshift('depart');
words.unshift('despisest');
words.unshift('diblathaim');
words.unshift('directly');
words.unshift('dishonesty');
words.unshift('distracted');
words.unshift('dominion');
words.unshift('dreamer');
words.unshift('dulcimer');
words.unshift('eastward');
words.unshift('eighteenth');
words.unshift('elihoreph');
words.unshift('embrace');
words.unshift('endeavored');
words.unshift('ensign');
words.unshift('ephraim');
words.unshift('eshtemoa');
words.unshift('evening');
words.unshift('excellest');
words.unshift('extended');
words.unshift('fairer');
words.unshift('fastings');
words.unshift('feign');
words.unshift('fight');
words.unshift('fishermen');
words.unshift('flint');
words.unshift('foolishness');
words.unshift('forever');
words.unshift('forts');
words.unshift('fresh');
words.unshift('furnish');
words.unshift('gallio');
words.unshift('gebal');
words.unshift('gezrites');
words.unshift('girt');
words.unshift('goath');
words.unshift('government');
words.unshift('greeteth');
words.unshift('guiltless');
words.unshift('haggai');
words.unshift('hamstrung');
words.unshift('happy');
words.unshift('harum');
words.unshift('hattush');
words.unshift('heard');
words.unshift('heir');
words.unshift('herbs');
words.unshift('hezronites');
words.unshift('hivite');
words.unshift('honored');
words.unshift('hostages');
words.unshift('huntest');
words.unshift('idalah');
words.unshift('impenitent');
words.unshift('inferior');
words.unshift('insomuch');
words.unshift('ira');
words.unshift('isuah');
words.unshift('jabneh');
words.unshift('japhia');
words.unshift('jeduthun');
words.unshift('jerahmeelites');
words.unshift('jew');
words.unshift('joined');
words.unshift('joy');
words.unshift('kadmonites');
words.unshift('kid');
words.unshift('kneaded');
words.unshift('lack');
words.unshift('languish');
words.unshift('lazarus');
words.unshift('legions');
words.unshift('libnath');
words.unshift('likhi');
words.unshift('lock');
words.unshift('louder');
words.unshift('lysias');
words.unshift('magpiash');
words.unshift('malchus');
words.unshift('marble');
words.unshift('mastery');
words.unshift('meddle');
words.unshift('members');
words.unshift('mesech');
words.unshift('midian');
words.unshift('ministered');
words.unshift('mithnite');
words.unshift('morasthite');
words.unshift('mower');
words.unshift('myrtle');
words.unshift('naphish');
words.unshift('necks');
words.unshift('net');
words.unshift('noadiah');
words.unshift('nursed');
words.unshift('occurrent');
words.unshift('omnipotent');
words.unshift('orchard');
words.unshift('outside');
words.unshift('owed');
words.unshift('palti');
words.unshift('partition');
words.unshift('paulus');
words.unshift('peoples');
words.unshift('persecute');
words.unshift('phares');
words.unshift('pilate');
words.unshift('plagues');
words.unshift('plentiful');
words.unshift('poorer');
words.unshift('powerful');
words.unshift('presented');
words.unshift('prison');
words.unshift('promoted');
words.unshift('provision');
words.unshift('purely');
words.unshift('quarter');
words.unshift('rahab');
words.unshift('ravening');
words.unshift('rebuking');
words.unshift('refined');
words.unshift('release');
words.unshift('rent');
words.unshift('requirest');
words.unshift('return');
words.unshift('rezon');
words.unshift('riseth');
words.unshift('roof');
words.unshift('rump');
words.unshift('sail');
words.unshift('sanctuaries');
words.unshift('savors');
words.unshift('scorpions');
words.unshift('second');
words.unshift('sellers');
words.unshift('served');
words.unshift('shaft');
words.unshift('sharaim');
words.unshift('shedder');
words.unshift('shepho');
words.unshift('shimshai');
words.unshift('shophan');
words.unshift('shuppim');
words.unshift('sihor');
words.unshift('sippai');
words.unshift('slandereth');
words.unshift('smelling');
words.unshift('softer');
words.unshift('sores');
words.unshift('sparrows');
words.unshift('spoil');
words.unshift('staff');
words.unshift('steel');
words.unshift('stool');
words.unshift('stretched');
words.unshift('stumblingblocks');
words.unshift('suffice');
words.unshift('surnamed');
words.unshift('swore');
words.unshift('take');
words.unshift('task');
words.unshift('temani');
words.unshift('testator');
words.unshift('thessalonica');
words.unshift('threatening');
words.unshift('tie');
words.unshift('titus');
words.unshift('torments');
words.unshift('translation');
words.unshift('tributaries');
words.unshift('tubal');
words.unshift('unchangeable');
words.unshift('unlawful');
words.unshift('upbraideth');
words.unshift('uzza');
words.unshift('verily');
words.unshift('visage');
words.unshift('walk');
words.unshift('washing');
words.unshift('wayside');
words.unshift('wellspring');
words.unshift('whisperer');
words.unshift('win');
words.unshift('withereth');
words.unshift('work');
words.unshift('wrest');
words.unshift('yours');
words.unshift('zealously');
words.unshift('zetham');
words.unshift('zophim');
words.unshift('zuzims');
return words;
},
FindSharedSet: function(results) {
try {
// FindSharedSet takes an array of reference arrays, and figures out which references are shared
// by all arrays/sets, then returns a single array of references.
for (var j in results) {
var refs = results[j];
if (refs != null) {
for (var i = 0; i < refs.length; i++) {
var r = refs[i].split(":");
// convert references to single integers.
// Book * 100000, Chapter * 1000, Verse remains same, add all together.
var ref = parseInt(r[0]) * 100000000;
ref = ref + parseInt(r[1]) * 10000;
ref = ref + parseInt(r[2]);
results[j][i] = ref;
}
} else {
return null;
}
}
// get the first result
var result = results[0];
// for each additional result, get the shared set
for (i = 1; i < results.length; i++) {
result = this.ReturnSharedSet(results[i], result);
}
// convert the references back into book, chapter and verse.
for (i = 0; i < result.length; i++) {
ref = result[i];
result[i] = parseInt(ref / 100000000) + ":" + parseInt((ref % 100000000) / 10000) + ":" + ((ref % 100000000) % 10000);
}
return result;
} catch (err) {
Util.HandleError(err);
}
return null;
},
ReturnSharedSet: function(x, y) {
try {
/// <summary>
/// Takes two javascript arrays and returns an array
/// containing a set of values shared by arrays.
/// </summary>
// declare iterator
var i = 0;
// declare terminator
var t = (x.length < y.length) ? x.length : y.length;
// sort the arrays
x.sort(SortNumeric);
y.sort(SortNumeric);
// in this loop, we remove from the arrays, the
// values that aren't shared between them.
while (i < t) {
if (x[i] == y[i]) {
i++;
}
if (x[i] < y[i]) {
x.splice(i, 1);
}
if (x[i] > y[i]) {
y.splice(i, 1);
}
t = (x.length < y.length) ? x.length : y.length;
// we have to make sure to remove any extra values
// at the end of an array when we reach the end of
// the other.
if (t == i && t < x.length) {
x.splice(i, x.length - i);
}
if (t == i && t < y.length) {
y.splice(i, x.length - i);
}
}
// we could return y, because at this time, both arrays
// are identical.
return x;
} catch (err) {
Util.HandleError(err);
}
return null;
},
AttachEvents: function(t) {
t.find(".link").click(function(e) {
Util.HandleLink(e);
});
}
};