Skip to content

Commit db239a3

Browse files
committed
Fixed bug with maxDistance and pagination setting combination, fixed bugs with googleGeocode and reverseGoogleGeocode methods
1 parent 0362245 commit db239a3

File tree

6 files changed

+38
-23
lines changed

6 files changed

+38
-23
lines changed

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

+14-10
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*! jQuery Google Maps Store Locator - v2.0.3 - 2014-12-11
1+
/*! jQuery Google Maps Store Locator - v2.0.4 - 2014-12-15
22
* http://www.bjornblog.com/web/jquery-store-locator-plugin
33
* Copyright (c) 2014 Bjorn Holine; Licensed MIT */
44

@@ -430,7 +430,7 @@
430430
// If a default location is set
431431
if (this.settings.defaultLoc === true) {
432432
// The address needs to be determined for the directions link
433-
var r = new this.reverseGoogleGeocode();
433+
var r = new this.reverseGoogleGeocode(this);
434434
var latlng = new google.maps.LatLng(this.settings.defaultLat, this.settings.defaultLng);
435435
r.geocode({'latLng': latlng}, function (data) {
436436
if (data !== null) {
@@ -472,8 +472,8 @@
472472
/**
473473
* Geocode function used to geocode the origin (entered location)
474474
*/
475-
googleGeocode: function () {
476-
var _this = this;
475+
googleGeocode: function (thisObj) {
476+
var _this = thisObj;
477477
var geocoder = new google.maps.Geocoder();
478478
this.geocode = function (request, callbackFunction) {
479479
geocoder.geocode(request, function (results, status) {
@@ -493,8 +493,8 @@
493493
/**
494494
* Reverse geocode to get address for automatic options needed for directions link
495495
*/
496-
reverseGoogleGeocode: function () {
497-
var _this = this;
496+
reverseGoogleGeocode: function (thisObj) {
497+
var _this = thisObj;
498498
var geocoder = new google.maps.Geocoder();
499499
this.geocode = function (request, callbackFunction) {
500500
geocoder.geocode(request, function (results, status) {
@@ -641,6 +641,7 @@
641641
* @returns {string}
642642
*/
643643
_paginationOutput: function(currentPage, totalPages) {
644+
644645
currentPage = parseFloat(currentPage);
645646
var output = '';
646647
var nextPage = currentPage + 1;
@@ -652,7 +653,7 @@
652653
}
653654

654655
// Add the numbers
655-
for (var p = 0; p < totalPages; p++) {
656+
for (var p = 0; p < Math.ceil(totalPages); p++) {
656657
var n = p + 1;
657658

658659
if (p === currentPage) {
@@ -935,7 +936,7 @@
935936
var _this = this;
936937
var mappingObj = {};
937938
// The address needs to be determined for the directions link
938-
var r = new this.reverseGoogleGeocode();
939+
var r = new this.reverseGoogleGeocode(this);
939940
var latlng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
940941
r.geocode({'latLng': latlng}, function (data) {
941942
if (data !== null) {
@@ -1122,7 +1123,7 @@
11221123
this._start();
11231124
}
11241125
else if(addressInput !== '') {
1125-
var g = new this.googleGeocode();
1126+
var g = new this.googleGeocode(this);
11261127
g.geocode({'address': addressInput, 'region': region}, function (data) {
11271128
if (data !== null) {
11281129
olat = data.latitude;
@@ -1151,7 +1152,6 @@
11511152
* Checks distance of each location and setups up the locationset array
11521153
*
11531154
* @param data {Object} location data object
1154-
* @param l {number} iterator from the loop processing the data in the mapping function below
11551155
* @param lat {number} origin latitude
11561156
* @param lng {number} origin longitude
11571157
* @param firstRun {boolean} initial load check
@@ -1663,6 +1663,10 @@
16631663
storeNumToShow = _this.settings.locationsPerPage;
16641664
storeStart = page * _this.settings.locationsPerPage;
16651665

1666+
if( (storeStart + storeNumToShow) > locationset.length ) {
1667+
storeNumToShow = _this.settings.locationsPerPage - ((storeStart + storeNumToShow) - locationset.length);
1668+
}
1669+
16661670
locationset = locationset.slice(storeStart, storeStart + storeNumToShow);
16671671
storeNum = locationset.length;
16681672
}

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

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

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "jquery-storelocator-plugin",
3-
"version": "2.0.3",
3+
"version": "2.0.4",
44
"description": "This jQuery plugin takes advantage of Google Maps API version 3 to create an easy to implement store locator. No back-end programming is required, you just need to feed it KML, XML, or JSON data with all the location information.",
55
"repository": {
66
"type": "git",

readme.md

+7
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@ for even faster loading.
2727

2828
## Changelog
2929

30+
Version 2.0.4
31+
32+
* Fixed bug with maxDistance and pagination setting combination. The last page of of the pagination results was set to
33+
use the locationsPerPage setting instead of the remaining number, which could have resulted in the plugin trying to
34+
load undefined locations.
35+
* Fixed bugs with googleGeocode and reverseGoogleGeocode methods in which references to "this" were undefined.
36+
3037
### Version 2.0.3
3138

3239
* Fixed bug with maxDistance setting - updated locationsSetup method so that the locationset array uses array.push

src/js/jquery.storelocator.js

+13-9
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@
428428
// If a default location is set
429429
if (this.settings.defaultLoc === true) {
430430
// The address needs to be determined for the directions link
431-
var r = new this.reverseGoogleGeocode();
431+
var r = new this.reverseGoogleGeocode(this);
432432
var latlng = new google.maps.LatLng(this.settings.defaultLat, this.settings.defaultLng);
433433
r.geocode({'latLng': latlng}, function (data) {
434434
if (data !== null) {
@@ -470,8 +470,8 @@
470470
/**
471471
* Geocode function used to geocode the origin (entered location)
472472
*/
473-
googleGeocode: function () {
474-
var _this = this;
473+
googleGeocode: function (thisObj) {
474+
var _this = thisObj;
475475
var geocoder = new google.maps.Geocoder();
476476
this.geocode = function (request, callbackFunction) {
477477
geocoder.geocode(request, function (results, status) {
@@ -491,8 +491,8 @@
491491
/**
492492
* Reverse geocode to get address for automatic options needed for directions link
493493
*/
494-
reverseGoogleGeocode: function () {
495-
var _this = this;
494+
reverseGoogleGeocode: function (thisObj) {
495+
var _this = thisObj;
496496
var geocoder = new google.maps.Geocoder();
497497
this.geocode = function (request, callbackFunction) {
498498
geocoder.geocode(request, function (results, status) {
@@ -639,6 +639,7 @@
639639
* @returns {string}
640640
*/
641641
_paginationOutput: function(currentPage, totalPages) {
642+
642643
currentPage = parseFloat(currentPage);
643644
var output = '';
644645
var nextPage = currentPage + 1;
@@ -650,7 +651,7 @@
650651
}
651652

652653
// Add the numbers
653-
for (var p = 0; p < totalPages; p++) {
654+
for (var p = 0; p < Math.ceil(totalPages); p++) {
654655
var n = p + 1;
655656

656657
if (p === currentPage) {
@@ -933,7 +934,7 @@
933934
var _this = this;
934935
var mappingObj = {};
935936
// The address needs to be determined for the directions link
936-
var r = new this.reverseGoogleGeocode();
937+
var r = new this.reverseGoogleGeocode(this);
937938
var latlng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
938939
r.geocode({'latLng': latlng}, function (data) {
939940
if (data !== null) {
@@ -1120,7 +1121,7 @@
11201121
this._start();
11211122
}
11221123
else if(addressInput !== '') {
1123-
var g = new this.googleGeocode();
1124+
var g = new this.googleGeocode(this);
11241125
g.geocode({'address': addressInput, 'region': region}, function (data) {
11251126
if (data !== null) {
11261127
olat = data.latitude;
@@ -1149,7 +1150,6 @@
11491150
* Checks distance of each location and setups up the locationset array
11501151
*
11511152
* @param data {Object} location data object
1152-
* @param l {number} iterator from the loop processing the data in the mapping function below
11531153
* @param lat {number} origin latitude
11541154
* @param lng {number} origin longitude
11551155
* @param firstRun {boolean} initial load check
@@ -1661,6 +1661,10 @@
16611661
storeNumToShow = _this.settings.locationsPerPage;
16621662
storeStart = page * _this.settings.locationsPerPage;
16631663

1664+
if( (storeStart + storeNumToShow) > locationset.length ) {
1665+
storeNumToShow = _this.settings.locationsPerPage - ((storeStart + storeNumToShow) - locationset.length);
1666+
}
1667+
16641668
locationset = locationset.slice(storeStart, storeStart + storeNumToShow);
16651669
storeNum = locationset.length;
16661670
}

storelocator.jquery.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"title": "jQuery Google Maps Store Locator",
44
"description": "This jQuery plugin takes advantage of Google Maps API version 3 to create an easy to implement store locator. No back-end programming is required, you just need to feed it KML, XML, or JSON data with all the location information.",
55
"keywords": ["jquery","locator","store", "location", "locations", "maps", "map", "stores", "find"],
6-
"version": "2.0.3",
6+
"version": "2.0.4",
77
"author": {
88
"name": "Bjorn Holine",
99
"url": "http://www.bjornblog.com/"

0 commit comments

Comments
 (0)