Skip to content

Commit 0c77f81

Browse files
committed
Added featuredPostal setting to restrict featured locations by postal code
1 parent 1145d04 commit 0c77f81

File tree

5 files changed

+400
-264
lines changed

5 files changed

+400
-264
lines changed

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

Lines changed: 196 additions & 131 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*! jQuery Google Maps Store Locator - v3.0.1 - 2018-09-29
1+
/*! jQuery Google Maps Store Locator - v3.0.1 - 2018-11-25
22
* http://www.bjornblog.com/web/jquery-store-locator-plugin
33
* Copyright (c) 2018 Bjorn Holine; Licensed MIT */
44

@@ -17,129 +17,131 @@
1717
var featuredset = [], locationset = [], normalset = [], markers = [];
1818
var filters = {}, locationData = {}, GeoCodeCalc = {}, mappingObj = {};
1919

20-
// Create the defaults once. DO NOT change these settings in this file - settings should be overridden in the plugin call
21-
var defaults = {
22-
'ajaxData' : null,
23-
'altDistanceNoResult' : false,
24-
'autoComplete' : false,
25-
'autoCompleteDisableListener': false,
26-
'autoCompleteOptions' : {},
27-
'autoGeocode' : false,
28-
'bounceMarker' : true,
29-
'catMarkers' : null,
30-
'dataLocation' : 'data/locations.json',
31-
'dataRaw' : null,
32-
'dataType' : 'json',
33-
'debug' : false,
34-
'defaultLat' : null,
35-
'defaultLng' : null,
36-
'defaultLoc' : false,
37-
'disableAlphaMarkers' : false,
38-
'distanceAlert' : 60,
39-
'dragSearch' : false,
40-
'exclusiveFiltering' : false,
41-
'exclusiveTax' : null,
42-
'featuredLocations' : false,
43-
'fullMapStart' : false,
44-
'fullMapStartBlank' : false,
45-
'fullMapStartListLimit' : false,
46-
'infoBubble' : null,
47-
'inlineDirections' : false,
48-
'lengthUnit' : 'm',
49-
'listColor1' : '#ffffff',
50-
'listColor2' : '#eeeeee',
51-
'loading' : false,
52-
'locationsPerPage' : 10,
53-
'mapSettings' : {
54-
mapTypeId: google.maps.MapTypeId.ROADMAP,
55-
zoom : 12
56-
},
57-
'markerCluster' : null,
58-
'markerImg' : null,
59-
'markerDim' : null,
60-
'maxDistance' : false,
61-
'modal' : false,
62-
'nameAttribute' : 'name',
63-
'nameSearch' : false,
64-
'noForm' : false,
65-
'openNearest' : false,
66-
'originMarker' : false,
67-
'originMarkerDim' : null,
68-
'originMarkerImg' : null,
69-
'pagination' : false,
70-
'querystringParams' : false,
71-
'selectedMarkerImg' : null,
72-
'selectedMarkerImgDim' : null,
73-
'sessionStorage' : false,
74-
'slideMap' : true,
75-
'sortBy' : null,
76-
'storeLimit' : 26,
77-
'taxonomyFilters' : null,
78-
'visibleMarkersList' : false,
79-
'xmlElement' : 'marker',
80-
// HTML elements
81-
'addressID' : 'bh-sl-address',
82-
'closeIcon' : 'bh-sl-close-icon',
83-
'formContainer' : 'bh-sl-form-container',
84-
'formID' : 'bh-sl-user-location',
85-
'geocodeID' : null,
86-
'lengthSwapID' : 'bh-sl-length-swap',
87-
'loadingContainer' : 'bh-sl-loading',
88-
'locationList' : 'bh-sl-loc-list',
89-
'mapID' : 'bh-sl-map',
90-
'maxDistanceID' : 'bh-sl-maxdistance',
91-
'modalContent' : 'bh-sl-modal-content',
92-
'modalWindow' : 'bh-sl-modal-window',
93-
'orderID' : 'bh-sl-order',
94-
'overlay' : 'bh-sl-overlay',
95-
'regionID' : 'bh-sl-region',
96-
'searchID' : 'bh-sl-search',
97-
'sortID' : 'bh-sl-sort',
98-
'taxonomyFiltersContainer' : 'bh-sl-filters-container',
99-
// Templates
100-
'infowindowTemplatePath' : 'assets/js/plugins/storeLocator/templates/infowindow-description.html',
101-
'listTemplatePath' : 'assets/js/plugins/storeLocator/templates/location-list-description.html',
102-
'KMLinfowindowTemplatePath' : 'assets/js/plugins/storeLocator/templates/kml-infowindow-description.html',
103-
'KMLlistTemplatePath' : 'assets/js/plugins/storeLocator/templates/kml-location-list-description.html',
104-
'listTemplateID' : null,
105-
'infowindowTemplateID' : null,
106-
// Callbacks
107-
'callbackAutoGeoSuccess' : null,
108-
'callbackBeforeSend' : null,
109-
'callbackCloseDirections' : null,
110-
'callbackCreateMarker' : null,
111-
'callbackDirectionsRequest' : null,
112-
'callbackFilters' : null,
113-
'callbackFormVals' : null,
114-
'callbackGeocodeRestrictions': null,
115-
'callbackJsonp' : null,
116-
'callbackListClick' : null,
117-
'callbackMapSet' : null,
118-
'callbackMarkerClick' : null,
119-
'callbackModalClose' : null,
120-
'callbackModalOpen' : null,
121-
'callbackModalReady' : null,
122-
'callbackNearestLoc' : null,
123-
'callbackNoResults' : null,
124-
'callbackNotify' : null,
125-
'callbackOrder' : null,
126-
'callbackPageChange' : null,
127-
'callbackRegion' : null,
128-
'callbackSorting' : null,
129-
'callbackSuccess' : null,
130-
// Language options
131-
'addressErrorAlert' : 'Unable to find address',
132-
'autoGeocodeErrorAlert' : 'Automatic location detection failed. Please fill in your address or zip code.',
133-
'distanceErrorAlert' : 'Unfortunately, our closest location is more than ',
134-
'kilometerLang' : 'kilometer',
135-
'kilometersLang' : 'kilometers',
136-
'mileLang' : 'mile',
137-
'milesLang' : 'miles',
138-
'noResultsTitle' : 'No results',
139-
'noResultsDesc' : 'No locations were found with the given criteria. Please modify your selections or input.',
140-
'nextPage' : 'Next »',
141-
'prevPage' : '« Prev'
142-
};
20+
// Create the defaults once. DO NOT change these settings in this file - settings should be overridden in the plugin call
21+
var defaults = {
22+
'ajaxData' : null,
23+
'altDistanceNoResult' : false,
24+
'autoComplete' : false,
25+
'autoCompleteDisableListener': false,
26+
'autoCompleteOptions' : {},
27+
'autoGeocode' : false,
28+
'bounceMarker' : true,
29+
'catMarkers' : null,
30+
'dataLocation' : 'data/locations.json',
31+
'dataRaw' : null,
32+
'dataType' : 'json',
33+
'debug' : false,
34+
'defaultLat' : null,
35+
'defaultLng' : null,
36+
'defaultLoc' : false,
37+
'disableAlphaMarkers' : false,
38+
'distanceAlert' : 60,
39+
'dragSearch' : false,
40+
'exclusiveFiltering' : false,
41+
'exclusiveTax' : null,
42+
'featuredDistance' : null,
43+
'featuredLocations' : false,
44+
'featuredPostal' : false,
45+
'fullMapStart' : false,
46+
'fullMapStartBlank' : false,
47+
'fullMapStartListLimit' : false,
48+
'infoBubble' : null,
49+
'inlineDirections' : false,
50+
'lengthUnit' : 'm',
51+
'listColor1' : '#ffffff',
52+
'listColor2' : '#eeeeee',
53+
'loading' : false,
54+
'locationsPerPage' : 10,
55+
'mapSettings' : {
56+
mapTypeId: google.maps.MapTypeId.ROADMAP,
57+
zoom : 12
58+
},
59+
'markerCluster' : null,
60+
'markerImg' : null,
61+
'markerDim' : null,
62+
'maxDistance' : false,
63+
'modal' : false,
64+
'nameAttribute' : 'name',
65+
'nameSearch' : false,
66+
'noForm' : false,
67+
'openNearest' : false,
68+
'originMarker' : false,
69+
'originMarkerDim' : null,
70+
'originMarkerImg' : null,
71+
'pagination' : false,
72+
'querystringParams' : false,
73+
'selectedMarkerImg' : null,
74+
'selectedMarkerImgDim' : null,
75+
'sessionStorage' : false,
76+
'slideMap' : true,
77+
'sortBy' : null,
78+
'storeLimit' : 26,
79+
'taxonomyFilters' : null,
80+
'visibleMarkersList' : false,
81+
'xmlElement' : 'marker',
82+
// HTML elements
83+
'addressID' : 'bh-sl-address',
84+
'closeIcon' : 'bh-sl-close-icon',
85+
'formContainer' : 'bh-sl-form-container',
86+
'formID' : 'bh-sl-user-location',
87+
'geocodeID' : null,
88+
'lengthSwapID' : 'bh-sl-length-swap',
89+
'loadingContainer' : 'bh-sl-loading',
90+
'locationList' : 'bh-sl-loc-list',
91+
'mapID' : 'bh-sl-map',
92+
'maxDistanceID' : 'bh-sl-maxdistance',
93+
'modalContent' : 'bh-sl-modal-content',
94+
'modalWindow' : 'bh-sl-modal-window',
95+
'orderID' : 'bh-sl-order',
96+
'overlay' : 'bh-sl-overlay',
97+
'regionID' : 'bh-sl-region',
98+
'searchID' : 'bh-sl-search',
99+
'sortID' : 'bh-sl-sort',
100+
'taxonomyFiltersContainer' : 'bh-sl-filters-container',
101+
// Templates
102+
'infowindowTemplatePath' : 'assets/js/plugins/storeLocator/templates/infowindow-description.html',
103+
'listTemplatePath' : 'assets/js/plugins/storeLocator/templates/location-list-description.html',
104+
'KMLinfowindowTemplatePath' : 'assets/js/plugins/storeLocator/templates/kml-infowindow-description.html',
105+
'KMLlistTemplatePath' : 'assets/js/plugins/storeLocator/templates/kml-location-list-description.html',
106+
'listTemplateID' : null,
107+
'infowindowTemplateID' : null,
108+
// Callbacks
109+
'callbackAutoGeoSuccess' : null,
110+
'callbackBeforeSend' : null,
111+
'callbackCloseDirections' : null,
112+
'callbackCreateMarker' : null,
113+
'callbackDirectionsRequest' : null,
114+
'callbackFilters' : null,
115+
'callbackFormVals' : null,
116+
'callbackGeocodeRestrictions': null,
117+
'callbackJsonp' : null,
118+
'callbackListClick' : null,
119+
'callbackMapSet' : null,
120+
'callbackMarkerClick' : null,
121+
'callbackModalClose' : null,
122+
'callbackModalOpen' : null,
123+
'callbackModalReady' : null,
124+
'callbackNearestLoc' : null,
125+
'callbackNoResults' : null,
126+
'callbackNotify' : null,
127+
'callbackOrder' : null,
128+
'callbackPageChange' : null,
129+
'callbackRegion' : null,
130+
'callbackSorting' : null,
131+
'callbackSuccess' : null,
132+
// Language options
133+
'addressErrorAlert' : 'Unable to find address',
134+
'autoGeocodeErrorAlert' : 'Automatic location detection failed. Please fill in your address or zip code.',
135+
'distanceErrorAlert' : 'Unfortunately, our closest location is more than ',
136+
'kilometerLang' : 'kilometer',
137+
'kilometersLang' : 'kilometers',
138+
'mileLang' : 'mile',
139+
'milesLang' : 'miles',
140+
'noResultsTitle' : 'No results',
141+
'noResultsDesc' : 'No locations were found with the given criteria. Please modify your selections or input.',
142+
'nextPage' : 'Next »',
143+
'prevPage' : '« Prev'
144+
};
143145

