Skip to content

Commit 62aeee9

Browse files
committed
Removed featuredPostal setting as it didn't seem practical - large cities can have multiple postal codes, had to do a reverse geocode to guarantee a postal code result from geocode, slowed down featuredset determination.
Added another featured location for testing
1 parent fdb9579 commit 62aeee9

File tree

6 files changed

+59
-96
lines changed

6 files changed

+59
-96
lines changed

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

Lines changed: 28 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
/*! jQuery Google Maps Store Locator - v3.1.0 - 2018-11-25
1+
/*! jQuery Google Maps Store Locator - v3.1.0 - 2019-11-17
22
* http://www.bjornblog.com/web/jquery-store-locator-plugin
3-
* Copyright (c) 2018 Bjorn Holine; Licensed MIT */
3+
* Copyright (c) 2019 Bjorn Holine; Licensed MIT */
44

55
;(function ($, window, document, undefined) {
66
'use strict';
@@ -41,7 +41,6 @@
4141
'exclusiveTax' : null,
4242
'featuredDistance' : null,
4343
'featuredLocations' : false,
44-
'featuredPostal' : false,
4544
'fullMapStart' : false,
4645
'fullMapStartBlank' : false,
4746
'fullMapStartListLimit' : false,
@@ -779,6 +778,7 @@
779778
if (results[0]) {
780779
var result = {};
781780
result.address = results[0].formatted_address;
781+
result.fullResult = results[0];
782782
callbackFunction(result);
783783
}
784784
} else {
@@ -2571,61 +2571,43 @@
25712571
});
25722572
},
25732573

