1(function ($) { 2 3 "use strict"; 4 5 $(document).on('onEventToggleOpen', function (e, data) { 6 7 if ( data.event.location == '' ) { 8 return; 9 } 10 11 var glob = data.glob; 12 var $instance = data.$instance; 13 var helper = data.helper; 14 15 var event = data.event; 16 var $event = $instance.$events.find('.stec-layout-event.active'); 17 var $inner = $event.find('.stec-layout-event-inner-location'); 18 19 $inner.html(function (index, html) { 20 21 return html 22 .replace(/stec_replace_location/g, event.location) 23 .replace(/stec_replace_details/g, event.location_details); 24 }); 25 26 if ( $.trim($inner.find('.stec-layout-event-inner-location-details').text()) == "" ) { 27 $inner.find('.stec-layout-event-inner-location-optional-details').hide(); 28 } 29 30 /** 31 * @todo Instance or Single? 32 */ 33 var gmap = function () { 34 35 this.$tabCont = ""; 36 this.directionsService = ""; 37 this.directionsDisplay = ""; 38 this.map = ""; 39 this.geocoder = ""; 40 this.mapDiv = ""; 41 this.marker = ""; 42 this.address = ""; 43 44 this.init = function ($el) { 45 46 var parent = this; 47 48 parent.mapDiv = $el.get(0); 49 50 parent.map = new window.google.maps.Map(parent.mapDiv, { 51 zoom: 15 52 }); 53 54 parent.geocoder = new window.google.maps.Geocoder(); 55 56 parent.directionsService = new window.google.maps.DirectionsService; 57 parent.directionsDisplay = new window.google.maps.DirectionsRenderer; 58 59 parent.directionsDisplay.setMap(parent.map); 60 61 parent.$tabCont = $el.parents(".stec-layout-event-inner-location"); 62 63 parent.address = parent.$tabCont.find(".stec-layout-event-inner-location-address").text(); 64 65 parent.setLocation(parent.address); 66 67 // start end directions 68 var $start = parent.$tabCont.find('input[name="start"]'); 69 70 var $end = parent.$tabCont.find('input[name="end"]'); 71 72 if ( $.trim($end.val()) == "" ) { 73 $end.val(parent.$tabCont.find(".stec-layout-event-inner-location-address").text()); 74 } 75 76 if ( $.trim($start.val()) == "" ) { 77 parent.fillMyLocation($start); 78 } 79 80 this.bindControls(); 81 82 // Remove tab preloaders 83 $inner.find('.stec-layout-event-inner-preload-wrap').children().first().unwrap(); 84 $inner.find('.stec-layout-event-inner-preload-wrap').remove(); 85 $inner.find('.stec-preloader').remove(); 86 87 }; 88 89 this.bindControls = function () { 90 91 var parent = this; 92 93 helper.onResizeEnd(function () { 94 parent.refresh(); 95 }, 150, 'stec-unbind-window-resize-on-event-close-' + glob.options.id); 96 97 parent.$tabCont 98 .parents('.stec-layout-event-inner') 99 .find('[data-tab="stec-layout-event-inner-location"]') 100 .on(helper.clickHandle(), function (e) { 101 102 parent.refresh(false); 103 }); 104 105 106 parent.$tabCont.find(".stec-layout-event-inner-location-left-button").on(helper.clickHandle(), function (e) { 107 e.preventDefault(); 108 109 var $tabCont = $(this).parents(".stec-layout-event-inner-location"); 110 111 var $start = $tabCont.find('input[name="start"]'); 112 var $end = $tabCont.find('input[name="end"]'); 113 var eventLocation = $end.val(); 114 115 if ( event.location_use_coord == 1 ) { 116 var latlng = event.location_forecast.split(','); 117 118 eventLocation = {
119 lat: parseFloat($.trim(latlng[0])), 120 lng: parseFloat($.trim(latlng[1])) 121 }; 122 } 123 124 if ( $start.val() && eventLocation ) { 125 parent.getDirection($start.val(), eventLocation); 126 } 127 }); 128 129 }, 130 this.refresh = function (centerOnLocation) { 131 132 var parent = this; 133 134 setTimeout(function () { 135 window.google.maps.event.trigger(parent.mapDiv, 'resize'); 136 137 if ( centerOnLocation === true ) { 138 parent.setLocation(parent.address); 139 } 140 }, 10); // timeout fixes resize bug 141 142 }; 143 144 this.fillMyLocation = function ($el) { 145 146 var parent = this; 147 148 if ( glob.options.myLocation ) { 149 $el.val(glob.options.myLocation); 150 return; 151 } 152 153 if ( navigator.geolocation ) { 154 155 navigator.geolocation.getCurrentPosition( 156 function (position) { 157 158 var pos = position.coords.latitude + " " + position.coords.longitude; 159 parent.geocoder.geocode({'address': pos}, function (results, status) { 160 glob.options.myLocation = (results[0].formatted_address); 161 $el.val(glob.options.myLocation); 162 }); 163 }, 164 function (a, b, c) { 165 console.log('Navigator Geolocation Error'); 166 } 167 ); 168 } 169 }; 170 171 this.setLocation = function (address) { 172 173 var parent = this; 174 175 if ( event.location_use_coord == 1 ) { 176 177 var latlng = event.location_forecast.split(','); 178 179 var pos = { 180 lat: parseFloat($.trim(latlng[0])), 181 lng: parseFloat($.trim(latlng[1])) 182 }; 183 184 parent.map.setCenter(pos); 185 parent.marker = new window.google.maps.Marker({ 186 map: parent.map, 187 position: pos, 188 title: address 189 }); 190 191 } else { 192 parent.geocoder.geocode({'address': address}, function (results, status) { 193 if ( status === window.google.maps.GeocoderStatus.OK ) { 194 parent.map.setCenter(results[0].geometry.location); 195 parent.marker = new window.google.maps.Marker({ 196 map: parent.map, 197 position: results[0].geometry.location, 198 title: address 199 }); 200 201 } else { 202 console.log("Geocoder error: " + status); 203 } 204 }); 205 } 206 207 208 parent.refresh(); 209 }; 210 211 this.getDirection = function (a, b) { 212 213 var parent = this; 214 215 parent.directionsService.route({ 216 origin: a, 217 destination: b ? b : parent.marker.position, 218 travelMode: window.google.maps.TravelMode.DRIVING 219 }, function (response, status) { 220 221 if ( status === window.google.maps.DirectionsStatus.OK ) { 222 parent.directionsDisplay.setDirections(response); 223 } else { 224 console.log("Direction Service Error"); 225 226 $inner.find('.stec-layout-event-inner-location-direction-error').stop().fadeTo(250, 1, function () { 227 228 setTimeout(function () { 229 230 $inner.find('.stec-layout-event-inner-location-direction-error').fadeTo(250, 0); 231 232 }, 3000); 233 234 }); 235 } 236 237 }); 238 }; 239 }; 240 241 function loadMap($event) { 242 243 var $mapCont = $event.find(".stec-layout-event-inner-location-right-gmap"); 244 245 // init once 246 if ( $mapCont.children().length <= 0 ) { 247 new gmap().init($mapCont); 248 } 249 } 250 251 252 $(document).on('stec-tab-click-' + glob.options.id, function () { 253 if ( $inner.is(':visible') ) { 254 var $event = $inner.parents('.stec-layout-event'); 255 loadMap($event); 256 } 257 }); 258 259 // Remove preloader 260 $inner.find('.stec-layout-event-inner-preload-wrap').children().first().unwrap(); 261 $inner.find('.stec-layout-event-inner-preload-wrap').remove(); 262 $inner.find('.stec-preloader').remove(); 263 264 }); 265 266})(jQuery);
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.