1
1
/*
2
- * storeLocator v1.4.6 - jQuery Google Maps Store Locator Plugin
2
+ * storeLocator v1.4.7 - jQuery Google Maps Store Locator Plugin
3
3
* (c) Copyright 2013, Bjorn Holine (http://www.bjornblog.com)
4
4
* Released under the MIT license
5
5
* Distance calculation function by Chris Pietschmann: http://pietschsoft.com/post/2008/02/01/Calculate-Distance-Between-Geocodes-in-C-and-JavaScript.aspx
@@ -43,6 +43,7 @@ $.fn.storeLocator = function(options) {
43
43
'noForm' : false ,
44
44
'loading' : false ,
45
45
'loadingDiv' : 'loading-map' ,
46
+ 'featuredLocations' : false ,
46
47
'infowindowTemplatePath' : 'templates/infowindow-description.html' ,
47
48
'listTemplatePath' : 'templates/location-list-description.html' ,
48
49
'KMLinfowindowTemplatePath' : 'templates/kml-infowindow-description.html' ,
@@ -112,12 +113,16 @@ $.fn.storeLocator = function(options) {
112
113
113
114
var userinput , olat , olng , marker , letter , storenum ;
114
115
var locationset = [ ] ;
116
+ var featuredset = [ ] ;
117
+ var normalset = [ ] ;
115
118
var markers = [ ] ;
116
119
var prefix = 'storeLocator' ;
117
120
118
121
//Resets for multiple re-submissions
119
122
function reset ( ) {
120
123
locationset = [ ] ;
124
+ featuredset = [ ] ;
125
+ normalset = [ ] ;
121
126
markers = [ ] ;
122
127
$ ( document ) . off ( 'click.' + prefix , '#' + settings . listDiv + ' li' ) ;
123
128
}
@@ -389,20 +394,21 @@ $.fn.storeLocator = function(options) {
389
394
var hours2 = this . hours2 ;
390
395
var hours3 = this . hours3 ;
391
396
var category = this . category ;
397
+ var featured = this . featured ;
392
398
393
399
var distance = GeoCodeCalc . CalcDistance ( orig_lat , orig_lng , lat , lng , GeoCodeCalc . EarthRadius ) ;
394
400
395
401
//Create the array
396
402
if ( settings . maxDistance === true && firstRun !== true ) {
397
403
if ( distance < maxDistance ) {
398
- locationset [ i ] = [ distance , name , lat , lng , address , address2 , city , state , postal , country , phone , email , web , hours1 , hours2 , hours3 , category ] ;
404
+ locationset [ i ] = [ distance , name , lat , lng , address , address2 , city , state , postal , country , phone , email , web , hours1 , hours2 , hours3 , category , featured ] ;
399
405
}
400
406
else {
401
407
return ;
402
408
}
403
409
}
404
410
else {
405
- locationset [ i ] = [ distance , name , lat , lng , address , address2 , city , state , postal , country , phone , email , web , hours1 , hours2 , hours3 , category ] ;
411
+ locationset [ i ] = [ distance , name , lat , lng , address , address2 , city , state , postal , country , phone , email , web , hours1 , hours2 , hours3 , category , featured ] ;
406
412
}
407
413
408
414
i ++ ;
@@ -454,32 +460,55 @@ $.fn.storeLocator = function(options) {
454
460
var hours2 = $ ( this ) . attr ( 'hours2' ) ;
455
461
var hours3 = $ ( this ) . attr ( 'hours3' ) ;
456
462
var category = $ ( this ) . attr ( 'category' ) ;
463
+ var featured = $ ( this ) . attr ( 'featured' ) ;
457
464
458
465
var distance = GeoCodeCalc . CalcDistance ( orig_lat , orig_lng , lat , lng , GeoCodeCalc . EarthRadius ) ;
459
466
460
467
//Create the array
461
468
if ( settings . maxDistance === true && firstRun !== true ) {
462
469
if ( distance < maxDistance ) {
463
- locationset [ i ] = [ distance , name , lat , lng , address , address2 , city , state , postal , country , phone , email , web , hours1 , hours2 , hours3 , category ] ;
470
+ locationset [ i ] = [ distance , name , lat , lng , address , address2 , city , state , postal , country , phone , email , web , hours1 , hours2 , hours3 , category , featured ] ;
464
471
}
465
472
else {
466
473
return ;
467
474
}
468
475
}
469
476
else {
470
- locationset [ i ] = [ distance , name , lat , lng , address , address2 , city , state , postal , country , phone , email , web , hours1 , hours2 , hours3 , category ] ;
477
+ locationset [ i ] = [ distance , name , lat , lng , address , address2 , city , state , postal , country , phone , email , web , hours1 , hours2 , hours3 , category , featured ] ;
471
478
}
472
479
473
480
i ++ ;
474
481
} ) ;
475
482
}
476
483
477
- //Sort the multi-dimensional array numerically by distance
478
- locationset . sort ( function ( a , b ) {
479
- var x = a [ 0 ] ;
480
- var y = b [ 0 ] ;
481
- return ( ( x < y ) ? - 1 : ( ( x > y ) ? 1 : 0 ) ) ;
482
- } ) ;
484
+ //Distance sorting function
485
+ function sort_numerically ( locationsarray ) {
486
+ locationsarray . sort ( function ( a , b ) {
487
+ var x = a [ 0 ] ;
488
+ var y = b [ 0 ] ;
489
+ return ( ( x < y ) ? - 1 : ( ( x > y ) ? 1 : 0 ) ) ;
490
+ } ) ;
491
+ }
492
+
493
+ //Sort the multi-dimensional array by distance
494
+ sort_numerically ( locationset ) ;
495
+
496
+ //Featured locations filtering
497
+ if ( settings . featuredLocations === true ) {
498
+ //Create array for featured locations
499
+ featuredset = $ . grep ( locationset , function ( val , i ) {
500
+ return val [ 17 ] === "true" ;
501
+ } ) ;
502
+
503
+ //Create array for normal locations
504
+ normalset = $ . grep ( locationset , function ( val , i ) {
505
+ return val [ 17 ] !== "true" ;
506
+ } ) ;
507
+
508
+ //Combine the arrays
509
+ locationset = [ ] ;
510
+ locationset = featuredset . concat ( normalset ) ;
511
+ }
483
512
484
513
//Get the length unit
485
514
var distUnit = ( settings . lengthUnit === "km" ) ? settings . kilometersLang : settings . milesLang ;
@@ -500,7 +529,7 @@ $.fn.storeLocator = function(options) {
500
529
//Create the map with jQuery
501
530
$ ( function ( ) {
502
531
503
- var storeDistance , storeName , storeAddress1 , storeAddress2 , storeCity , storeState , storeCountry , storeZip , storePhone , storeEmail , storeWeb , storeHours1 , storeHours2 , storeHours3 , storeDescription , storeCat ;
532
+ var storeDistance , storeName , storeAddress1 , storeAddress2 , storeCity , storeState , storeCountry , storeZip , storePhone , storeEmail , storeWeb , storeHours1 , storeHours2 , storeHours3 , storeDescription , storeCat , storeFeatured ;
504
533
505
534
//Instead of repeating the same thing twice below
506
535
function create_location_variables ( loopcount ) {
@@ -520,6 +549,7 @@ $.fn.storeLocator = function(options) {
520
549
storeHours2 = locationset [ loopcount ] [ 14 ] ;
521
550
storeHours3 = locationset [ loopcount ] [ 15 ] ;
522
551
storeCat = locationset [ loopcount ] [ 16 ] ;
552
+ storeFeatured = locationset [ loopcount ] [ 17 ] ;
523
553
}
524
554
525
555
//There are less variables for KML files
@@ -605,7 +635,8 @@ $.fn.storeLocator = function(options) {
605
635
"hours3" : storeHours3 ,
606
636
"length" : distLength ,
607
637
"origin" : origin ,
608
- "category" : storeCat
638
+ "category" : storeCat ,
639
+ "featured" : storeFeatured
609
640
}
610
641
]
611
642
} ;
0 commit comments