Skip to content

Commit 5bd7583

Browse files
committed
Re-worked handling of no results
1 parent ef8cee5 commit 5bd7583

File tree

4 files changed

+215
-176
lines changed

4 files changed

+215
-176
lines changed

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

+106-87
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*! jQuery Google Maps Store Locator - v2.5.2 - 2016-04-03
1+
/*! jQuery Google Maps Store Locator - v2.5.3 - 2016-04-03
22
* http://www.bjornblog.com/web/jquery-store-locator-plugin
33
* Copyright (c) 2016 Bjorn Holine; Licensed MIT */
44

@@ -481,7 +481,7 @@
481481
},
482482
dataType : dataTypeRead,
483483
jsonpCallback: (this.settings.dataType === 'jsonp' ? this.settings.callbackJsonp : null)
484-
}).done(function (p) {
484+
}).done(function(p) {
485485
d.resolve(p);
486486

487487
// Loading remove
@@ -1810,6 +1810,45 @@
18101810
});
18111811
},
18121812

1813+
/**
1814+
* Handle no results
1815+
*/
1816+
emptyResult: function() {
1817+
this.writeDebug('emptyResult',arguments);
1818+
var center,
1819+
locList = $('.' + this.settings.locationList + ' ul'),
1820+
myOptions = this.settings.mapSettings,
1821+
noResults;
1822+
1823+
// Create the map
1824+
var map = new google.maps.Map(document.getElementById(this.settings.mapID), myOptions);
1825+
1826+
// Callback
1827+
if (this.settings.callbackNoResults) {
1828+
this.settings.callbackNoResults.call(this, map, myOptions);
1829+
}
1830+
1831+
// Empty the location list
1832+
locList.empty();
1833+
1834+
// Append the no results message
1835+
noResults = $('<li><div class="bh-sl-noresults-title">' + this.settings.noResultsTitle + '</div><br><div class="bh-sl-noresults-desc">' + this.settings.noResultsDesc + '</li>').hide().fadeIn();
1836+
locList.append(noResults);
1837+
1838+
// Center on the original origin or 0,0 if not available
1839+
if ((olat) && (olng)) {
1840+
center = new google.maps.LatLng(olat, olng);
1841+
} else {
1842+
center = new google.maps.LatLng(0, 0);
1843+
}
1844+
1845+
map.setCenter(center);
1846+
1847+
if (originalZoom) {
1848+
map.setZoom(originalZoom);
1849+
}
1850+
},
1851+
18131852
/**
18141853
* The primary mapping function that runs everything
18151854
*
@@ -1883,7 +1922,8 @@
18831922
this.writeDebug('processData',mappingObject);
18841923
var _this = this;
18851924
var i = 0;
1886-
var orig_lat, orig_lng, origin, name, maxDistance, marker, bounds, storeStart, storeNumToShow, myOptions, noResults, distError, openMap;
1925+
var orig_lat, orig_lng, origin, name, maxDistance, marker, bounds, storeStart, storeNumToShow, myOptions, distError, openMap;
1926+
var taxFilters = {};
18871927
if (!this.isEmptyObject(mappingObject)) {
18881928
orig_lat = mappingObject.lat;
18891929
orig_lng = mappingObject.lng;
@@ -1984,7 +2024,6 @@
19842024

19852025
// Taxonomy filtering setup
19862026
if (_this.settings.taxonomyFilters !== null || _this.settings.nameSearch === true) {
1987-
var taxFilters = {};
19882027

19892028
for(var k in filters) {
19902029
if (filters.hasOwnProperty(k) && filters[k].length > 0) {
@@ -2006,24 +2045,6 @@
20062045
}
20072046
}
20082047

2009-
// Handle no results
2010-
if (_this.isEmptyObject(locationset)) {
2011-
// Callback
2012-
if (_this.settings.callbackNoResults) {
2013-
_this.settings.callbackNoResults.call(this);
2014-
}
2015-
2016-
// Append the no results message
2017-
noResults = $('<li><div class="bh-sl-noresults-title">' + _this.settings.noResultsTitle + '</div><br><div class="bh-sl-noresults-desc">' + _this.settings.noResultsDesc + '</li>').hide().fadeIn();
2018-
2019-
// Setup a no results location
2020-
locationset[0] = {
2021-
'distance': 0,
2022-
'lat' : 0,
2023-
'lng': 0
2024-
};
2025-
}
2026-
20272048
// Sort the multi-dimensional array by distance
20282049
if (typeof origin !== 'undefined') {
20292050
_this.sortNumerically(locationset);
@@ -2047,29 +2068,36 @@
20472068
}
20482069

20492070
// Check the closest marker
2050-
if (_this.settings.maxDistance === true && firstRun !== true && maxDistance) {
2051-
if (typeof locationset[0] === 'undefined' || locationset[0].distance > maxDistance) {
2052-
_this.notify(_this.settings.distanceErrorAlert + maxDistance + ' ' + distUnit);
2053-
return;
2071+
if (_this.isEmptyObject(taxFilters)) {
2072+
if (_this.settings.maxDistance === true && firstRun !== true && maxDistance) {
2073+
if (typeof locationset[0] === 'undefined' || locationset[0].distance > maxDistance) {
2074+
_this.notify(_this.settings.distanceErrorAlert + maxDistance + ' ' + distUnit);
2075+
}
20542076
}
2055-
}
2056-
else {
2057-
if (_this.settings.distanceAlert !== -1 && locationset[0].distance > _this.settings.distanceAlert) {
2058-
_this.notify(_this.settings.distanceErrorAlert + _this.settings.distanceAlert + ' ' + distUnit);
2059-
distError = true;
2077+
else {
2078+
if (_this.settings.distanceAlert !== -1 && locationset[0].distance > _this.settings.distanceAlert) {
2079+
_this.notify(_this.settings.distanceErrorAlert + _this.settings.distanceAlert + ' ' + distUnit);
2080+
distError = true;
2081+
}
20602082
}
20612083
}
20622084

2063-
// Output page numbers if pagination setting is true
2064-
if (_this.settings.pagination === true) {
2065-
_this.paginationSetup(page);
2066-
}
2067-
20682085
// Slide in the map container
20692086
if (_this.settings.slideMap === true) {
20702087
$this.slideDown();
20712088
}
20722089

2090+
// Handle no results
2091+
if (_this.isEmptyObject(locationset)) {
2092+
_this.emptyResult();
2093+
return;
2094+
}
2095+
2096+
// Output page numbers if pagination setting is true
2097+
if (_this.settings.pagination === true) {
2098+
_this.paginationSetup(page);
2099+
}
2100+
20732101
// Set up the modal window
20742102
if (_this.settings.modal === true) {
20752103
// Callback
@@ -2240,9 +2268,7 @@
22402268
bounds.extend(point);
22412269
}
22422270
// Pass variables to the pop-up infowindows
2243-
if (typeof noResults === 'undefined') {
2244-
_this.createInfowindow(marker, null, infowindow, storeStart, page);
2245-
}
2271+
_this.createInfowindow(marker, null, infowindow, storeStart, page);
22462272
}
22472273

22482274
// Center and zoom if no origin or zoom was provided, or distance of first marker is greater than distanceAlert
@@ -2253,63 +2279,56 @@
22532279
// Create the links that focus on the related marker
22542280
var locList = $('.' + _this.settings.locationList + ' ul');
22552281
locList.empty();
2256-
// Check the locationset and continue with the list setup or show no results message
2257-
if(locationset[0].lat === 0 && locationset[0].lng === 0) {
2258-
locList.append(noResults);
2259-
}
2260-
else {
2261-
// Set up the location list markup
2262-
if (firstRun && _this.settings.fullMapStartListLimit !== false && !isNaN(_this.settings.fullMapStartListLimit) && _this.settings.fullMapStartListLimit !== -1) {
2263-
for (var m = 0; m < _this.settings.fullMapStartListLimit; m++) {
2264-
var currentMarker = markers[m];
2265-
_this.listSetup(currentMarker, storeStart, page);
2266-
}
2267-
} else {
2268-
$(markers).each(function (x) {
2269-
var currentMarker = markers[x];
2270-
_this.listSetup(currentMarker, storeStart, page);
2271-
});
2282+
2283+
// Set up the location list markup
2284+
if (firstRun && _this.settings.fullMapStartListLimit !== false && !isNaN(_this.settings.fullMapStartListLimit) && _this.settings.fullMapStartListLimit !== -1) {
2285+
for (var m = 0; m < _this.settings.fullMapStartListLimit; m++) {
2286+
var currentMarker = markers[m];
2287+
_this.listSetup(currentMarker, storeStart, page);
22722288
}
2289+
} else {
2290+
$(markers).each(function (x) {
2291+
var currentMarker = markers[x];
2292+
_this.listSetup(currentMarker, storeStart, page);
2293+
});
22732294
}
22742295

22752296
// Handle clicks from the list
2276-
if (typeof noResults === 'undefined') {
2277-
$(document).on('click.' + pluginName, '.' + _this.settings.locationList + ' li', function () {
2278-
var markerId = $(this).data('markerid');
2279-
var selectedMarker = markers[markerId];
2280-
2281-
// List click callback
2282-
if (_this.settings.callbackListClick) {
2283-
_this.settings.callbackListClick.call(this, markerId, selectedMarker);
2284-
}
2297+
$(document).on('click.' + pluginName, '.' + _this.settings.locationList + ' li', function () {
2298+
var markerId = $(this).data('markerid');
2299+
var selectedMarker = markers[markerId];
22852300

2286-
map.panTo(selectedMarker.getPosition());
2287-
var listLoc = 'left';
2288-
if (_this.settings.bounceMarker === true) {
2289-
selectedMarker.setAnimation(google.maps.Animation.BOUNCE);
2290-
setTimeout(function () {
2291-
selectedMarker.setAnimation(null);
2292-
_this.createInfowindow(selectedMarker, listLoc, infowindow, storeStart, page);
2293-
}, 700
2294-
);
2295-
}
2296-
else {
2297-
_this.createInfowindow(selectedMarker, listLoc, infowindow, storeStart, page);
2298-
}
2301+
// List click callback
2302+
if (_this.settings.callbackListClick) {
2303+
_this.settings.callbackListClick.call(this, markerId, selectedMarker);
2304+
}
22992305

2300-
// Custom selected marker override
2301-
if (_this.settings.selectedMarkerImg !== null) {
2302-
_this.changeSelectedMarker(selectedMarker);
2303-
}
2306+
map.panTo(selectedMarker.getPosition());
2307+
var listLoc = 'left';
2308+
if (_this.settings.bounceMarker === true) {
2309+
selectedMarker.setAnimation(google.maps.Animation.BOUNCE);
2310+
setTimeout(function () {
2311+
selectedMarker.setAnimation(null);
2312+
_this.createInfowindow(selectedMarker, listLoc, infowindow, storeStart, page);
2313+
}, 700
2314+
);
2315+
}
2316+
else {
2317+
_this.createInfowindow(selectedMarker, listLoc, infowindow, storeStart, page);
2318+
}
23042319

2305-
// Focus on the list
2306-
$('.' + _this.settings.locationList + ' li').removeClass('list-focus');
2307-
$('.' + _this.settings.locationList + ' li[data-markerid=' + markerId + ']').addClass('list-focus');
2308-
});
2309-
}
2320+
// Custom selected marker override
2321+
if (_this.settings.selectedMarkerImg !== null) {
2322+
_this.changeSelectedMarker(selectedMarker);
2323+
}
2324+
2325+
// Focus on the list
2326+
$('.' + _this.settings.locationList + ' li').removeClass('list-focus');
2327+
$('.' + _this.settings.locationList + ' li[data-markerid=' + markerId + ']').addClass('list-focus');
2328+
});
23102329

23112330
// Prevent bubbling from list content links
2312-
$(document).on('click.'+pluginName, '.' + _this.settings.locationList + ' li a', function (e) {
2331+
$(document).on('click.'+pluginName, '.' + _this.settings.locationList + ' li a', function(e) {
23132332
e.stopPropagation();
23142333
});
23152334

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

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

readme.md

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ filtering.
3838
### Version 2.5.3
3939

4040
* Removed check from createMarker method that removed spaces from categories - created issues with categories that have spaces.
41+
* Re-worked handling of no results.
4142
* Updated createMarker method to ensure custom category marker images are converted to integers if strings are passed for dimensions.
4243
* Updated autoGeocode and default location functionality so that max distance is applied on initial load.
4344

0 commit comments

Comments
 (0)