|
1 |
| -/*! jQuery Google Maps Store Locator - v2.0.0 - 2014-10-19 |
| 1 | +/*! jQuery Google Maps Store Locator - v2.0.0 - 2014-10-21 |
2 | 2 | * http://www.bjornblog.com/web/jquery-store-locator-plugin
|
3 | 3 | * Copyright (c) 2014 Bjorn Holine; Licensed MIT */
|
4 | 4 |
|
|
15 | 15 | }
|
16 | 16 |
|
17 | 17 | // Variables used across multiple methods
|
18 |
| - var $this, listTemplate, infowindowTemplate, dataTypeRead, originalOrigin, originalData, originalDataRequest, originalZoom, searchInput, addressInput, olat, olng, storeNum, directionsDisplay, directionsService; |
| 18 | + var $this, listTemplate, infowindowTemplate, dataTypeRead, originalOrigin, originalData, originalZoom, dataRequest, searchInput, addressInput, olat, olng, storeNum, directionsDisplay, directionsService; |
19 | 19 | var featuredset = [], locationset = [], normalset = [], markers = [];
|
20 | 20 | var filters = {}, locationData = {}, GeoCodeCalc = {}, mappingObj = {};
|
21 | 21 |
|
|
433 | 433 | },
|
434 | 434 |
|
435 | 435 | /**
|
436 |
| - * Check for existing filter selections |
437 |
| - * |
| 436 | + * Find the existing checked boxes for each checkbox filter |
| 437 | + * |
| 438 | + * @param key {string} object key |
438 | 439 | */
|
439 |
| - checkFilters: function () { |
440 |
| - $.each(this.settings.taxonomyFilters, function (k, v) { |
441 |
| - // Find the existing checked boxes for each checkbox filter |
442 |
| - $(v + ' input[type=checkbox]').each(function () { |
443 |
| - if ($(this).prop('checked')) { |
444 |
| - var filterVal = $(this).attr('id'); |
445 |
| - |
446 |
| - // Only add the taxonomy id if it doesn't already exist |
447 |
| - if (filters[k].indexOf(filterVal) === -1) { |
448 |
| - filters[k].push(filterVal); |
449 |
| - } |
450 |
| - } |
451 |
| - }); |
452 |
| - |
453 |
| - // Find the existing selected value for each select filter |
454 |
| - $(v + ' select').each(function () { |
| 440 | + existingCheckedFilters: function(key) { |
| 441 | + $(this.settings.taxonomyFilters[key] + ' input[type=checkbox]').each(function () { |
| 442 | + if ($(this).prop('checked')) { |
455 | 443 | var filterVal = $(this).attr('id');
|
456 | 444 |
|
457 | 445 | // Only add the taxonomy id if it doesn't already exist
|
458 |
| - if (filters[k].indexOf(filterVal) === -1) { |
459 |
| - filters[k].push(filterVal); |
| 446 | + if (filters[key].indexOf(filterVal) === -1) { |
| 447 | + filters[key].push(filterVal); |
460 | 448 | }
|
461 |
| - }); |
| 449 | + } |
462 | 450 | });
|
463 | 451 | },
|
464 | 452 |
|
| 453 | + /** |
| 454 | + * Find the existing selected value for each select filter |
| 455 | + * |
| 456 | + * @param key {string} object key |
| 457 | + */ |
| 458 | + existingSelectedFilters: function(key) { |
| 459 | + $(this.settings.taxonomyFilters[key] + ' select').each(function () { |
| 460 | + var filterVal = $(this).attr('id'); |
| 461 | + |
| 462 | + // Only add the taxonomy id if it doesn't already exist |
| 463 | + if (filters[key].indexOf(filterVal) === -1) { |
| 464 | + filters[key].push(filterVal); |
| 465 | + } |
| 466 | + }); |
| 467 | + }, |
| 468 | + |
| 469 | + /** |
| 470 | + * Check for existing filter selections |
| 471 | + * |
| 472 | + */ |
| 473 | + checkFilters: function () { |
| 474 | + for(var key in this.settings.taxonomyFilters) { |
| 475 | + if(this.settings.taxonomyFilters.hasOwnProperty(key)) { |
| 476 | + // Find the existing checked boxes for each checkbox filter |
| 477 | + this.existingCheckedFilters(key); |
| 478 | + |
| 479 | + // Find the existing selected value for each select filter |
| 480 | + this.existingSelectedFilters(key); |
| 481 | + } |
| 482 | + } |
| 483 | + }, |
| 484 | + |
465 | 485 | /**
|
466 | 486 | * Get the filter key from the taxonomyFilter setting
|
467 | 487 | *
|
|
1185 | 1205 | if (typeof page === 'undefined') {
|
1186 | 1206 | page = 0;
|
1187 | 1207 | }
|
1188 |
| - |
| 1208 | + |
1189 | 1209 | // Data request
|
1190 | 1210 | if (typeof origin === 'undefined' && this.settings.nameSearch === true) {
|
1191 |
| - originalDataRequest = _this._getData(); |
| 1211 | + dataRequest = _this._getData(); |
1192 | 1212 | }
|
1193 | 1213 | else {
|
1194 | 1214 | // Setup the origin point
|
|
1197 | 1217 | // If the origin hasn't changed use the existing data so we aren't making unneeded AJAX requests
|
1198 | 1218 | if((typeof originalOrigin !== 'undefined') && (origin === originalOrigin) && (typeof originalData !== 'undefined')) {
|
1199 | 1219 | origin = originalOrigin;
|
1200 |
| - originalDataRequest = originalData; |
| 1220 | + dataRequest = originalData; |
1201 | 1221 | }
|
1202 | 1222 | else {
|
1203 | 1223 | // Do the data request - doing this in mapping so the lat/lng and address can be passed over and used if needed
|
1204 |
| - originalDataRequest = _this._getData(olat, olng, origin); |
| 1224 | + dataRequest = _this._getData(olat, olng, origin); |
1205 | 1225 | }
|
1206 | 1226 | }
|
1207 | 1227 |
|
1208 | 1228 | /**
|
1209 | 1229 | * Process the location data
|
1210 | 1230 | */
|
1211 |
| - originalDataRequest.done(function (data) { |
| 1231 | + dataRequest.done(function (data) { |
1212 | 1232 | var $mapDiv = $('#' + _this.settings.mapID);
|
1213 | 1233 | // Get the length unit
|
1214 | 1234 | var distUnit = (_this.settings.lengthUnit === 'km') ? _this.settings.kilometersLang : _this.settings.milesLang;
|
1215 | 1235 |
|
1216 | 1236 | // Save data and origin separately so we can potentially avoid multiple AJAX requests
|
1217 |
| - originalData = originalDataRequest; |
| 1237 | + originalData = dataRequest; |
1218 | 1238 | originalOrigin = origin;
|
1219 | 1239 |
|
1220 | 1240 | // Callback
|
|
1305 | 1325 | // Process XML
|
1306 | 1326 | $(data).find(_this.settings.xmlElement).each(function () {
|
1307 | 1327 | var locationData = {};
|
1308 |
| - |
| 1328 | + |
1309 | 1329 | $.each(this.attributes, function (i, attrib) {
|
1310 | 1330 | locationData[attrib.name] = attrib.value;
|
1311 | 1331 | });
|
|
1344 | 1364 | if (_this.settings.taxonomyFilters !== null || _this.settings.nameSearch === true) {
|
1345 | 1365 | var taxFilters = {};
|
1346 | 1366 |
|
1347 |
| - $.each(filters, function (k, v) { |
1348 |
| - if (v.length > 0) { |
| 1367 | + for(var k in filters) { |
| 1368 | + if (filters.hasOwnProperty(k) && filters[k].length > 0) { |
1349 | 1369 | // Let's use regex
|
1350 |
| - for (var z = 0; z < v.length; z++) { |
| 1370 | + for (var z = 0; z < filters[k].length; z++) { |
1351 | 1371 | // Creating a new object so we don't mess up the original filters
|
1352 | 1372 | if (!taxFilters[k]) {
|
1353 | 1373 | taxFilters[k] = [];
|
1354 | 1374 | }
|
1355 |
| - taxFilters[k][z] = '(?=.*\\b' + v[z].replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1") + '\\b)'; |
| 1375 | + taxFilters[k][z] = '(?=.*\\b' + filters[k][z].replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1") + '\\b)'; |
1356 | 1376 | }
|
1357 | 1377 | }
|
1358 |
| - }); |
1359 |
| - |
| 1378 | + } |
1360 | 1379 | // Filter the data
|
1361 | 1380 | if (!_this.isEmptyObject(taxFilters)) {
|
1362 | 1381 | locationset = $.grep(locationset, function (val) {
|
@@ -1642,106 +1661,108 @@
|
1642 | 1661 | * Taxonomy filtering
|
1643 | 1662 | */
|
1644 | 1663 | taxonomyFiltering: function() {
|
1645 |
| - var _this = this; |
| 1664 | + var _this = this; |
1646 | 1665 |
|
1647 |
| - // Set up the filters |
1648 |
| - $.each(this.settings.taxonomyFilters, function (k) { |
1649 |
| - filters[k] = []; |
1650 |
| - }); |
| 1666 | + // Set up the filters |
| 1667 | + for(var key in this.settings.taxonomyFilters) { |
| 1668 | + if(this.settings.taxonomyFilters.hasOwnProperty(key)) { |
| 1669 | + filters[key] = []; |
| 1670 | + } |
| 1671 | + } |
1651 | 1672 |
|
1652 |
| - // Handle filter updates |
1653 |
| - $('.' + this.settings.taxonomyFiltersContainer).on('change.'+pluginName, 'input, select', function (e) { |
1654 |
| - e.stopPropagation(); |
| 1673 | + // Handle filter updates |
| 1674 | + $('.' + this.settings.taxonomyFiltersContainer).on('change.'+pluginName, 'input, select', function (e) { |
| 1675 | + e.stopPropagation(); |
1655 | 1676 |
|
1656 |
| - var filterId, filterContainer, filterKey; |
1657 |
| - |
1658 |
| - // Handle checkbox filters |
1659 |
| - if ($(this).is('input[type="checkbox"]')) { |
1660 |
| - // First check for existing selections |
1661 |
| - _this.checkFilters(); |
1662 |
| - |
1663 |
| - filterId = $(this).val(); |
1664 |
| - filterContainer = $(this).closest('.bh-sl-filters').attr('id'); |
1665 |
| - filterKey = _this.getFilterKey(filterContainer); |
1666 |
| - |
1667 |
| - if (filterKey) { |
1668 |
| - // Add or remove filters based on checkbox values |
1669 |
| - if ($(this).prop('checked')) { |
1670 |
| - // Add ids to the filter arrays as they are checked |
1671 |
| - filters[filterKey].push(filterId); |
1672 |
| - if ($('#' + _this.settings.mapID).hasClass('bh-sl-map-open') === true) { |
1673 |
| - if ((olat) && (olng)) { |
1674 |
| - _this.settings.mapSettings.zoom = 0; |
1675 |
| - _this.processForm(); |
1676 |
| - } |
1677 |
| - else { |
1678 |
| - _this.mapping(mappingObj); |
1679 |
| - } |
1680 |
| - } |
1681 |
| - } |
1682 |
| - else { |
1683 |
| - // Remove ids from the filter arrays as they are unchecked |
1684 |
| - var filterIndex = filters[filterKey].indexOf(filterId); |
1685 |
| - if (filterIndex > -1) { |
1686 |
| - filters[filterKey].splice(filterIndex, 1); |
1687 |
| - if ($('#' + _this.settings.mapID).hasClass('bh-sl-map-open') === true) { |
1688 |
| - if ((olat) && (olng)) { |
1689 |
| - if (_this.countFilters() === 0) { |
1690 |
| - _this.settings.mapSettings.zoom = originalZoom; |
1691 |
| - } |
1692 |
| - else { |
1693 |
| - _this.settings.mapSettings.zoom = 0; |
1694 |
| - } |
1695 |
| - _this.processForm(); |
1696 |
| - } |
1697 |
| - else { |
1698 |
| - _this.mapping(mappingObj); |
1699 |
| - } |
1700 |
| - } |
1701 |
| - } |
1702 |
| - } |
1703 |
| - } |
1704 |
| - } |
1705 |
| - // Handle select or radio filters |
1706 |
| - else if ($(this).is('select') || $(this).is('input[type="radio"]')) { |
1707 |
| - // First check for existing selections |
1708 |
| - _this.checkFilters(); |
1709 |
| - |
1710 |
| - filterId = $(this).val(); |
1711 |
| - filterContainer = $(this).closest('.bh-sl-filters').attr('id'); |
1712 |
| - filterKey = _this.getFilterKey(filterContainer); |
1713 |
| - |
1714 |
| - // Check for blank filter on select since default val could be empty |
1715 |
| - if (filterId) { |
1716 |
| - if (filterKey) { |
1717 |
| - filters[filterKey] = [filterId]; |
1718 |
| - if ($('#' + _this.settings.mapID).hasClass('bh-sl-map-open') === true) { |
1719 |
| - if ((olat) && (olng)) { |
1720 |
| - _this.settings.mapSettings.zoom = 0; |
1721 |
| - _this.processForm(); |
1722 |
| - } |
1723 |
| - else { |
1724 |
| - _this.mapping(mappingObj); |
1725 |
| - } |
1726 |
| - } |
1727 |
| - } |
1728 |
| - } |
1729 |
| - // Reset if the default option is selected |
1730 |
| - else { |
1731 |
| - if (filterKey) { |
1732 |
| - filters[filterKey] = []; |
1733 |
| - } |
1734 |
| - _this.reset(); |
1735 |
| - if ((olat) && (olng)) { |
1736 |
| - _this.settings.mapSettings.zoom = originalZoom; |
1737 |
| - _this.processForm(); |
1738 |
| - } |
1739 |
| - else { |
1740 |
| - _this.mapping(mappingObj); |
1741 |
| - } |
1742 |
| - } |
1743 |
| - } |
1744 |
| - }); |
| 1677 | + var filterId, filterContainer, filterKey; |
| 1678 | + |
| 1679 | + // Handle checkbox filters |
| 1680 | + if ($(this).is('input[type="checkbox"]')) { |
| 1681 | + // First check for existing selections |
| 1682 | + _this.checkFilters(); |
| 1683 | + |
| 1684 | + filterId = $(this).val(); |
| 1685 | + filterContainer = $(this).closest('.bh-sl-filters').attr('id'); |
| 1686 | + filterKey = _this.getFilterKey(filterContainer); |
| 1687 | + |
| 1688 | + if (filterKey) { |
| 1689 | + // Add or remove filters based on checkbox values |
| 1690 | + if ($(this).prop('checked')) { |
| 1691 | + // Add ids to the filter arrays as they are checked |
| 1692 | + filters[filterKey].push(filterId); |
| 1693 | + if ($('#' + _this.settings.mapID).hasClass('bh-sl-map-open') === true) { |
| 1694 | + if ((olat) && (olng)) { |
| 1695 | + _this.settings.mapSettings.zoom = 0; |
| 1696 | + _this.processForm(); |
| 1697 | + } |
| 1698 | + else { |
| 1699 | + _this.mapping(mappingObj); |
| 1700 | + } |
| 1701 | + } |
| 1702 | + } |
| 1703 | + else { |
| 1704 | + // Remove ids from the filter arrays as they are unchecked |
| 1705 | + var filterIndex = filters[filterKey].indexOf(filterId); |
| 1706 | + if (filterIndex > -1) { |
| 1707 | + filters[filterKey].splice(filterIndex, 1); |
| 1708 | + if ($('#' + _this.settings.mapID).hasClass('bh-sl-map-open') === true) { |
| 1709 | + if ((olat) && (olng)) { |
| 1710 | + if (_this.countFilters() === 0) { |
| 1711 | + _this.settings.mapSettings.zoom = originalZoom; |
| 1712 | + } |
| 1713 | + else { |
| 1714 | + _this.settings.mapSettings.zoom = 0; |
| 1715 | + } |
| 1716 | + _this.processForm(); |
| 1717 | + } |
| 1718 | + else { |
| 1719 | + _this.mapping(mappingObj); |
| 1720 | + } |
| 1721 | + } |
| 1722 | + } |
| 1723 | + } |
| 1724 | + } |
| 1725 | + } |
| 1726 | + // Handle select or radio filters |
| 1727 | + else if ($(this).is('select') || $(this).is('input[type="radio"]')) { |
| 1728 | + // First check for existing selections |
| 1729 | + _this.checkFilters(); |
| 1730 | + |
| 1731 | + filterId = $(this).val(); |
| 1732 | + filterContainer = $(this).closest('.bh-sl-filters').attr('id'); |
| 1733 | + filterKey = _this.getFilterKey(filterContainer); |
| 1734 | + |
| 1735 | + // Check for blank filter on select since default val could be empty |
| 1736 | + if (filterId) { |
| 1737 | + if (filterKey) { |
| 1738 | + filters[filterKey] = [filterId]; |
| 1739 | + if ($('#' + _this.settings.mapID).hasClass('bh-sl-map-open') === true) { |
| 1740 | + if ((olat) && (olng)) { |
| 1741 | + _this.settings.mapSettings.zoom = 0; |
| 1742 | + _this.processForm(); |
| 1743 | + } |
| 1744 | + else { |
| 1745 | + _this.mapping(mappingObj); |
| 1746 | + } |
| 1747 | + } |
| 1748 | + } |
| 1749 | + } |
| 1750 | + // Reset if the default option is selected |
| 1751 | + else { |
| 1752 | + if (filterKey) { |
| 1753 | + filters[filterKey] = []; |
| 1754 | + } |
| 1755 | + _this.reset(); |
| 1756 | + if ((olat) && (olng)) { |
| 1757 | + _this.settings.mapSettings.zoom = originalZoom; |
| 1758 | + _this.processForm(); |
| 1759 | + } |
| 1760 | + else { |
| 1761 | + _this.mapping(mappingObj); |
| 1762 | + } |
| 1763 | + } |
| 1764 | + } |
| 1765 | + }); |
1745 | 1766 | }
|
1746 | 1767 |
|
1747 | 1768 | });
|
|
0 commit comments