Skip to content

Commit eb904d9

Browse files
committed
Test file path fixes, cleanup, optimization
1 parent 4fa6811 commit eb904d9

File tree

5 files changed

+317
-274
lines changed

5 files changed

+317
-274
lines changed

dist/assets/js/plugins/storeLocator/jquery.storelocator.js

Lines changed: 154 additions & 133 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*! jQuery Google Maps Store Locator - v2.0.0 - 2014-10-19
1+
/*! jQuery Google Maps Store Locator - v2.0.0 - 2014-10-21
22
* http://www.bjornblog.com/web/jquery-store-locator-plugin
33
* Copyright (c) 2014 Bjorn Holine; Licensed MIT */
44

@@ -15,7 +15,7 @@
1515
}
1616

1717
// 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;
1919
var featuredset = [], locationset = [], normalset = [], markers = [];
2020
var filters = {}, locationData = {}, GeoCodeCalc = {}, mappingObj = {};
2121

@@ -433,35 +433,55 @@
433433
},
434434

435435
/**
436-
* Check for existing filter selections
437-
*
436+
* Find the existing checked boxes for each checkbox filter
437+
*
438+
* @param key {string} object key
438439
*/
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')) {
455443
var filterVal = $(this).attr('id');
456444

457445
// 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);
460448
}
461-
});
449+
}
462450
});
463451
},
464452

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+
465485
/**
466486
* Get the filter key from the taxonomyFilter setting
467487
*
@@ -1185,10 +1205,10 @@
11851205
if (typeof page === 'undefined') {
11861206
page = 0;
11871207
}
1188-
1208+
11891209
// Data request
11901210
if (typeof origin === 'undefined' && this.settings.nameSearch === true) {
1191-
originalDataRequest = _this._getData();
1211+
dataRequest = _this._getData();
11921212
}
11931213
else {
11941214
// Setup the origin point
@@ -1197,24 +1217,24 @@
11971217
// If the origin hasn't changed use the existing data so we aren't making unneeded AJAX requests
11981218
if((typeof originalOrigin !== 'undefined') && (origin === originalOrigin) && (typeof originalData !== 'undefined')) {
11991219
origin = originalOrigin;
1200-
originalDataRequest = originalData;
1220+
dataRequest = originalData;
12011221
}
12021222
else {
12031223
// 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);
12051225
}
12061226
}
12071227

12081228
/**
12091229
* Process the location data
12101230
*/
1211-
originalDataRequest.done(function (data) {
1231+
dataRequest.done(function (data) {
12121232
var $mapDiv = $('#' + _this.settings.mapID);
12131233
// Get the length unit
12141234
var distUnit = (_this.settings.lengthUnit === 'km') ? _this.settings.kilometersLang : _this.settings.milesLang;
12151235

12161236
// Save data and origin separately so we can potentially avoid multiple AJAX requests
1217-
originalData = originalDataRequest;
1237+
originalData = dataRequest;
12181238
originalOrigin = origin;
12191239

12201240
// Callback
@@ -1305,7 +1325,7 @@
13051325
// Process XML
13061326
$(data).find(_this.settings.xmlElement).each(function () {
13071327
var locationData = {};
1308-
1328+
13091329
$.each(this.attributes, function (i, attrib) {
13101330
locationData[attrib.name] = attrib.value;
13111331
});
@@ -1344,19 +1364,18 @@
13441364
if (_this.settings.taxonomyFilters !== null || _this.settings.nameSearch === true) {
13451365
var taxFilters = {};
13461366

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) {
13491369
// Let's use regex
1350-
for (var z = 0; z < v.length; z++) {
1370+
for (var z = 0; z < filters[k].length; z++) {
13511371
// Creating a new object so we don't mess up the original filters
13521372
if (!taxFilters[k]) {
13531373
taxFilters[k] = [];
13541374
}
1355-
taxFilters[k][z] = '(?=.*\\b' + v[z].replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1") + '\\b)';
1375+
taxFilters[k][z] = '(?=.*\\b' + filters[k][z].replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1") + '\\b)';
13561376
}
13571377
}
1358-
});
1359-
1378+
}
13601379
// Filter the data
13611380
if (!_this.isEmptyObject(taxFilters)) {
13621381
locationset = $.grep(locationset, function (val) {
@@ -1642,106 +1661,108 @@
16421661
* Taxonomy filtering
16431662
*/
16441663
taxonomyFiltering: function() {
1645-
var _this = this;
1664+
var _this = this;
16461665

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+
}
16511672

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();
16551676

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+
});
17451766
}
17461767

17471768
});

0 commit comments

Comments
 (0)