Skip to content

Commit 5e383e3

Browse files
committed
Worked through max distance bug with category filtering, added global mappingObj object, merged getFormValues function into processForm function
1 parent 48fd7c5 commit 5e383e3

File tree

4 files changed

+72
-108
lines changed

4 files changed

+72
-108
lines changed

dist/categories-example.html

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ <h1>Using Chipotle as an Example</h1>
2020
<div class="form-input">
2121
<label for="address">Enter Address or Zip Code:</label>
2222
<input type="text" id="address" name="address" />
23+
<select id="maxdistance" name="maxdistance">
24+
<option value="10">10 Miles</option>
25+
<option value="20">20 Miles</option>
26+
<option value="30">30 Miles</option>
27+
<option value="40">40 Miles</option>
28+
</select>
2329
</div>
2430

2531
<button id="bh-sl-submit" type="submit">Submit</button>
@@ -97,6 +103,9 @@ <h1>Using Chipotle as an Example</h1>
97103
<li>
98104
<input type="radio" name="postal" value="55402">55402
99105
</li>
106+
<li>
107+
<input type="radio" name="postal" value="55317">55317
108+
</li>
100109
</ul>
101110
</div>
102111
</form>
@@ -118,11 +127,12 @@ <h1>Using Chipotle as an Example</h1>
118127
<script>
119128
$(function() {
120129
$('#map-container').storeLocator({
130+
'maxDistance': true,
121131
'taxonomyFilters' : {
122132
'category' : 'category-filters-container1',
123133
'features' : 'category-filters-container2',
124134
'city' : 'city-filter',
125-
'postal': 'postal-filter'
135+
'postal': 'postal-filter'
126136
}
127137
});
128138
});

dist/js/jquery.storelocator.js

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

@@ -17,7 +17,7 @@
1717
// Variables used across multiple functions
1818
var $this, listTemplate, infowindowTemplate, dataTypeRead, originalData, originalDataRequest, originalZoom, nameInput, addressInput, olat, olng, storeNum, directionsDisplay, directionsService;
1919
var featuredset = [], locationset = [], normalset = [], markers = [];
20-
var filters = {}, locationData = {}, GeoCodeCalc = {};
20+
var filters = {}, locationData = {}, GeoCodeCalc = {}, mappingObj = {};
2121

2222
// Create the defaults once. Do not change these settings in this file - settings should be overridden in the plugin call
2323
var defaults = {
@@ -281,26 +281,6 @@
281281
this.formEventHandler();
282282
},
283283

284-
/**
285-
* Handle form submission
286-
*
287-
* @param e {event}
288-
*/
289-
getFormValues: function (e) {
290-
// Stop the form submission
291-
e.preventDefault();
292-
293-
if (this.settings.maxDistance === true) {
294-
var maxDistance = $('#' + this.settings.maxDistanceID).val();
295-
// Start the mapping
296-
this.processForm(maxDistance);
297-
}
298-
else {
299-
// Start the mapping
300-
this.processForm();
301-
}
302-
},
303-
304284
/**
305285
* Form event handler setup
306286
*/
@@ -309,17 +289,17 @@
309289
// ASP.net or regular submission?
310290
if (this.settings.noForm === true) {
311291
$(document).on('click', '.' + this.settings.formContainerDiv + ' button', function (e) {
312-
_this.getFormValues(e);
292+
_this.processForm(e);
313293
});
314294
$(document).on('keyup', function (e) {
315295
if (e.keyCode === 13 && $('#' + _this.settings.inputID).is(':focus')) {
316-
_this.getFormValues(e);
296+
_this.processForm(e);
317297
}
318298
});
319299
}
320300
else {
321301
$(document).on('submit', '#' + this.settings.formID, function (e) {
322-
_this.getFormValues(e);
302+
_this.processForm(e);
323303
});
324304
}
325305
},
@@ -423,7 +403,6 @@
423403
*/
424404
start: function () {
425405
var _this = this;
426-
var mappingObj = {};
427406
// If a default location is set
428407
if (this.settings.defaultLoc === true) {
429408
// The address needs to be determined for the directions link
@@ -850,19 +829,7 @@
850829
* @param newPage
851830
*/
852831
paginationChange: function (newPage) {
853-
var maxDistance;
854-
var mappingObj = {};
855-
856-
if (this.settings.maxDistance === true) {
857-
maxDistance = $('#' + this.settings.maxDistanceID).val();
858-
}
859832

860-
this.reset();
861-
mappingObj.lat = olat;
862-
mappingObj.lng = olng;
863-
mappingObj.origin = addressInput;
864-
mappingObj.name = nameInput;
865-
mappingObj.distance = maxDistance;
866833
mappingObj.page = newPage;
867834
this.mapping(mappingObj);
868835
},
@@ -959,11 +926,21 @@
959926
/**
960927
* Process the form values and/or query string
961928
*
962-
* @param distance {number} optional maximum distance
929+
* @param e {event}
963930
*/
964-
processForm: function (distance) {
931+
processForm: function (e) {
965932
var _this = this;
966-
var mappingObj = {};
933+
var distance = null;
934+
935+
// Stop the form submission
936+
if(typeof e !== 'undefined') {
937+
e.preventDefault();
938+
}
939+
940+
// Get the distance if set
941+
if (this.settings.maxDistance === true) {
942+
distance = $('#' + this.settings.maxDistanceID).val();
943+
}
967944

968945
if(this.settings.querystringParams === true) {
969946

@@ -1025,17 +1002,17 @@
10251002
* @param origin {string} origin address
10261003
* @param maxDistance {number} optional maximum distance
10271004
*/
1028-
mapping: function (mappingObj) {
1005+
mapping: function (mappingObject) {
10291006
var _this = this;
10301007
var orig_lat, orig_lng, origin, name, maxDistance, page, firstRun, marker, bounds, storeStart, storeNumToShow, myOptions, noResults;
10311008
var i = 0;
1032-
if (!this.isEmptyObject(mappingObj)) {
1033-
orig_lat = mappingObj.lat;
1034-
orig_lng = mappingObj.lng;
1035-
origin = mappingObj.origin;
1036-
name = mappingObj.name;
1037-
maxDistance = mappingObj.distance;
1038-
page = mappingObj.page;
1009+
if (!this.isEmptyObject(mappingObject)) {
1010+
orig_lat = mappingObject.lat;
1011+
orig_lng = mappingObject.lng;
1012+
origin = mappingObject.origin;
1013+
name = mappingObject.name;
1014+
maxDistance = mappingObject.distance;
1015+
page = mappingObject.page;
10391016
}
10401017

10411018
// Enable the visual refresh https://developers.google.com/maps/documentation/javascript/basics#VisualRefresh
@@ -1514,7 +1491,7 @@
15141491
_this.processForm();
15151492
}
15161493
else {
1517-
_this.mapping();
1494+
_this.mapping(mappingObj);
15181495
}
15191496
}
15201497
}
@@ -1535,7 +1512,7 @@
15351512
_this.processForm();
15361513
}
15371514
else {
1538-
_this.mapping();
1515+
_this.mapping(mappingObj);
15391516
}
15401517
}
15411518
}
@@ -1562,7 +1539,7 @@
15621539
_this.processForm();
15631540
}
15641541
else {
1565-
_this.mapping();
1542+
_this.mapping(mappingObj);
15661543
}
15671544
}
15681545
}
@@ -1578,7 +1555,7 @@
15781555
_this.processForm();
15791556
}
15801557
else {
1581-
_this.mapping();
1558+
_this.mapping(mappingObj);
15821559
}
15831560
}
15841561
}

0 commit comments

Comments
 (0)