|
1 | | -/*! jQuery Google Maps Store Locator - v1.4.9 - 2014-10-05 |
| 1 | +/*! jQuery Google Maps Store Locator - v1.4.9 - 2014-10-11 |
2 | 2 | * http://www.bjornblog.com/web/jquery-store-locator-plugin |
3 | 3 | * Copyright (c) 2014 Bjorn Holine; Licensed MIT */ |
4 | 4 |
|
|
199 | 199 | destroy: function () { |
200 | 200 | // Reset |
201 | 201 | this.reset(); |
| 202 | + var mapContainer = $('#' + this.settings.mapID); |
202 | 203 |
|
203 | 204 | // Remove marker event listeners |
204 | 205 | if(markers.length) { |
|
209 | 210 |
|
210 | 211 | // Remove markup |
211 | 212 | $('.' + this.settings.locationList + ' ul').empty(); |
212 | | - if($('#' + this.settings.mapID).hasClass('bh-sl-map-open')) { |
213 | | - $('#' + this.settings.mapID).empty(); |
214 | | - $('#' + this.settings.mapID).removeClass('bh-sl-map-open'); |
| 213 | + if(mapContainer.hasClass('bh-sl-map-open')) { |
| 214 | + mapContainer.empty().removeClass('bh-sl-map-open'); |
215 | 215 | } |
216 | 216 |
|
217 | 217 | // Remove modal markup |
|
220 | 220 | } |
221 | 221 |
|
222 | 222 | // Remove map style from cotnainer |
223 | | - $('#' + this.settings.mapID).attr('style', ''); |
| 223 | + mapContainer.attr('style', ''); |
224 | 224 |
|
225 | 225 | // Hide map container |
226 | 226 | $this.hide(); |
|
356 | 356 | /** |
357 | 357 | * AJAX data request |
358 | 358 | * |
359 | | - * @param lat (number) |
360 | | - * @param lng (number) |
361 | | - * @param address (string) |
| 359 | + * @param lat {number} |
| 360 | + * @param lng {number} |
| 361 | + * @param address {string} |
362 | 362 | * @returns {*} |
363 | 363 | */ |
364 | 364 | getData: function (lat, lng, address) { |
|
490 | 490 | // If show full map option is true |
491 | 491 | if (this.settings.fullMapStart === true) { |
492 | 492 | if(this.settings.querystringParams === true && this.getQueryString(this.settings.addressID) || this.getQueryString(this.settings.searchID)) { |
493 | | - this.processForm(); |
| 493 | + this.processForm(null); |
494 | 494 | } |
495 | 495 | else { |
496 | | - this.mapping(); |
| 496 | + this.mapping(null); |
497 | 497 | } |
498 | 498 | } |
499 | 499 |
|
|
567 | 567 | /** |
568 | 568 | * Checks to see if the object is empty. Using this instead of $.isEmptyObject for legacy browser support |
569 | 569 | * |
570 | | - * @param obj {object} the object to check |
| 570 | + * @param obj {Object} the object to check |
571 | 571 | * @returns {boolean} |
572 | 572 | */ |
573 | 573 | isEmptyObject: function (obj) { |
|
642 | 642 | var filterTest = true; |
643 | 643 |
|
644 | 644 | for (var k in filters) { |
645 | | - if (!(new RegExp(filters[k].join(''), 'i').test(data[k]))) { |
646 | | - filterTest = false; |
| 645 | + if (filters.hasOwnProperty(k)) { |
| 646 | + if (!(new RegExp(filters[k].join(''), 'i').test(data[k]))) { |
| 647 | + filterTest = false; |
| 648 | + } |
647 | 649 | } |
648 | 650 | } |
649 | 651 |
|
|
725 | 727 | /** |
726 | 728 | * Marker image setup |
727 | 729 | * |
728 | | - * @param markerUrl (string) path to marker image |
729 | | - * @param markerWidth (number} width of mearker |
730 | | - * @param markerHeight (number) height of marker |
731 | | - * @returns {object} Google Maps icon object |
| 730 | + * @param markerUrl {string} path to marker image |
| 731 | + * @param markerWidth {number} width of mearker |
| 732 | + * @param markerHeight {number} height of marker |
| 733 | + * @returns {Object} Google Maps icon object |
732 | 734 | */ |
733 | 735 | markerImage: function (markerUrl, markerWidth, markerHeight) { |
734 | 736 | var markerImg; |
|
754 | 756 | /** |
755 | 757 | * Map marker setup |
756 | 758 | * |
757 | | - * @param point {object} LatLng of current location |
758 | | - * @param name (string) location name |
759 | | - * @param address (string) location address |
760 | | - * @param letter (string) optional letter used for front-end identification and correlation between list and points |
761 | | - * @param category (string) location category/categories |
| 759 | + * @param point {Object} LatLng of current location |
| 760 | + * @param name {string} location name |
| 761 | + * @param address {string} location address |
| 762 | + * @param letter {string} optional letter used for front-end identification and correlation between list and points |
| 763 | + * @param map {Object} the Google Map |
| 764 | + * @param category {string} location category/categories |
762 | 765 | * @returns {google.maps.Marker} |
763 | 766 | */ |
764 | 767 | createMarker: function (point, name, address, letter, map, category) { |
|
826 | 829 | /** |
827 | 830 | * Define the location data for the templates |
828 | 831 | * |
829 | | - * @param currentMarker {object} Google Maps marker |
830 | | - * @param storeStart (number) optional first location on the current page |
831 | | - * @param page (number) optional current page |
| 832 | + * @param currentMarker {Object} Google Maps marker |
| 833 | + * @param storeStart {number} optional first location on the current page |
| 834 | + * @param page {number} optional current page |
832 | 835 | * @returns {{location: *[]}} |
833 | 836 | */ |
834 | 837 | defineLocationData: function (currentMarker, storeStart, page) { |
|
882 | 885 | /** |
883 | 886 | * Set up the list templates |
884 | 887 | * |
885 | | - * @param marker {object} Google Maps marker |
| 888 | + * @param marker {Object} Google Maps marker |
886 | 889 | * @param storeStart {number} optional first location on the current page |
887 | 890 | * @param page {number} optional current page |
888 | 891 | */ |
|
895 | 898 | $('.' + this.settings.locationList + ' ul').append(listHtml); |
896 | 899 | }, |
897 | 900 |
|
898 | | - // Infowindows |
| 901 | + /** |
| 902 | + * Create the infowindow |
| 903 | + * |
| 904 | + * @param marker {Object} Google Maps marker object |
| 905 | + * @param location {string} indicates if the list or a map marker was clicked |
| 906 | + * @param infowindow Google Maps InfoWindow constructor |
| 907 | + * @param storeStart {number} |
| 908 | + * @param page {number} |
| 909 | + */ |
899 | 910 | createInfowindow: function (marker, location, infowindow, storeStart, page) { |
900 | 911 | var _this = this; |
901 | 912 | // Define the location data |
|
917 | 928 | // Focus on the list |
918 | 929 | $('.' + _this.settings.locationList + ' li').removeClass('list-focus'); |
919 | 930 | var markerId = marker.get('id'); |
920 | | - $('.' + _this.settings.locationList + ' li[data-markerid=' + markerId + ']').addClass('list-focus'); |
| 931 | + var selectedLocation = $('.' + _this.settings.locationList + ' li[data-markerid=' + markerId + ']'); |
| 932 | + selectedLocation.addClass('list-focus'); |
921 | 933 |
|
922 | 934 | // Scroll list to selected marker |
923 | | - var container = $('.' + _this.settings.locationList), scrollTo = $('.' + _this.settings.locationList + ' li[data-markerid=' + markerId + ']'); |
924 | | - $('.' + _this.settings.locationList).animate({ |
925 | | - scrollTop: scrollTo.offset().top - container.offset().top + container.scrollTop() |
| 935 | + var container = $('.' + _this.settings.locationList); |
| 936 | + container.animate({ |
| 937 | + scrollTop: selectedLocation.offset().top - container.offset().top + container.scrollTop() |
926 | 938 | }); |
927 | 939 | }); |
928 | 940 | } |
929 | 941 | }, |
930 | 942 |
|
931 | 943 | /** |
932 | 944 | * HTML5 geocoding function for automatic location detection |
| 945 | + * |
| 946 | + * @param position |
933 | 947 | */ |
934 | 948 | autoGeocodeQuery: function (position) { |
935 | 949 | var _this = this; |
|
946 | 960 | _this.mapping(mappingObj); |
947 | 961 | } else { |
948 | 962 | // Unable to geocode |
949 | | - alert(this.settings.addressErrorAlert); |
| 963 | + alert(_this.settings.addressErrorAlert); |
950 | 964 | } |
951 | 965 | }); |
952 | 966 | }, |
953 | 967 |
|
954 | 968 | /** |
955 | 969 | * Handle autoGeocode failure |
956 | 970 | * |
957 | | - * @param error |
958 | 971 | */ |
959 | | - autoGeocodeError: function (error) { |
| 972 | + autoGeocodeError: function () { |
960 | 973 | // If automatic detection doesn't work show an error |
961 | 974 | alert(this.settings.autoGeocodeErrorAlert); |
962 | 975 | }, |
|
1121 | 1134 | _this.mapping(mappingObj); |
1122 | 1135 | } else { |
1123 | 1136 | // Unable to geocode |
1124 | | - alert(this.settings.addressErrorAlert); |
| 1137 | + alert(_this.settings.addressErrorAlert); |
1125 | 1138 | } |
1126 | 1139 | }); |
1127 | 1140 | } |
|
1133 | 1146 |
|
1134 | 1147 | /** |
1135 | 1148 | * The primary mapping function that runs everything |
1136 | | - * |
1137 | | - * @param data {kml,xml,or json} all location data |
1138 | | - * @param orig_lat {number} origin latitude |
1139 | | - * @param orig_lng {number} origin longitude |
1140 | | - * @param origin {string} origin address |
1141 | | - * @param maxDistance {number} optional maximum distance |
| 1149 | + * |
| 1150 | + * @param mappingObject {Object} all the mapping properties - latitude, longitude, origin, name, max distance, page |
1142 | 1151 | */ |
1143 | 1152 | mapping: function (mappingObject) { |
1144 | 1153 | var _this = this; |
|
1187 | 1196 | * Process the location data |
1188 | 1197 | */ |
1189 | 1198 | originalDataRequest.then(function (data) { |
| 1199 | + var mapContainer = $('#' + _this.settings.mapID); |
| 1200 | + |
1190 | 1201 | // Callback |
1191 | 1202 | if (_this.settings.callbackSuccess) { |
1192 | 1203 | _this.settings.callbackSuccess.call(this); |
1193 | 1204 | } |
1194 | 1205 |
|
1195 | 1206 | // Set a variable for fullMapStart so we can detect the first run |
1196 | | - if (_this.settings.fullMapStart === true && $('#' + _this.settings.mapID).hasClass('bh-sl-map-open') === false) { |
| 1207 | + if (_this.settings.fullMapStart === true && mapContainer.hasClass('bh-sl-map-open') === false) { |
1197 | 1208 | firstRun = true; |
1198 | 1209 | } |
1199 | 1210 | else { |
1200 | 1211 | _this.reset(); |
1201 | 1212 | } |
1202 | 1213 |
|
1203 | | - $('#' + _this.settings.mapID).addClass('bh-sl-map-open'); |
| 1214 | + mapContainer.addClass('bh-sl-map-open'); |
1204 | 1215 |
|
1205 | 1216 | // Process the location data depending on the data format type |
1206 | 1217 | if (_this.settings.dataType === 'json' || _this.settings.dataType === 'jsonp') { |
|
1329 | 1340 |
|
1330 | 1341 | // Filter the data |
1331 | 1342 | if (!_this.isEmptyObject(taxFilters)) { |
1332 | | - var filteredset = $.grep(locationset, function (val, i) { |
| 1343 | + locationset = $.grep(locationset, function (val) { |
1333 | 1344 | return _this.filterData(val, taxFilters); |
1334 | 1345 | }); |
1335 | | - |
1336 | | - locationset = filteredset; |
1337 | 1346 | } |
1338 | 1347 | } |
1339 | 1348 |
|
1340 | 1349 | if (_this.isEmptyObject(locationset)) { |
1341 | 1350 | // Hide the map and locations if they're showing |
1342 | | - if ($('#' + _this.settings.mapID).hasClass('bh-sl-map-open')) { |
| 1351 | + if (mapContainer.hasClass('bh-sl-map-open')) { |
1343 | 1352 | $this.hide(); |
1344 | 1353 | } |
1345 | 1354 |
|
|
1367 | 1376 | }); |
1368 | 1377 |
|
1369 | 1378 | // Create array for normal locations |
1370 | | - normalset = $.grep(locationset, function (val, i) { |
| 1379 | + normalset = $.grep(locationset, function (val) { |
1371 | 1380 | return val.featured !== 'true'; |
1372 | 1381 | }); |
1373 | 1382 |
|
|
1562 | 1571 | } |
1563 | 1572 |
|
1564 | 1573 | // Create the links that focus on the related marker |
1565 | | - $('.' + _this.settings.locationList + ' ul').empty(); |
| 1574 | + var locList = $('.' + _this.settings.locationList + ' ul'); |
| 1575 | + locList.empty(); |
1566 | 1576 | // Check the locationset and continue with the list setup or show no results message |
1567 | 1577 | if(locationset[0].lat === 0 && locationset[0].lng === 0) { |
1568 | | - $('.' + _this.settings.locationList + ' ul').append(noResults); |
| 1578 | + locList.append(noResults); |
1569 | 1579 | } |
1570 | 1580 | else { |
1571 | 1581 | $(markers).each(function (x) { |
|
0 commit comments