Skip to content

Commit 233d8d3

Browse files
committed
Added callback documentation, added map reset functionality, fixed issue with max distance and query string setting combination
1 parent 65dfbcd commit 233d8d3

20 files changed

+347
-14
lines changed

callbacks.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
### jQuery Google Maps Store Locator callbacks
2+
3+
Several callbacks are available for use with the jQuery Store Locator plugin. The purpose of the callbacks is to allow
4+
developers to add custom functionality with JavaScript and/or jQuery upon certain events that happen when using the
5+
plugin. The functions listed below are executed at the time of these events.
6+
7+
When calling the plugin, a callback can be set to a function name or a function can be set up within the settings:
8+
9+
```javascript
10+
$('#bh-sl-map-container').storeLocator({
11+
callbackSuccess: function(){
12+
// Whatever you want here
13+
}
14+
});
15+
```
16+
17+
Separate function example:
18+
19+
```javascript
20+
function doSomethingOnSuccess() {
21+
// Whatever you want here
22+
}
23+
24+
$('#bh-sl-map-container').storeLocator({
25+
callbackSuccess: doSomethingOnSuccess()
26+
});
27+
```
28+
29+
30+
| Function | Description |
31+
|---|---|
32+
| [callbackNotify](callbacks/callback-notification.md) | Notification callback |
33+
| [callbackBeforeSend](callbacks/callback-beforesend.md) | Before location data request callback |
34+
| [callbackDirectionsRequest](callbacks/callback-directionsrequest.md) | Directions request callback |
35+
| [callbackCloseDirections](callbacks/callback-closedirections.md) | Close directions callback |
36+
| [callbackNoResults](callbacks/callback-noresults.md) | No results callback |
37+
| [callbackJsonp](callbacks/callback-jsonp.md) | JSONP callback |
38+
| [callbackSuccess](callbacks/callback-success.md) | Success callback |
39+
| [callbackMapSet](callbacks/callback-mapset.md) | Map set callback |
40+
| [callbackModalOpen](callbacks/callback-modalopen.md) | Modal open callback |
41+
| [callbackModalReady](callbacks/callback-modalready.md) | Modal ready callback |
42+
| [callbackModalClose](callbacks/callback-modalclose.md) | Modal close callback |
43+
| [callbackMarkerClick](callbacks/callback-markerclick.md) | Marker click callback |
44+
| [callbackListClick](callbacks/callback-listclick.md) | Location list click callback |
45+
| [callbackPageChange](callbacks/callback-pagechange.md) | Page change callback |
46+
| [callbackFilters](callbacks/callback-filters.md) | Filters callback |

callbacks/callback-beforesend.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# callbackBeforeSend
2+
3+
## Description
4+
5+
Fires right before the location data request. If not using the full map start setting the user’s origin will have
6+
already been determined.
7+
8+
## Parameters
9+
10+
| Name | Type | Description |
11+
|---|---|---|
12+
| lat | float | Origin latitude |
13+
| lng | float | Origin longitude |
14+
| address | string | The full origin address |

callbacks/callback-closedirections.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# callbackCloseDirections
2+
3+
## Description
4+
5+
Fires when the directions are closed when using the inline directions setting.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# callbackDirectionsRequest
2+
3+
## Description
4+
5+
Fires upon a directions request when using the inline directions setting.
6+
7+
## Parameters
8+
9+
| Name | Type | Description |
10+
|---|---|---|
11+
| origin | string | Origin address |
12+
| locID | int | Location ID of directions to |
13+
| map | object | Google map object |

callbacks/callback-filters.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# callbackFilters
2+
3+
## Description
4+
5+
Fires when a filter is changed.
6+
7+
## Parameters
8+
9+
| Name | Type | Description |
10+
|---|---|---|
11+
| filters | array | Array of selected filters |

callbacks/callback-jsonp.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# callbackJsonp
2+
3+
## Description
4+
5+
Callback function for a JSONP data request. This will be used instead of the random name automatically generated by
6+
jQuery.

