Skip to content

Commit f5dc3a5

Browse files
committed
Added ability to indicate multiple query string parameter values (for checkboxes) with a comma separated list value, added functionality to select/check filters on load from query string parameter values
1 parent 273836e commit f5dc3a5

File tree

4 files changed

+106
-6
lines changed

4 files changed

+106
-6
lines changed

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

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*! jQuery Google Maps Store Locator - v2.7.3 - 2017-04-26
1+
/*! jQuery Google Maps Store Locator - v2.7.3 - 2017-04-30
22
* http://www.bjornblog.com/web/jquery-store-locator-plugin
33
* Copyright (c) 2017 Bjorn Holine; Licensed MIT */
44

@@ -1750,22 +1750,71 @@
17501750
}
17511751
},
17521752

1753+
/**
1754+
* Select the indicated values from query string parameters.
1755+
*
1756+
* @param taxonomy {string} Current taxonomy.
1757+
* @param value {array} Query string array values.
1758+
*/
1759+
selectQueryStringFilters: function( taxonomy, value ) {
1760+
this.writeDebug('selectQueryStringFilters', arguments);
1761+
1762+
var $taxGroupContainer = $('#' + this.settings.taxonomyFilters[taxonomy]);
1763+
1764+
// Handle checkboxes.
1765+
if ( $taxGroupContainer.find('input[type="checkbox"]').length ) {
1766+
1767+
for ( var i = 0; i < value.length; i++ ) {
1768+
$taxGroupContainer.find('input:checkbox[value=' + value[i] + ']').prop('checked', true);
1769+
}
1770+
1771+
}
1772+
1773+
// Handle select fields.
1774+
if ( $taxGroupContainer.find('select').length ) {
1775+
// Only expecting one value for select fields.
1776+
$taxGroupContainer.find('option[value=' + value[0] + ']').prop('selected', true);
1777+
}
1778+
1779+
// Handle radio buttons.
1780+
if ( $taxGroupContainer.find('input[type="radio"]').length ) {
1781+
// Only one value for radio button.
1782+
$taxGroupContainer.find('input:radio[value=' + value[0] + ']').prop('checked', true);
1783+
}
1784+
},
1785+
17531786
/**
17541787
* Check query string parameters for filter values.
17551788
*/
17561789
checkQueryStringFilters: function () {
17571790
this.writeDebug('checkQueryStringFilters',arguments);
1791+
17581792
// Loop through the filters.
17591793
for(var key in filters) {
17601794
if(filters.hasOwnProperty(key)) {
17611795
var filterVal = this.getQueryString(key);
17621796

1797+
// Check for multiple values separated by comma.
1798+
if ( filterVal.indexOf( ',' ) !== -1 ) {
1799+
filterVal = filterVal.split( ',' );
1800+
}
1801+
17631802
// Only add the taxonomy id if it doesn't already exist
17641803
if (typeof filterVal !== 'undefined' && filterVal !== '' && filters[key].indexOf(filterVal) === -1) {
1765-
filters[key] = [filterVal];
1804+
if ( Array.isArray( filterVal ) ) {
1805+
filters[key] = filterVal;
1806+
} else {
1807+
filters[key] = [filterVal];
1808+
}
1809+
}
1810+
1811+
// Select the filters indicated in the query string.
1812+
if ( filters[key].length ) {
1813+
this.selectQueryStringFilters( key, filters[key] );
17661814
}
17671815
}
17681816
}
1817+
17691818
},
17701819

17711820
/**

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

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

readme.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ filtering.
3737

3838
### Version 2.7.3
3939

40+
* Added ability to indicate multiple query string parameter values (for checkboxes) with a comma separated list value.
4041
* Added autoCompleteDisableListener setting to disable the listener that immediately triggers a search when an auto complete location option is selected.
42+
* Added functionality to select/check filters on load from query string parameter values.
4143
* Added location details object to callbackListClick and callbackMarkerClick objects.
4244
* Fixed Handlebars targeting issue triggered by placing an unordered list within the location list template.
4345
* Updated callbackListClick documentation to include second market object parameter.

src/js/jquery.storelocator.js

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1747,22 +1747,71 @@
17471747
}
17481748
},
17491749

1750+
/**
1751+
* Select the indicated values from query string parameters.
1752+
*
1753+
* @param taxonomy {string} Current taxonomy.
1754+
* @param value {array} Query string array values.
1755+
*/
1756+
selectQueryStringFilters: function( taxonomy, value ) {
1757+
this.writeDebug('selectQueryStringFilters', arguments);
1758+
1759+
var $taxGroupContainer = $('#' + this.settings.taxonomyFilters[taxonomy]);
1760+
1761+
// Handle checkboxes.
1762+
if ( $taxGroupContainer.find('input[type="checkbox"]').length ) {
1763+
1764+
for ( var i = 0; i < value.length; i++ ) {
1765+
$taxGroupContainer.find('input:checkbox[value=' + value[i] + ']').prop('checked', true);
1766+
}
1767+
1768+
}
1769+
1770+
// Handle select fields.
1771+
if ( $taxGroupContainer.find('select').length ) {
1772+
// Only expecting one value for select fields.
1773+
$taxGroupContainer.find('option[value=' + value[0] + ']').prop('selected', true);
1774+
}
1775+
1776+
// Handle radio buttons.
1777+
if ( $taxGroupContainer.find('input[type="radio"]').length ) {
1778+
// Only one value for radio button.
1779+
$taxGroupContainer.find('input:radio[value=' + value[0] + ']').prop('checked', true);
1780+
}
1781+
},
1782+
17501783
/**
17511784
* Check query string parameters for filter values.
17521785
*/
17531786
checkQueryStringFilters: function () {
17541787
this.writeDebug('checkQueryStringFilters',arguments);
1788+
17551789
// Loop through the filters.
17561790
for(var key in filters) {
17571791
if(filters.hasOwnProperty(key)) {
17581792
var filterVal = this.getQueryString(key);
17591793

1794+
// Check for multiple values separated by comma.
1795+
if ( filterVal.indexOf( ',' ) !== -1 ) {
1796+
filterVal = filterVal.split( ',' );
1797+
}
1798+
17601799
// Only add the taxonomy id if it doesn't already exist
17611800
if (typeof filterVal !== 'undefined' && filterVal !== '' && filters[key].indexOf(filterVal) === -1) {
1762-
filters[key] = [filterVal];
1801+
if ( Array.isArray( filterVal ) ) {
1802+
filters[key] = filterVal;
1803+
} else {
1804+
filters[key] = [filterVal];
1805+
}
1806+
}
1807+
1808+
// Select the filters indicated in the query string.
1809+
if ( filters[key].length ) {
1810+
this.selectQueryStringFilters( key, filters[key] );
17631811
}
17641812
}
17651813
}
1814+
17661815
},
17671816

17681817
/**

0 commit comments

Comments
 (0)