Skip to content

Commit 1fe9fee

Browse files
committed
Added altDistanceNoResult setting to display no results message vs. all locations when closest location is further than distanceAlert setting
1 parent d562ce7 commit 1fe9fee

File tree

4 files changed

+27
-12
lines changed

4 files changed

+27
-12
lines changed

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

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*! jQuery Google Maps Store Locator - v2.7.5 - 2018-02-15
1+
/*! jQuery Google Maps Store Locator - v2.7.5 - 2018-02-16
22
* http://www.bjornblog.com/web/jquery-store-locator-plugin
33
* Copyright (c) 2018 Bjorn Holine; Licensed MIT */
44

@@ -91,6 +91,7 @@
9191
'exclusiveFiltering' : false,
9292
'exclusiveTax' : null,
9393
'querystringParams' : false,
94+
'altDistanceNoResult' : false,
9495
'debug' : false,
9596
'sessionStorage' : false,
9697
'markerCluster' : null,
@@ -680,9 +681,9 @@
680681
this.writeDebug('htmlGeocode',arguments);
681682
var _this = this;
682683

683-
if (this.settings.sessionStorage === true && window.sessionStorage && window.sessionStorage.getItem('myGeo')){
684-
this.writeDebug('Using Session Saved Values for GEO');
685-
this.autoGeocodeQuery(JSON.parse(window.sessionStorage.getItem('myGeo')));
684+
if (_this.settings.sessionStorage === true && window.sessionStorage && window.sessionStorage.getItem('myGeo')){
685+
_this.writeDebug('Using Session Saved Values for GEO');
686+
_this.autoGeocodeQuery(JSON.parse(window.sessionStorage.getItem('myGeo')));
686687
return false;
687688
}
688689
else if (navigator.geolocation) {
@@ -2578,7 +2579,7 @@
25782579
}
25792580

25802581
// Save the closest location to a variable for openNearest setting.
2581-
if (_this.settings.openNearest === true && typeof locationset[0] !== 'undefined') {
2582+
if (typeof locationset[0] !== 'undefined') {
25822583
nearestLoc = locationset[0];
25832584
}
25842585

@@ -2609,6 +2610,12 @@
26092610
_this.paginationSetup(page);
26102611
}
26112612

2613+
// Alternative method to display no results if locations are too far away instead of all locations.
2614+
if (_this.settings.altDistanceNoResult === true && nearestLoc.distance > _this.settings.distanceAlert) {
2615+
_this.emptyResult();
2616+
return;
2617+
}
2618+
26122619
// Handle no results
26132620
if (_this.isEmptyObject(locationset) || locationset[0].result === 'none') {
26142621
_this.emptyResult();

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

Lines changed: 3 additions & 3 deletions
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.5
3939

40+
* Added altDistanceNoResult setting to display no results message vs. all locations when closest location is further than distanceAlert setting.
4041
* Added callbackAutoGeoSuccess callback that fires after the geolocation API returns a successful result.
4142
* Added callbackFormVals callback that fires after the form values have been processed from the form.
4243
* Added callbackGeocodeRestrictions callback that allows the componentRestrictions object to be overridden.

src/js/jquery.storelocator.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@
8787
'exclusiveFiltering' : false,
8888
'exclusiveTax' : null,
8989
'querystringParams' : false,
90+
'altDistanceNoResult' : false,
9091
'debug' : false,
9192
'sessionStorage' : false,
9293
'markerCluster' : null,
@@ -676,9 +677,9 @@
676677
this.writeDebug('htmlGeocode',arguments);
677678
var _this = this;
678679

679-
if (this.settings.sessionStorage === true && window.sessionStorage && window.sessionStorage.getItem('myGeo')){
680-
this.writeDebug('Using Session Saved Values for GEO');
681-
this.autoGeocodeQuery(JSON.parse(window.sessionStorage.getItem('myGeo')));
680+
if (_this.settings.sessionStorage === true && window.sessionStorage && window.sessionStorage.getItem('myGeo')){
681+
_this.writeDebug('Using Session Saved Values for GEO');
682+
_this.autoGeocodeQuery(JSON.parse(window.sessionStorage.getItem('myGeo')));
682683
return false;
683684
}
684685
else if (navigator.geolocation) {
@@ -2574,7 +2575,7 @@
25742575
}
25752576

25762577
// Save the closest location to a variable for openNearest setting.
2577-
if (_this.settings.openNearest === true && typeof locationset[0] !== 'undefined') {
2578+
if (typeof locationset[0] !== 'undefined') {
25782579
nearestLoc = locationset[0];
25792580
}
25802581

@@ -2605,6 +2606,12 @@
26052606
_this.paginationSetup(page);
26062607
}
26072608

2609+
// Alternative method to display no results if locations are too far away instead of all locations.
2610+
if (_this.settings.altDistanceNoResult === true && nearestLoc.distance > _this.settings.distanceAlert) {
2611+
_this.emptyResult();
2612+
return;
2613+
}
2614+
26082615
// Handle no results
26092616
if (_this.isEmptyObject(locationset) || locationset[0].result === 'none') {
26102617
_this.emptyResult();

0 commit comments

Comments
 (0)