From 7d0482cbb1063ee6f1097454eb51062719c6ff1a Mon Sep 17 00:00:00 2001 From: walljm Date: Wed, 2 Jan 2013 16:50:24 -0500 Subject: [PATCH] tweaked json text conversion to make smaller. switched out text parsing from xml to json. --- DynamicBibleUtility/DynamicBibleUtility.suo | Bin 30720 -> 30720 bytes .../DynamicBibleUtility/Text.cs | 13 +- .../DynamicBibleUtility/frmMain.cs | 27 ++--- js/common.js | 113 +++++++++++------- 4 files changed, 84 insertions(+), 69 deletions(-) diff --git a/DynamicBibleUtility/DynamicBibleUtility.suo b/DynamicBibleUtility/DynamicBibleUtility.suo index 23f0459f4c2e46955bd427191ba8975dc372e4b7..ec1bde4c296e2d2f28ba380be97e1e3601582cdd 100644 GIT binary patch delta 1310 zcmZqpz}WDCaf1&FqwHiw7I`*@+h(O&FEknG5LTX%j6%d z1}y*n|NlQ(hs}c3kb!|gdU7U{ay>{$m4Sf)M5{9}FlaC^FlaI`FhnviFvK!2FvLOS zK=S%XY$FB+24e;W1``Gb22%zG1~Uc*26F}m1`7rT21^D81}g>z20sP{h8hM223rOO zhExUy273ku1`h@X21f=41}6pv24@C_$=vLs^%)Ed3|Mk31FT4OT?3vQ3)h? zsz_&Yi742K+#vJgm_W{9m|QP;fAT#crO6FaVUxqewI(0Xd&Kx=a=e-BBxwg$W(Ed^ zXOkIittTIl)|k9OQi46=JQqmcJ6EK^s4}@! zCYVJU%ANd0#(%Q2sO{ti*)NP*lS}3PvuQIhFg#(LTqW-}`Bae(qt4{7^7V|mlS>u; zGwMw)RrKc&V_;yAgX-tDVPIh3VgxyrVY0p0!N~`d92lQWW=yD`l+Z9q#bvUKtij|G z6@N}fH3kL-9;mL#UsS*W#Ae69z@Wi6xk}ZGLxq8XK>#Yh`HLzK(_|xihs_Qe4vdq8 zof(-X8)Vr`(mKq^sKda(pbS+v`HNNnha$)YFo6>75EeEV=Zm&KC!;t60|O{UfU+T@ z!Q@h%dNz<#ZZJ;%rQ^xT2nu-_n1&MFp2_-}GLz>C6;I|7)1R!BtppA{5s-q@nx>O$ zgpNyI|cS^hzr+7iMF*g?e+ zOsy^(1H)QX28L(a3=Ce33=B593=GE^85m&lsSFhiC2;41-1~;XnZb%-l7+-%Bb!~5 m_hpD}&M>{AF?mIt$ixJf%~Rq`Bv^Ps&OKM8vH43G4)y)mvPc|2^1Tu0m2r)1)2r@7*Og>knG5LTX%j6%d z1}yy`0Ub6ARw)Js2IbU2g-$yq_!H4F?4wovxuA8Z=+AW1I<1_o~i1_mDn1_oaS z28Ld!f&c~vhCl`eh9Cw8h8YYD3?U2*4517R3}I0D2nGg*NCpOmCX`K8|P$;{GwCyBUlfTB|ps%CPD zNC1a40|Ns$RDca6BgQuQmx$+NXIb0H4WiDRj9gG3fszN01}I3G7{Fli0cnRxN(Uw% zka8AgW^g*p=wfAHWnfipU~J^<RLKk80s2Ym~CzlYG9n)BBnN3 zO>BpfE`tGs0fQrh0fRGxC4&Kj8yGq>7&Fu|=rN=)lru~c51Smxp*6Wd!eR0Z37*M4 z5(<+au!ykoGB7Y)nrvvKIJv=0YLcYJa$)$4t*~}Oi7#46&u9Ej-QGu#rG@txczMj!ya;d_9M$5^iivAn| z3=9miP-%V}1_p*&aHugbM4acE9LQlixk1uHGKV3R!Ir_9A%`K8A(bJIp@abxzl;nF zlj|krCm&F9V2qf2ASXg2-gGKY^QE0{d7Tq3t>j-X@sfps;XfK+$YiLRd?3eb@|0`? z)*P34uF{iKTv+5lPB>MhGr2^?pOZm`fq{VqBmzo+UsU`#89|1qK}Fc?7#JAlGfb{h z_2K}D3q!>>e^KROn!LHlVUiHbW)}?`MmAPMJp(<%$$=bJ+=d1wt`;ti&W5!$lV9kW zPSQHe2`(Cxp_(Uu(F&OCB5O0bLEB@phlwIzDD5yXFf3$XU|7V!z_6Hsfnf chs = new List(); } public class Chapter { - public string ch = ""; + public int ch = -1; public List vss = new List(); } public class Verse { - public string vs = ""; - public List words = new List(); + public int v = -1; + public List w = new List(); } public class Text { - public string txt = ""; - public string str = ""; - public int i = -1; + public string t = ""; + public string s = ""; } } diff --git a/DynamicBibleUtility/DynamicBibleUtility/frmMain.cs b/DynamicBibleUtility/DynamicBibleUtility/frmMain.cs index 125ed6b1..ef0efde8 100644 --- a/DynamicBibleUtility/DynamicBibleUtility/frmMain.cs +++ b/DynamicBibleUtility/DynamicBibleUtility/frmMain.cs @@ -273,32 +273,25 @@ namespace DynamicBibleUtility if (el.Name == "BIBLEBOOK") { Book bk = new Book(); - bk.bk = el.FirstAttribute.Value.ToString(); + bk.bk = Convert.ToInt32(el.FirstAttribute.Value.ToString()); foreach (XElement chn in el.Nodes()) { Chapter ch = new Chapter(); - ch.ch = chn.FirstAttribute.Value; + ch.ch = Convert.ToInt32(chn.FirstAttribute.Value); foreach (XElement vs in chn.Nodes()) { Verse v = new Verse(); - v.vs = vs.FirstAttribute.Value; + v.v = Convert.ToInt32(vs.FirstAttribute.Value); int i = 0; foreach (object o in vs.Nodes()) { Text t = new Text(); if (o.GetType() == typeof(XElement)) { - t.txt = ((XElement)o).Value; + t.t = ((XElement)o).Value; if (((XElement)o).Name == "gr") { - if (Convert.ToInt32(bk.bk) >= 40) - { - t.str = "G" + ((XElement)o).FirstAttribute.Value; - } - else - { - t.str = "H" + ((XElement)o).FirstAttribute.Value; - } + t.s = ((XElement)o).FirstAttribute.Value; } else if ((((XElement)o).Name.ToString().ToLower() == "style")) { @@ -308,24 +301,24 @@ namespace DynamicBibleUtility { throw new Exception("Unknown Element"); } - t.i = i++; + //t.i = i++; } else if (o.GetType() == typeof(XText)) { - t.txt = ((XText)o).Value; - t.i = i++; + t.t = ((XText)o).Value; + //t.i = i++; } else { throw new Exception("Unknown Element"); } - v.words.Add(t); + v.w.Add(t); } ch.vss.Add(v); } bk.chs.Add(ch); - System.IO.File.WriteAllText(bk.bk.ToString() + "-"+ch.ch+".json", Serialize(ch)); + System.IO.File.WriteAllText(bk.bk.ToString() + "-" + ch.ch + ".json", Serialize(ch).Replace(",\"s\":\"\"", "")); } bbl.Add(bk); diff --git a/js/common.js b/js/common.js index b8c07aa9..33fbbaf6 100644 --- a/js/common.js +++ b/js/common.js @@ -3,19 +3,18 @@ function SortNumeric(x, y) return x - y } -String.prototype.trim = function() -{ - return this.replace(/^\s+|\s+$/g, ""); -} -String.prototype.ltrim = function() -{ - return this.replace(/^\s+/, ""); -} -String.prototype.rtrim = function() -{ - return this.replace(/\s+$/, ""); -} - + String.prototype.trim = function() + { + 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) { try @@ -127,7 +126,10 @@ function Search(sv) } } - $( "#result" ).sortable({ axis: "x", handle: ".handle" }); + $( "#result" ).sortable({ + axis: "x", + handle: ".handle" + }); } catch (err) { @@ -267,7 +269,7 @@ var Bible = { { var r = ""; // make the end verse pretty. - var tvs = cs[cs.length - 1].vs.length; + var tvs = cs[cs.length - 1].vss.length; if (ev == "*" || ev > tvs) { @@ -280,20 +282,30 @@ var Bible = { { r += "Chapter: " + cs[j].ch + "
"; } - var vs = cs[j].vs; + var vss = cs[j].vss; - for (var m = 0; m < vs.length; m++) + for (var m = 0; m < vss.length; m++) { - var v = vs[m]; + var v = vss[m]; - r += "" + $(v).attr("n") + ". "; + r += "" + v.v + ". "; - for (var w = 0; w < v.childNodes.length; w++) + for (var w = 0; w < v.w.length; w++) { - r += Traverse(v.childNodes[w], testament); + 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 += "" + v.w[w].t.trim() + ""+sp; + } + else + { + r += v.w[w].t; + } } - - r += "
"; } } @@ -318,24 +330,21 @@ var Bible = { { try { - var xml = []; // the verses from the chapter. + var chapters = []; // the verses from the chapter. var cs = []; // the verses requested. var r = {}; for (var i = sch; i <= ech; i++) { - var url = "xml/" + b + "-" + i + ".xml" + var url = "bibles/kjv_strongs/" + b + "-" + i + ".json" $.ajax({ async: false, type: "GET", url: url, - dataType: "xml", + dataType: "json", success: function(d, t, x) { - xml.push({ - "ch": i, - "vs": d - }); + chapters.push(d); }, error: function(request, status, error) { @@ -344,9 +353,9 @@ var Bible = { }); } - for (var j = 0; j < xml.length; j++) + for (var j = 0; j < chapters.length; j++) { - var vs = []; + var vss = []; var start; var end; @@ -359,8 +368,9 @@ var Bible = { { start = 1; } - - if ((j + 1) == xml.length) + + // figure out the end verse + if ((j + 1) == chapters.length) { end = ev; } @@ -369,27 +379,34 @@ var Bible = { end = "*"; } - var tvs = $(xml[j].vs).find("v").length; - // get the verses requested. + var tvs = chapters[j].vss.length; if (end == "*" || end > tvs) { end = tvs; } - for (var i = start; i <= end; i++) + for (i = start; i <= end; i++) { - vs.push($(xml[j].vs).find('v[n="' + i + '"]')[0]) + // 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": xml[j].ch, - "vs": vs + "ch": chapters[j].ch, + "vss": vss }); } r.cs = cs; - r.testament = $(xml[0].vs).find("b").attr("testament"); + if (b >= 40) + { + r.testament = "new"; + } + else + { + r.testament = "old"; + } return r; } catch (err) @@ -581,12 +598,18 @@ var Strongs = { var t = Strongs.BuildStrongs(r); var d = $("
").append(t); - d.dialog({draggable:true, width: 600, height: 500, resizable: true, title: "Strongs Definition", + d.dialog({ + draggable:true, + width: 600, + height: 500, + resizable: true, + title: "Strongs Definition", buttons: { - "Close": function() { - $( this ).dialog( "close" ); + "Close": function() { + $( this ).dialog( "close" ); + } } - }}); + }); return false; } catch (err)