144146
// Plugin constructor
145147
function Plugin(element, options) {
@@ -234,7 +236,8 @@
234236

235237
/**
236238
* Destroy
237-
* Note: The Google map is not destroyed here because Google recommends using a single instance and reusing it (it's not really supported)
239+
* Note: The Google map is not destroyed here because Google recommends using a single instance and reusing it
240+
* (it's not really supported)
238241
*/
239242
destroy: function () {
240243
this.writeDebug('destroy');
@@ -1122,7 +1125,8 @@
11221125
* @param point {Object} LatLng of current location
11231126
* @param name {string} location name
11241127
* @param address {string} location address
1125-
* @param letter {string} optional letter used for front-end identification and correlation between list and points
1128+
* @param letter {string} optional letter used for front-end identification and correlation between list and
1129+
* points
11261130
* @param map {Object} the Google Map
11271131
* @param category {string} location category/categories
11281132
* @returns {Object} Google Maps marker
@@ -1879,7 +1883,8 @@
18791883
},
18801884

18811885
/**
1882-
* Set up front-end ordering functionality - this ties in to sorting and that has to be enabled for this to work.
1886+
* Set up front-end ordering functionality - this ties in to sorting and that has to be enabled for this to
1887+
* work.
18831888
*/
18841889
order: function() {
18851890
this.writeDebug('order',arguments);
@@ -2566,10 +2571,60 @@
25662571
});
25672572
},
25682573

