1/* temporarily stores locations when settings are changed */ 2var PlaceKeeper = (function() { 3 4 var currentWindow = null, 5 currentData = null; 6 7 function storePlace() { 8 currentData = getFirstLocation(); 9 } 10 11 function getFirstLocation() { 12 currentWindow = (sofia.app.windowManager) ? 13 sofia.app.windowManager.getWindows().filter(function(w) { return w.className == 'BibleWindow'})[0] : 14 null; 15 16 var data = (currentWindow != null) ? currentWindow.getData() : null; 17 18 return data; 19 } 20 21 function restorePlace() { 22 if (currentWindow != null) { 23 // 24 //firstWindow.trigger('message', {type:'globalmessage', messagetype: 'nav', }) 25 26 currentWindow.trigger('globalmessage', { 27 type: 'globalmessage', 28 target: currentWindow, 29 data: { 30 messagetype: 'nav', 31 type: 'bible', 32 locationInfo: currentData // firstWindow.getData() 33 } 34 }); 35 } 36 37 } 38 39 return { 40 storePlace: storePlace, 41 restorePlace: restorePlace, 42 getFirstLocation: getFirstLocation 43 } 44 45})(); 46 47/* stores locations for back/foward buttons on browser */ 48var TextNavigation = (function() { 49 50 var locations = [], 51 locationIndex = -1; 52 53 $(window).on('popstate', handleBrowserNavigation); 54 55 function handleBrowserNavigation(e) { 56 console.log('handleNavigation', e, e.state); 57 58 if (e.originalEvent && e.originalEvent.state != null && typeof e.originalEvent.state.locationid != 'undefined') { 59 60 var newlocationid = e.originalEvent.state.locationid, 61 type = ''; 62 63 64 if (locationIndex-1 > -1 && locations[locationIndex-1] == newlocationid) { 65 locationIndex--; 66 type = 'back'; 67 } else if (locationIndex+1 < locations.length && locations[locationIndex+1] == newlocationid) { 68 locationIndex++; 69 type = 'forward'; 70 } 71 72 setLocation(newlocationid); 73 74 textNavigation.trigger('locationchange', {type: type}); 75 } 76 77 } 78 79 80 // upon startup, store the first place 81 function firstState(locationid) { 82 console.log('firststate',locationid); 83 84 locations.push(locationid); 85 locationIndex = 0; 86 87 window.history.replaceState({"locationid": locationid}, null, window.location.href); 88 } 89 90 // each additional change 91 function locationChange(locationid, type) { 92 93 // slice off anything after this one 94 while (locationIndex > locations.length-1) { 95 locations.pop(); 96 } 97 98 locations.push(locationid); 99 locationIndex++; 100 101 window.history.pushState({"locationid": locationid}, null, window.location.href); 102 103 104 textNavigation.trigger('locationchange', {type: type}); 105 } 106 107 108 function setLocation(locationid) { 109 // break off and be sure to add the trailing verse 1 (JN1_1) 110 var fragmentid = locationid.indexOf('_') > -1 ? locationid : locationid + '_1', 111 sectionid = fragmentid.split('_')[0]; 112 113 sofia.app.handleGlobalMessage({ 114 type: 'globalmessage', 115 target: this, 116 data: { 117 messagetype:'nav', 118 type: 'bible', 119 locationInfo: { 120 fragmentid: fragmentid, 121 sectionid: sectionid, 122 offset: 0 123 } 124 } 125 }); 126 } 127 128 function back() { 129 130 window.history.go(-1); 131 132 /* 133 if (locationIndex > 0) { 134 locationIndex--; 135 var locationid = locations[locationIndex]; 136 setLocation(locationid); 137 } 138 */ 139 } 140 141 function forward() { 142 143 window.history.go(1); 144 145 146 /* 147 if (locationIndex < locations.length-1) { 148 // get this location 149 locationIndex++; 150 var locationid = locations[locationIndex]; 151 setLocation(locationid); 152 } 153 */ 154 } 155 156 function getLocations() { 157 return locations; 158 } 159 160 function getLocationIndex() { 161 return locationIndex; 162 } 163 164 165 var textNavigation = { 166 locationChange: locationChange, 167 firstState: firstState, 168 forward: forward, 169 back: back, 170 getLocationIndex: getLocationIndex, 171 getLocations: getLocations 172 } 173 174 textNavigation = $.extend(true, textNavigation, EventEmitter); 175 176 return textNavigation; 177})();
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.