|
1 |
| -/*! jQuery Google Maps Store Locator - v2.0.7 - 2015-04-02 |
| 1 | +/*! jQuery Google Maps Store Locator - v2.0.8 - 2015-07-19 |
2 | 2 | * http://www.bjornblog.com/web/jquery-store-locator-plugin
|
3 | 3 | * Copyright (c) 2015 Bjorn Holine; Licensed MIT */
|
4 | 4 |
|
|
372 | 372 | $(document).on('click.'+pluginName, '.' + this.settings.formContainer + ' button', function (e) {
|
373 | 373 | _this.processForm(e);
|
374 | 374 | });
|
375 |
| - $(document).on('keyup.'+pluginName, function (e) { |
| 375 | + $(document).on('keydown.'+pluginName, function (e) { |
376 | 376 | if (e.keyCode === 13 && $('#' + _this.settings.addressID).is(':focus')) {
|
377 | 377 | _this.processForm(e);
|
378 | 378 | }
|
|
472 | 472 |
|
473 | 473 | // If show full map option is true
|
474 | 474 | if (this.settings.fullMapStart === true) {
|
475 |
| - if(this.settings.querystringParams === true && this.getQueryString(this.settings.addressID) || this.getQueryString(this.settings.searchID)) { |
| 475 | + if((this.settings.querystringParams === true && this.getQueryString(this.settings.addressID)) || (this.settings.querystringParams === true && this.getQueryString(this.settings.searchID)) || (this.settings.querystringParams === true && this.getQueryString(this.settings.maxDistanceID))) { |
476 | 476 | this.processForm(null);
|
477 | 477 | }
|
478 | 478 | else {
|
|
1031 | 1031 | * @returns {string} formatted address
|
1032 | 1032 | */
|
1033 | 1033 | getAddressByMarker: function(markerID) {
|
1034 |
| - var formattedAddress = null; |
| 1034 | + var formattedAddress = ""; |
1035 | 1035 | // Set up formatted address
|
1036 | 1036 | if(locationset[markerID].address){ formattedAddress += locationset[markerID].address + ' '; }
|
1037 | 1037 | if(locationset[markerID].address2){ formattedAddress += locationset[markerID].address2 + ' '; }
|
|
1132 | 1132 | processForm: function (e) {
|
1133 | 1133 | var _this = this;
|
1134 | 1134 | var distance = null;
|
| 1135 | + var $addressInput = $('#' + this.settings.addressID); |
| 1136 | + var $searchInput = $('#' + this.settings.searchID); |
| 1137 | + var $distanceInput = $('#' + this.settings.maxDistanceID); |
1135 | 1138 |
|
1136 | 1139 | // Stop the form submission
|
1137 | 1140 | if(typeof e !== 'undefined' && e !== null) {
|
1138 | 1141 | e.preventDefault();
|
1139 | 1142 | }
|
1140 | 1143 |
|
1141 |
| - // Get the distance if set |
1142 |
| - if (this.settings.maxDistance === true) { |
1143 |
| - distance = $('#' + this.settings.maxDistanceID).val(); |
1144 |
| - } |
1145 |
| - |
| 1144 | + // Query string parameters |
1146 | 1145 | if(this.settings.querystringParams === true) {
|
1147 |
| - |
1148 | 1146 | // Check for query string parameters
|
1149 |
| - if(this.getQueryString(this.settings.addressID) || this.getQueryString(this.settings.searchID)){ |
| 1147 | + if(this.getQueryString(this.settings.addressID) || this.getQueryString(this.settings.searchID) || this.getQueryString(this.settings.maxDistanceID)){ |
1150 | 1148 | addressInput = this.getQueryString(this.settings.addressID);
|
1151 | 1149 | searchInput = this.getQueryString(this.settings.searchID);
|
| 1150 | + distance = this.getQueryString(this.settings.maxDistanceID); |
| 1151 | + |
| 1152 | + // The form should override the query string parameters |
| 1153 | + if($('#' + this.settings.addressID).val() !== '') { |
| 1154 | + addressInput = $addressInput.val(); |
| 1155 | + } |
| 1156 | + if($searchInput.val() !== '') { |
| 1157 | + searchInput = $searchInput.val(); |
| 1158 | + } |
| 1159 | + if($distanceInput.val() !== '') { |
| 1160 | + distance = $distanceInput.val(); |
| 1161 | + } |
1152 | 1162 | }
|
1153 | 1163 | else{
|
1154 | 1164 | // Get the user input and use it
|
1155 |
| - addressInput = $('#' + this.settings.addressID).val(); |
1156 |
| - searchInput = $('#' + this.settings.searchID).val(); |
| 1165 | + addressInput = $addressInput.val(); |
| 1166 | + searchInput = $searchInput.val(); |
| 1167 | + // Get the distance if set |
| 1168 | + if (this.settings.maxDistance === true) { |
| 1169 | + distance = $distanceInput.val(); |
| 1170 | + } |
1157 | 1171 | }
|
1158 | 1172 | }
|
1159 | 1173 | else {
|
1160 | 1174 | // Get the user input and use it
|
1161 |
| - addressInput = $('#' + this.settings.addressID).val(); |
1162 |
| - searchInput = $('#' + this.settings.searchID).val(); |
| 1175 | + addressInput = $addressInput.val(); |
| 1176 | + searchInput = $searchInput.val(); |
| 1177 | + // Get the distance if set |
| 1178 | + if (this.settings.maxDistance === true) { |
| 1179 | + distance = $distanceInput.val(); |
| 1180 | + } |
1163 | 1181 | }
|
1164 | 1182 |
|
1165 | 1183 | // Get the region setting if set
|
|
1169 | 1187 | this._start();
|
1170 | 1188 | }
|
1171 | 1189 | else if(addressInput !== '') {
|
1172 |
| - var g = new this.googleGeocode(this); |
1173 |
| - g.geocode({'address': addressInput, 'region': region}, function (data) { |
1174 |
| - if (data !== null) { |
1175 |
| - olat = data.latitude; |
1176 |
| - olng = data.longitude; |
1177 |
| - |
1178 |
| - // Run the mapping function |
1179 |
| - mappingObj.lat = olat; |
1180 |
| - mappingObj.lng = olng; |
1181 |
| - mappingObj.origin = addressInput; |
1182 |
| - mappingObj.name = searchInput; |
1183 |
| - mappingObj.distance = distance; |
1184 |
| - _this.mapping(mappingObj); |
1185 |
| - } else { |
1186 |
| - // Unable to geocode |
1187 |
| - _this.notify(_this.settings.addressErrorAlert); |
1188 |
| - } |
1189 |
| - }); |
| 1190 | + |
| 1191 | + // Geocode the origin if needed |
| 1192 | + if(typeof originalOrigin !== 'undefined' && typeof olat !== 'undefined' && typeof olng !== 'undefined' && (addressInput === originalOrigin)) { |
| 1193 | + // Run the mapping function |
| 1194 | + mappingObj.lat = olat; |
| 1195 | + mappingObj.lng = olng; |
| 1196 | + mappingObj.origin = addressInput; |
| 1197 | + mappingObj.name = searchInput; |
| 1198 | + mappingObj.distance = distance; |
| 1199 | + _this.mapping(mappingObj); |
| 1200 | + } |
| 1201 | + else { |
| 1202 | + var g = new this.googleGeocode(this); |
| 1203 | + g.geocode({'address': addressInput, 'region': region}, function (data) { |
| 1204 | + if (data !== null) { |
| 1205 | + olat = data.latitude; |
| 1206 | + olng = data.longitude; |
| 1207 | + |
| 1208 | + // Run the mapping function |
| 1209 | + mappingObj.lat = olat; |
| 1210 | + mappingObj.lng = olng; |
| 1211 | + mappingObj.origin = addressInput; |
| 1212 | + mappingObj.name = searchInput; |
| 1213 | + mappingObj.distance = distance; |
| 1214 | + _this.mapping(mappingObj); |
| 1215 | + } else { |
| 1216 | + // Unable to geocode |
| 1217 | + _this.notify(_this.settings.addressErrorAlert); |
| 1218 | + } |
| 1219 | + }); |
| 1220 | + } |
1190 | 1221 | }
|
1191 | 1222 | else if(searchInput !== '') {
|
1192 | 1223 | mappingObj.name = searchInput;
|
|
1213 | 1244 |
|
1214 | 1245 | // Create the array
|
1215 | 1246 | if (this.settings.maxDistance === true && firstRun !== true && typeof maxDistance !== 'undefined' && maxDistance !== null) {
|
1216 |
| - if (data.distance < maxDistance) { |
| 1247 | + if (data.distance <= maxDistance) { |
| 1248 | + locationset.push( data ); |
| 1249 | + } |
| 1250 | + else { |
| 1251 | + return; |
| 1252 | + } |
| 1253 | + } |
| 1254 | + else if(this.settings.maxDistance === true && this.settings.querystringParams === true && this.settings.maxDistance === true && typeof maxDistance !== 'undefined' && maxDistance !== null) { |
| 1255 | + if (data.distance <= maxDistance) { |
1217 | 1256 | locationset.push( data );
|
1218 | 1257 | }
|
1219 | 1258 | else {
|
|
1857 | 1896 | e.preventDefault();
|
1858 | 1897 | var locID = $(this).closest('li').attr('data-markerid');
|
1859 | 1898 | _this.directionsRequest(origin, locID, map);
|
1860 |
| - }); |
1861 | 1899 |
|
1862 |
| - // Close directions |
1863 |
| - $(document).on('click.'+pluginName, '.' + _this.settings.locationList + ' .bh-sl-close-icon', function () { |
1864 |
| - _this.closeDirections(); |
| 1900 | + // Close directions |
| 1901 | + $(document).on('click.'+pluginName, '.' + _this.settings.locationList + ' .bh-sl-close-icon', function () { |
| 1902 | + _this.closeDirections(); |
| 1903 | + }); |
1865 | 1904 | });
|
1866 | 1905 | }
|
1867 | 1906 |
|
|
0 commit comments