|
1 |
| -/*! jQuery Google Maps Store Locator - v1.4.9 - 2014-05-25 |
| 1 | +/*! jQuery Google Maps Store Locator - v1.4.9 - 2014-06-09 |
2 | 2 | * http://www.bjornblog.com/web/jquery-store-locator-plugin
|
3 | 3 | * Copyright (c) 2014 Bjorn Holine; Licensed MIT */
|
4 | 4 |
|
@@ -74,7 +74,7 @@ $.fn.storeLocator = function(options){
|
74 | 74 | return this.each(function(){
|
75 | 75 |
|
76 | 76 | var $this = $(this);
|
77 |
| - var listTemplate, infowindowTemplate, dataTypeRead, originalData; |
| 77 | + var listTemplate, infowindowTemplate, dataTypeRead, originalData, originalZoom; |
78 | 78 |
|
79 | 79 | //KML is read as XML
|
80 | 80 | if (settings.dataType === 'kml') {
|
@@ -108,6 +108,9 @@ $.fn.storeLocator = function(options){
|
108 | 108 | originalData = data;
|
109 | 109 | });
|
110 | 110 |
|
| 111 | + //Save the original zoom setting so it can be retrieved if taxonomy filtering resets it |
| 112 | + originalZoom = settings.mapSettings.zoom; |
| 113 | + |
111 | 114 | /**
|
112 | 115 | * Load the external template files first
|
113 | 116 | */
|
@@ -226,7 +229,7 @@ $.fn.storeLocator = function(options){
|
226 | 229 | });
|
227 | 230 |
|
228 | 231 | //Handle filter updates - TODO: This is only working with the map already open at the moment - need to add something to the form submit
|
229 |
| - $('.bh-storelocator-filters-container').on('change', 'input', function(e){ |
| 232 | + $('.bh-storelocator-filters-container').on('change.'+prefix, 'input', function(e){ |
230 | 233 | e.stopPropagation();
|
231 | 234 |
|
232 | 235 | //First check if it's a checkbox or select drop-down
|
@@ -254,25 +257,31 @@ $.fn.storeLocator = function(options){
|
254 | 257 | if($(this).prop('checked')){
|
255 | 258 | //Add ids to the filter arrays as they are checked
|
256 | 259 | filters[locFilterKey].push(catId);
|
257 |
| - reset(); |
258 |
| - if((olat) && (olng)){ |
259 |
| - begin_mapping(); |
260 |
| - } |
261 |
| - else{ |
262 |
| - mapping(originalData); |
| 260 | + if($('#'+settings.mapDiv).hasClass('bh-storelocator-map-open') === true){ |
| 261 | + reset(); |
| 262 | + if((olat) && (olng)){ |
| 263 | + settings.mapSettings.zoom = 0; |
| 264 | + begin_mapping(); |
| 265 | + } |
| 266 | + else{ |
| 267 | + mapping(originalData); |
| 268 | + } |
263 | 269 | }
|
264 | 270 | }
|
265 | 271 | else {
|
266 | 272 | //Remove ids from the filter arrays as they are unchecked
|
267 | 273 | var filterIndex = filters[locFilterKey].indexOf(catId);
|
268 | 274 | if(filterIndex > -1){
|
269 | 275 | filters[locFilterKey].splice(filterIndex, 1);
|
270 |
| - reset(); |
271 |
| - if((olat) && (olng)){ |
272 |
| - begin_mapping(); |
273 |
| - } |
274 |
| - else { |
275 |
| - mapping(originalData); |
| 276 | + if($('#'+settings.mapDiv).hasClass('bh-storelocator-map-open') === true){ |
| 277 | + reset(); |
| 278 | + if((olat) && (olng)){ |
| 279 | + settings.mapSettings.zoom = originalZoom; //TODO: Maybe move into reset function |
| 280 | + begin_mapping(); |
| 281 | + } |
| 282 | + else { |
| 283 | + mapping(originalData); |
| 284 | + } |
276 | 285 | }
|
277 | 286 | }
|
278 | 287 | }
|
@@ -579,14 +588,14 @@ $.fn.storeLocator = function(options){
|
579 | 588 | var destinationsArray = [];
|
580 | 589 |
|
581 | 590 | //Set a variable for fullMapStart so we can detect the first run
|
582 |
| - if(settings.fullMapStart === true && $(settings.mapDiv).hasClass('mapOpen') === false){ |
| 591 | + if(settings.fullMapStart === true && $('#'+settings.mapDiv).hasClass('bh-storelocator-map-open') === false){ |
583 | 592 | firstRun = true;
|
584 | 593 | }
|
585 | 594 | else{
|
586 | 595 | reset();
|
587 | 596 | }
|
588 | 597 |
|
589 |
| - $(settings.mapDiv).addClass('mapOpen'); |
| 598 | + $('#' + settings.mapDiv).addClass('bh-storelocator-map-open'); |
590 | 599 |
|
591 | 600 | //Depending on your data structure and what you want to include in the maps, you may need to change the following variables or comment them out
|
592 | 601 | if(settings.dataType === 'json' || settings.dataType === 'jsonp'){
|
@@ -709,28 +718,41 @@ $.fn.storeLocator = function(options){
|
709 | 718 | var taxFilters = {};
|
710 | 719 |
|
711 | 720 | $.each(filters, function(k,v){
|
712 |
| - //Let's use regex |
713 |
| - for(var z = 0; z < v.length; z++){ |
714 |
| - //Creating a new object so we don't mess up the original filters |
715 |
| - if(!taxFilters[k]){ |
716 |
| - taxFilters[k] = []; |
| 721 | + if(v.length > 0){ |
| 722 | + //Let's use regex |
| 723 | + for(var z = 0; z < v.length; z++){ |
| 724 | + //Creating a new object so we don't mess up the original filters |
| 725 | + if(!taxFilters[k]){ |
| 726 | + taxFilters[k] = []; |
| 727 | + } |
| 728 | + taxFilters[k][z] = '(?=.*\\b' |
| 729 | + + v[z].replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1") |
| 730 | + + '\\b)'; |
717 | 731 | }
|
718 |
| - taxFilters[k][z] = '(?=.*\\b' |
719 |
| - + v[z].replace(/([\^\$\/\.\*\+\?\|\(\)\[\]\{\}\\])/g, "\\$1") |
720 |
| - + '\\b)'; |
721 | 732 | }
|
722 | 733 | });
|
723 | 734 |
|
724 | 735 | //Filter the data
|
725 |
| - var filteredset = $.grep(locationset, function(val, i){ |
726 |
| - return checkFilters(val, taxFilters); |
727 |
| - }); |
| 736 | + if(!$.isEmptyObject(taxFilters)){ |
| 737 | + var filteredset = $.grep(locationset, function(val, i){ |
| 738 | + return checkFilters(val, taxFilters); |
| 739 | + }); |
728 | 740 |
|
729 |
| - if(filteredset.length){ |
730 | 741 | locationset = filteredset;
|
731 | 742 | }
|
732 | 743 | }
|
733 | 744 |
|
| 745 | + //TODO: isEmptyObject not supported in old IE - use another method |
| 746 | + if($.isEmptyObject(locationset)){ |
| 747 | + locationset[0] = { |
| 748 | + 'address': 'No locations were found with the given criteria. Please modify your selections or input.', |
| 749 | + 'address2': '', |
| 750 | + 'lat': '', |
| 751 | + 'lng': '', |
| 752 | + 'name': 'No results' |
| 753 | + } |
| 754 | + } |
| 755 | + |
734 | 756 | //Distance calculation update testing - there is a 100 element request limit
|
735 | 757 | /*if(locationset.length < 26){
|
736 | 758 | var matrix = calculateDistances(originsArray, destinationsArray);
|
@@ -882,8 +904,8 @@ $.fn.storeLocator = function(options){
|
882 | 904 | }
|
883 | 905 |
|
884 | 906 | //Google maps settings
|
885 |
| - if((settings.fullMapStart === true && firstRun === true) || settings.mapSettings.zoom === 0){ |
886 |
| - var myOptions = settings.mapSettings; |
| 907 | + if((settings.fullMapStart === true && firstRun === true) || (settings.mapSettings.zoom === 0)){ |
| 908 | + var myOptions = settings.mapSettings; |
887 | 909 | var bounds = new google.maps.LatLngBounds();
|
888 | 910 | }
|
889 | 911 | else{
|
@@ -930,7 +952,7 @@ $.fn.storeLocator = function(options){
|
930 | 952 | create_infowindow(marker);
|
931 | 953 | }
|
932 | 954 |
|
933 |
| - //Center and zoom if no origin or zoom was provided |
| 955 | + //Center and zoom if no origin or zoom was provided or upon taxonomy filter |
934 | 956 | if((settings.fullMapStart === true && firstRun === true) || (settings.mapSettings.zoom === 0)){
|
935 | 957 | map.fitBounds(bounds);
|
936 | 958 | }
|
|
0 commit comments