2574+
/**
2575+
* Restrict featured locations from displaying in results by a specific distance
2576+
*
2577+
* @returns {Array}
2578+
*/
2579+
featuredDistanceRestriction: function() {
2580+
this.writeDebug('featuredDistanceRestriction',arguments);
2581+
var _this = this;
2582+
2583+
featuredset = $.grep(featuredset, function (val) {
2584+
2585+
if (val.hasOwnProperty('distance')) {
2586+
return parseFloat(val.distance) <= parseFloat(_this.settings.featuredDistance);
2587+
}
2588+
});
2589+
2590+
return featuredset;
2591+
},
2592+
25742593
/**
2575-
* Restrict featured locations by distance and/or postal code.
2594+
* Restrict featured locations by distance.
25762595
*
2577-
* @param mappingObject
2578-
* @returns {Array}
2596+
* @returns {Array}
25792597
*/
25802598
featuredRestrictions: function(mappingObject) {
25812599
this.writeDebug('featuredRestrictions',arguments);
25822600

2583-
if (this.settings.featuredPostal === false && this.settings.featuredDistance === null) {
2601+
if (this.settings.featuredDistance === null) {
25842602
return featuredset;
25852603
}
25862604

25872605
// Featured locations radius restriction.
25882606
if (this.settings.featuredDistance !== null) {
2589-
var _this = this;
2590-
2591-
featuredset = $.grep(featuredset, function (val) {
2592-
2593-
if (val.hasOwnProperty('distance')) {
2594-
return parseFloat(val.distance) <= parseFloat(_this.settings.featuredDistance);
2595-
}
2596-
});
2607+
featuredset = this.featuredDistanceRestriction(mappingObject);
25972608
}
25982609

2599-
// Featured locations postal code restriction.
2600-
if (this.settings.featuredPostal === true) {
2601-
var postalCode = null;
2602-
2603-
// Check for postal code in the Geocoding result.
2604-
if (typeof mappingObject === 'object' && mappingObject.hasOwnProperty('geocodeResult')) {
2605-
2606-
for (var i = 0; i < mappingObject.geocodeResult.address_components.length; i++) {
2607-
2608-
for (var x = 0; x < mappingObject.geocodeResult.address_components[x].types.length; x++) {
2609-
2610-
if (mappingObject.geocodeResult.address_components[i].types[x] === 'postal_code') {
2611-
postalCode = mappingObject.geocodeResult.address_components[i].short_name;
2612-
}
2613-
}
2614-
}
2615-
}
2616-
2617-
// Do the restriction with the determined postal code if it was found.
2618-
if (postalCode !== null) {
2619-
featuredset = $.grep(featuredset, function (val) {
2620-
2621-
if (val.hasOwnProperty('postal')) {
2622-
return val.postal === postalCode;
2623-
}
2624-
});
2625-
}
2626-
}
2627-
2628-
return featuredset;
2610+
return featuredset;
26292611
},
26302612

26312613
/**
@@ -2867,6 +2849,7 @@
28672849

28682850
// Featured locations filtering
28692851
if (_this.settings.featuredLocations === true) {
2852+
28702853
// Create array for featured locations
28712854
featuredset = $.grep(locationset, function (val) {
28722855

@@ -3098,7 +3081,6 @@
30983081
if (_this.settings.callbackFilters) {
30993082
_this.settings.callbackFilters.call(this, filters, mappingObject);
31003083
}
3101-
31023084
},
31033085

31043086
/**

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

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/data/locations.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@
295295
"hours1": "Mon-Sun 11am-10pm",
296296
"hours2": "",
297297
"hours3": "",
298-
"featured": "",
298+
"featured": "true",
299299
"features": "Online Ordering",
300300
"date": "08/17/17"
301301
},

options.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
| exclusiveTax | null | Set to an array of taxonomies that should filter exclusively vs. inclusively. |
2525
| featuredDistance | null | Restrict the featured locations from displaying by a certain distance (use number value). |
2626
| featuredLocations | false | Set to true to enable featuring locations at the top of the location list (no matter the distance). Add featured=”true” to featured locations in your XML or JSON locations data. |
27-
| featuredPostal | false | Restrict the featured locations from displaying by requiring a match of the postal code to the searched location. |
2827
| fullMapStart | false | Set to true if you want to immediately show a map of all locations. The map will center and zoom automatically. |
2928
| fullMapStartBlank | false | Set to a zoom integer if you want to immediately show a blank map without any locations. |
3029
| fullMapStartListLimit | false | Set to a number to limit the number of items displayed in the location list with full map start. |

readme.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ filtering.
3838
### Version 3.1.0
3939

4040
* Added featuredDistance setting to restrict featured locations by a specified distance.
41-
* Added featuredPostal setting to restrict featured locations by postal code.
4241

4342
### Version 3.0.1
4443

src/js/jquery.storelocator.js

Lines changed: 26 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
'exclusiveTax' : null,
3838
'featuredDistance' : null,
3939
'featuredLocations' : false,
40-
'featuredPostal' : false,
4140
'fullMapStart' : false,
4241
'fullMapStartBlank' : false,
4342
'fullMapStartListLimit' : false,
@@ -775,6 +774,7 @@
775774
if (results[0]) {
776775
var result = {};
777776
result.address = results[0].formatted_address;
777+
result.fullResult = results[0];
778778
callbackFunction(result);
779779
}
780780
} else {
@@ -2567,61 +2567,43 @@
25672567
});
25682568
},
25692569

2570+
/**
2571+
* Restrict featured locations from displaying in results by a specific distance
2572+
*
2573+
* @returns {Array}
2574+
*/
2575+
featuredDistanceRestriction: function() {
2576+
this.writeDebug('featuredDistanceRestriction',arguments);
2577+
var _this = this;
2578+
2579+
featuredset = $.grep(featuredset, function (val) {
2580+
2581+
if (val.hasOwnProperty('distance')) {
2582+
return parseFloat(val.distance) <= parseFloat(_this.settings.featuredDistance);
2583+
}
2584+
});
2585+
2586+
return featuredset;
2587+
},
2588+
25702589
/**
2571-
* Restrict featured locations by distance and/or postal code.
2590+
* Restrict featured locations by distance.
25722591
*
2573-
* @param mappingObject
2574-
* @returns {Array}
2592+
* @returns {Array}
25752593
*/
25762594
featuredRestrictions: function(mappingObject) {
25772595
this.writeDebug('featuredRestrictions',arguments);
25782596

2579-
if (this.settings.featuredPostal === false && this.settings.featuredDistance === null) {
2597+
if (this.settings.featuredDistance === null) {
25802598
return featuredset;
25812599
}
25822600

25832601
// Featured locations radius restriction.
25842602
if (this.settings.featuredDistance !== null) {
2585-
var _this = this;
2586-
2587-
featuredset = $.grep(featuredset, function (val) {
2588-
2589-
if (val.hasOwnProperty('distance')) {
2590-
return parseFloat(val.distance) <= parseFloat(_this.settings.featuredDistance);
2591-
}
2592-
});
2603+
featuredset = this.featuredDistanceRestriction(mappingObject);
25932604
}
25942605

2595-
// Featured locations postal code restriction.
2596-
if (this.settings.featuredPostal === true) {
2597-
var postalCode = null;
2598-
2599-
// Check for postal code in the Geocoding result.
2600-
if (typeof mappingObject === 'object' && mappingObject.hasOwnProperty('geocodeResult')) {
2601-
2602-
for (var i = 0; i < mappingObject.geocodeResult.address_components.length; i++) {
2603-
2604-
for (var x = 0; x < mappingObject.geocodeResult.address_components[x].types.length; x++) {
2605-
2606-
if (mappingObject.geocodeResult.address_components[i].types[x] === 'postal_code') {
2607-
postalCode = mappingObject.geocodeResult.address_components[i].short_name;
2608-
}
2609-
}
2610-
}
2611-
}
2612-
2613-
// Do the restriction with the determined postal code if it was found.
2614-
if (postalCode !== null) {
2615-
featuredset = $.grep(featuredset, function (val) {
2616-
2617-
if (val.hasOwnProperty('postal')) {
2618-
return val.postal === postalCode;
2619-
}
2620-
});
2621-
}
2622-
}
2623-
2624-
return featuredset;
2606+
return featuredset;
26252607
},
26262608

26272609
/**
@@ -2863,6 +2845,7 @@
28632845

28642846
// Featured locations filtering
28652847
if (_this.settings.featuredLocations === true) {
2848+
28662849
// Create array for featured locations
28672850
featuredset = $.grep(locationset, function (val) {
28682851

0 commit comments

Comments
 (0)