1var Maps = (function($, window, document, undefined) { 2 3 var loadedMap = {}; 4 5 var getUserLocation = function(callback, callbackFail) { 6 if (navigator.geolocation) { 7 navigator.geolocation.getCurrentPosition(function(position) { 8 callback(position); 9 }, function(error) { 10 var errorMessage = ''; 11 switch(error.code) { 12 case error.PERMISSION_DENIED: 13 errorMessage = "You denied the request for Geolocation." 14 break; 15 case error.POSITION_UNAVAILABLE: 16 errorMessage = "We're sorry, but your location information is unavailable." 17 break; 18 case error.TIMEOUT: 19 errorMessage = "We're sorry, but the request to get your location timed out." 20 break; 21 case error.UNKNOWN_ERROR: 22 errorMessage = "We're sorry but there was a problem getting your location." 23 break; 24 } 25 26 if (typeof Swal != 'undefined') 27 Swal.fire({type: 'warning', title: "Error!", text: errorMessage}); 28 else if (typeof swal != 'undefined') 29 swal({title: "Error!", text: errorMessage, type: "error", allowOutsideClick: true}); 30 31 //callbackFail(); 32 } 33 ); 34 } 35 else { 36 if (typeof Swal != 'undefined') 37 Swal.fire({type: 'warning', title: "Error!", text: "We're sorry but this feature is unsupported by your browser."}); 38 else if (typeof swal != 'undefined') 39 swal({title: "Error!", text: "We're sorry but this feature is unsupported by your browser.", type: "error", allowOutsideClick: true}); 40 41 //callbackFail(); 42 } 43 44 }; 45 46 var initGetUserLocation = function() { 47 $('#header-search-use-my-location-loading').show(); 48 getUserLocation(function(position) { 49 window.location.href = '/locations?lat=' + position.coords.latitude + '&lng=' + position.coords.longitude; 50 }, function() { 51 $('#header-search-use-my-location-loading').hide(); 52 }); 53 }; 54 55 var makeLinkable = function() { 56 var $this = $(this); 57 var $link = $this.find('a'); 58 window.location.href = $link.attr('href'); 59 }; 60 61 window.mapboxgl.accessToken = 'pk.eyJ1IjoicHRpbmRhbGwiLCJhIjoiY2ptYnphdmFrMDlxNDNwczRncG1pbnIyMSJ9.w4jiaYQ88OpNK6IaWPukXA'; 62 63 var initMap = function(selector, zoom, _locations, hideInfoWindow) { 64 var zoom = zoom ? zoom : null; 65 var selector = selector ? selector : '#map'; 66 67 if (_locations) 68 mapLocations = _locations; 69 70 if (typeof mapLocations != 'undefined' && mapLocations.length && $(selector).length) { 71 var markers = [], locations = []; 72 73 var icon = {url: typeof mapPinIcon == 'undefined' ? '/files/icons/map-pin.png' : mapPinIcon}; 74 var locationCount = mapLocations.length; 75 $.each(mapLocations, function(k, v) { 76 var infoWindow = ['<p class="info-window">']; 77 78 if (v.address) 79 infoWindow.push(v.address + '<br />'); 80 81 infoWindow.push(v.city + ', ' + v.state + ' ' + v.zip_code + '<br />'); 82 83 if (v.phone_number != '') { 84 v.phone_number = v.phone_number.replace(/[^0-9]/g, ''); 85 var areacode = v.phone_number.substring(0, 3); 86 var exch = v.phone_number.substring(3, 6); 87 var num = v.phone_number.substring(6, 10); 88 infoWindow.push("(" + areacode + ") " + exch + "-" + num + "<br />"); 89 } 90 91 if (locationCount == 1 && 'addressQueryParam' in v) { 92 infoWindow.push('<a href="https://maps.apple.com/?daddr=' + v.addressQueryParam + '&dirflg=d&t=h" target="_blank">Get Directions</a>'); 93 } 94 else { 95 if ('slug' in v) { 96 var slug = v.slug; 97 if (!slug.match(/^[0-9a-f]{32}$/gi)) { 98 infoWindow.push('<a href="http://fitnesstogether.com/' + slug + '" target="_blank">fitnesstogether.com/' + slug + '</a>'); 99 } 100 } 101 else { 102 // for schools 103 if (v.website) { 104 infoWindow.push('<a href="' + v.website + '" target="_blank">' + v.website + '</a>'); 105 } 106 107 } 108 } 109 110 infoWindow.push('</p>'); 111 112 infoWindow = infoWindow.join(''); 113 114 if (hideInfoWindow) 115 infoWindow = null; 116 117 if (v.latitude != '' && v.longitude != '') {
118 //var markerEl = $('<div>').addClass('marker').css({'background-image': 'url(' + icon.url + ')', 'background-size': '100% 100%', 'width': '30px', 'height': '44px'}).get(0); 119 // add element: markerEl to marker option 120 markers.push( 121 new mapboxgl.Marker({color: '#666'}).setLngLat([v.longitude, v.latitude]).setPopup(new mapboxgl.Popup().setHTML(infoWindow)) 122 ); 123 } 124 }); 125 126 if (markers.length) { 127 if (selector in loadedMap) { 128 loadedMap[selector].off(); 129 loadedMap[selector].remove(); 130 } 131 132 var map = new mapboxgl.Map({ 133 container: selector.substring(1), 134 style: 'mapbox://styles/mapbox/light-v10', 135 scrollZoom: false 136 }); 137 map.addControl(new mapboxgl.NavigationControl()); 138 139 var markerBounds = new mapboxgl.LngLatBounds(); 140 markers.forEach(function(v) { 141 v.addTo(map); 142 markerBounds.extend(v.getLngLat()); 143 }); 144 145 var lastPopupId = -1; 146 window.openMapBox = function(id) { 147 if (markers[id]) { 148 if (lastPopupId >= 0) 149 markers[lastPopupId].togglePopup(); 150 151 markers[id].togglePopup(); 152 lastPopupId = id; 153 } 154 } 155 156 if (markers.length == 1) { 157 openMapBox(0); 158 map.jumpTo({zoom: 16, center: markers[0].getLngLat()}); 159 } 160 else { 161 map.fitBounds(markerBounds, {padding: 40, duration: 500}); 162 } 163 164 return loadedMap[selector] = map; 165 } 166 } 167 168 return false; 169 }; 170 171 $(function() { 172 Maps.go(); 173 }); 174 175 return { 176 go: function() { 177 var i, j = this.init; 178 179 for (i in j) { 180 j.hasOwnProperty(i) && j[i](); 181 } 182 }, 183 init: { 184 185 general: function() { 186 187 }, 188 189 maps: function() { 190 initMap(); 191 } 192 }, 193 util: { 194 initMap: function(selector, zoom, locations, hideInfoWindow) { 195 return initMap(selector, zoom, locations, hideInfoWindow); 196 }, 197 198 initGetUserLocation: function() { 199 initGetUserLocation(); 200 }, 201 202 getUserLocation: function(callback, callbackFail) { 203 getUserLocation(callback, callbackFail); 204 } 205 } 206 }; 207 208})(jQuery, this, this.document); 209
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.