1 2var TextComparisonWindow = function(id, parent, init_data) { 3 4 //console.log('text comparisino', init_data ); 5 6 7 var header = $('<div class="window-header" >' + 8 '<input type="text" class="app-input comparison-fragmentid" value="" />' + 9 '<input type="text" class="app-input comparison-texts" value="NR, ND" />' + // lpnrmw 10 // '<input type="button" value="GO" data-i18n="[value]windows.comparison.button" class="comparison-button header-button i18n" />' + 11 '<input type="button" value="VAI" data-i18n="[value]windows.comparison.button" class="comparison-button header-button i18n" />' + // lpnrmw 12 '</div>').appendTo(parent.node), 13 main = $('<div class="comparison-main">' + 14 '</div>').appendTo(parent.node), 15 footer = $('<div class="comparison-footer">' + 16 '</div>').appendTo(parent.node) 17 18 inputFragment = header.find('.comparison-fragmentid'), 19 inputTexts = header.find('.comparison-texts'), 20 goButton = header.find('.comparison-button'); 21 22 23 inputFragment.on('keydown', handleEnter); 24 inputTexts.on('keydown', handleEnter); 25 26 goButton.on('click', function() { 27 //console.log('clicked'); 28 doComparison(); 29 }); 30 31 32 function init() { 33 34 inputFragment.val( init_data.fragmentid ? init_data.fragmentid : init_data.params.fragmentid ? init_data.params.fragmentid : ''); 35 inputTexts.val( init_data.textids ? init_data.textids : init_data.params.textids ? init_data.params.textids : '' ); 36 37 doComparison(); 38 39 } 40 41 function handleEnter(e) { 42 if (e.which == 13) { 43 doComparison(); 44 } 45 } 46 47 var sectionid = '', 48 reference = '', 49 textAbbrs = '', 50 textids = [], 51 textIndex = -1, 52 textData = [], 53 textInfoData = null, 54 isComparing = false; 55 56 function doComparison() { 57 58 if (isComparing) { 59 return; 60 } 61 //console.log('iscomp'); 62 isComparing = true; 63 64 main.html(); 65 main.addClass('loading-indicator'); 66 67 68 reference = new bible.Reference(inputFragment.val()); 69 if (typeof reference.toSection == 'undefined') { 70 isComparing = false; // lpnrmw 71 return; 72 } 73 //inputFragment.val( reference.toString() ); // lpnrmw 74 sectionid = reference.toSection().split('_')[0]; // 'JN1'; 75 textAbbrs = inputTexts.val().split(','); 76 textids = []; 77 textIndex = -1; 78 textData = []; 79 80 TextLoader.loadTexts(function(tid) { 81 textInfoData = tid; 82 83 84 for (var i=0, il=textAbbrs.length; i<il; i++ ) { 85 var abbr = textAbbrs[i].trim().toLowerCase(); 86 87 if (abbr != '') { 88 89 var possibleTexts = textInfoData.filter(function(t) { 90 91 return t.abbr.toLowerCase().indexOf(abbr) > -1; 92 }); 93 94 if (possibleTexts.length > 0) { 95 textids.push(possibleTexts[0].id); 96 } 97 } 98 } 99 100 getNextText(); 101 102 }); 103 104 105 106 } 107 108 //var textids = ['eng-NASB1995', 'eng_net', 'eng_web']; // , 'esv']; 109 110 function getNextText() { 111 112 textIndex++; 113 114 if (textIndex < textids.length) { 115 116 var textid = textids[textIndex]; 117 118 TextLoader.getText(textid, function(textInfo) { 119 120 121 TextLoader.loadSection( textInfo, sectionid, function(content) { 122 //TextLoader.loadSection( textid, sectionid, function(content) { 123 124 textData.push({textInfo: textInfo, 125 content: content}); 126 127 getNextText(); 128 129 }); 130 }); 131 132 //} else if (textIndex == textids.length+1){ 133 } else { 134 135 // complete! 136 processData(); 137 } 138 139 } 140 141 142 143 function processData() { 144 145 if (textData.length <= 1) { 146 147 main.removeClass('loading-indicator'); 148 isComparing = false; // lpnrmw 149 return; 150 151 } 152 153 154 var html = '<table class="comparison-table section">'; // using 'section' to get fonts and such 155 156 // heading 157 html += '<thead>'; 158 html += '<th></th>'; 159 for (var i=0, il = textData.length; i<il; i++) { 160 html += '<th>' + textData[i].textInfo.abbr + '</th>'; 161 } 162 html += '</thead>'; 163 164 html += '<tbody>'; 165 166 var startVerse = reference.verse1 > 0 ? reference.verse1 : 1, 167 endVerse = reference.verse2 > 0 ? reference.verse2 : bible.BOOK_DATA[ reference.bookid ].chapters[reference.chapter]; 168 169 for (var verse=startVerse; verse<=endVerse; verse++) { 170 171 var verseid = sectionid + '_' + verse.toString(), 172 baseText = getPlainText(textData[0].content, verseid); 173 174 html += '<tr>'; 175 176 html += '<th>' + verse + '</th>'; 177 178 html += '<td class="reading-text" style="width:' + (100/textData.length) + '%">' + baseText + '</td>'; 179 180 181 // comparison 182 for (var i=1, il = textData.length; i<il; i++) { 183 var comparisonText = getPlainText(textData[i].content, verseid); 184 185 html += '<td class="reading-text" style="width:' + (100/textData.length) + '%">' + 186 rejoinPunctuation( 187 diffString( 188 separatePunctuation(baseText) 189 , 190 separatePunctuation(comparisonText) 191 ) 192 ) + 193 '</td>'; 194 195 } 196 197 198 html += '<tr>'; 199 } 200 201 202 203 html += '</tbody>'; 204 205 206 html += '</table>'; 207 208 main.html(html); 209 210 main.removeClass('loading-indicator'); 211 212 // trigger settings change 213 ext.trigger('settingschange', {type: 'settingschange', target: this, data: getData() }); 214 215 isComparing = false;
216 } 217 218 function separatePunctuation(input) { 219 220 return input.replace(/([\.,;])/gi,' $1'); // ââââ 221 } 222 223 function rejoinPunctuation(input) { 224 225 // fix HTML 226 input = input.replace(/\s+<\/([^>]+)>/gi,'</$1> '); 227 228 // connect 229 input = input.replace(/<\/ins>\s+<ins>/gi,' '); 230 input = input.replace(/<\/del>\s+<del>/gi,' '); 231 232 // fix punctuation 233 input = input.replace(/\s+([\.,;])/gi,'$1'); // ââ 234 235 return input; 236 } 237 238 239 function getPlainText(content, verseid) { 240 241 var verseNodes = content.find('.' + verseid), 242 plainText = ''; 243 244 for (var i=0, il=verseNodes.length; i<il; i++) { 245 246 var verseNode = $(verseNodes[i]); 247 248 verseNode.find('.note, .cf, .v-num, .verse-num').remove(); 249 250 var text = verseNode.html(); 251 252 text = text.replace(/<[^>]+>/gi,''); 253 254 plainText += text + ' '; 255 } 256 257 return plainText; 258 259 } 260 261 262 263 264 265 266 function size(width, height) { 267 main 268 .width(width) 269 .height(height - footer.outerHeight() - header.outerHeight() ); 270 } 271 272 function getData() { 273 274 var 275 data = { 276 params: { 277 win: 'comparison', 278 textids: inputTexts.val(), 279 fragmentid: inputFragment.val() 280 } 281 }; 282 283 return data; 284 } 285 286 function close() { 287 288 ext.clearListeners(); 289 } 290 291 var ext = { 292 size: size, 293 getData: getData, 294 sendMessage: function() { 295 // nothing for now 296 }, 297 close: close 298 }; 299 ext = $.extend(true, ext, EventEmitter); 300 301 302 ext.on('message', function(e) { 303 // nothing for now 304 }); 305 306 init(); 307 308 return ext; 309}; 310 311sofia.initMethods.push(function() { 312 313 sofia.windowTypes.push( { 314 className:'TextComparisonWindow', 315 param: 'comparison', 316 paramKeys: { 317 'textids': 't', 318 'fragmentid': 'f' 319 }, 320 init: { 321 textids: 'NR, CEI1974', // lpnrmw 322 fragmentid: 'Gen 1:1-2' // lpnrmw 323 } 324 }); 325});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.