1
- /*! jQuery Google Maps Store Locator - v1.4.9 - 2014-06-22
1
+ /*! jQuery Google Maps Store Locator - v1.4.9 - 2014-06-29
2
2
* http://www.bjornblog.com/web/jquery-store-locator-plugin
3
3
* Copyright (c) 2014 Bjorn Holine; Licensed MIT */
4
4
@@ -220,20 +220,47 @@ $.fn.storeLocator = function(options){
220
220
*/
221
221
function checkFilters ( ) {
222
222
$ . each ( settings . taxonomyFilters , function ( k , v ) {
223
- //Find the existing checked boxes for each filter
223
+ //Find the existing checked boxes for each checkbox filter
224
224
$ ( v + ' input[type=checkbox]' ) . each ( function ( ) {
225
225
if ( $ ( this ) . prop ( 'checked' ) ) {
226
- var catVal = $ ( this ) . attr ( 'id' ) ;
226
+ var filterVal = $ ( this ) . attr ( 'id' ) ;
227
227
228
228
//Only add the taxonomy id if it doesn't already exist
229
- if ( filters [ k ] . indexOf ( catVal ) === - 1 ) {
230
- filters [ k ] . push ( catVal ) ;
229
+ if ( filters [ k ] . indexOf ( filterVal ) === - 1 ) {
230
+ filters [ k ] . push ( filterVal ) ;
231
231
}
232
232
}
233
233
} ) ;
234
+
235
+ //Find the existing selected value for each select filter
236
+ $ ( v + ' select' ) . each ( function ( ) {
237
+ var filterVal = $ ( this ) . attr ( 'id' ) ;
238
+
239
+ //Only add the taxonomy id if it doesn't already exist
240
+ if ( filters [ k ] . indexOf ( filterVal ) === - 1 ) {
241
+ filters [ k ] . push ( filterVal ) ;
242
+ }
243
+ } ) ;
234
244
} ) ;
235
245
}
236
246
247
+ /**
248
+ * Get the filter key from the taxonomyFilter setting
249
+ *
250
+ * @param filterContainer {string} ID of the changed filter's container
251
+ */
252
+ function getFilterKey ( filterContainer ) {
253
+ for ( var key in settings . taxonomyFilters ) {
254
+ if ( settings . taxonomyFilters . hasOwnProperty ( key ) ) {
255
+ for ( var i = 0 ; i < settings . taxonomyFilters [ key ] . length ; i ++ ) {
256
+ if ( settings . taxonomyFilters [ key ] === filterContainer ) {
257
+ return key ;
258
+ }
259
+ }
260
+ }
261
+ }
262
+ }
263
+
237
264
//Taxonomy filtering
238
265
if ( settings . taxonomyFilters !== null ) {
239
266
@@ -243,72 +270,100 @@ $.fn.storeLocator = function(options){
243
270
} ) ;
244
271
245
272
//Handle filter updates
246
- $ ( '.bh-storelocator-filters-container' ) . on ( 'change.' + prefix , 'input' , function ( e ) {
273
+ $ ( '.bh-storelocator-filters-container' ) . on ( 'change.' + prefix , 'input, select ' , function ( e ) {
247
274
e . stopPropagation ( ) ;
248
275
249
- //First check if it's a checkbox or select drop-down
250
- if ( $ ( this ) . is ( 'input[type="checkbox"]' ) ) {
251
- var catId , locFilterContainer , locFilterKey ; //TODO: Change variable loc names to something else
276
+ var filterId , filterContainer , filterKey ;
252
277
278
+ //Handle checkbox filters
279
+ if ( $ ( this ) . is ( 'input[type="checkbox"]' ) ) {
253
280
//First check for existing selections
254
281
checkFilters ( ) ;
255
282
256
- catId = $ ( this ) . val ( ) ;
257
- locFilterContainer = $ ( this ) . closest ( 'ul' ) . attr ( 'id' ) ;
283
+ filterId = $ ( this ) . val ( ) ;
284
+ filterContainer = $ ( this ) . closest ( '.bh-storelocator-filters' ) . attr ( 'id' ) ;
285
+ filterKey = getFilterKey ( filterContainer ) ;
258
286
259
- //Get the correct filter key
260
- for ( var key in settings . taxonomyFilters ) {
261
- if ( settings . taxonomyFilters . hasOwnProperty ( key ) ) {
262
- for ( var i = 0 ; i < settings . taxonomyFilters [ key ] . length ; i ++ ) {
263
- if ( settings . taxonomyFilters [ key ] === locFilterContainer ) {
264
- locFilterKey = key ;
287
+ if ( filterKey ) {
288
+ //Add or remove filters based on checkbox values
289
+ if ( $ ( this ) . prop ( 'checked' ) ) {
290
+ //Add ids to the filter arrays as they are checked
291
+ filters [ filterKey ] . push ( filterId ) ;
292
+ if ( $ ( '#' + settings . mapDiv ) . hasClass ( 'bh-storelocator-map-open' ) === true ) {
293
+ reset ( ) ;
294
+ if ( ( olat ) && ( olng ) ) {
295
+ settings . mapSettings . zoom = 0 ;
296
+ begin_mapping ( ) ;
297
+ }
298
+ else {
299
+ mapping ( originalData ) ;
265
300
}
266
301
}
267
302
}
268
- }
269
-
270
- //Add or remove filters based on checkbox values
271
- if ( $ ( this ) . prop ( 'checked' ) ) {
272
- //Add ids to the filter arrays as they are checked
273
- filters [ locFilterKey ] . push ( catId ) ;
274
- if ( $ ( '#' + settings . mapDiv ) . hasClass ( 'bh-storelocator-map-open' ) === true ) {
275
- reset ( ) ;
276
- if ( ( olat ) && ( olng ) ) {
277
- settings . mapSettings . zoom = 0 ;
278
- begin_mapping ( ) ;
279
- }
280
- else {
281
- mapping ( originalData ) ;
303
+ else {
304
+ //Remove ids from the filter arrays as they are unchecked
305
+ var filterIndex = filters [ filterKey ] . indexOf ( filterId ) ;
306
+ if ( filterIndex > - 1 ) {
307
+ filters [ filterKey ] . splice ( filterIndex , 1 ) ;
308
+ if ( $ ( '#' + settings . mapDiv ) . hasClass ( 'bh-storelocator-map-open' ) === true ) {
309
+ reset ( ) ;
310
+ if ( ( olat ) && ( olng ) ) {
311
+ if ( countFilters ( ) === 0 ) {
312
+ settings . mapSettings . zoom = originalZoom ;
313
+ }
314
+ else {
315
+ settings . mapSettings . zoom = 0 ;
316
+ }
317
+ begin_mapping ( ) ;
318
+ }
319
+ else {
320
+ mapping ( originalData ) ;
321
+ }
322
+ }
282
323
}
283
324
}
284
325
}
285
- else {
286
- //Remove ids from the filter arrays as they are unchecked
287
- var filterIndex = filters [ locFilterKey ] . indexOf ( catId ) ;
288
- if ( filterIndex > - 1 ) {
289
- filters [ locFilterKey ] . splice ( filterIndex , 1 ) ;
326
+ }
327
+ //Handle select filters
328
+ else if ( $ ( this ) . is ( 'select' ) ) {
329
+ //First check for existing selections
330
+ checkFilters ( ) ;
331
+
332
+ filterId = $ ( this ) . val ( ) ;
333
+ filterContainer = $ ( this ) . closest ( '.bh-storelocator-filters' ) . attr ( 'id' ) ;
334
+ filterKey = getFilterKey ( filterContainer ) ;
335
+
336
+ //Check for blank filter on select since default val could be empty
337
+ if ( filterId ) {
338
+ if ( filterKey ) {
339
+ filters [ filterKey ] = [ filterId ] ;
290
340
if ( $ ( '#' + settings . mapDiv ) . hasClass ( 'bh-storelocator-map-open' ) === true ) {
291
341
reset ( ) ;
292
342
if ( ( olat ) && ( olng ) ) {
293
- if ( countFilters ( ) === 0 ) {
294
- settings . mapSettings . zoom = originalZoom ;
295
- }
296
- else {
297
- settings . mapSettings . zoom = 0 ;
298
- }
343
+ settings . mapSettings . zoom = 0 ;
299
344
begin_mapping ( ) ;
300
345
}
301
- else {
346
+ else {
302
347
mapping ( originalData ) ;
303
348
}
304
349
}
305
350
}
306
351
}
352
+ //Reset if the default option is selected
353
+ else {
354
+ if ( filterKey ) {
355
+ filters [ filterKey ] = [ ] ;
356
+ }
357
+ reset ( ) ;
358
+ if ( ( olat ) && ( olng ) ) {
359
+ settings . mapSettings . zoom = originalZoom ;
360
+ begin_mapping ( ) ;
361
+ }
362
+ else {
363
+ mapping ( originalData ) ;
364
+ }
365
+ }
307
366
}
308
- //Select filters
309
- /*else {
310
-
311
- }*/
312
367
} ) ;
313
368
}
314
369
@@ -721,15 +776,18 @@ $.fn.storeLocator = function(options){
721
776
} ) ;
722
777
}
723
778
724
- function filterData ( data , filters ) {
779
+ function filterData ( data , filters ) {
780
+ var filterTest = true ;
781
+
725
782
for ( var k in filters ) {
726
783
if ( ! ( new RegExp ( filters [ k ] . join ( "" ) ) . test ( data [ k ] ) ) ) {
727
- return false ;
728
- }
729
- else {
730
- return true ;
784
+ filterTest = false ;
731
785
}
732
786
}
787
+
788
+ if ( filterTest ) {
789
+ return true ;
790
+ }
733
791
}
734
792
735
793
//Taxonomy filtering setup
0 commit comments