callbacks/callback-listclick.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# callbackListClick
2+
3+
## Description
4+
5+
Fires after a location list item is clicked.
6+
7+
## Parameters
8+
9+
| Name | Type | Description |
10+
|---|---|---|
11+
| markerId | int | Corresponding marker ID |

callbacks/callback-mapset.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# callbackMapSet
2+
3+
## Description
4+
5+
Fires after the map has been loaded.
6+
7+
## Parameters
8+
9+
| Name | Type | Description |
10+
|---|---|---|
11+
| map | object | Google map object |
12+
| originPoint | object | Google LatLng object of the origin coordinates |
13+
| originalZoom | int | The initial map zoom level |
14+
| myOptions | object | All of the map settings |

callbacks/callback-markerclick.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# callbackMarkerClick
2+
3+
## Description
4+
5+
Fires when a marker on the map is clicked.
6+
7+
## Parameters
8+
9+
| Name | Type | Description |
10+
|---|---|---|
11+
| marker | object | Google Maps marker object |
12+
| markerId | int | Marker ID number |
13+
| $selectedLocation | object | Corresponding location list DOM element |

callbacks/callback-modalclose.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# callbackModalClose
2+
3+
## Description
4+
5+
Fires when the modal window is closed.

callbacks/callback-modalopen.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# callbackModalOpen
2+
3+
## Description
4+
5+
Fires when the modal window opens when using the modal setting.

callbacks/callback-modalready.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# callbackModalReady
2+
3+
## Description
4+
5+
Fires when the content of the modal is generated.

callbacks/callback-noresults.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# callbackNoResults
2+
3+
## Description
4+
5+
Fires when there are no results.
6+
7+
## Parameters
8+
9+
| Name | Type | Description |
10+
|---|---|---|
11+
| map | object | Google map object |
12+
| myOptions | object | All the map settings |

callbacks/callback-notification.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# callbackNotify
2+
3+
## Description
4+
5+
There are a few instances in which a JavaScript alert will be displayed with the plugin. Examples of this include when
6+
geocoding fails, if the locations are farther from the user’s origin than the distance alert limit setting, etc. This
7+
callback can be used if you’d rather notify the user with something other than alerts.
8+
9+
## Parameters
10+
11+
| Name | Type | Description |
12+
|---|---|---|
13+
| notifyText | string | The notification string to be displayed |

callbacks/callback-pagechange.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# callbackPageChange
2+
3+
## Description
4+
5+
Fires when the page is changed with the pagination setting enabled.
6+
7+
## Parameters
8+
9+
| Name | Type | Description |
10+
|---|---|---|
11+
| newPage | int | Page number that was clicked |

callbacks/callback-success.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# callbackSuccess
2+
3+
## Description
4+
5+
Fires after the location data has been successfully called.

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

Lines changed: 77 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*! jQuery Google Maps Store Locator - v2.6.3 - 2016-09-07
1+
/*! jQuery Google Maps Store Locator - v2.6.3 - 2016-09-22
22
* http://www.bjornblog.com/web/jquery-store-locator-plugin
33
* Copyright (c) 2016 Bjorn Holine; Licensed MIT */
44

@@ -93,6 +93,7 @@
9393
'sessionStorage' : false,
9494
'markerCluster' : null,
9595
'infoBubble' : null,
96+
// Callbacks
9697
'callbackNotify' : null,
9798
'callbackBeforeSend' : null,
9899
'callbackSuccess' : null,
@@ -252,6 +253,7 @@
252253

253254
/**
254255
* Reset function
256+
* This method clears out all the variables and removes events. It does not reload the map.
255257
*/
256258
reset: function () {
257259
this.writeDebug('reset');
@@ -278,6 +280,57 @@
278280
}
279281
},
280282