2574+
/**
2575+
* Restrict featured locations by distance and/or postal code.
2576+
*
2577+
* @param mappingObject
2578+
* @returns {Array}
2579+
*/
2580+
featurdRestrictions: function(mappingObject) {
2581+
this.writeDebug('featurdRestrictions',arguments);
2582+
2583+
if (this.settings.featuredPostal === false && this.settings.featuredPostal === null) {
2584+
return featuredset;
2585+
}
2586+
2587+
// Featured locations radius restriction.
2588+
if (this.settings.featuredPostal !== null) {
2589+
}
2590+
2591+
// Featured locations postal code restriction.
2592+
if (this.settings.featuredPostal === true) {
2593+
var postalCode = null;
2594+
2595+
// Check for postal code in the Geocoding result.
2596+
if (typeof mappingObject === 'object' && mappingObject.hasOwnProperty('geocodeResult')) {
2597+
2598+
for (var i = 0; i < mappingObject.geocodeResult.address_components.length; i++) {
2599+
2600+
for (var x = 0; x < mappingObject.geocodeResult.address_components[x].types.length; x++) {
2601+
2602+
if (mappingObject.geocodeResult.address_components[i].types[x] === 'postal_code') {
2603+
postalCode = mappingObject.geocodeResult.address_components[i].short_name;
2604+
}
2605+
}
2606+
}
2607+
}
2608+
2609+
// Do the restriction with the determined postal code if it was found.
2610+
if (postalCode !== null) {
2611+
featuredset = $.grep(featuredset, function (val) {
2612+
2613+
if (val.hasOwnProperty('postal')) {
2614+
return val.postal === postalCode;
2615+
}
2616+
});
2617+
}
2618+
}
2619+
2620+
return featuredset;
2621+
},
2622+
25692623
/**
25702624
* The primary mapping function that runs everything
25712625
*
2572-
* @param mappingObject {Object} all the potential mapping properties - latitude, longitude, origin, name, max distance, page
2626+
* @param mappingObject {Object} all the potential mapping properties - latitude, longitude, origin, name, max
2627+
* distance, page
25732628
*/
25742629
mapping: function (mappingObject) {
25752630
this.writeDebug('mapping',arguments);
@@ -2631,7 +2686,8 @@
26312686
/**
26322687
* Processes the location data
26332688
*
2634-
* @param mappingObject {Object} all the potential mapping properties - latitude, longitude, origin, name, max distance, page
2689+
* @param mappingObject {Object} all the potential mapping properties - latitude, longitude, origin, name, max
2690+
* distance, page
26352691
* @param originPoint {Object} LatLng of origin point
26362692
* @param data {Object} location data
26372693
* @param page {number} current page number
@@ -2805,12 +2861,21 @@
28052861
if (_this.settings.featuredLocations === true) {
28062862
// Create array for featured locations
28072863
featuredset = $.grep(locationset, function (val) {
2808-
return val.featured === 'true';
2864+
2865+
if (val.hasOwnProperty('featured')) {
2866+
return val.featured === 'true';
2867+
}
28092868
});
28102869

2870+
// Featured location restrictions.
2871+
featuredset = _this.featurdRestrictions(mappingObject);
2872+
28112873
// Create array for normal locations
28122874
normalset = $.grep(locationset, function (val) {
2813-
return val.featured !== 'true';
2875+
2876+
if (val.hasOwnProperty('featured')) {
2877+
return val.featured !== 'true';
2878+
}
28142879
});
28152880

28162881
// Combine the arrays

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.

options.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@
2222
| dragSearch | false | Set to true to perform a new search after the map is dragged. |
2323
| exclusiveFiltering | false | Set to true to enable exclusive taxonomy filtering rather than the default inclusive. |
2424
| exclusiveTax | null | Set to an array of taxonomies that should filter exclusively vs. inclusively. |
25+
| featuredDistance | null | Restrict the featured locations from displaying by a certain distance. |
2526
| 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. |
2628
| fullMapStart | false | Set to true if you want to immediately show a map of all locations. The map will center and zoom automatically. |
2729
| fullMapStartBlank | false | Set to a zoom integer if you want to immediately show a blank map without any locations. |
2830
| fullMapStartListLimit | false | Set to a number to limit the number of items displayed in the location list with full map start. |

0 commit comments

Comments
 (0)