This commit is contained in:
walljm 2013-04-15 14:31:44 -04:00
commit 0ad2f1bf41
4 changed files with 924 additions and 1248 deletions

View File

@ -1,7 +1,7 @@
// // This code was written by Jeremy and Jason Wall.
// This code was written by Jason Wall. Feel free to use, and if you can, include a link back to www.walljm.com // Feel free to use, and if you can, include a link back to www.walljm.com
// Jason@walljm.com // www.walljm.com // Jason@walljm.com // www.walljm.com
// // Jeremy@marzhillstudios.com // jeremy.marzhillstudios.com
String.prototype.trim = function() { String.prototype.trim = function() {
return this.replace(/^\s+|\s+$/g, ""); return this.replace(/^\s+|\s+$/g, "");
@ -645,3 +645,14 @@ function bookName(booknum) {
return book[booknum]; return book[booknum];
} }
Reference.prototype.toString = function() {
var ref = this.bookname.concat(" ").
concat(this.startchapter).concat(":").
concat(this.startverse);
if (this.startchapter == this.endchapter) {
return ref.concat("-").concat(this.endverse);
}
return ref.concat("-").concat(this.endchapter)
.concat(":").concat(this.endverse);
};

View File

@ -1,61 +1,46 @@
function SortNumeric(x, y) function SortNumeric(x, y) {
{ return x - y;
return x - y
} }
String.prototype.trim = function() String.prototype.trim = function() {
{
return this.replace(/^\s+|\s+$/g, ""); return this.replace(/^\s+|\s+$/g, "");
} };
String.prototype.ltrim = function()
{
return this.replace(/^\s+/, "");
}
String.prototype.rtrim = function()
{
return this.replace(/\s+$/, "");
}
function Traverse(node, testament) String.prototype.ltrim = function() {
{ return this.replace(/^\s+/, "");
try };
{
String.prototype.rtrim = function() {
return this.replace(/\s+$/, "");
};
function Traverse(node, testament) {
try {
var treeText = ""; var treeText = "";
if (node != null) if (node != null) {
{ if (node.hasChildNodes()) {
if (node.hasChildNodes()) if (node.nodeName == "s") {
{
if (node.nodeName == "s")
{
// you need to test if this is the OT or NT and set the attribute accordingly. // you need to test if this is the OT or NT and set the attribute accordingly.
var t = ""; var t = "";
if (testament == "old") if (testament == "old") {
{
t = "H"; t = "H";
} }
if (testament == "new") if (testament == "new") {
{
t = "G"; 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>"; 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 } else {
{
treeText += '<' + node.nodeName + '>'; treeText += '<' + node.nodeName + '>';
for (var i = 0; i < node.childNodes.length; i++) for (var i = 0; i < node.childNodes.length; i++) {
{
treeText += Traverse(node.childNodes.item(i), testament); treeText += Traverse(node.childNodes.item(i), testament);
} }
treeText += '</' + node.nodeName + '>'; treeText += '</' + node.nodeName + '>';
} }
} else } else {
{ if (node.nodeValue != null) {
if (node.nodeValue != null) if (node.nodeValue.search(/^(\,|\.|\:|\?|\;|\!)/) != -1) {
{
if (node.nodeValue.search(/^(\,|\.|\:|\?|\;|\!)/) != -1)
{
treeText += node.nodeValue; treeText += node.nodeValue;
} else } else {
{
treeText += " " + node.nodeValue; treeText += " " + node.nodeValue;
} }
} }
@ -63,33 +48,25 @@ function Traverse(node, testament)
} }
return treeText; return treeText;
} }
catch (err) catch (err) {
{
Util.HandleError(err); Util.HandleError(err);
} }
return null;
} }
function Search(sv) function Search(sv) {
{ try {
try
{
var qs = sv.split(";"); var qs = sv.split(";");
for (var x in qs) for (var x in qs) {
{
var q = qs[x].trim(); var q = qs[x].trim();
if (q != "") if (q != "") {
{
// its a search term. // its a search term.
if (q.search(/[0-9]/i) == -1) if (q.search(/[0-9]/i) == -1) {
{
// get new results. // get new results.
Words.FindReferences(q); Words.FindReferences(q);
} } else if (q.search(/(H|G)[0-9]/i) != -1) {
// its a strongs lookup // its a strongs lookup
else if (q.search(/(H|G)[0-9]/i) != -1)
{
var dict = q.substring(0, 1); var dict = q.substring(0, 1);
if (dict.search(/h/i) != -1) { if (dict.search(/h/i) != -1) {
dict = "heb"; dict = "heb";
@ -100,73 +77,60 @@ function Search(sv)
var Ss = q.split(' '); var Ss = q.split(' ');
var results = []; var results = [];
for (var s in Ss) for (var s in Ss) {
{
results.push(Strongs.GetStrongs(Ss[s], dict)); results.push(Strongs.GetStrongs(Ss[s], dict));
} }
for (var result in results) for (var result in results) {
{
// display results. // display results.
if ($("#display-strongs-as-dialog")[0].checked) if ($("#display-strongs-as-dialog")[0].checked) {
{
Strongs.DisplayStrongsDialog(results[result]); Strongs.DisplayStrongsDialog(results[result]);
} } else {
else
{
Strongs.DisplayStrongs(results[result]); Strongs.DisplayStrongs(results[result]);
} }
} }
} } else {
// its a verse reference. // its a verse reference.
else var passage = "";
{ if (q.trim() != "") {
if (q.trim() != "")
{
var myref = new Reference(q.trim()); var myref = new Reference(q.trim());
var r = Bible.GetPassage(myref.book, myref.startchapter, myref.endchapter, myref.startverse, myref.endverse); var r = Bible.GetPassage(myref.book, myref.startchapter, myref.endchapter, myref.startverse, myref.endverse);
Bible.DisplayPassage(r.cs, myref.book, myref.startchapter, myref.endchapter, myref.startverse, myref.endverse, r.testament); Bible.DisplayPassage(r.cs, myref, r.testament);
} }
} }
} }
} }
$( "#result" ).sortable({ $( "#result" ).sortable({
axis: "x", axis: "x",
handle: ".handle" handle: ".handle"
}); });
} }
catch (err) catch (err) {
{
Util.HandleError(err); Util.HandleError(err);
} }
return false; return false;
} }
var Settings = { var Settings = {
Load: function() Load: function() {
{
var str = $.cookie('settings'); var str = $.cookie('settings');
if (str != null) if (str != null) {
{
var s = str.split(","); var s = str.split(",");
$("#resultwrap").css("float", s[0]); $("#resultwrap").css("float", s[0]);
$("#searchresultswrap").css("float", s[0]); $("#searchresultswrap").css("float", s[0]);
if (s[1] == "none") if (s[1] == "none") {
{
$("#searchresultswrap").css("display", "none"); $("#searchresultswrap").css("display", "none");
$("#showhidesearch").html("Show Search"); $("#showhidesearch").html("Show Search");
$("#resultwrap").css("width", "100%"); $("#resultwrap").css("width", "100%");
} } else {
else
{
$("#searchresultswrap").css("display", "block"); $("#searchresultswrap").css("display", "block");
$("#showhidesearch").html("Hide Search"); $("#showhidesearch").html("Hide Search");
$("#resultwrap").css("width", "70%"); $("#resultwrap").css("width", "70%");
@ -176,8 +140,7 @@ var Settings = {
$("#result").css("font-family", s[3]); $("#result").css("font-family", s[3]);
} }
}, },
Save: function() Save: function() {
{
var s = {}; var s = {};
s.Panes = $("#resultwrap").css("float"); s.Panes = $("#resultwrap").css("float");
s.Search = $("#searchresultswrap").css("display"); s.Search = $("#searchresultswrap").css("display");
@ -190,218 +153,166 @@ var Settings = {
expires: 365 expires: 365
}); });
}, },
ShowHideSearch: function() ShowHideSearch: function() {
{
var o = $("#showhidesearch"); var o = $("#showhidesearch");
var s = $("#searchresultswrap"); var s = $("#searchresultswrap");
var r = $("#resultwrap"); var r = $("#resultwrap");
if (s.css("display") != "none") if (s.css("display") != "none") {
{
s.css("display", "none"); s.css("display", "none");
o.html("Show Search"); o.html("Show Search");
r.css("width", "100%"); r.css("width", "100%");
} } else {
else
{
s.css("display", "block"); s.css("display", "block");
o.html("Hide Search"); o.html("Hide Search");
r.css("width", "70%"); r.css("width", "70%");
} }
this.Save(); this.Save();
}, },
SwitchPanes: function() SwitchPanes: function() {
{
var s = $("#searchresultswrap"); var s = $("#searchresultswrap");
var r = $("#resultwrap"); var r = $("#resultwrap");
var v = s.css("float"); var v = s.css("float");
if (v == "right") if (v == "right") {
{
s.css("float", "left"); s.css("float", "left");
r.css("float", "left"); r.css("float", "left");
} } else {
else
{
s.css("float", "right"); s.css("float", "right");
r.css("float", "right"); r.css("float", "right");
} }
this.Save(); this.Save();
}, },
IncreaseResultFontSize: function() IncreaseResultFontSize: function() {
{
var s = $("#result").css("font-size"); var s = $("#result").css("font-size");
$("#result").css("font-size", parseInt(s) + 1); $("#result").css("font-size", parseInt(s) + 1);
this.Save(); this.Save();
}, },
DecreaseResultFontSize: function() DecreaseResultFontSize: function() {
{
var s = $("#result").css("font-size"); var s = $("#result").css("font-size");
$("#result").css("font-size", parseInt(s) - 1); $("#result").css("font-size", parseInt(s) - 1);
this.Save(); this.Save();
}, },
ChangeResultFont: function(fontfamily) ChangeResultFont: function(fontfamily) {
{
$("#result").css("font-family", fontfamily); $("#result").css("font-family", fontfamily);
this.Save(); this.Save();
} }
} };
var Util = { var Util = {
HandleLink: function(e) HandleLink: function(e) {
{
Search($(e.target).text()); Search($(e.target).text());
}, },
HandleHiddenLink: function(e) HandleHiddenLink: function(e) {
{
Search($(e.target).find(".searchvalue").text()); Search($(e.target).find(".searchvalue").text());
}, },
RemoveResult: function(e) RemoveResult: function(e) {
{
$(e.target).parent().parent().remove(); $(e.target).parent().parent().remove();
}, },
HandleError: function(e) HandleError: function(e) {
{
// for now we're going to put the error in the main result div. // 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>"); 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>");
return false; return false;
} }
} };
var Bible = { var Bible = {
DisplayPassage: function(cs, b, sch, ech, sv, ev, testament) DisplayPassage: function(cs, ref, testament) {
{ console.log(ref.toSource());
try try {
{
var r = ""; var r = "";
// make the end verse pretty. // make the end verse pretty.
var tvs = cs[cs.length - 1].vss.length; var tvs = cs[cs.length - 1].vss.length;
if (ev == "*" || ev > tvs) for (var j = 0; j < cs.length; j++) {
{ if (Number(ref.startchapter) < Number(ref.endchapter)) {
ev = tvs;
}
for (var j = 0; j < cs.length; j++)
{
if (sch < ech)
{
r += "<b>Chapter: " + cs[j].ch + "</b><br />"; r += "<b>Chapter: " + cs[j].ch + "</b><br />";
} }
var vss = cs[j].vss; var vss = cs[j].vss;
for (var m = 0; m < vss.length; m++) for (var m = 0; m < vss.length; m++) {
{
var v = vss[m]; var v = vss[m];
r += "<b>" + v.v + ".</b> "; r += "<b>" + v.v + ".</b> ";
for (var w = 0; w < v.w.length; w++) for (var w = 0; w < v.w.length; w++) {
{ if (v.w[w].s != undefined) {
if (v.w[w].s != undefined)
{
var strongs_pre = ""; var strongs_pre = "";
if (testament == "old") { if (testament == "old") { strongs_pre = "H"; }
strongs_pre = "H"; if (testament == "new") {strongs_pre = "G"; }
}
if (testament == "new") {
strongs_pre = "G";
}
var sp = ""; var sp = "";
if (v.w[w].t.substr(v.w[w].t.length-1) == " ") { if (v.w[w].t.substr(v.w[w].t.length-1) == " ") { sp = " "; }
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; 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 {
else
{
r += v.w[w].t; r += v.w[w].t;
} }
} }
r += "<br />"; 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><span class='resultbody'>" + "<h2>" + bookName(b) + " " + sch + ":" + sv + "-" + ech + ":" + ev + "</h2>" + r + "</span><br clear='all' /></div>"); 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><span class='resultbody'>" + "<h2>" + ref.toString() + "</h2>" + r + "</span><br clear='all' /></div>");
t.find(".hiddenlink").click(function(e) t.find(".hiddenlink").click(function(e) {
{
Util.HandleHiddenLink(e); Util.HandleHiddenLink(e);
}); });
t.find(".removeresult").click(function(e) t.find(".removeresult").click(function(e) {
{
Util.RemoveResult(e); Util.RemoveResult(e);
}); });
$("#result").prepend(t); $("#result").prepend(t);
} }
catch (err) catch (err) {
{
Util.HandleError(err); Util.HandleError(err);
} }
}, },
GetPassage: function(b, sch, ech, sv, ev) GetPassage: function(b, sch, ech, sv, ev) {
{ try {
try
{
var chapters = []; // the verses from the chapter. var chapters = []; // the verses from the chapter.
var cs = []; // the verses requested. var cs = []; // the verses requested.
var r = {}; var r = {};
for (var i = sch; i <= ech; i++) for (var i = sch; i <= ech; i++) {
{ var url = "bibles/kjv_strongs/" + b + "-" + i + ".json";
var url = "bibles/kjv_strongs/" + b + "-" + i + ".json"
$.ajax({ $.ajax({
async: false, async: false,
type: "GET", type: "GET",
url: url, url: url,
dataType: "json", dataType: "json",
success: function(d, t, x) success: function(d, t, x) {
{
chapters.push(d); chapters.push(d);
}, },
error: function(request, status, error) error: function(request, status, error) {
{
Util.HandleError(error, request); Util.HandleError(error, request);
} }
}); });
} }
for (var j = 0; j < chapters.length; j++) for (var j = 0; j < chapters.length; j++) {
{
var vss = []; var vss = [];
var start; var start;
var end; var end;
// figure out the start verse. // figure out the start verse.
if (j == 0) if (j == 0) {
{
start = sv; start = sv;
} } else {
else
{
start = 1; start = 1;
} }
// figure out the end verse // figure out the end verse
if ((j + 1) == chapters.length) if ((j + 1) == chapters.length) {
{
end = ev; end = ev;
} } else {
else
{
end = "*"; end = "*";
} }
// get the verses requested. // get the verses requested.
var tvs = chapters[j].vss.length; var tvs = chapters[j].vss.length;
if (end == "*" || end > tvs) if (end == "*" || end > tvs) {
{
end = tvs; end = tvs;
} }
for (i = start; i <= end; i++) for (i = start; i <= end; i++) {
{
// we're using c based indexes here, so the index is 1 less than the verse #. // we're using c based indexes here, so the index is 1 less than the verse #.
vss.push(chapters[j].vss[i-1]); vss.push(chapters[j].vss[i-1]);
} }
@ -413,31 +324,25 @@ var Bible = {
} }
r.cs = cs; r.cs = cs;
if (b >= 40) if (b >= 40) {
{
r.testament = "new"; r.testament = "new";
} } else {
else
{
r.testament = "old"; r.testament = "old";
} }
return r; return r;
} } catch (err) {
catch (err)
{
Util.HandleError(err); Util.HandleError(err);
} }
return null;
} }
} };
var Strongs = { var Strongs = {
GetStrongs: function(sn, dict) GetStrongs: function(sn, dict) {
{ try {
try
{
var self = this; var self = this;
var results = {}; var results = {};
var url = dict + parseInt((sn - 1) / 100) + ".xml" var url = dict + parseInt((sn - 1) / 100) + ".xml";
if (dict == "grk") { if (dict == "grk") {
results.prefix = "G"; results.prefix = "G";
} else { } else {
@ -450,12 +355,10 @@ var Strongs = {
type: "GET", type: "GET",
url: "xml/" + url, url: "xml/" + url,
dataType: "xml", dataType: "xml",
success: function(d, t, x) success: function(d, t, x) {
{
results.strongs = d; results.strongs = d;
}, },
error: function(request, status, error) error: function(request, status, error) {
{
Util.HandleError(error, request); Util.HandleError(error, request);
} }
}); });
@ -465,18 +368,15 @@ var Strongs = {
type: "GET", type: "GET",
url: "xml/cr" + url, url: "xml/cr" + url,
dataType: "xml", dataType: "xml",
success: function(d, t, x) success: function(d, t, x) {
{
results.crossrefs = d; results.crossrefs = d;
}, },
error: function(request, status, error) error: function(request, status, error) {
{
Util.HandleError(error, request); Util.HandleError(error, request);
} }
}); });
if (dict == "grk") if (dict == "grk") {
{
url = "xml/rs" + parseInt((sn - 1) / 1000) + ".xml"; url = "xml/rs" + parseInt((sn - 1) / 1000) + ".xml";
// rmac is a two get process. // rmac is a two get process.
$.ajax({ $.ajax({
@ -484,12 +384,10 @@ var Strongs = {
type: "GET", type: "GET",
url: url, url: url,
dataType: "xml", dataType: "xml",
success: function(d, t, x) success: function(d, t, x) {
{
results.rmac = d; results.rmac = d;
}, },
error: function(request, status, error) error: function(request, status, error) {
{
Util.HandleError(error, request); Util.HandleError(error, request);
} }
}); });
@ -502,27 +400,22 @@ var Strongs = {
type: "GET", type: "GET",
url: url, url: url,
dataType: "xml", dataType: "xml",
success: function(d, t, x) success: function(d, t, x) {
{
results.rmac = d; results.rmac = d;
}, },
error: function(request, status, error) error: function(request, status, error) {
{
Util.HandleError(error, request); Util.HandleError(error, request);
} }
}); });
} }
return results; return results;
} } catch (err) {
catch (err)
{
Util.HandleError(err); Util.HandleError(err);
} }
return null;
}, },
BuildStrongs: function(r) BuildStrongs: function(r) {
{ try {
try
{
// first deal with strongs data. // first deal with strongs data.
var entry = $(r.strongs).find("i#" + r.prefix + r.sn); var entry = $(r.strongs).find("i#" + r.prefix + r.sn);
var title = $(entry).find("t").text(); var title = $(entry).find("t").text();
@ -539,12 +432,10 @@ var Strongs = {
var crtxt = "<div class='scr'><b>Cross References:</b> <a href='javascript:void()' class='showhide'>Show</a><br /><span class='contents'>"; 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) cr.each(function(i) {
{
crtxt += "<b>" + $(this).find("t").text() + ":</b> "; crtxt += "<b>" + $(this).find("t").text() + ":</b> ";
$(this).find("r").each(function(j) $(this).find("r").each(function(j) {
{
var ref = $(this).attr("r").split(";"); var ref = $(this).attr("r").split(";");
crtxt += "<a href='javascript:void();' class='link'>" + bookName(ref[0]) + " " + ref[1] + ":" + ref[2] + "</a>, "; crtxt += "<a href='javascript:void();' class='link'>" + bookName(ref[0]) + " " + ref[1] + ":" + ref[2] + "</a>, ";
}); });
@ -555,12 +446,10 @@ var Strongs = {
// ...processing statements go here... // ...processing statements go here...
var rtxt = ""; var rtxt = "";
if (r.prefix == "G") 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'>"; 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() $(r.rmac).find('i[id="' + r.rmaccode.toUpperCase() + '"]').find("d").each(function() {
{
rtxt += $(this).text() + "<br />"; rtxt += $(this).text() + "<br />";
}); });
rtxt += "</span></div>"; rtxt += "</span></div>";
@ -570,45 +459,36 @@ var Strongs = {
// ok. we have to do this because click events seem to be cumulative with jquery. // 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>"); 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) t.find(".link").click(function(e) {
{
Util.HandleLink(e); Util.HandleLink(e);
}); });
t.find(".removeresult").click(function(e) t.find(".removeresult").click(function(e) {
{
Util.RemoveResult(e); Util.RemoveResult(e);
}); });
t.find(".showhide").click(function(e) t.find(".showhide").click(function(e) {
{
Strongs.ShowHide(e); Strongs.ShowHide(e);
}); });
return t; return t;
} } catch (err) {
catch (err)
{
Util.HandleError(err); Util.HandleError(err);
} }
return null;
}, },
DisplayStrongs: function(r) DisplayStrongs: function(r) {
{ try {
try
{
var t = Strongs.BuildStrongs(r); var t = Strongs.BuildStrongs(r);
$("#result").prepend(t); $("#result").prepend(t);
return false; return false;
} } catch (err) {
catch (err)
{
Util.HandleError(err); Util.HandleError(err);
} }
return null;
}, },
DisplayStrongsDialog: function(r) DisplayStrongsDialog: function(r) {
{ try {
try
{
var t = Strongs.BuildStrongs(r); var t = Strongs.BuildStrongs(r);
var d = $("<div></div>").append(t); var d = $("<div></div>").append(t);
@ -625,24 +505,19 @@ var Strongs = {
} }
}); });
return false; return false;
} } catch (err) {
catch (err)
{
Util.HandleError(err); Util.HandleError(err);
} }
return null;
}, },
ShowHide: function(e) ShowHide: function(e) {
{
var o = $(e.target); var o = $(e.target);
var c = o.parent().find(".contents"); var c = o.parent().find(".contents");
if (c.css("display") != "none") if (c.css("display") != "none") {
{
c.css("display", "none"); c.css("display", "none");
o.html("Show"); o.html("Show");
} } else {
else
{
c.css("display", "inline"); c.css("display", "inline");
o.html("Hide"); o.html("Hide");
} }
@ -650,29 +525,22 @@ var Strongs = {
} }
var Words = { var Words = {
ConvertResultsToArray: function(r) ConvertResultsToArray: function(r) {
{ try {
try
{
var results = new Array(); var results = new Array();
$(r).each(function() $(r).each(function() {
{
results.push([$(this).attr("b"), $(this).attr("ch"), $(this).attr("v")]); results.push([$(this).attr("b"), $(this).attr("ch"), $(this).attr("v")]);
}); });
return results; return results;
} } catch (err) {
catch (err)
{
Util.HandleError(err); Util.HandleError(err);
} }
return null;
}, },
DisplayResults: function(results, q) DisplayResults: function(results, q) {
{ try {
try
{
var txt = "<h4>Query: <a href='javascript:void();' class='link'>" + q + "</a></h4><ul>"; var txt = "<h4>Query: <a href='javascript:void();' class='link'>" + q + "</a></h4><ul>";
for (var i = 0; i < results.length; i++) for (var i = 0; i < results.length; i++) {
{
var r = results[i].split(":"); 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 += "<li /><a href='javascript:void();' class='link' alt='" + bookName(r[0]) + " " + r[1] + ":" + r[2] + "'>" + bookName(r[0]) + " " + r[1] + ":" + r[2] + "</a>";
} }
@ -680,50 +548,40 @@ var Words = {
var t = $(txt); var t = $(txt);
t.find(".link").click(function(e) t.find(".link").click(function(e) {
{
Util.HandleLink(e); Util.HandleLink(e);
}); });
$("#searchresults").html(t); $("#searchresults").html(t);
$("#searchTotal").html(results.length); $("#searchTotal").html(results.length);
return false; return false;
} } catch (err) {
catch (err)
{
Util.HandleError(err); Util.HandleError(err);
} }
return null;
}, },
FindReferences: function(qry) FindReferences: function(qry) {
{ try {
try
{
qry = qry.toLowerCase(); qry = qry.toLowerCase();
var qs = qry.split(" "); var qs = qry.split(" ");
var words = this.BuildIndexArray().sort(); var words = this.BuildIndexArray().sort();
var results = new Array(); var results = new Array();
// Loop through each query term. // Loop through each query term.
for (i = 0; i < qs.length; i++) for (i = 0; i < qs.length; i++) {
{
var q = qs[i].replace("'", ""); // we don't included ticks in our words. 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. // For each query term, figure out which xml file it is in, and get it.
// getSearchRefs returns an array of references. // getSearchRefs returns an array of references.
for (var w = 0; w < words.length; w++) 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 we are at the end of the array, we want to use a different test.
if (w == 0) if (w == 0) {
{ if (q <= words[w]) {
if (q <= words[w])
{
results.unshift(this.GetSearchReferences("index/" + words[w] + "idx.json", q)); results.unshift(this.GetSearchReferences("index/" + words[w] + "idx.json", q));
break; break;
} }
} else } else {
{ if (q <= words[w] && q > words[w - 1]) {
if (q <= words[w] && q > words[w - 1])
{
results.unshift(this.GetSearchReferences("index/" + words[w] + "idx.json", q)); results.unshift(this.GetSearchReferences("index/" + words[w] + "idx.json", q));
break; break;
} }
@ -733,26 +591,21 @@ var Words = {
// Now we need to test results. If there is more than one item in the array, we need to find the set // 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. // that is shared by all of them. IF not, we can just return those refs.
if (results.length == 1) if (results.length == 1) {
{
this.DisplayResults(results[0], qry); this.DisplayResults(results[0], qry);
} else } else {
{
this.DisplayResults(this.FindSharedSet(results), qry); this.DisplayResults(this.FindSharedSet(results), qry);
} }
return false; return false;
} } catch (err) {
catch (err)
{
Util.HandleError(err); Util.HandleError(err);
} }
return null;
}, },
GetSearchReferences: function(url, query) GetSearchReferences: function(url, query) {
{ try {
try
{
// getSearchRefs takes a url and uses ajax to retrieve the references and returns an array of references. // getSearchRefs takes a url and uses ajax to retrieve the references and returns an array of references.
var r; var r;
@ -761,33 +614,26 @@ var Words = {
type: "GET", type: "GET",
url: url, url: url,
dataType: "json", dataType: "json",
success: function(d, t, x) success: function(d, t, x) {
{
r = d; r = d;
}, },
error: function(request, status, error) error: function(request, status, error) {
{
Util.HandleError(error, request); Util.HandleError(error, request);
} }
}); });
// find the right word // find the right word
var refs = $.grep(r, function(o,i) var refs = $.grep(r, function(o,i) {
{
return o.word == query; return o.word == query;
}); });
return refs[0].refs; return refs[0].refs;
} } catch (err) {
catch (err)
{
Util.HandleError(err); Util.HandleError(err);
} }
return null;
}, },
BuildIndexArray: function() BuildIndexArray: function() {
{
try
{
var words = new Array(); var words = new Array();
words.unshift('abiram'); words.unshift('abiram');
words.unshift('accepteth'); words.unshift('accepteth');
@ -1037,25 +883,16 @@ var Words = {
words.unshift('zophim'); words.unshift('zophim');
words.unshift('zuzims'); words.unshift('zuzims');
return words; return words;
}
catch (err)
{
Util.HandleError(err);
}
}, },
FindSharedSet: function(results) FindSharedSet: function(results) {
{ try {
try
{
// FindSharedSet takes an array of reference arrays, and figures out which references are shared // 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. // by all arrays/sets, then returns a single array of references.
for (var j in results) for (var j in results) {
{
var refs = results[j]; var refs = results[j];
for (var i = 0; i < refs.length; i++) for (var i = 0; i < refs.length; i++) {
{
var r = refs[i].split(":"); var r = refs[i].split(":");
// convert references to single integers. // convert references to single integers.
// Book * 100000, Chapter * 1000, Verse remains same, add all together. // Book * 100000, Chapter * 1000, Verse remains same, add all together.
@ -1070,29 +907,24 @@ var Words = {
var result = results[0]; var result = results[0];
// for each additional result, get the shared set // for each additional result, get the shared set
for (i = 1; i < results.length; i++) for (i = 1; i < results.length; i++) {
{
result = this.ReturnSharedSet(results[i], result); result = this.ReturnSharedSet(results[i], result);
} }
// convert the references back into book, chapter and verse. // convert the references back into book, chapter and verse.
for (i = 0; i < result.length; i++) for (i = 0; i < result.length; i++) {
{
ref = result[i]; ref = result[i];
result[i] = parseInt(ref / 100000000)+":"+parseInt((ref % 100000000) / 10000)+":"+((ref % 100000000) % 10000); result[i] = parseInt(ref / 100000000)+":"+parseInt((ref % 100000000) / 10000)+":"+((ref % 100000000) % 10000);
} }
return result; return result;
} } catch (err) {
catch (err)
{
Util.HandleError(err); Util.HandleError(err);
} }
return null;
}, },
ReturnSharedSet: function(x, y) ReturnSharedSet: function(x, y) {
{ try {
try
{
/// <summary> /// <summary>
/// Takes two javascript arrays and returns an array /// Takes two javascript arrays and returns an array
/// containing a set of values shared by arrays. /// containing a set of values shared by arrays.
@ -1102,7 +934,7 @@ var Words = {
var i = 0; var i = 0;
// declare terminator // declare terminator
var t = (x.length < y.length) ? x.length : y.length var t = (x.length < y.length) ? x.length : y.length;
// sort the arrays // sort the arrays
x.sort(SortNumeric); x.sort(SortNumeric);
@ -1110,18 +942,14 @@ var Words = {
// in this loop, we remove from the arrays, the // in this loop, we remove from the arrays, the
// values that aren't shared between them. // values that aren't shared between them.
while (i < t) while (i < t) {
{ if (x[i] == y[i]) {
if (x[i] == y[i])
{
i++; i++;
} }
if (x[i] < y[i]) if (x[i] < y[i]) {
{
x.splice(i, 1); x.splice(i, 1);
} }
if (x[i] > y[i]) if (x[i] > y[i]) {
{
y.splice(i, 1); y.splice(i, 1);
} }
t = (x.length < y.length) ? x.length : y.length; t = (x.length < y.length) ? x.length : y.length;
@ -1139,10 +967,9 @@ var Words = {
// we could return y, because at this time, both arrays // we could return y, because at this time, both arrays
// are identical. // are identical.
return x; return x;
} } catch (err) {
catch (err)
{
Util.HandleError(err); Util.HandleError(err);
} }
return null;
} }
} };

View File

@ -1,7 +1,7 @@
// // This code was written by Jeremy and Jason Wall.
// This code was written by Jason Wall. Feel free to use, and if you can, include a link back to www.walljm.com // Feel free to use, and if you can, include a link back to www.walljm.com
// Jason@walljm.com // www.walljm.com // Jason@walljm.com // www.walljm.com
// // Jeremy@marzhillstudios.com // jeremy.marzhillstudios.com
String.prototype.trim = function() { String.prototype.trim = function() {
return this.replace(/^\s+|\s+$/g, ""); return this.replace(/^\s+|\s+$/g, "");
@ -645,3 +645,14 @@ function bookName(booknum) {
return book[booknum]; return book[booknum];
} }
Reference.prototype.toString = function() {
var ref = this.bookname.concat(" ").
concat(this.startchapter).concat(":").
concat(this.startverse);
if (this.startchapter == this.endchapter) {
return ref.concat("-").concat(this.endverse);
}
return ref.concat("-").concat(this.endchapter)
.concat(":").concat(this.endverse);
};

View File

@ -1,61 +1,46 @@
function SortNumeric(x, y) function SortNumeric(x, y) {
{ return x - y;
return x - y
} }
String.prototype.trim = function() String.prototype.trim = function() {
{
return this.replace(/^\s+|\s+$/g, ""); return this.replace(/^\s+|\s+$/g, "");
} };
String.prototype.ltrim = function()
{
return this.replace(/^\s+/, "");
}
String.prototype.rtrim = function()
{
return this.replace(/\s+$/, "");
}
function Traverse(node, testament) String.prototype.ltrim = function() {
{ return this.replace(/^\s+/, "");
try };
{
String.prototype.rtrim = function() {
return this.replace(/\s+$/, "");
};
function Traverse(node, testament) {
try {
var treeText = ""; var treeText = "";
if (node != null) if (node != null) {
{ if (node.hasChildNodes()) {
if (node.hasChildNodes()) if (node.nodeName == "s") {
{
if (node.nodeName == "s")
{
// you need to test if this is the OT or NT and set the attribute accordingly. // you need to test if this is the OT or NT and set the attribute accordingly.
var t = ""; var t = "";
if (testament == "old") if (testament == "old") {
{
t = "H"; t = "H";
} }
if (testament == "new") if (testament == "new") {
{
t = "G"; 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>"; 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 } else {
{
treeText += '<' + node.nodeName + '>'; treeText += '<' + node.nodeName + '>';
for (var i = 0; i < node.childNodes.length; i++) for (var i = 0; i < node.childNodes.length; i++) {
{
treeText += Traverse(node.childNodes.item(i), testament); treeText += Traverse(node.childNodes.item(i), testament);
} }
treeText += '</' + node.nodeName + '>'; treeText += '</' + node.nodeName + '>';
} }
} else } else {
{ if (node.nodeValue != null) {
if (node.nodeValue != null) if (node.nodeValue.search(/^(\,|\.|\:|\?|\;|\!)/) != -1) {
{
if (node.nodeValue.search(/^(\,|\.|\:|\?|\;|\!)/) != -1)
{
treeText += node.nodeValue; treeText += node.nodeValue;
} else } else {
{
treeText += " " + node.nodeValue; treeText += " " + node.nodeValue;
} }
} }
@ -63,33 +48,25 @@ function Traverse(node, testament)
} }
return treeText; return treeText;
} }
catch (err) catch (err) {
{
Util.HandleError(err); Util.HandleError(err);
} }
return null;
} }
function Search(sv) function Search(sv) {
{ try {
try
{
var qs = sv.split(";"); var qs = sv.split(";");
for (var x in qs) for (var x in qs) {
{
var q = qs[x].trim(); var q = qs[x].trim();
if (q != "") if (q != "") {
{
// its a search term. // its a search term.
if (q.search(/[0-9]/i) == -1) if (q.search(/[0-9]/i) == -1) {
{
// get new results. // get new results.
Words.FindReferences(q); Words.FindReferences(q);
} } else if (q.search(/(H|G)[0-9]/i) != -1) {
// its a strongs lookup // its a strongs lookup
else if (q.search(/(H|G)[0-9]/i) != -1)
{
var dict = q.substring(0, 1); var dict = q.substring(0, 1);
if (dict.search(/h/i) != -1) { if (dict.search(/h/i) != -1) {
dict = "heb"; dict = "heb";
@ -100,73 +77,60 @@ function Search(sv)
var Ss = q.split(' '); var Ss = q.split(' ');
var results = []; var results = [];
for (var s in Ss) for (var s in Ss) {
{
results.push(Strongs.GetStrongs(Ss[s], dict)); results.push(Strongs.GetStrongs(Ss[s], dict));
} }
for (var result in results) for (var result in results) {
{
// display results. // display results.
if ($("#display-strongs-as-dialog")[0].checked) if ($("#display-strongs-as-dialog")[0].checked) {
{
Strongs.DisplayStrongsDialog(results[result]); Strongs.DisplayStrongsDialog(results[result]);
} } else {
else
{
Strongs.DisplayStrongs(results[result]); Strongs.DisplayStrongs(results[result]);
} }
} }
} } else {
// its a verse reference. // its a verse reference.
else var passage = "";
{ if (q.trim() != "") {
if (q.trim() != "")
{
var myref = new Reference(q.trim()); var myref = new Reference(q.trim());
var r = Bible.GetPassage(myref.book, myref.startchapter, myref.endchapter, myref.startverse, myref.endverse); var r = Bible.GetPassage(myref.book, myref.startchapter, myref.endchapter, myref.startverse, myref.endverse);
Bible.DisplayPassage(r.cs, myref.book, myref.startchapter, myref.endchapter, myref.startverse, myref.endverse, r.testament); Bible.DisplayPassage(r.cs, myref, r.testament);
} }
} }
} }
} }
$( "#result" ).sortable({ $( "#result" ).sortable({
axis: "x", axis: "x",
handle: ".handle" handle: ".handle"
}); });
} }
catch (err) catch (err) {
{
Util.HandleError(err); Util.HandleError(err);
} }
return false; return false;
} }
var Settings = { var Settings = {
Load: function() Load: function() {
{
var str = $.cookie('settings'); var str = $.cookie('settings');
if (str != null) if (str != null) {
{
var s = str.split(","); var s = str.split(",");
$("#resultwrap").css("float", s[0]); $("#resultwrap").css("float", s[0]);
$("#searchresultswrap").css("float", s[0]); $("#searchresultswrap").css("float", s[0]);
if (s[1] == "none") if (s[1] == "none") {
{
$("#searchresultswrap").css("display", "none"); $("#searchresultswrap").css("display", "none");
$("#showhidesearch").html("Show Search"); $("#showhidesearch").html("Show Search");
$("#resultwrap").css("width", "100%"); $("#resultwrap").css("width", "100%");
} } else {
else
{
$("#searchresultswrap").css("display", "block"); $("#searchresultswrap").css("display", "block");
$("#showhidesearch").html("Hide Search"); $("#showhidesearch").html("Hide Search");
$("#resultwrap").css("width", "70%"); $("#resultwrap").css("width", "70%");
@ -176,8 +140,7 @@ var Settings = {
$("#result").css("font-family", s[3]); $("#result").css("font-family", s[3]);
} }
}, },
Save: function() Save: function() {
{
var s = {}; var s = {};
s.Panes = $("#resultwrap").css("float"); s.Panes = $("#resultwrap").css("float");
s.Search = $("#searchresultswrap").css("display"); s.Search = $("#searchresultswrap").css("display");
@ -190,218 +153,166 @@ var Settings = {
expires: 365 expires: 365
}); });
}, },
ShowHideSearch: function() ShowHideSearch: function() {
{
var o = $("#showhidesearch"); var o = $("#showhidesearch");
var s = $("#searchresultswrap"); var s = $("#searchresultswrap");
var r = $("#resultwrap"); var r = $("#resultwrap");
if (s.css("display") != "none") if (s.css("display") != "none") {
{
s.css("display", "none"); s.css("display", "none");
o.html("Show Search"); o.html("Show Search");
r.css("width", "100%"); r.css("width", "100%");
} } else {
else
{
s.css("display", "block"); s.css("display", "block");
o.html("Hide Search"); o.html("Hide Search");
r.css("width", "70%"); r.css("width", "70%");
} }
this.Save(); this.Save();
}, },
SwitchPanes: function() SwitchPanes: function() {
{
var s = $("#searchresultswrap"); var s = $("#searchresultswrap");
var r = $("#resultwrap"); var r = $("#resultwrap");
var v = s.css("float"); var v = s.css("float");
if (v == "right") if (v == "right") {
{
s.css("float", "left"); s.css("float", "left");
r.css("float", "left"); r.css("float", "left");
} } else {
else
{
s.css("float", "right"); s.css("float", "right");
r.css("float", "right"); r.css("float", "right");
} }
this.Save(); this.Save();
}, },
IncreaseResultFontSize: function() IncreaseResultFontSize: function() {
{
var s = $("#result").css("font-size"); var s = $("#result").css("font-size");
$("#result").css("font-size", parseInt(s) + 1); $("#result").css("font-size", parseInt(s) + 1);
this.Save(); this.Save();
}, },
DecreaseResultFontSize: function() DecreaseResultFontSize: function() {
{
var s = $("#result").css("font-size"); var s = $("#result").css("font-size");
$("#result").css("font-size", parseInt(s) - 1); $("#result").css("font-size", parseInt(s) - 1);
this.Save(); this.Save();
}, },
ChangeResultFont: function(fontfamily) ChangeResultFont: function(fontfamily) {
{
$("#result").css("font-family", fontfamily); $("#result").css("font-family", fontfamily);
this.Save(); this.Save();
} }
} };
var Util = { var Util = {
HandleLink: function(e) HandleLink: function(e) {
{
Search($(e.target).text()); Search($(e.target).text());
}, },
HandleHiddenLink: function(e) HandleHiddenLink: function(e) {
{
Search($(e.target).find(".searchvalue").text()); Search($(e.target).find(".searchvalue").text());
}, },
RemoveResult: function(e) RemoveResult: function(e) {
{
$(e.target).parent().parent().remove(); $(e.target).parent().parent().remove();
}, },
HandleError: function(e) HandleError: function(e) {
{
// for now we're going to put the error in the main result div. // 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>"); 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>");
return false; return false;
} }
} };
var Bible = { var Bible = {
DisplayPassage: function(cs, b, sch, ech, sv, ev, testament) DisplayPassage: function(cs, ref, testament) {
{ console.log(ref.toSource());
try try {
{
var r = ""; var r = "";
// make the end verse pretty. // make the end verse pretty.
var tvs = cs[cs.length - 1].vss.length; var tvs = cs[cs.length - 1].vss.length;
if (ev == "*" || ev > tvs) for (var j = 0; j < cs.length; j++) {
{ if (Number(ref.startchapter) < Number(ref.endchapter)) {
ev = tvs;
}
for (var j = 0; j < cs.length; j++)
{
if (sch < ech)
{
r += "<b>Chapter: " + cs[j].ch + "</b><br />"; r += "<b>Chapter: " + cs[j].ch + "</b><br />";
} }
var vss = cs[j].vss; var vss = cs[j].vss;
for (var m = 0; m < vss.length; m++) for (var m = 0; m < vss.length; m++) {
{
var v = vss[m]; var v = vss[m];
r += "<b>" + v.v + ".</b> "; r += "<b>" + v.v + ".</b> ";
for (var w = 0; w < v.w.length; w++) for (var w = 0; w < v.w.length; w++) {
{ if (v.w[w].s != undefined) {
if (v.w[w].s != undefined)
{
var strongs_pre = ""; var strongs_pre = "";
if (testament == "old") { if (testament == "old") { strongs_pre = "H"; }
strongs_pre = "H"; if (testament == "new") {strongs_pre = "G"; }
}
if (testament == "new") {
strongs_pre = "G";
}
var sp = ""; var sp = "";
if (v.w[w].t.substr(v.w[w].t.length-1) == " ") { if (v.w[w].t.substr(v.w[w].t.length-1) == " ") { sp = " "; }
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; 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 {
else
{
r += v.w[w].t; r += v.w[w].t;
} }
} }
r += "<br />"; 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><span class='resultbody'>" + "<h2>" + bookName(b) + " " + sch + ":" + sv + "-" + ech + ":" + ev + "</h2>" + r + "</span><br clear='all' /></div>"); 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><span class='resultbody'>" + "<h2>" + ref.toString() + "</h2>" + r + "</span><br clear='all' /></div>");
t.find(".hiddenlink").click(function(e) t.find(".hiddenlink").click(function(e) {
{
Util.HandleHiddenLink(e); Util.HandleHiddenLink(e);
}); });
t.find(".removeresult").click(function(e) t.find(".removeresult").click(function(e) {
{
Util.RemoveResult(e); Util.RemoveResult(e);
}); });
$("#result").prepend(t); $("#result").prepend(t);
} }
catch (err) catch (err) {
{
Util.HandleError(err); Util.HandleError(err);
} }
}, },
GetPassage: function(b, sch, ech, sv, ev) GetPassage: function(b, sch, ech, sv, ev) {
{ try {
try
{
var chapters = []; // the verses from the chapter. var chapters = []; // the verses from the chapter.
var cs = []; // the verses requested. var cs = []; // the verses requested.
var r = {}; var r = {};
for (var i = sch; i <= ech; i++) for (var i = sch; i <= ech; i++) {
{ var url = "bibles/kjv_strongs/" + b + "-" + i + ".json";
var url = "bibles/kjv_strongs/" + b + "-" + i + ".json"
$.ajax({ $.ajax({
async: false, async: false,
type: "GET", type: "GET",
url: url, url: url,
dataType: "json", dataType: "json",
success: function(d, t, x) success: function(d, t, x) {
{
chapters.push(d); chapters.push(d);
}, },
error: function(request, status, error) error: function(request, status, error) {
{
Util.HandleError(error, request); Util.HandleError(error, request);
} }
}); });
} }
for (var j = 0; j < chapters.length; j++) for (var j = 0; j < chapters.length; j++) {
{
var vss = []; var vss = [];
var start; var start;
var end; var end;
// figure out the start verse. // figure out the start verse.
if (j == 0) if (j == 0) {
{
start = sv; start = sv;
} } else {
else
{
start = 1; start = 1;
} }
// figure out the end verse // figure out the end verse
if ((j + 1) == chapters.length) if ((j + 1) == chapters.length) {
{
end = ev; end = ev;
} } else {
else
{
end = "*"; end = "*";
} }
// get the verses requested. // get the verses requested.
var tvs = chapters[j].vss.length; var tvs = chapters[j].vss.length;
if (end == "*" || end > tvs) if (end == "*" || end > tvs) {
{
end = tvs; end = tvs;
} }
for (i = start; i <= end; i++) for (i = start; i <= end; i++) {
{
// we're using c based indexes here, so the index is 1 less than the verse #. // we're using c based indexes here, so the index is 1 less than the verse #.
vss.push(chapters[j].vss[i-1]); vss.push(chapters[j].vss[i-1]);
} }
@ -413,31 +324,25 @@ var Bible = {
} }
r.cs = cs; r.cs = cs;
if (b >= 40) if (b >= 40) {
{
r.testament = "new"; r.testament = "new";
} } else {
else
{
r.testament = "old"; r.testament = "old";
} }
return r; return r;
} } catch (err) {
catch (err)
{
Util.HandleError(err); Util.HandleError(err);
} }
return null;
} }
} };
var Strongs = { var Strongs = {
GetStrongs: function(sn, dict) GetStrongs: function(sn, dict) {
{ try {
try
{
var self = this; var self = this;
var results = {}; var results = {};
var url = dict + parseInt((sn - 1) / 100) + ".xml" var url = dict + parseInt((sn - 1) / 100) + ".xml";
if (dict == "grk") { if (dict == "grk") {
results.prefix = "G"; results.prefix = "G";
} else { } else {
@ -450,12 +355,10 @@ var Strongs = {
type: "GET", type: "GET",
url: "xml/" + url, url: "xml/" + url,
dataType: "xml", dataType: "xml",
success: function(d, t, x) success: function(d, t, x) {
{
results.strongs = d; results.strongs = d;
}, },
error: function(request, status, error) error: function(request, status, error) {
{
Util.HandleError(error, request); Util.HandleError(error, request);
} }
}); });
@ -465,18 +368,15 @@ var Strongs = {
type: "GET", type: "GET",
url: "xml/cr" + url, url: "xml/cr" + url,
dataType: "xml", dataType: "xml",
success: function(d, t, x) success: function(d, t, x) {
{
results.crossrefs = d; results.crossrefs = d;
}, },
error: function(request, status, error) error: function(request, status, error) {
{
Util.HandleError(error, request); Util.HandleError(error, request);
} }
}); });
if (dict == "grk") if (dict == "grk") {
{
url = "xml/rs" + parseInt((sn - 1) / 1000) + ".xml"; url = "xml/rs" + parseInt((sn - 1) / 1000) + ".xml";
// rmac is a two get process. // rmac is a two get process.
$.ajax({ $.ajax({
@ -484,12 +384,10 @@ var Strongs = {
type: "GET", type: "GET",
url: url, url: url,
dataType: "xml", dataType: "xml",
success: function(d, t, x) success: function(d, t, x) {
{
results.rmac = d; results.rmac = d;
}, },
error: function(request, status, error) error: function(request, status, error) {
{
Util.HandleError(error, request); Util.HandleError(error, request);
} }
}); });
@ -502,27 +400,22 @@ var Strongs = {
type: "GET", type: "GET",
url: url, url: url,
dataType: "xml", dataType: "xml",
success: function(d, t, x) success: function(d, t, x) {
{
results.rmac = d; results.rmac = d;
}, },
error: function(request, status, error) error: function(request, status, error) {
{
Util.HandleError(error, request); Util.HandleError(error, request);
} }
}); });
} }
return results; return results;
} } catch (err) {
catch (err)
{
Util.HandleError(err); Util.HandleError(err);
} }
return null;
}, },
BuildStrongs: function(r) BuildStrongs: function(r) {
{ try {
try
{
// first deal with strongs data. // first deal with strongs data.
var entry = $(r.strongs).find("i#" + r.prefix + r.sn); var entry = $(r.strongs).find("i#" + r.prefix + r.sn);
var title = $(entry).find("t").text(); var title = $(entry).find("t").text();
@ -539,12 +432,10 @@ var Strongs = {
var crtxt = "<div class='scr'><b>Cross References:</b> <a href='javascript:void()' class='showhide'>Show</a><br /><span class='contents'>"; 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) cr.each(function(i) {
{
crtxt += "<b>" + $(this).find("t").text() + ":</b> "; crtxt += "<b>" + $(this).find("t").text() + ":</b> ";
$(this).find("r").each(function(j) $(this).find("r").each(function(j) {
{
var ref = $(this).attr("r").split(";"); var ref = $(this).attr("r").split(";");
crtxt += "<a href='javascript:void();' class='link'>" + bookName(ref[0]) + " " + ref[1] + ":" + ref[2] + "</a>, "; crtxt += "<a href='javascript:void();' class='link'>" + bookName(ref[0]) + " " + ref[1] + ":" + ref[2] + "</a>, ";
}); });
@ -555,12 +446,10 @@ var Strongs = {
// ...processing statements go here... // ...processing statements go here...
var rtxt = ""; var rtxt = "";
if (r.prefix == "G") 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'>"; 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() $(r.rmac).find('i[id="' + r.rmaccode.toUpperCase() + '"]').find("d").each(function() {
{
rtxt += $(this).text() + "<br />"; rtxt += $(this).text() + "<br />";
}); });
rtxt += "</span></div>"; rtxt += "</span></div>";
@ -570,45 +459,36 @@ var Strongs = {
// ok. we have to do this because click events seem to be cumulative with jquery. // 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>"); 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) t.find(".link").click(function(e) {
{
Util.HandleLink(e); Util.HandleLink(e);
}); });
t.find(".removeresult").click(function(e) t.find(".removeresult").click(function(e) {
{
Util.RemoveResult(e); Util.RemoveResult(e);
}); });
t.find(".showhide").click(function(e) t.find(".showhide").click(function(e) {
{
Strongs.ShowHide(e); Strongs.ShowHide(e);
}); });
return t; return t;
} } catch (err) {
catch (err)
{
Util.HandleError(err); Util.HandleError(err);
} }
return null;
}, },
DisplayStrongs: function(r) DisplayStrongs: function(r) {
{ try {
try
{
var t = Strongs.BuildStrongs(r); var t = Strongs.BuildStrongs(r);
$("#result").prepend(t); $("#result").prepend(t);
return false; return false;
} } catch (err) {
catch (err)
{
Util.HandleError(err); Util.HandleError(err);
} }
return null;
}, },
DisplayStrongsDialog: function(r) DisplayStrongsDialog: function(r) {
{ try {
try
{
var t = Strongs.BuildStrongs(r); var t = Strongs.BuildStrongs(r);
var d = $("<div></div>").append(t); var d = $("<div></div>").append(t);
@ -625,24 +505,19 @@ var Strongs = {
} }
}); });
return false; return false;
} } catch (err) {
catch (err)
{
Util.HandleError(err); Util.HandleError(err);
} }
return null;
}, },
ShowHide: function(e) ShowHide: function(e) {
{
var o = $(e.target); var o = $(e.target);
var c = o.parent().find(".contents"); var c = o.parent().find(".contents");
if (c.css("display") != "none") if (c.css("display") != "none") {
{
c.css("display", "none"); c.css("display", "none");
o.html("Show"); o.html("Show");
} } else {
else
{
c.css("display", "inline"); c.css("display", "inline");
o.html("Hide"); o.html("Hide");
} }
@ -650,29 +525,22 @@ var Strongs = {
} }
var Words = { var Words = {
ConvertResultsToArray: function(r) ConvertResultsToArray: function(r) {
{ try {
try
{
var results = new Array(); var results = new Array();
$(r).each(function() $(r).each(function() {
{
results.push([$(this).attr("b"), $(this).attr("ch"), $(this).attr("v")]); results.push([$(this).attr("b"), $(this).attr("ch"), $(this).attr("v")]);
}); });
return results; return results;
} } catch (err) {
catch (err)
{
Util.HandleError(err); Util.HandleError(err);
} }
return null;
}, },
DisplayResults: function(results, q) DisplayResults: function(results, q) {
{ try {
try
{
var txt = "<h4>Query: <a href='javascript:void();' class='link'>" + q + "</a></h4><ul>"; var txt = "<h4>Query: <a href='javascript:void();' class='link'>" + q + "</a></h4><ul>";
for (var i = 0; i < results.length; i++) for (var i = 0; i < results.length; i++) {
{
var r = results[i].split(":"); 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 += "<li /><a href='javascript:void();' class='link' alt='" + bookName(r[0]) + " " + r[1] + ":" + r[2] + "'>" + bookName(r[0]) + " " + r[1] + ":" + r[2] + "</a>";
} }
@ -680,50 +548,40 @@ var Words = {
var t = $(txt); var t = $(txt);
t.find(".link").click(function(e) t.find(".link").click(function(e) {
{
Util.HandleLink(e); Util.HandleLink(e);
}); });
$("#searchresults").html(t); $("#searchresults").html(t);
$("#searchTotal").html(results.length); $("#searchTotal").html(results.length);
return false; return false;
} } catch (err) {
catch (err)
{
Util.HandleError(err); Util.HandleError(err);
} }
return null;
}, },
FindReferences: function(qry) FindReferences: function(qry) {
{ try {
try
{
qry = qry.toLowerCase(); qry = qry.toLowerCase();
var qs = qry.split(" "); var qs = qry.split(" ");
var words = this.BuildIndexArray().sort(); var words = this.BuildIndexArray().sort();
var results = new Array(); var results = new Array();
// Loop through each query term. // Loop through each query term.
for (i = 0; i < qs.length; i++) for (i = 0; i < qs.length; i++) {
{
var q = qs[i].replace("'", ""); // we don't included ticks in our words. 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. // For each query term, figure out which xml file it is in, and get it.
// getSearchRefs returns an array of references. // getSearchRefs returns an array of references.
for (var w = 0; w < words.length; w++) 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 we are at the end of the array, we want to use a different test.
if (w == 0) if (w == 0) {
{ if (q <= words[w]) {
if (q <= words[w])
{
results.unshift(this.GetSearchReferences("index/" + words[w] + "idx.json", q)); results.unshift(this.GetSearchReferences("index/" + words[w] + "idx.json", q));
break; break;
} }
} else } else {
{ if (q <= words[w] && q > words[w - 1]) {
if (q <= words[w] && q > words[w - 1])
{
results.unshift(this.GetSearchReferences("index/" + words[w] + "idx.json", q)); results.unshift(this.GetSearchReferences("index/" + words[w] + "idx.json", q));
break; break;
} }
@ -733,26 +591,21 @@ var Words = {
// Now we need to test results. If there is more than one item in the array, we need to find the set // 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. // that is shared by all of them. IF not, we can just return those refs.
if (results.length == 1) if (results.length == 1) {
{
this.DisplayResults(results[0], qry); this.DisplayResults(results[0], qry);
} else } else {
{
this.DisplayResults(this.FindSharedSet(results), qry); this.DisplayResults(this.FindSharedSet(results), qry);
} }
return false; return false;
} } catch (err) {
catch (err)
{
Util.HandleError(err); Util.HandleError(err);
} }
return null;
}, },
GetSearchReferences: function(url, query) GetSearchReferences: function(url, query) {
{ try {
try
{
// getSearchRefs takes a url and uses ajax to retrieve the references and returns an array of references. // getSearchRefs takes a url and uses ajax to retrieve the references and returns an array of references.
var r; var r;
@ -761,33 +614,26 @@ var Words = {
type: "GET", type: "GET",
url: url, url: url,
dataType: "json", dataType: "json",
success: function(d, t, x) success: function(d, t, x) {
{
r = d; r = d;
}, },
error: function(request, status, error) error: function(request, status, error) {
{
Util.HandleError(error, request); Util.HandleError(error, request);
} }
}); });
// find the right word // find the right word
var refs = $.grep(r, function(o,i) var refs = $.grep(r, function(o,i) {
{
return o.word == query; return o.word == query;
}); });
return refs[0].refs; return refs[0].refs;
} } catch (err) {
catch (err)
{
Util.HandleError(err); Util.HandleError(err);
} }
return null;
}, },
BuildIndexArray: function() BuildIndexArray: function() {
{
try
{
var words = new Array(); var words = new Array();
words.unshift('abiram'); words.unshift('abiram');
words.unshift('accepteth'); words.unshift('accepteth');
@ -1037,25 +883,16 @@ var Words = {
words.unshift('zophim'); words.unshift('zophim');
words.unshift('zuzims'); words.unshift('zuzims');
return words; return words;
}
catch (err)
{
Util.HandleError(err);
}
}, },
FindSharedSet: function(results) FindSharedSet: function(results) {
{ try {
try
{
// FindSharedSet takes an array of reference arrays, and figures out which references are shared // 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. // by all arrays/sets, then returns a single array of references.
for (var j in results) for (var j in results) {
{
var refs = results[j]; var refs = results[j];
for (var i = 0; i < refs.length; i++) for (var i = 0; i < refs.length; i++) {
{
var r = refs[i].split(":"); var r = refs[i].split(":");
// convert references to single integers. // convert references to single integers.
// Book * 100000, Chapter * 1000, Verse remains same, add all together. // Book * 100000, Chapter * 1000, Verse remains same, add all together.
@ -1070,29 +907,24 @@ var Words = {
var result = results[0]; var result = results[0];
// for each additional result, get the shared set // for each additional result, get the shared set
for (i = 1; i < results.length; i++) for (i = 1; i < results.length; i++) {
{
result = this.ReturnSharedSet(results[i], result); result = this.ReturnSharedSet(results[i], result);
} }
// convert the references back into book, chapter and verse. // convert the references back into book, chapter and verse.
for (i = 0; i < result.length; i++) for (i = 0; i < result.length; i++) {
{
ref = result[i]; ref = result[i];
result[i] = parseInt(ref / 100000000)+":"+parseInt((ref % 100000000) / 10000)+":"+((ref % 100000000) % 10000); result[i] = parseInt(ref / 100000000)+":"+parseInt((ref % 100000000) / 10000)+":"+((ref % 100000000) % 10000);
} }
return result; return result;
} } catch (err) {
catch (err)
{
Util.HandleError(err); Util.HandleError(err);
} }
return null;
}, },
ReturnSharedSet: function(x, y) ReturnSharedSet: function(x, y) {
{ try {
try
{
/// <summary> /// <summary>
/// Takes two javascript arrays and returns an array /// Takes two javascript arrays and returns an array
/// containing a set of values shared by arrays. /// containing a set of values shared by arrays.
@ -1102,7 +934,7 @@ var Words = {
var i = 0; var i = 0;
// declare terminator // declare terminator
var t = (x.length < y.length) ? x.length : y.length var t = (x.length < y.length) ? x.length : y.length;
// sort the arrays // sort the arrays
x.sort(SortNumeric); x.sort(SortNumeric);
@ -1110,18 +942,14 @@ var Words = {
// in this loop, we remove from the arrays, the // in this loop, we remove from the arrays, the
// values that aren't shared between them. // values that aren't shared between them.
while (i < t) while (i < t) {
{ if (x[i] == y[i]) {
if (x[i] == y[i])
{
i++; i++;
} }
if (x[i] < y[i]) if (x[i] < y[i]) {
{
x.splice(i, 1); x.splice(i, 1);
} }
if (x[i] > y[i]) if (x[i] > y[i]) {
{
y.splice(i, 1); y.splice(i, 1);
} }
t = (x.length < y.length) ? x.length : y.length; t = (x.length < y.length) ? x.length : y.length;
@ -1139,10 +967,9 @@ var Words = {
// we could return y, because at this time, both arrays // we could return y, because at this time, both arrays
// are identical. // are identical.
return x; return x;
} } catch (err) {
catch (err)
{
Util.HandleError(err); Util.HandleError(err);
} }
return null;
} }
} };