283+
/**
284+
* Reset the form filters
285+
*/
286+
formFiltersReset: function () {
287+
this.writeDebug('formFiltersReset');
288+
if (this.settings.taxonomyFilters === null) {
289+
return;
290+
}
291+
292+
var $inputs = $('.' + this.settings.taxonomyFiltersContainer + ' input'),
293+
$selects = $('.' + this.settings.taxonomyFiltersContainer + ' select');
294+
295+
if ( typeof($inputs) !== 'object') {
296+
return;
297+
}
298+
299+
// Loop over the input fields
300+
$inputs.each(function() {
301+
if ($(this).is('input[type="checkbox"]') || $(this).is('input[type="radio"]')) {
302+
$(this).prop('checked',false);
303+
}
304+
});
305+
306+
// Loop over select fields
307+
$selects.each(function() {
308+
$(this).prop('selectedIndex',0);
309+
});
310+
},
311+
312+
/**
313+
* Reload everything
314+
* This method does a reset of everything and reloads the map as it would first appear.
315+
*/
316+
mapReload: function() {
317+
this.writeDebug('mapReload');
318+
this.reset();
319+
320+
if ( this.settings.taxonomyFilters !== null ) {
321+
this.formFiltersReset();
322+
this.taxonomyFiltersInit();
323+
}
324+
325+
if ((olat) && (olng)) {
326+
this.settings.mapSettings.zoom = originalZoom;
327+
this.processForm();
328+
}
329+
else {
330+
this.mapping(mappingObj);
331+
}
332+
},
333+
281334
/**
282335
* Notifications
283336
* Some errors use alert by default. This is overridable with the callbackNotify option
@@ -434,6 +487,13 @@
434487
_this.processForm(e);
435488
});
436489
}
490+
491+
// Reset button trigger
492+
if ($('.bh-sl-reset').length && $('#' + this.settings.mapID).length) {
493+
$(document).on('click.' + pluginName, '.bh-sl-reset', function () {
494+
_this.mapReload();
495+
});
496+
}
437497
},
438498

439499
/**
@@ -1649,6 +1709,7 @@
16491709
checkFilters: function () {
16501710
this.writeDebug('checkFilters');
16511711
for(var key in this.settings.taxonomyFilters) {
1712+
16521713
if(this.settings.taxonomyFilters.hasOwnProperty(key)) {
16531714
// Find the existing checked boxes for each checkbox filter
16541715
this._existingCheckedFilters(key);
@@ -1699,18 +1760,28 @@
16991760
},
17001761

17011762
/**
1702-
* Taxonomy filtering
1763+
* Initialize or reset the filters object to its original state
17031764
*/
1704-
taxonomyFiltering: function() {
1705-
this.writeDebug('taxonomyFiltering');
1706-
var _this = this;
1765+
taxonomyFiltersInit: function () {
1766+
this.writeDebug('taxonomyFiltersInit');
17071767

17081768
// Set up the filters
17091769
for(var key in this.settings.taxonomyFilters) {
17101770
if(this.settings.taxonomyFilters.hasOwnProperty(key)) {
17111771
filters[key] = [];
17121772
}
17131773
}
1774+
},
1775+
1776+
/**
1777+
* Taxonomy filtering
1778+
*/
1779+
taxonomyFiltering: function() {
1780+
this.writeDebug('taxonomyFiltering');
1781+
var _this = this;
1782+
1783+
// Set up the filters
1784+
_this.taxonomyFiltersInit();
17141785

17151786
// Check query string for taxonomy parameter keys.
17161787
_this.checkQueryStringFilters();
@@ -2135,7 +2206,7 @@
21352206

21362207
// Check the closest marker
21372208
if (_this.isEmptyObject(taxFilters)) {
2138-
if (_this.settings.maxDistance === true && firstRun !== true && maxDistance) {
2209+
if (_this.settings.maxDistance === true && maxDistance) {
21392210
if (typeof locationset[0] === 'undefined' || locationset[0].distance > maxDistance) {
21402211
_this.notify(_this.settings.distanceErrorAlert + maxDistance + ' ' + distUnit);
21412212
}

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: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ filtering.
3939

4040
* Added [InfoBubble](https://github.com/googlemaps/js-info-bubble) support and example file.
4141
* Added markerAlphaColor setting to change the marker letter color.
42+
* Added reset functionality that can be triggered via a button that has the CSS class "bh-sl-reset".
4243
* Added query string parameter filter check so that results can be filtered with URL query strings.
44+
* Fixed issue with maxDistance and querystringParams settings combonation.
4345

4446
### Version 2.6.2
4547

0 commit comments

Comments
 (0)