|
1 | | -/*! jQuery Google Maps Store Locator - v2.5.2 - 2016-04-03 |
| 1 | +/*! jQuery Google Maps Store Locator - v2.5.3 - 2016-04-03 |
2 | 2 | * http://www.bjornblog.com/web/jquery-store-locator-plugin |
3 | 3 | * Copyright (c) 2016 Bjorn Holine; Licensed MIT */ |
4 | 4 |
|
|
481 | 481 | }, |
482 | 482 | dataType : dataTypeRead, |
483 | 483 | jsonpCallback: (this.settings.dataType === 'jsonp' ? this.settings.callbackJsonp : null) |
484 | | - }).done(function (p) { |
| 484 | + }).done(function(p) { |
485 | 485 | d.resolve(p); |
486 | 486 |
|
487 | 487 | // Loading remove |
|
1810 | 1810 | }); |
1811 | 1811 | }, |
1812 | 1812 |
|
| 1813 | + /** |
| 1814 | + * Handle no results |
| 1815 | + */ |
| 1816 | + emptyResult: function() { |
| 1817 | + this.writeDebug('emptyResult',arguments); |
| 1818 | + var center, |
| 1819 | + locList = $('.' + this.settings.locationList + ' ul'), |
| 1820 | + myOptions = this.settings.mapSettings, |
| 1821 | + noResults; |
| 1822 | + |
| 1823 | + // Create the map |
| 1824 | + var map = new google.maps.Map(document.getElementById(this.settings.mapID), myOptions); |
| 1825 | + |
| 1826 | + // Callback |
| 1827 | + if (this.settings.callbackNoResults) { |
| 1828 | + this.settings.callbackNoResults.call(this, map, myOptions); |
| 1829 | + } |
| 1830 | + |
| 1831 | + // Empty the location list |
| 1832 | + locList.empty(); |
| 1833 | + |
| 1834 | + // Append the no results message |
| 1835 | + noResults = $('<li><div class="bh-sl-noresults-title">' + this.settings.noResultsTitle + '</div><br><div class="bh-sl-noresults-desc">' + this.settings.noResultsDesc + '</li>').hide().fadeIn(); |
| 1836 | + locList.append(noResults); |
| 1837 | + |
| 1838 | + // Center on the original origin or 0,0 if not available |
| 1839 | + if ((olat) && (olng)) { |
| 1840 | + center = new google.maps.LatLng(olat, olng); |
| 1841 | + } else { |
| 1842 | + center = new google.maps.LatLng(0, 0); |
| 1843 | + } |
| 1844 | + |
| 1845 | + map.setCenter(center); |
| 1846 | + |
| 1847 | + if (originalZoom) { |
| 1848 | + map.setZoom(originalZoom); |
| 1849 | + } |
| 1850 | + }, |
| 1851 | + |
1813 | 1852 | /** |
1814 | 1853 | * The primary mapping function that runs everything |
1815 | 1854 | * |
|
1883 | 1922 | this.writeDebug('processData',mappingObject); |
1884 | 1923 | var _this = this; |
1885 | 1924 | var i = 0; |
1886 | | - var orig_lat, orig_lng, origin, name, maxDistance, marker, bounds, storeStart, storeNumToShow, myOptions, noResults, distError, openMap; |
| 1925 | + var orig_lat, orig_lng, origin, name, maxDistance, marker, bounds, storeStart, storeNumToShow, myOptions, distError, openMap; |
| 1926 | + var taxFilters = {}; |
1887 | 1927 | if (!this.isEmptyObject(mappingObject)) { |
1888 | 1928 | orig_lat = mappingObject.lat; |
1889 | 1929 | orig_lng = mappingObject.lng; |
|
1984 | 2024 |
|
1985 | 2025 | // Taxonomy filtering setup |
1986 | 2026 | if (_this.settings.taxonomyFilters !== null || _this.settings.nameSearch === true) { |
1987 | | - var taxFilters = {}; |
1988 | 2027 |
|
1989 | 2028 | for(var k in filters) { |
1990 | 2029 | if (filters.hasOwnProperty(k) && filters[k].length > 0) { |
|
2006 | 2045 | } |
2007 | 2046 | } |
2008 | 2047 |
|
2009 | | - // Handle no results |
2010 | | - if (_this.isEmptyObject(locationset)) { |
2011 | | - // Callback |
2012 | | - if (_this.settings.callbackNoResults) { |
2013 | | - _this.settings.callbackNoResults.call(this); |
2014 | | - } |
2015 | | - |
2016 | | - // Append the no results message |
2017 | | - noResults = $('<li><div class="bh-sl-noresults-title">' + _this.settings.noResultsTitle + '</div><br><div class="bh-sl-noresults-desc">' + _this.settings.noResultsDesc + '</li>').hide().fadeIn(); |
2018 | | - |
2019 | | - // Setup a no results location |
2020 | | - locationset[0] = { |
2021 | | - 'distance': 0, |
2022 | | - 'lat' : 0, |
2023 | | - 'lng': 0 |
2024 | | - }; |
2025 | | - } |
2026 | | - |
2027 | 2048 | // Sort the multi-dimensional array by distance |
2028 | 2049 | if (typeof origin !== 'undefined') { |
2029 | 2050 | _this.sortNumerically(locationset); |
|
2047 | 2068 | } |
2048 | 2069 |
|
2049 | 2070 | // Check the closest marker |
2050 | | - if (_this.settings.maxDistance === true && firstRun !== true && maxDistance) { |
2051 | | - if (typeof locationset[0] === 'undefined' || locationset[0].distance > maxDistance) { |
2052 | | - _this.notify(_this.settings.distanceErrorAlert + maxDistance + ' ' + distUnit); |
2053 | | - return; |
| 2071 | + if (_this.isEmptyObject(taxFilters)) { |
| 2072 | + if (_this.settings.maxDistance === true && firstRun !== true && maxDistance) { |
| 2073 | + if (typeof locationset[0] === 'undefined' || locationset[0].distance > maxDistance) { |
| 2074 | + _this.notify(_this.settings.distanceErrorAlert + maxDistance + ' ' + distUnit); |
| 2075 | + } |
2054 | 2076 | } |
2055 | | - } |
2056 | | - else { |
2057 | | - if (_this.settings.distanceAlert !== -1 && locationset[0].distance > _this.settings.distanceAlert) { |
2058 | | - _this.notify(_this.settings.distanceErrorAlert + _this.settings.distanceAlert + ' ' + distUnit); |
2059 | | - distError = true; |
| 2077 | + else { |
| 2078 | + if (_this.settings.distanceAlert !== -1 && locationset[0].distance > _this.settings.distanceAlert) { |
| 2079 | + _this.notify(_this.settings.distanceErrorAlert + _this.settings.distanceAlert + ' ' + distUnit); |
| 2080 | + distError = true; |
| 2081 | + } |
2060 | 2082 | } |
2061 | 2083 | } |
2062 | 2084 |
|
2063 | | - // Output page numbers if pagination setting is true |
2064 | | - if (_this.settings.pagination === true) { |
2065 | | - _this.paginationSetup(page); |
2066 | | - } |
2067 | | - |
2068 | 2085 | // Slide in the map container |
2069 | 2086 | if (_this.settings.slideMap === true) { |
2070 | 2087 | $this.slideDown(); |
2071 | 2088 | } |
2072 | 2089 |
|
| 2090 | + // Handle no results |
| 2091 | + if (_this.isEmptyObject(locationset)) { |
| 2092 | + _this.emptyResult(); |
| 2093 | + return; |
| 2094 | + } |
| 2095 | + |
| 2096 | + // Output page numbers if pagination setting is true |
| 2097 | + if (_this.settings.pagination === true) { |
| 2098 | + _this.paginationSetup(page); |
| 2099 | + } |
| 2100 | + |
2073 | 2101 | // Set up the modal window |
2074 | 2102 | if (_this.settings.modal === true) { |
2075 | 2103 | // Callback |
|
2240 | 2268 | bounds.extend(point); |
2241 | 2269 | } |
2242 | 2270 | // Pass variables to the pop-up infowindows |
2243 | | - if (typeof noResults === 'undefined') { |
2244 | | - _this.createInfowindow(marker, null, infowindow, storeStart, page); |
2245 | | - } |
| 2271 | + _this.createInfowindow(marker, null, infowindow, storeStart, page); |
2246 | 2272 | } |
2247 | 2273 |
|
2248 | 2274 | // Center and zoom if no origin or zoom was provided, or distance of first marker is greater than distanceAlert |
|
2253 | 2279 | // Create the links that focus on the related marker |
2254 | 2280 | var locList = $('.' + _this.settings.locationList + ' ul'); |
2255 | 2281 | locList.empty(); |
2256 | | - // Check the locationset and continue with the list setup or show no results message |
2257 | | - if(locationset[0].lat === 0 && locationset[0].lng === 0) { |
2258 | | - locList.append(noResults); |
2259 | | - } |
2260 | | - else { |
2261 | | - // Set up the location list markup |
2262 | | - if (firstRun && _this.settings.fullMapStartListLimit !== false && !isNaN(_this.settings.fullMapStartListLimit) && _this.settings.fullMapStartListLimit !== -1) { |
2263 | | - for (var m = 0; m < _this.settings.fullMapStartListLimit; m++) { |
2264 | | - var currentMarker = markers[m]; |
2265 | | - _this.listSetup(currentMarker, storeStart, page); |
2266 | | - } |
2267 | | - } else { |
2268 | | - $(markers).each(function (x) { |
2269 | | - var currentMarker = markers[x]; |
2270 | | - _this.listSetup(currentMarker, storeStart, page); |
2271 | | - }); |
| 2282 | + |
| 2283 | + // Set up the location list markup |
| 2284 | + if (firstRun && _this.settings.fullMapStartListLimit !== false && !isNaN(_this.settings.fullMapStartListLimit) && _this.settings.fullMapStartListLimit !== -1) { |
| 2285 | + for (var m = 0; m < _this.settings.fullMapStartListLimit; m++) { |
| 2286 | + var currentMarker = markers[m]; |
| 2287 | + _this.listSetup(currentMarker, storeStart, page); |
2272 | 2288 | } |
| 2289 | + } else { |
| 2290 | + $(markers).each(function (x) { |
| 2291 | + var currentMarker = markers[x]; |
| 2292 | + _this.listSetup(currentMarker, storeStart, page); |
| 2293 | + }); |
2273 | 2294 | } |
2274 | 2295 |
|
2275 | 2296 | // Handle clicks from the list |
2276 | | - if (typeof noResults === 'undefined') { |
2277 | | - $(document).on('click.' + pluginName, '.' + _this.settings.locationList + ' li', function () { |
2278 | | - var markerId = $(this).data('markerid'); |
2279 | | - var selectedMarker = markers[markerId]; |
2280 | | - |
2281 | | - // List click callback |
2282 | | - if (_this.settings.callbackListClick) { |
2283 | | - _this.settings.callbackListClick.call(this, markerId, selectedMarker); |
2284 | | - } |
| 2297 | + $(document).on('click.' + pluginName, '.' + _this.settings.locationList + ' li', function () { |
| 2298 | + var markerId = $(this).data('markerid'); |
| 2299 | + var selectedMarker = markers[markerId]; |
2285 | 2300 |
|
2286 | | - map.panTo(selectedMarker.getPosition()); |
2287 | | - var listLoc = 'left'; |
2288 | | - if (_this.settings.bounceMarker === true) { |
2289 | | - selectedMarker.setAnimation(google.maps.Animation.BOUNCE); |
2290 | | - setTimeout(function () { |
2291 | | - selectedMarker.setAnimation(null); |
2292 | | - _this.createInfowindow(selectedMarker, listLoc, infowindow, storeStart, page); |
2293 | | - }, 700 |
2294 | | - ); |
2295 | | - } |
2296 | | - else { |
2297 | | - _this.createInfowindow(selectedMarker, listLoc, infowindow, storeStart, page); |
2298 | | - } |
| 2301 | + // List click callback |
| 2302 | + if (_this.settings.callbackListClick) { |
| 2303 | + _this.settings.callbackListClick.call(this, markerId, selectedMarker); |
| 2304 | + } |
2299 | 2305 |
|
2300 | | - // Custom selected marker override |
2301 | | - if (_this.settings.selectedMarkerImg !== null) { |
2302 | | - _this.changeSelectedMarker(selectedMarker); |
2303 | | - } |
| 2306 | + map.panTo(selectedMarker.getPosition()); |
| 2307 | + var listLoc = 'left'; |
| 2308 | + if (_this.settings.bounceMarker === true) { |
| 2309 | + selectedMarker.setAnimation(google.maps.Animation.BOUNCE); |
| 2310 | + setTimeout(function () { |
| 2311 | + selectedMarker.setAnimation(null); |
| 2312 | + _this.createInfowindow(selectedMarker, listLoc, infowindow, storeStart, page); |
| 2313 | + }, 700 |
| 2314 | + ); |
| 2315 | + } |
| 2316 | + else { |
| 2317 | + _this.createInfowindow(selectedMarker, listLoc, infowindow, storeStart, page); |
| 2318 | + } |
2304 | 2319 |
|
2305 | | - // Focus on the list |
2306 | | - $('.' + _this.settings.locationList + ' li').removeClass('list-focus'); |
2307 | | - $('.' + _this.settings.locationList + ' li[data-markerid=' + markerId + ']').addClass('list-focus'); |
2308 | | - }); |
2309 | | - } |
| 2320 | + // Custom selected marker override |
| 2321 | + if (_this.settings.selectedMarkerImg !== null) { |
| 2322 | + _this.changeSelectedMarker(selectedMarker); |
| 2323 | + } |
| 2324 | + |
| 2325 | + // Focus on the list |
| 2326 | + $('.' + _this.settings.locationList + ' li').removeClass('list-focus'); |
| 2327 | + $('.' + _this.settings.locationList + ' li[data-markerid=' + markerId + ']').addClass('list-focus'); |
| 2328 | + }); |
2310 | 2329 |
|
2311 | 2330 | // Prevent bubbling from list content links |
2312 | | - $(document).on('click.'+pluginName, '.' + _this.settings.locationList + ' li a', function (e) { |
| 2331 | + $(document).on('click.'+pluginName, '.' + _this.settings.locationList + ' li a', function(e) { |
2313 | 2332 | e.stopPropagation(); |
2314 | 2333 | }); |
2315 | 2334 |
|
|
0 commit comments