Skip to content

Commit

Permalink
Merge pull request #296 from bjorn2404/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
bjorn2404 authored Jul 26, 2023
2 parents 2b00f0f + 66d42fa commit 5996dd6
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 26 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jquery-storelocator-plugin",
"version": "3.1.12",
"version": "3.1.13",
"description": "This jQuery plugin takes advantage of Google Maps API version 3 to create an easy to implement store locator. No back-end programming is required, you just need to feed it KML, XML, or JSON data with all the location information.",
"repository": {
"type": "git",
Expand Down
50 changes: 39 additions & 11 deletions dist/assets/js/plugins/storeLocator/jquery.storelocator.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*! jQuery Google Maps Store Locator - v3.1.12 - 2023-06-19
/*! jQuery Google Maps Store Locator - v3.1.13 - 2023-07-25
* http://www.bjornblog.com/web/jquery-store-locator-plugin
* Copyright (c) 2023 Bjorn Holine; Licensed MIT */

Expand All @@ -15,7 +15,7 @@
// Variables used across multiple methods
var $this, map, listTemplate, infowindowTemplate, dataTypeRead, originalOrigin, originalData, originalZoom, dataRequest, searchInput, addressInput, olat, olng, storeNum, directionsDisplay, directionsService, prevSelectedMarkerBefore, prevSelectedMarkerAfter, firstRun, reload, nameAttrs, originalFilterVals;
var featuredset = [], locationset = [], normalset = [], markers = [];
var filters = {}, locationData = {}, GeoCodeCalc = {}, mappingObj = {};
var filters = {}, locationData = {}, GeoCodeCalc = {}, mappingObj = {}, disabledFilterVals = {};

// Create the defaults once. DO NOT change these settings in this file - settings should be overridden in the plugin call
var defaults = {
Expand Down Expand Up @@ -565,6 +565,7 @@
// Track changes to the address search field.
$('#' + this.settings.addressID).on('change.'+pluginName, function () {
originalFilterVals = undefined;
disabledFilterVals = {};

// Unset origin tracking if input field is removed.
if (
Expand Down Expand Up @@ -2276,7 +2277,6 @@

if ($('#' + _this.settings.mapID).hasClass('bh-sl-map-open') === true) {
if ((olat) && (olng)) {
_this.settings.mapSettings.zoom = 0;
_this.processForm();
}
else {
Expand All @@ -2294,9 +2294,7 @@
if (_this.countFilters() === 0) {
_this.settings.mapSettings.zoom = originalZoom;
}
else {
_this.settings.mapSettings.zoom = 0;
}

_this.processForm();
}
else {
Expand All @@ -2322,7 +2320,6 @@
filters[filterKey] = [filterVal];
if ($('#' + _this.settings.mapID).hasClass('bh-sl-map-open') === true) {
if ((olat) && (olng)) {
_this.settings.mapSettings.zoom = 0;
_this.processForm();
}
else {
Expand Down Expand Up @@ -2876,13 +2873,19 @@
for (var i = 0; i < _this.settings.taxonomyFilters[key].length; i++) {
if (_this.settings.taxonomyFilters.hasOwnProperty(key)) {
$('#' + _this.settings.taxonomyFilters[key] + ' input, #' + _this.settings.taxonomyFilters[key] + ' option').each(function () {
if ($(this).val() !== '' && Array.from(new Set(availableValues[key].split(','))).indexOf($(this).val()) === -1) {

// Initial determination of values that should be disabled.
if ($(this).val() !== '' && ! Array.from(new Set(availableValues[key].split(','))).includes($(this).val())) {
if (! disabledFilterVals.hasOwnProperty(key)) {
disabledFilterVals[key] = [];
}

// Handle select options and radio button values when there is no address input.
if (
(typeof addressInput === 'undefined' || addressInput === '') &&
($(this).prop('tagName') === 'OPTION' || $(this).prop('type') === 'radio') &&
_this.hasSingleGroupFilterVal(filters, key)
_this.hasSingleGroupFilterVal(filters, key) &&
Array.from(new Set(originalFilterVals[key].split(','))).includes($(this).val())
) {
return;
}
Expand All @@ -2892,11 +2895,32 @@
(typeof addressInput !== 'undefined' || addressInput !== '') &&
($(this).prop('tagName') === 'OPTION' || $(this).prop('type') === 'radio') &&
_this.hasSingleGroupFilterVal(filters, key) &&
Array.from(new Set(originalFilterVals[key].split(','))).indexOf($(this).val()) !== -1
Array.from(new Set(originalFilterVals[key].split(','))).includes($(this).val()) &&
_this.countFilters() === 1
) {
return;
}

// Keep select options and radio button available values after one filter has been selected.
if (
($(this).prop('tagName') === 'OPTION' || $(this).prop('type') === 'radio') &&
_this.hasSingleGroupFilterVal(filters, key) &&
_this.countFilters() > 1 &&
Array.from(new Set(originalFilterVals[key].split(','))).includes($(this).val()) &&
! disabledFilterVals[key].includes($(this).val())
) {
return;
}

// Track disabled values.
if (
disabledFilterVals.hasOwnProperty(key) &&
Array.isArray(disabledFilterVals[key]) &&
! disabledFilterVals[key].includes($(this).val())
) {
disabledFilterVals[key].push($(this).val());
}

$(this).attr('disabled', true);
}
});
Expand Down Expand Up @@ -3177,7 +3201,11 @@
}

// Disable filter inputs if there are no locations with the values left.
if (firstRun !== true && this.settings.taxonomyFilters !== null && this.settings.exclusiveFiltering === false) {
if (
(firstRun !== true && _this.settings.exclusiveFiltering === false) ||
(_this.settings.fullMapStart === true && _this.settings.exclusiveFiltering === false) ||
(_this.settings.defaultLoc === true && _this.settings.exclusiveFiltering === false)
) {
_this.maybeDisableFilterOptions();
}

Expand Down

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jquery-storelocator-plugin",
"version": "3.1.12",
"version": "3.1.13",
"description": "This jQuery plugin takes advantage of Google Maps API version 3 to create an easy to implement store locator. No back-end programming is required, you just need to feed it KML, XML, or JSON data with all the location information.",
"repository": {
"type": "git",
Expand Down
6 changes: 6 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ filtering.

## Changelog

### Version 3.1.13

* Fixed additional disable filtering functionality related to select options and radio buttons by globally tracking the disabled values.
* Removed zoom reset to zero on taxonomy filtering to keep searched location in view.
* Updated maybeDisableFilterOptions to run when full map start or default location settings are enabled.

### Version 3.1.12

* Added automatic reset functionality that fires when address input field value is removed (changed to blank).
Expand Down
48 changes: 38 additions & 10 deletions src/js/jquery.storelocator.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// Variables used across multiple methods
var $this, map, listTemplate, infowindowTemplate, dataTypeRead, originalOrigin, originalData, originalZoom, dataRequest, searchInput, addressInput, olat, olng, storeNum, directionsDisplay, directionsService, prevSelectedMarkerBefore, prevSelectedMarkerAfter, firstRun, reload, nameAttrs, originalFilterVals;
var featuredset = [], locationset = [], normalset = [], markers = [];
var filters = {}, locationData = {}, GeoCodeCalc = {}, mappingObj = {};
var filters = {}, locationData = {}, GeoCodeCalc = {}, mappingObj = {}, disabledFilterVals = {};

// Create the defaults once. DO NOT change these settings in this file - settings should be overridden in the plugin call
var defaults = {
Expand Down Expand Up @@ -561,6 +561,7 @@
// Track changes to the address search field.
$('#' + this.settings.addressID).on('change.'+pluginName, function () {
originalFilterVals = undefined;
disabledFilterVals = {};

// Unset origin tracking if input field is removed.
if (
Expand Down Expand Up @@ -2272,7 +2273,6 @@

if ($('#' + _this.settings.mapID).hasClass('bh-sl-map-open') === true) {
if ((olat) && (olng)) {
_this.settings.mapSettings.zoom = 0;
_this.processForm();
}
else {
Expand All @@ -2290,9 +2290,7 @@
if (_this.countFilters() === 0) {
_this.settings.mapSettings.zoom = originalZoom;
}
else {
_this.settings.mapSettings.zoom = 0;
}

_this.processForm();
}
else {
Expand All @@ -2318,7 +2316,6 @@
filters[filterKey] = [filterVal];
if ($('#' + _this.settings.mapID).hasClass('bh-sl-map-open') === true) {
if ((olat) && (olng)) {
_this.settings.mapSettings.zoom = 0;
_this.processForm();
}
else {
Expand Down Expand Up @@ -2872,13 +2869,19 @@
for (var i = 0; i < _this.settings.taxonomyFilters[key].length; i++) {
if (_this.settings.taxonomyFilters.hasOwnProperty(key)) {
$('#' + _this.settings.taxonomyFilters[key] + ' input, #' + _this.settings.taxonomyFilters[key] + ' option').each(function () {
if ($(this).val() !== '' && Array.from(new Set(availableValues[key].split(','))).indexOf($(this).val()) === -1) {

// Initial determination of values that should be disabled.
if ($(this).val() !== '' && ! Array.from(new Set(availableValues[key].split(','))).includes($(this).val())) {
if (! disabledFilterVals.hasOwnProperty(key)) {
disabledFilterVals[key] = [];
}

// Handle select options and radio button values when there is no address input.
if (
(typeof addressInput === 'undefined' || addressInput === '') &&
($(this).prop('tagName') === 'OPTION' || $(this).prop('type') === 'radio') &&
_this.hasSingleGroupFilterVal(filters, key)
_this.hasSingleGroupFilterVal(filters, key) &&
Array.from(new Set(originalFilterVals[key].split(','))).includes($(this).val())
) {
return;
}
Expand All @@ -2888,11 +2891,32 @@
(typeof addressInput !== 'undefined' || addressInput !== '') &&
($(this).prop('tagName') === 'OPTION' || $(this).prop('type') === 'radio') &&
_this.hasSingleGroupFilterVal(filters, key) &&
Array.from(new Set(originalFilterVals[key].split(','))).indexOf($(this).val()) !== -1
Array.from(new Set(originalFilterVals[key].split(','))).includes($(this).val()) &&
_this.countFilters() === 1
) {
return;
}

// Keep select options and radio button available values after one filter has been selected.
if (
($(this).prop('tagName') === 'OPTION' || $(this).prop('type') === 'radio') &&
_this.hasSingleGroupFilterVal(filters, key) &&
_this.countFilters() > 1 &&
Array.from(new Set(originalFilterVals[key].split(','))).includes($(this).val()) &&
! disabledFilterVals[key].includes($(this).val())
) {
return;
}

// Track disabled values.
if (
disabledFilterVals.hasOwnProperty(key) &&
Array.isArray(disabledFilterVals[key]) &&
! disabledFilterVals[key].includes($(this).val())
) {
disabledFilterVals[key].push($(this).val());
}

$(this).attr('disabled', true);
}
});
Expand Down Expand Up @@ -3173,7 +3197,11 @@
}

// Disable filter inputs if there are no locations with the values left.
if (firstRun !== true && this.settings.taxonomyFilters !== null && this.settings.exclusiveFiltering === false) {
if (
(firstRun !== true && _this.settings.exclusiveFiltering === false) ||
(_this.settings.fullMapStart === true && _this.settings.exclusiveFiltering === false) ||
(_this.settings.defaultLoc === true && _this.settings.exclusiveFiltering === false)
) {
_this.maybeDisableFilterOptions();
}

Expand Down
2 changes: 1 addition & 1 deletion storelocator.jquery.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"title": "jQuery Google Maps Store Locator",
"description": "This jQuery plugin takes advantage of Google Maps API version 3 to create an easy to implement store locator. No back-end programming is required, you just need to feed it KML, XML, or JSON data with all the location information.",
"keywords": ["jquery","locator","store","dealer","location", "locations", "maps", "map", "stores", "find"],
"version": "3.1.12",
"version": "3.1.13",
"author": {
"name": "Bjorn Holine",
"url": "https://www.bjornblog.com/"
Expand Down

0 comments on commit 5996dd6

Please sign in to comment.