1/** 2 * Main Document Application 3 * 4 * @author John Dyer (http://j.hn/) 5 */ 6 7jQuery(function($) { 8 9 if (typeof window.console == 'undefined') 10 window.console = {log:function() {}}; 11 12 // updates languages 13 docs.Localizer.localize(); 14 15 // setup main site areas 16 docs.DocManager.init($('#header'), $('#footer'), $('#content'), $(window)); 17 18 // test for AJAX capabilities 19 $.ajax({ 20 url: 'mobile.html', 21 22 dataType: 'text', 23 24 error: function(e) { 25 26 var modal = docs.createModal('error', '<strong>Error</strong>: Browser doesn\'t support local files').size(500,300).center(); 27 28 modal.content.html( 29 '<p>Windows, Start, Run</p>' + 30 '<code>"%UserProfile%\\AppData\\Local\\Google\\Chrome\\Application\\chrome.exe" --allow-file-access-from-files</code>' + 31 '<p>Mac, Terminal</p>' + 32 '<code>/Applications/Google\\ Chrome.app/Contents/MacOS/Google\\ Chrome --allow-file-access-from-files</code>' 33 ); 34 modal.show(); 35 36 //alert('Your browser does not support loading local files. If you are using Chrome, you need to launch it with --allow-file-access-from-files ') 37 }, 38 39 success: function() { 40 41 // load versions, then start doing other stuff 42 bible.versions.getVersions(function(versions) { 43 44 //console.log('versions', versions); 45 46 if (bible.versions.versionKeys.length == 0) { 47 var modal = docs.createModal('error', '<strong>Error</strong>: No Bibles installed').size(500,300).center(); 48 49 modal.content.html( 50 '<p>No Bibles were found on this installation.</p>' + 51 '<p> To get started, go to <a href="https://github.com/digitalbiblesociety/browserbible/" target="_blank">github.com/digitalbiblesociety/browserbible</a> to download publicly available texts, and install them in the following folder:</p> <code>/app/content/bibles/</code>' 52 ); 53 modal.show(); 54 55 return; 56 } 57 58 var defaultDocSettings = (docs.Features.hasTouch) ? 59 { 60 docs: [ 61 { 62 version: 'eng_nasb', 63 location: 'John.3.1', 64 linked: true 65 } 66 ] 67 } 68 : 69 { 70 docs: [ 71 { 72 version: 'eng_nasb', 73 location: 'John.3.1', 74 linked: true 75 }, 76 { 77 version: 'eng_sblgnt', 78 location: 'John.3.1', 79 linked: true 80 } 81 ] 82 }; 83 84 // load cookie/localStorage settings 85 var docSettings = $.jStorage.get('docs-settings', defaultDocSettings); 86 87 88 89 // get from URL 90 function parseQuerystring(querystring) { 91 // remove any preceding url and split 92 querystring = querystring.substring(querystring.indexOf('?')+1).split('&'); 93 var params = {}, pair, d = decodeURIComponent; 94 // march and parse 95 for (var i = querystring.length - 1; i >= 0; i--) { 96 pair = querystring[i].split('='); 97 params[d(pair[0])] = d(pair[1]); 98 } 99 100 return params; 101 }; 102 103 function convertQuerystringToSettings( querystringParams, max) { 104 105 var queryDocs = []; 106 107 if (querystringParams['location1'] != 'undefined') { 108 109 for (var i=1; i<=max; i++) { 110 var 111 version = querystringParams['document' + i.toString()], 112 location = querystringParams['location' + i.toString()], 113 linked = querystringParams['linked' + i.toString()]; 114 115 if (typeof version != 'undefined' && typeof location != 'undefined') { 116 queryDocs.push({ 117 version: version, 118 location: location, 119 linked: linked 120 });
121 } 122 } 123 } 124 125 return queryDocs; 126 } 127 128 // test ?location=1 129 if (window.location.search.length > 0) { 130 131 var querystringParams = parseQuerystring( window.location.search.substring(1) ); 132 var queryDocs = convertQuerystringToSettings( querystringParams , 3); 133 134 if (queryDocs.length > 0) { 135 docSettings.docs = queryDocs; 136 } 137 } 138 139 // test #location=1 140 if (window.location.href.indexOf('#') > -1) { 141 var hashParams = parseQuerystring( window.location.href.substring( window.location.href.indexOf('#') + 1) ); 142 var hashDocs = convertQuerystringToSettings( hashParams , 3); 143 144 if (hashDocs.length > 0) { 145 docSettings.docs = hashDocs; 146 } 147 } 148 149 150 // LOAD interface 151 docs.DocManager.loadSettings(docSettings); 152 153 154 155 156 157 docs.DocManager.addEventListener('navigation', function(e) { 158 docs.DocManager.saveSettings(); 159 }); 160 161 // startup plugins 162 for (var i=0, il=docs.plugins.length; i<il; i++) { 163 docs.plugins[i].init( docs.DocManager); 164 } 165 166 // search 167 docs.Search = (function() { 168 169 var searchWindow = docs.createModal('search', 'Search'), 170 171 searchInput = $('<input type="text" class="search-text" />').appendTo(searchWindow.menu), 172 searchVersion = $('<select class="search-version">' + bible.BibleNavigator.getOptions() + '</select>').appendTo(searchWindow.menu), 173 searchButton = $('<input type="button" class="search-button" value="Search" />').appendTo(searchWindow.menu), 174 cancelButton = $('<input type="button" class="cancel-button" value="Cancel" disabled />').appendTo(searchWindow.menu), 175 printButton = $('<input type="button" class="print-button" value="Print" />').appendTo(searchWindow.menu); 176 177 178 searchWindow.footer.html(' -'); 179 searchWindow.size(580,400).center(); 180 searchWindow.content.css({'overflow': 'auto'}); 181 182 $(window).on('resize', function() { 183 searchWindow.center(); 184 }); 185 186 searchInput.on('keyup', function(e) { 187 if (e.keyCode === 13) 188 doSearch(); 189 }); 190 searchButton.on('click', function() { 191 doSearch(); 192 }); 193 cancelButton.on('click', function() { 194 bible.BibleSearch.cancelSearch(); 195 }); 196 197 198 printButton.on('click', function() { 199 200 var printWin = window.open('','','letf=0,top=0,width=1,height=1,toolbar=0,scrollbars=0,status=0');
201 printWin.document.write('<!DOCTYPE html><html><head>' + 202 '<link href="css/studybible.css" rel="stylesheet">' + 203 '</head><body>' + searchWindow.content[0].innerHTML + '</body></html>'); 204 printWin.document.close(); 205 printWin.focus(); 206 printWin.print(); 207 printWin.close(); 208 }); 209 210 searchWindow.content.on('click', 'span.verse', function() { 211 212 docs.DocManager.documents[0].navigateById($(this).attr('data-osis') , true); 213 214 //searchWindow.hide(); 215 }); 216 217 218 function doSearch() { 219 220 if (window.location.href.indexOf('file:') == -1) { 221 222 console.warn('this will be slow'); 223 224 } 225 226 var input = searchInput.val(), 227 version = searchVersion.val(); 228 229 console.log(input, version); 230 231 searchWindow.content.empty(); 232 cancelButton.prop('disabled', false); 233 234 bible.BibleSearch.search( input, version, 235 236 // chapter progress 237 function(bookOsisID, chapterIndex, resultsCount, startDate) { 238 239 //if (showFeedback) { 240 searchWindow.footer.html('found: ' + resultsCount + '; time: ' + (( new Date() - startDate)/1000) + '; searching: ' + bible.BOOK_DATA[ bookOsisID ].names['eng'][0] + ' ' + (chapterIndex+1).toString() ) 241 //searchProgress.width( (bookIndex+1)/66 * sbw ); 242 //} 243 244 }, 245 246 // ended 247 function(resultHtml, resultsCount, startDate) { 248 249 searchWindow.content.html(resultHtml); 250 251 searchWindow.footer.html('found: ' + resultsCount + '; time: ' + (( new Date() - startDate)/1000) + ''); 252 253 cancelButton.prop('disabled', true); 254 255 //searchButton.prop('disabled', false); 256 //searchText.prop('disbled', false); 257 } 258 ); 259 } 260 261 return { 262 searchVersion: searchVersion, 263 searchWindow: searchWindow, 264 searchInput: searchInput, 265 doSearch: doSearch 266 } 267 268 })(); // search function creation 269 270 }); // getversions callback 271 272 } // main AJAX test success callback 273 }); 274 275});
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.