Skip to content

Commit c54b8aa

Browse files
committed
Moved taxonomy filtering into its own function
1 parent 3a74d08 commit c54b8aa

File tree

3 files changed

+229
-215
lines changed

3 files changed

+229
-215
lines changed

dist/js/jquery.storelocator.js

Lines changed: 114 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*! jQuery Google Maps Store Locator - v1.4.9 - 2014-07-13
1+
/*! jQuery Google Maps Store Locator - v1.4.9 - 2014-07-14
22
* http://www.bjornblog.com/web/jquery-store-locator-plugin
33
* Copyright (c) 2014 Bjorn Holine; Licensed MIT */
44

@@ -1246,116 +1246,123 @@
12461246
});
12471247
},
12481248

1249+
/**
1250+
* Taxonomy filtering
1251+
*/
1252+
taxonomyFiltering: function() {
1253+
var _this = this;
1254+
1255+
// Set up the filters
1256+
$.each(this.settings.taxonomyFilters, function (k) {
1257+
filters[k] = [];
1258+
});
1259+
1260+
// Handle filter updates
1261+
$('.bh-storelocator-filters-container').on('change.' + prefix, 'input, select', function (e) {
1262+
e.stopPropagation();
1263+
1264+
var filterId, filterContainer, filterKey;
1265+
1266+
// Handle checkbox filters
1267+
if ($(this).is('input[type="checkbox"]')) {
1268+
// First check for existing selections
1269+
_this.checkFilters();
1270+
1271+
filterId = $(this).val();
1272+
filterContainer = $(this).closest('.bh-storelocator-filters').attr('id');
1273+
filterKey = _this.getFilterKey(filterContainer);
1274+
1275+
if (filterKey) {
1276+
// Add or remove filters based on checkbox values
1277+
if ($(this).prop('checked')) {
1278+
// Add ids to the filter arrays as they are checked
1279+
filters[filterKey].push(filterId);
1280+
if ($('#' + _this.settings.mapDiv).hasClass('bh-storelocator-map-open') === true) {
1281+
_this.reset();
1282+
if ((olat) && (olng)) {
1283+
_this.settings.mapSettings.zoom = 0;
1284+
_this.beginMapping();
1285+
}
1286+
else {
1287+
_this.mapping(originalData);
1288+
}
1289+
}
1290+
}
1291+
else {
1292+
// Remove ids from the filter arrays as they are unchecked
1293+
var filterIndex = filters[filterKey].indexOf(filterId);
1294+
if (filterIndex > -1) {
1295+
filters[filterKey].splice(filterIndex, 1);
1296+
if ($('#' + _this.settings.mapDiv).hasClass('bh-storelocator-map-open') === true) {
1297+
_this.reset();
1298+
if ((olat) && (olng)) {
1299+
if (_this.countFilters() === 0) {
1300+
_this.settings.mapSettings.zoom = originalZoom;
1301+
}
1302+
else {
1303+
_this.settings.mapSettings.zoom = 0;
1304+
}
1305+
_this.beginMapping();
1306+
}
1307+
else {
1308+
_this.mapping(originalData);
1309+
}
1310+
}
1311+
}
1312+
}
1313+
}
1314+
}
1315+
// Handle select or radio filters
1316+
else if ($(this).is('select') || $(this).is('input[type="radio"]')) {
1317+
// First check for existing selections
1318+
_this.checkFilters();
1319+
1320+
filterId = $(this).val();
1321+
filterContainer = $(this).closest('.bh-storelocator-filters').attr('id');
1322+
filterKey = _this.getFilterKey(filterContainer);
1323+
1324+
// Check for blank filter on select since default val could be empty
1325+
if (filterId) {
1326+
if (filterKey) {
1327+
filters[filterKey] = [filterId];
1328+
if ($('#' + _this.settings.mapDiv).hasClass('bh-storelocator-map-open') === true) {
1329+
_this.reset();
1330+
if ((olat) && (olng)) {
1331+
_this.settings.mapSettings.zoom = 0;
1332+
_this.beginMapping();
1333+
}
1334+
else {
1335+
_this.mapping(originalData);
1336+
}
1337+
}
1338+
}
1339+
}
1340+
// Reset if the default option is selected
1341+
else {
1342+
if (filterKey) {
1343+
filters[filterKey] = [];
1344+
}
1345+
_this.reset();
1346+
if ((olat) && (olng)) {
1347+
_this.settings.mapSettings.zoom = originalZoom;
1348+
_this.beginMapping();
1349+
}
1350+
else {
1351+
_this.mapping(originalData);
1352+
}
1353+
}
1354+
}
1355+
});
1356+
},
1357+
12491358
/**
12501359
* Primary locator function runs after the templates are loaded
12511360
*/
12521361
locator: function () {
1253-
var _this = this;
1254-
// Taxonomy filtering
1255-
if (this.settings.taxonomyFilters !== null) {
1256-
1257-
// Set up the filters
1258-
$.each(this.settings.taxonomyFilters, function (k) {
1259-
filters[k] = [];
1260-
});
1261-
1262-
// Handle filter updates
1263-
$('.bh-storelocator-filters-container').on('change.' + prefix, 'input, select', function (e) {
1264-
e.stopPropagation();
1265-
1266-
var filterId, filterContainer, filterKey;
1267-
1268-
// Handle checkbox filters
1269-
if ($(this).is('input[type="checkbox"]')) {
1270-
// First check for existing selections
1271-
_this.checkFilters();
1272-
1273-
filterId = $(this).val();
1274-
filterContainer = $(this).closest('.bh-storelocator-filters').attr('id');
1275-
filterKey = _this.getFilterKey(filterContainer);
1276-
1277-
if (filterKey) {
1278-
// Add or remove filters based on checkbox values
1279-
if ($(this).prop('checked')) {
1280-
// Add ids to the filter arrays as they are checked
1281-
filters[filterKey].push(filterId);
1282-
if ($('#' + _this.settings.mapDiv).hasClass('bh-storelocator-map-open') === true) {
1283-
_this.reset();
1284-
if ((olat) && (olng)) {
1285-
_this.settings.mapSettings.zoom = 0;
1286-
_this.beginMapping();
1287-
}
1288-
else {
1289-
_this.mapping(originalData);
1290-
}
1291-
}
1292-
}
1293-
else {
1294-
// Remove ids from the filter arrays as they are unchecked
1295-
var filterIndex = filters[filterKey].indexOf(filterId);
1296-
if (filterIndex > -1) {
1297-
filters[filterKey].splice(filterIndex, 1);
1298-
if ($('#' + _this.settings.mapDiv).hasClass('bh-storelocator-map-open') === true) {
1299-
_this.reset();
1300-
if ((olat) && (olng)) {
1301-
if (_this.countFilters() === 0) {
1302-
_this.settings.mapSettings.zoom = originalZoom;
1303-
}
1304-
else {
1305-
_this.settings.mapSettings.zoom = 0;
1306-
}
1307-
_this.beginMapping();
1308-
}
1309-
else {
1310-
_this.mapping(originalData);
1311-
}
1312-
}
1313-
}
1314-
}
1315-
}
1316-
}
1317-
// Handle select or radio filters
1318-
else if ($(this).is('select') || $(this).is('input[type="radio"]')) {
1319-
// First check for existing selections
1320-
_this.checkFilters();
1321-
1322-
filterId = $(this).val();
1323-
filterContainer = $(this).closest('.bh-storelocator-filters').attr('id');
1324-
filterKey = _this.getFilterKey(filterContainer);
1325-
1326-
// Check for blank filter on select since default val could be empty
1327-
if (filterId) {
1328-
if (filterKey) {
1329-
filters[filterKey] = [filterId];
1330-
if ($('#' + _this.settings.mapDiv).hasClass('bh-storelocator-map-open') === true) {
1331-
_this.reset();
1332-
if ((olat) && (olng)) {
1333-
_this.settings.mapSettings.zoom = 0;
1334-
_this.beginMapping();
1335-
}
1336-
else {
1337-
_this.mapping(originalData);
1338-
}
1339-
}
1340-
}
1341-
}
1342-
// Reset if the default option is selected
1343-
else {
1344-
if (filterKey) {
1345-
filters[filterKey] = [];
1346-
}
1347-
_this.reset();
1348-
if ((olat) && (olng)) {
1349-
_this.settings.mapSettings.zoom = originalZoom;
1350-
_this.beginMapping();
1351-
}
1352-
else {
1353-
_this.mapping(originalData);
1354-
}
1355-
}
1356-
}
1357-
});
1358-
}
1362+
// Do taxonomy filtering if set
1363+
if (this.settings.taxonomyFilters !== null) {
1364+
this.taxonomyFiltering();
1365+
}
13591366

13601367
// Add modal window divs if set
13611368
if (this.settings.modalWindow === true) {

0 commit comments

Comments
 (0)