1 2/** 3 * Original language options 4 * 5 * @author John Dyer (http://j.hn/) 6 */ 7 8docs.plugins.push({ 9 10 init: function(docManager) { 11 12 // create popup 13 var 14 wordAwaitingData = null, 15 selectedWord = null, 16 selectedWordVersion = '', 17 lemmaSelectedClass = 'lemma-selected', 18 popup = docs.createModal('lemma', docs.Localizer.get('plugin_lemma_title')), 19 timer = null, 20 startTimer = function() { 21 stopTimer(); 22 console.log('starting timer'); 23 timer = setTimeout(function() { 24 $('.' + lemmaSelectedClass).removeClass(lemmaSelectedClass); 25 popup.hide(); 26 }, 1000); 27 }, 28 stopTimer = function() { 29 if (timer != null) { 30 clearTimeout(timer); 31 timer = null; 32 } 33 }; 34 35 popup.size(300,200); 36 popup.content.css('overflow','auto'); 37 38 popup.footer.remove(); 39 popup.window 40 .on('mouseleave', function() { 41 startTimer(); 42 }) 43 .on('mouseover', function() { 44 stopTimer(); 45 }) 46 .on('click', '.strong-search', function() { 47 48 //console.log('lemma clikc'); 49 var strongSearch = $(this), 50 strongKey = strongSearch.attr('data-strong'); 51 52 docs.Search.searchVersion.val( selectedWordVersion ); // selectedWord.closest('.document-container').find('.document-header select').val() ); 53 docs.Search.searchInput.val( strongKey ); 54 docs.Search.searchWindow.show(); 55 docs.Search.doSearch(); 56 }) 57 .find('.popup-close') 58 .on('click', function() { 59 stopTimer(); 60 $('.' + lemmaSelectedClass).removeClass(lemmaSelectedClass); 61 }) 62 .end(); 63 64 // force load 65 //loadScripts('G'); 66 //loadScripts('H'); 67 68 // finds data on a <span class="word"> and gets its morph and lemma data 69 function getWordData(word) { 70 71 var lemma = word.attr('data-lemma'), 72 lemmaParts = lemma != null ? lemma.split(' ') : [],
73 morph = word.attr('data-morph'), 74 morphParts = morph != null ? morph.split(' ') : [], 75 wordData = [], 76 strongLetter = '', 77 strongInfo = '', 78 strongKey = '', 79 outline = '', 80 strongNumber = 0, 81 strongData = {}; 82 83 if (lemmaParts.length > 0) { 84 85 for (var i=0, il=lemmaParts.length; i<il; i++) { 86 strongInfo = lemmaParts[i].replace('strong:',''); 87 strongLetter = strongInfo.substring(0,1); 88 strongNumber = parseInt(strongInfo.substring(1), 10); 89 strongKey = strongLetter + strongNumber.toString(); 90 morph = (i< morphParts.length) ? morphParts[i].replace('robinson:','') : ''; 91 92 if (strongLetter == 'H') { 93 94 if (typeof strongsHebrewDictionary == 'undefined' || typeof strongsHebrewOutlines == 'undefined') { 95 loadScripts('H'); 96 return null; 97 } 98 99 strongData = strongsHebrewDictionary[strongKey]; 100 outline = strongsHebrewOutlines[strongKey]; 101 } else if (strongLetter == 'G') { 102 103 if (typeof strongsGreekDictionary == 'undefined' || typeof strongsGreekOutlines == 'undefined') { 104 loadScripts('G'); 105 return null; 106 } 107 108 strongData = strongsGreekDictionary[strongKey]; 109 outline = strongsGreekOutlines[strongKey]; 110 } 111 112 if (typeof strongData != 'undefined') { 113 wordData.push({ 114 strongLetter: strongLetter, 115 strongData: strongData, 116 strongKey: strongKey, 117 outline: outline, 118 morph: morph, 119 frequency: (strongLetter == 'G') ? strongsGreekFrequencies[strongKey] : strongsHebrewFrequencies[strongKey ], 120 formattedMorph: (strongLetter == 'G' && morph != '') ? bible.morphology.Greek.getMorphology( morph ): '' 121 }); 122 } 123 } 124 } 125 126 return wordData; 127 128 }; 129 130 131 // define mouseover and click events for words 132 docManager.content.on('mouseover', 'span.w', function() { 133 134 var word = $(this); 135 136 loadWordIntoFooter(word); 137 138 }).on('click', 'span.w', function() { 139 140 // remove exising highlight 141 $('.' + lemmaSelectedClass).removeClass(lemmaSelectedClass); 142 143 var word = $(this); 144 145 selectedWordVersion = word.closest('.document-container').find('.document-header select').val(); 146 147 loadWordIntoPopup(word); 148 }); 149 150 function loadWordIntoPopup(word) { 151 152 // if this word is clicked a second time 153 if (selectedWord != null && selectedWord.html() == word.html() && popup.window.is(':visible')) { 154 word.removeClass(lemmaSelectedClass); 155 popup.hide(); 156 return; 157 } 158 159 160 // hghlight this one 161 word.addClass(lemmaSelectedClass); 162 163 // get data for word 164 var 165 wordData = getWordData(word), 166 formattedWords = []; 167 168 if (wordData == null) { 169 170 popup.content.html( 'Loading data' ); 171 wordAwaitingData = word; 172 173 } else if (wordData.length > 0) { 174 175 // store for lemma search 176 selectedWord = word; 177 178 fillPopup(wordData); 179 180 } 181 182 183 if (wordData == null || wordData.length > 0) { 184 // measure position 185 var 186 wordPos = word.offset(), 187 wordWidth = word.width(), 188 wordHeight = word.height(), 189 popupWidth = popup.window.outerWidth(true), 190 popupHeight = popup.window.outerHeight(true), 191 windowWidth = $(window).width(), 192 windowHeight = $(window).height(), 193 windowScrollTop = $(window).scrollTop(), 194 // default to below and to the right 195 top = (wordPos.top + wordHeight + popupHeight - windowScrollTop > windowHeight) ? wordPos.top - popupHeight - 5 : wordPos.top + wordHeight + 4, 196 left = (wordPos.left + popupWidth > windowWidth) ? windowWidth - popupWidth : wordPos.left; 197 198 console.log(wordPos.top + wordHeight + popupHeight - windowScrollTop, windowHeight); 199 200 // place me! 201 popup.window.css({top: top, left: left}); 202 popup.show(); 203 204 stopTimer(); 205 206 $(document).one('mousemove', function() { 207 startTimer(); 208 }); 209 } 210 211 } 212 213 function loadWordIntoFooter(word) { 214 215 var 216 wordData = getWordData(word), 217 formattedWords = []; 218 219 if (wordData != null && wordData.length > 0) { 220 221 for (var i=0, il=wordData.length; i<il; i++) { 222 formattedWords.push( 223 '<span class="lex-entry">' + 224 '<span class="lemma ' + (wordData[i].strongLetter == 'H' ? 'hebrew' : 'greek') + '">' + wordData[i].strongData.lemma + '</span> (<span class="strongs-number">' + wordData[i].strongKey + '</span>) ' + 225 (wordData[i].formattedMorph != '' ? '<span class="morphology">' + wordData[i].formattedMorph + '</span>' : '') + 226 ' - <span class="definition">' + wordData[i].strongData.strongs_def + '</span>' + 227 '</span>' 228 ); 229 } 230 231 word 232 .closest('.document-container') 233 .find('.document-footer') 234 .html(formattedWords.join('; '));
235 } 236 } 237 238 function fillPopup(wordData) { 239 240 var formattedWords = []; 241 242 // format for popup 243 for (var i=0, il=wordData.length; i<il; i++) { 244 formattedWords.push( 245 '<span class="lex-entry lemma-popup">' + 246 '<span class="lemma ' + (wordData[i].strongLetter == 'H' ? 'hebrew' : 'greek') + '">' + wordData[i].strongData.lemma + '</span> (<span class="strongs-number">' + wordData[i].strongKey + '</span>) ' + 247 (wordData[i].formattedMorph != '' ? '<span class="morphology">' + wordData[i].formattedMorph + '</span>' : '') + 248 '<span class="definition">' + wordData[i].strongData.strongs_def + '</span>' + 249 (wordData[i].outline != null ? '<div class="outline">' + wordData[i].outline + '</div>' : '') + 250 '<span class="strong-search" data-strong="' + wordData[i].strongKey + '">Find all occurrences (approximately ' + wordData[i].frequency + ')</span>' + 251 '</span>' 252 ); 253 } 254 255 // put the content inside 256 popup.content.html( formattedWords.join('<br><br>') ); 257 258 } 259 260 function loadScripts(lang) { 261 262 263 var 264 loadingIndex = 0, 265 266 scripts = lang == 'G' ? 267 ['strongs-greek-dictionary.js', 'strongs-greek-frequencies.js','strongs-greek-outlines.js'] : 268 ['strongs-hebrew-dictionary.js', 'strongs-hebrew-frequencies.js','strongs-hebrew-outlines.js'], 269 270 objects = lang == 'G' ? 271 ['strongsGreekDictionary', 'strongsGreekFrequencies', 'strongsGreekOutlines'] : 272 ['strongsHebrewDictionary', 'strongsHebrewFrequencies', 'strongsHebrewOutlines']; 273 274 // start loading data files 275 //setTimeout(function() { 276 loadNext(); 277 //}, 1500); 278 279 function loadNext() { 280 281 if (loadingIndex >= objects.length) { 282 283 if (wordAwaitingData != null) { 284 var wordData = getWordData(wordAwaitingData); 285 fillPopup(wordData); 286 wordAwaitingData = null; 287 } 288 289 return; 290 } 291 292 if (typeof window[objects[loadingIndex]] == 'undefined') { 293 294 $.ajax({
295 url: 'content/lexicons/' + scripts[loadingIndex], 296 dataType: 'script', 297 cache: true, 298 success: function() { 299 loadingIndex++; 300 loadNext(); 301 } 302 303 }); 304 305 } else { 306 // the script was already loaded so go to next 307 loadingIndex++; 308 loadNext(); 309 } 310 311 } 312 } 313 314 315 } 316});
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.