Skip to content

Commit 69e7ea5

Browse files
committed
Added callbackRegion callback, which allows region to be set before being sent to the Google Maps Geocoding API
1 parent b239293 commit 69e7ea5

File tree

6 files changed

+48
-15
lines changed

6 files changed

+48
-15
lines changed

callbacks.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ $('#bh-sl-map-container').storeLocator({
3030
| Function | Description |
3131
|---|---|
3232
| [callbackNotify](callbacks/callback-notification.md) | Notification callback |
33+
| [callbackRegion](callbacks/callback-region.md) | Region callback |
3334
| [callbackBeforeSend](callbacks/callback-beforesend.md) | Before location data request callback |
3435
| [callbackDirectionsRequest](callbacks/callback-directionsrequest.md) | Directions request callback |
3536
| [callbackCloseDirections](callbacks/callback-closedirections.md) | Close directions callback |

callbacks/callback-region.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# callbackRegion
2+
3+
## Description
4+
5+
Allows region to be set before being sent to the Google Maps Geocoding API. This could allow for additional
6+
processing of the user input or setting the region via other detection methods. Value should be set to a
7+
[ccTLD](https://developers.google.com/maps/documentation/geocoding/#RegionCodes) two letter country code. Ex: US,UK,CA
8+
9+
## Parameters
10+
11+
| Name | Type | Description |
12+
|---|---|---|
13+
| addressInput | string | User address input |
14+
| searchInput | string | User name search input when using nameSearch setting |
15+
| distance | string | User distance selection when using maxDistance setting |

dist/assets/js/plugins/storeLocator/jquery.storelocator.js

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@
9494
'infoBubble' : null,
9595
// Callbacks
9696
'callbackNotify' : null,
97+
'callbackRegion' : null,
9798
'callbackBeforeSend' : null,
9899
'callbackSuccess' : null,
99100
'callbackModalOpen' : null,
@@ -1505,11 +1506,12 @@
15051506
*/
15061507
processForm: function (e) {
15071508
this.writeDebug('processForm',arguments);
1508-
var _this = this;
1509-
var distance = null;
1510-
var $addressInput = $('#' + this.settings.addressID);
1511-
var $searchInput = $('#' + this.settings.searchID);
1512-
var $distanceInput = $('#' + this.settings.maxDistanceID);
1509+
var _this = this,
1510+
distance = null,
1511+
$addressInput = $('#' + this.settings.addressID),
1512+
$searchInput = $('#' + this.settings.searchID),
1513+
$distanceInput = $('#' + this.settings.maxDistanceID),
1514+
region = '';
15131515

15141516
// Stop the form submission
15151517
if(typeof e !== 'undefined' && e !== null) {
@@ -1555,8 +1557,14 @@
15551557
}
15561558
}
15571559

1558-
// Get the region setting if set
1559-
var region = $('#' + this.settings.regionID).val();
1560+
// Region
1561+
if (this.settings.callbackRegion) {
1562+
// Region override callback
1563+
region = this.settings.callbackRegion.call(this, addressInput, searchInput, distance);
1564+
} else {
1565+
// Region setting
1566+
region = $('#' + this.settings.regionID).val();
1567+
}
15601568

15611569
if (addressInput === '' && searchInput === '') {
15621570
this._start();

dist/assets/js/plugins/storeLocator/jquery.storelocator.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ filtering.
3737

3838
### Version 2.7.2
3939

40+
* Added [callbackRegion](callbacks/callback-region.md) callback, which allows region to be set before being sent to the Google Maps Geocoding API.
4041
* Fixed incorrect origin marker parameter order after code restructure.
4142
* Fixed [issue](https://github.com/bjorn2404/jQuery-Store-Locator-Plugin/issues/160) where searching by name after searching by address, without a new address, didn't reset the origin.
4243
* Merged pull-request from [ollea](https://github.com/ollea) that adds "getMap" function that returns a google.maps.Map instance.

src/js/jquery.storelocator.js

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@
9191
'infoBubble' : null,
9292
// Callbacks
9393
'callbackNotify' : null,
94+
'callbackRegion' : null,
9495
'callbackBeforeSend' : null,
9596
'callbackSuccess' : null,
9697
'callbackModalOpen' : null,
@@ -1502,11 +1503,12 @@
15021503
*/
15031504
processForm: function (e) {
15041505
this.writeDebug('processForm',arguments);
1505-
var _this = this;
1506-
var distance = null;
1507-
var $addressInput = $('#' + this.settings.addressID);
1508-
var $searchInput = $('#' + this.settings.searchID);
1509-
var $distanceInput = $('#' + this.settings.maxDistanceID);
1506+
var _this = this,
1507+
distance = null,
1508+
$addressInput = $('#' + this.settings.addressID),
1509+
$searchInput = $('#' + this.settings.searchID),
1510+
$distanceInput = $('#' + this.settings.maxDistanceID),
1511+
region = '';
15101512

15111513
// Stop the form submission
15121514
if(typeof e !== 'undefined' && e !== null) {
@@ -1552,8 +1554,14 @@
15521554
}
15531555
}
15541556

1555-
// Get the region setting if set
1556-
var region = $('#' + this.settings.regionID).val();
1557+
// Region
1558+
if (this.settings.callbackRegion) {
1559+
// Region override callback
1560+
region = this.settings.callbackRegion.call(this, addressInput, searchInput, distance);
1561+
} else {
1562+
// Region setting
1563+
region = $('#' + this.settings.regionID).val();
1564+
}
15571565

15581566
if (addressInput === '' && searchInput === '') {
15591567
this._start();

0 commit comments

Comments
 (0)