|
1 |
| -/*! jQuery Google Maps Store Locator - v3.0.1 - 2018-09-29 |
| 1 | +/*! jQuery Google Maps Store Locator - v3.0.1 - 2018-11-25 |
2 | 2 | * http://www.bjornblog.com/web/jquery-store-locator-plugin
|
3 | 3 | * Copyright (c) 2018 Bjorn Holine; Licensed MIT */
|
4 | 4 |
|
|
17 | 17 | var featuredset = [], locationset = [], normalset = [], markers = [];
|
18 | 18 | var filters = {}, locationData = {}, GeoCodeCalc = {}, mappingObj = {};
|
19 | 19 |
|
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 | + }; |
143 | 145 |
|
144 | 146 | // Plugin constructor
|
145 | 147 | function Plugin(element, options) {
|
|
234 | 236 |
|
235 | 237 | /**
|
236 | 238 | * 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) |
238 | 241 | */
|
239 | 242 | destroy: function () {
|
240 | 243 | this.writeDebug('destroy');
|
|
1122 | 1125 | * @param point {Object} LatLng of current location
|
1123 | 1126 | * @param name {string} location name
|
1124 | 1127 | * @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 |
1126 | 1130 | * @param map {Object} the Google Map
|
1127 | 1131 | * @param category {string} location category/categories
|
1128 | 1132 | * @returns {Object} Google Maps marker
|
|
1879 | 1883 | },
|
1880 | 1884 |
|
1881 | 1885 | /**
|
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. |
1883 | 1888 | */
|
1884 | 1889 | order: function() {
|
1885 | 1890 | this.writeDebug('order',arguments);
|
|
2566 | 2571 | });
|
2567 | 2572 | },
|
2568 | 2573 |
|
| 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 | + |
2569 | 2623 | /**
|
2570 | 2624 | * The primary mapping function that runs everything
|
2571 | 2625 | *
|
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 |
2573 | 2628 | */
|
2574 | 2629 | mapping: function (mappingObject) {
|
2575 | 2630 | this.writeDebug('mapping',arguments);
|
|
2631 | 2686 | /**
|
2632 | 2687 | * Processes the location data
|
2633 | 2688 | *
|
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 |
2635 | 2691 | * @param originPoint {Object} LatLng of origin point
|
2636 | 2692 | * @param data {Object} location data
|
2637 | 2693 | * @param page {number} current page number
|
|
2805 | 2861 | if (_this.settings.featuredLocations === true) {
|
2806 | 2862 | // Create array for featured locations
|
2807 | 2863 | featuredset = $.grep(locationset, function (val) {
|
2808 |
| - return val.featured === 'true'; |
| 2864 | + |
| 2865 | + if (val.hasOwnProperty('featured')) { |
| 2866 | + return val.featured === 'true'; |
| 2867 | + } |
2809 | 2868 | });
|
2810 | 2869 |
|
| 2870 | + // Featured location restrictions. |
| 2871 | + featuredset = _this.featurdRestrictions(mappingObject); |
| 2872 | + |
2811 | 2873 | // Create array for normal locations
|
2812 | 2874 | normalset = $.grep(locationset, function (val) {
|
2813 |
| - return val.featured !== 'true'; |
| 2875 | + |
| 2876 | + if (val.hasOwnProperty('featured')) { |
| 2877 | + return val.featured !== 'true'; |
| 2878 | + } |
2814 | 2879 | });
|
2815 | 2880 |
|
2816 | 2881 | // Combine the arrays
|
|
0 commit comments