Skip to content

Commit 372e832

Browse files
committed
Extended nameAttribute settings so multiple attributes can be searched
1 parent 780f2b3 commit 372e832

File tree

5 files changed

+202
-142
lines changed

5 files changed

+202
-142
lines changed

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

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*! jQuery Google Maps Store Locator - v3.1.9 - 2023-02-02
1+
/*! jQuery Google Maps Store Locator - v3.1.9 - 2023-02-03
22
* http://www.bjornblog.com/web/jquery-store-locator-plugin
33
* Copyright (c) 2023 Bjorn Holine; Licensed MIT */
44

@@ -13,7 +13,7 @@
1313
}
1414

1515
// Variables used across multiple methods
16-
var $this, map, listTemplate, infowindowTemplate, dataTypeRead, originalOrigin, originalData, originalZoom, dataRequest, searchInput, addressInput, olat, olng, storeNum, directionsDisplay, directionsService, prevSelectedMarkerBefore, prevSelectedMarkerAfter, firstRun, reload;
16+
var $this, map, listTemplate, infowindowTemplate, dataTypeRead, originalOrigin, originalData, originalZoom, dataRequest, searchInput, addressInput, olat, olng, storeNum, directionsDisplay, directionsService, prevSelectedMarkerBefore, prevSelectedMarkerAfter, firstRun, reload, nameAttrs;
1717
var featuredset = [], locationset = [], normalset = [], markers = [];
1818
var filters = {}, locationData = {}, GeoCodeCalc = {}, mappingObj = {};
1919

@@ -1062,8 +1062,12 @@
10621062
}
10631063
}
10641064

1065-
if (testResults.indexOf(true) === -1) {
1066-
filterTest = false;
1065+
if (nameAttrs.indexOf(k) !== -1 && testResults.indexOf(true) !== -1) {
1066+
return true;
1067+
} else {
1068+
if (testResults.indexOf(true) === -1) {
1069+
filterTest = false;
1070+
}
10671071
}
10681072
}
10691073
}
@@ -2869,7 +2873,23 @@
28692873
// Name search - using taxonomy filter to handle
28702874
if (_this.settings.nameSearch === true) {
28712875
if (typeof searchInput !== 'undefined' && '' !== searchInput) {
2872-
filters[_this.settings.nameAttribute] = [searchInput];
2876+
2877+
if (_this.settings.nameAttribute.indexOf(',')) {
2878+
nameAttrs = _this.settings.nameAttribute.split(',');
2879+
2880+
// Multiple name attributes should swap to exclusive filtering.
2881+
if (_this.settings.exclusiveTax !== null) {
2882+
_this.settings.exclusiveTax.concat(nameAttrs);
2883+
} else {
2884+
_this.settings.exclusiveTax = nameAttrs;
2885+
}
2886+
2887+
for (var a = 0; a < nameAttrs.length; a++) {
2888+
filters[nameAttrs[a].trim()] = [searchInput];
2889+
}
2890+
} else {
2891+
filters[_this.settings.nameAttribute] = [searchInput];
2892+
}
28732893
}
28742894

28752895
// Check for a previous value.
@@ -2895,14 +2915,23 @@
28952915
}
28962916

28972917
// Swap pattern matching depending on name search vs. taxonomy filtering.
2898-
if ( k === _this.settings.nameAttribute ) {
2899-
taxFilters[k][z] = '(?:^|\\s)' + filters[k][z].replace(/([.*+?^=!:${}()|\[\]\/\\]|&\s+)/g, '');
2918+
if (typeof nameAttrs !== 'undefined') {
2919+
if (nameAttrs.indexOf(k) !== -1) {
2920+
taxFilters[k][z] = '(?:^|\\s)' + filters[k][z].replace(/([.*+?^=!:${}()|\[\]\/\\]|&\s+)/g, '');
2921+
} else {
2922+
taxFilters[k][z] = '(?=.*' + filters[k][z].replace(/([.*+?^=!:${}()|\[\]\/\\]|&\s+)/g, '') + '(?!\\s))';
2923+
}
29002924
} else {
2901-
taxFilters[k][z] = '(?=.*' + filters[k][z].replace(/([.*+?^=!:${}()|\[\]\/\\]|&\s+)/g, '') + '(?!\\s))';
2925+
if (k === _this.settings.nameAttribute) {
2926+
taxFilters[k][z] = '(?:^|\\s)' + filters[k][z].replace(/([.*+?^=!:${}()|\[\]\/\\]|&\s+)/g, '');
2927+
} else {
2928+
taxFilters[k][z] = '(?=.*' + filters[k][z].replace(/([.*+?^=!:${}()|\[\]\/\\]|&\s+)/g, '') + '(?!\\s))';
2929+
}
29022930
}
29032931
}
29042932
}
29052933
}
2934+
29062935
// Filter the data
29072936
if (!_this.isEmptyObject(taxFilters)) {
29082937
locationset = $.grep(locationset, function (val) {

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

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)