457 lines
16 KiB
JavaScript

var Words = (function () {
function Words() {
}
Words.ConvertResultsToArray = function (r) {
try {
var results_1 = new Array();
$(r).each(function () {
results_1.push([$(this).attr("b"), $(this).attr("ch"), $(this).attr("v")]);
});
return results_1;
}
catch (err) {
Util.HandleError(err);
}
return null;
};
Words.DisplayResults = function (results, q) {
try {
var txt = "<h4>Query: <a href='javascript:void(0)' 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(0)' class='link' alt='" + Reference.bookName(r[0]) + " " + r[1] + ":" + r[2] + "'>" + Reference.bookName(r[0]) + " " + r[1] + ":" + r[2] + "</a>";
}
txt += "</ul>";
var t = $("#searchresults");
t.html(txt);
Words.AttachEvents(t);
$("#searchTotal").html(results.length);
return false;
}
catch (err) {
Util.HandleError(err);
}
return null;
};
Words.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 (var 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("data/index/" + words[w] + "idx.json", q));
break;
}
}
else {
if (q <= words[w] && q > words[w - 1]) {
results.unshift(this.GetSearchReferences("data/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;
};
Words.GetSearchReferences = function (url, query) {
try {
// getSearchRefs takes a url and uses ajax to retrieve the references and returns an array of references.
var r_1;
$.ajax({
async: false,
type: "GET",
url: url,
dataType: "json",
success: function (d, t, x) {
r_1 = d;
},
error: function (request, status, error) {
Util.HandleError(error);
}
});
// find the right word
var refs = $.grep(r_1, function (o, i) {
return o.word == query;
});
if (refs.length > 0) {
return refs[0].refs;
}
else {
return [];
}
}
catch (err) {
Util.HandleError(err);
}
return [];
};
Words.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;
};
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 (var i = 1; i < results.length; i++) {
result = this.ReturnSharedSet(results[i], result);
}
// convert the references back into book, chapter and verse.
for (var i = 0; i < result.length; i++) {
var ref = result[i];
result[i] = (ref / 100000000) + ":" + ((ref % 100000000) / 10000) + ":" + ((ref % 100000000) % 10000);
}
return result;
}
catch (err) {
Util.HandleError(err);
}
return null;
};
Words.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;
};
Words.AttachEvents = function (t) {
t.find(".link").click(function (e) {
Util.HandleLink(e);
});
};
return Words;
}());
;
//# sourceMappingURL=Words.js.map