Skip to content

Commit 4fa6811

Browse files
committed
Completed functionality to prevents unneeded AJAX requests
1 parent 74778c5 commit 4fa6811

File tree

4 files changed

+34
-22
lines changed

4 files changed

+34
-22
lines changed

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

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

@@ -15,7 +15,7 @@
1515
}
1616

1717
// Variables used across multiple methods
18-
var $this, listTemplate, infowindowTemplate, dataTypeRead, originalData, originalDataRequest, originalZoom, searchInput, addressInput, olat, olng, storeNum, directionsDisplay, directionsService;
18+
var $this, listTemplate, infowindowTemplate, dataTypeRead, originalOrigin, originalData, originalDataRequest, originalZoom, searchInput, addressInput, olat, olng, storeNum, directionsDisplay, directionsService;
1919
var featuredset = [], locationset = [], normalset = [], markers = [];
2020
var filters = {}, locationData = {}, GeoCodeCalc = {}, mappingObj = {};
2121

@@ -262,7 +262,7 @@
262262
},
263263

264264
/**
265-
* Load templates via Handlebars templates in /templates or inline via IDs
265+
* Load templates via Handlebars templates in /templates or inline via IDs - private
266266
*/
267267
_loadTemplates: function () {
268268
var source;
@@ -434,6 +434,7 @@
434434

435435
/**
436436
* Check for existing filter selections
437+
*
437438
*/
438439
checkFilters: function () {
439440
$.each(this.settings.taxonomyFilters, function (k, v) {
@@ -1193,8 +1194,15 @@
11931194
// Setup the origin point
11941195
var originPoint = new google.maps.LatLng(orig_lat, orig_lng);
11951196

1196-
// Do the initial data request - doing this in mapping so the lat/lng and address can be passed over and used if needed
1197-
originalDataRequest = _this._getData(olat, olng, origin);
1197+
// If the origin hasn't changed use the existing data so we aren't making unneeded AJAX requests
1198+
if((typeof originalOrigin !== 'undefined') && (origin === originalOrigin) && (typeof originalData !== 'undefined')) {
1199+
origin = originalOrigin;
1200+
originalDataRequest = originalData;
1201+
}
1202+
else {
1203+
// Do the data request - doing this in mapping so the lat/lng and address can be passed over and used if needed
1204+
originalDataRequest = _this._getData(olat, olng, origin);
1205+
}
11981206
}
11991207

12001208
/**
@@ -1205,8 +1213,9 @@
12051213
// Get the length unit
12061214
var distUnit = (_this.settings.lengthUnit === 'km') ? _this.settings.kilometersLang : _this.settings.milesLang;
12071215

1208-
// Save data separately so we can avoid multiple AJAX requests
1209-
originalData = data;
1216+
// Save data and origin separately so we can potentially avoid multiple AJAX requests
1217+
originalData = originalDataRequest;
1218+
originalOrigin = origin;
12101219

12111220
// Callback
12121221
if (_this.settings.callbackSuccess) {
@@ -1661,7 +1670,6 @@
16611670
// Add ids to the filter arrays as they are checked
16621671
filters[filterKey].push(filterId);
16631672
if ($('#' + _this.settings.mapID).hasClass('bh-sl-map-open') === true) {
1664-
_this.reset();
16651673
if ((olat) && (olng)) {
16661674
_this.settings.mapSettings.zoom = 0;
16671675
_this.processForm();
@@ -1677,7 +1685,6 @@
16771685
if (filterIndex > -1) {
16781686
filters[filterKey].splice(filterIndex, 1);
16791687
if ($('#' + _this.settings.mapID).hasClass('bh-sl-map-open') === true) {
1680-
_this.reset();
16811688
if ((olat) && (olng)) {
16821689
if (_this.countFilters() === 0) {
16831690
_this.settings.mapSettings.zoom = originalZoom;
@@ -1709,7 +1716,6 @@
17091716
if (filterKey) {
17101717
filters[filterKey] = [filterId];
17111718
if ($('#' + _this.settings.mapID).hasClass('bh-sl-map-open') === true) {
1712-
_this.reset();
17131719
if ((olat) && (olng)) {
17141720
_this.settings.mapSettings.zoom = 0;
17151721
_this.processForm();

0 commit comments

Comments
 (0)