1
1
/*
2
- * storeLocator v1.4.2 - jQuery Google Maps Store Locator Plugin
2
+ * storeLocator v1.4.3 - 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
@@ -51,7 +51,17 @@ $.fn.storeLocator = function(options) {
51
51
'callbackComplete' : null ,
52
52
'callbackSuccess' : null ,
53
53
'callbackModalOpen' : null ,
54
- 'callbackModalClose' : null
54
+ 'callbackModalClose' : null ,
55
+ //Language options
56
+ 'geocodeErrorAlert' : 'Geocode was not successful for the following reason: ' ,
57
+ 'blankInputAlert' : 'The input box was blank.' ,
58
+ 'addressErrorAlert' : 'Unable to find address' ,
59
+ 'autoGeocodeErrorAlert' : 'Automatic location detection failed. Please fill in your address or zip code.' ,
60
+ 'distanceErrorAlert' : 'Unfortunately, our closest location is more than ' ,
61
+ 'mileLang' : 'mile' ,
62
+ 'milesLang' : 'miles' ,
63
+ 'kilometerLang' : 'kilometer' ,
64
+ 'kilometersLang' : 'kilometers'
55
65
} , options ) ;
56
66
57
67
return this . each ( function ( ) {
@@ -101,6 +111,7 @@ $.fn.storeLocator = function(options) {
101
111
102
112
var userinput , olat , olng , marker , letter , storenum ;
103
113
var locationset = [ ] ;
114
+ var prefix = 'storeLocator' ;
104
115
105
116
//Add modal window divs if set
106
117
if ( settings . modalWindow === true )
@@ -146,7 +157,7 @@ $.fn.storeLocator = function(options) {
146
157
result . longitude = results [ 0 ] . geometry . location . lng ( ) ;
147
158
callbackFunction ( result ) ;
148
159
} else {
149
- alert ( "Geocode was not successful for the following reason: " + status ) ;
160
+ alert ( settings . geocodeErrorAlert + status ) ;
150
161
callbackFunction ( null ) ;
151
162
}
152
163
} ) ;
@@ -166,7 +177,7 @@ $.fn.storeLocator = function(options) {
166
177
callbackFunction ( result ) ;
167
178
}
168
179
} else {
169
- alert ( "Geocode was not successful for the following reason: " + status ) ;
180
+ alert ( settings . geocodeErrorAlert + status ) ;
170
181
callbackFunction ( null ) ;
171
182
}
172
183
} ) ;
@@ -176,8 +187,7 @@ $.fn.storeLocator = function(options) {
176
187
//Used to round miles to display
177
188
function roundNumber ( num , dec )
178
189
{
179
- var result = Math . round ( num * Math . pow ( 10 , dec ) ) / Math . pow ( 10 , dec ) ;
180
- return result ;
190
+ return Math . round ( num * Math . pow ( 10 , dec ) ) / Math . pow ( 10 , dec ) ;
181
191
}
182
192
183
193
//If a default location is set
@@ -192,7 +202,7 @@ $.fn.storeLocator = function(options) {
192
202
mapping ( settings . defaultLat , settings . defaultLng , originAddress ) ;
193
203
} else {
194
204
//Unable to geocode
195
- alert ( 'Unable to find address' ) ;
205
+ alert ( settings . addressErrorAlert ) ;
196
206
}
197
207
} ) ;
198
208
}
@@ -224,15 +234,15 @@ $.fn.storeLocator = function(options) {
224
234
mapping ( position . coords . latitude , position . coords . longitude , originAddress ) ;
225
235
} else {
226
236
//Unable to geocode
227
- alert ( 'Unable to find address' ) ;
237
+ alert ( settings . addressErrorAlert ) ;
228
238
}
229
239
} ) ;
230
240
}
231
241
232
242
function autoGeocode_error ( error )
233
243
{
234
244
//If automatic detection doesn't work show an error
235
- alert ( "Automatic location detection failed. Please fill in your address or zip code." ) ;
245
+ alert ( settings . autoGeocodeErrorAlert ) ;
236
246
}
237
247
238
248
//Set up the normal mapping
@@ -244,7 +254,7 @@ $.fn.storeLocator = function(options) {
244
254
if ( userinput === "" )
245
255
{
246
256
//Show alert and stop processing
247
- alert ( "The input box was blank." ) ;
257
+ alert ( settings . blankInputAlert ) ;
248
258
}
249
259
else
250
260
{
@@ -257,7 +267,7 @@ $.fn.storeLocator = function(options) {
257
267
mapping ( olat , olng , userinput , distance ) ;
258
268
} else {
259
269
//Unable to geocode
260
- alert ( 'ERROR! Unable to geocode address' ) ;
270
+ alert ( settings . addressErrorAlert ) ;
261
271
}
262
272
} ) ;
263
273
}
@@ -283,17 +293,17 @@ $.fn.storeLocator = function(options) {
283
293
284
294
//ASP.net or regular submission?
285
295
if ( settings . noForm === true ) {
286
- $ ( document ) . on ( 'click' , '#' + settings . formContainerDiv + ' #submit' , function ( e ) {
296
+ $ ( document ) . on ( 'click.' + prefix , '#' + settings . formContainerDiv + ' #submit' , function ( e ) {
287
297
get_form_values ( e ) ;
288
298
} ) ;
289
- $ ( document ) . keyup ( function ( e ) {
299
+ $ ( document ) . on ( 'keyup.' + prefix , function ( e ) {
290
300
if ( e . keyCode === 13 ) {
291
301
get_form_values ( e ) ;
292
302
}
293
303
} ) ;
294
304
}
295
305
else {
296
- $ ( document ) . on ( 'submit' , '#' + settings . formID , function ( e ) {
306
+ $ ( document ) . on ( 'submit.' + prefix , '#' + settings . formID , function ( e ) {
297
307
get_form_values ( e ) ;
298
308
} ) ;
299
309
}
@@ -380,20 +390,21 @@ $.fn.storeLocator = function(options) {
380
390
var hours1 = this . hours1 ;
381
391
var hours2 = this . hours2 ;
382
392
var hours3 = this . hours3 ;
393
+ var category = this . category ;
383
394
384
395
var distance = GeoCodeCalc . CalcDistance ( orig_lat , orig_lng , lat , lng , GeoCodeCalc . EarthRadius ) ;
385
396
386
397
//Create the array
387
398
if ( settings . maxDistance === true && firstRun !== true ) {
388
399
if ( distance < maxDistance ) {
389
- locationset [ i ] = [ distance , name , lat , lng , address , address2 , city , state , postal , phone , web , hours1 , hours2 , hours3 ] ;
400
+ locationset [ i ] = [ distance , name , lat , lng , address , address2 , city , state , postal , phone , web , hours1 , hours2 , hours3 , category ] ;
390
401
}
391
402
else {
392
403
return ;
393
404
}
394
405
}
395
406
else {
396
- locationset [ i ] = [ distance , name , lat , lng , address , address2 , city , state , postal , phone , web , hours1 , hours2 , hours3 ] ;
407
+ locationset [ i ] = [ distance , name , lat , lng , address , address2 , city , state , postal , phone , web , hours1 , hours2 , hours3 , category ] ;
397
408
}
398
409
399
410
i ++ ;
@@ -444,20 +455,21 @@ $.fn.storeLocator = function(options) {
444
455
var hours1 = $ ( this ) . attr ( 'hours1' ) ;
445
456
var hours2 = $ ( this ) . attr ( 'hours2' ) ;
446
457
var hours3 = $ ( this ) . attr ( 'hours3' ) ;
458
+ var category = $ ( this ) . attr ( 'category' ) ;
447
459
448
460
var distance = GeoCodeCalc . CalcDistance ( orig_lat , orig_lng , lat , lng , GeoCodeCalc . EarthRadius ) ;
449
461
450
462
//Create the array
451
463
if ( settings . maxDistance === true && firstRun !== true ) {
452
464
if ( distance < maxDistance ) {
453
- locationset [ i ] = [ distance , name , lat , lng , address , address2 , city , state , postal , phone , web , hours1 , hours2 , hours3 ] ;
465
+ locationset [ i ] = [ distance , name , lat , lng , address , address2 , city , state , postal , phone , web , hours1 , hours2 , hours3 , category ] ;
454
466
}
455
467
else {
456
468
return ;
457
469
}
458
470
}
459
471
else {
460
- locationset [ i ] = [ distance , name , lat , lng , address , address2 , city , state , postal , phone , web , hours1 , hours2 , hours3 ] ;
472
+ locationset [ i ] = [ distance , name , lat , lng , address , address2 , city , state , postal , phone , web , hours1 , hours2 , hours3 , category ] ;
461
473
}
462
474
463
475
i ++ ;
@@ -471,23 +483,26 @@ $.fn.storeLocator = function(options) {
471
483
return ( ( x < y ) ? - 1 : ( ( x > y ) ? 1 : 0 ) ) ;
472
484
} ) ;
473
485
486
+ //Get the length unit
487
+ var distUnit = ( settings . lengthUnit === "km" ) ? settings . kilometersLang : settings . milesLang ;
488
+
474
489
//Check the closest marker
475
490
if ( settings . maxDistance === true && firstRun !== true ) {
476
491
if ( locationset [ 0 ] === undefined || locationset [ 0 ] [ 0 ] > maxDistance ) {
477
- alert ( "Unfortunately, our closest location is more than " + maxDistance + " miles away." ) ;
492
+ alert ( settings . distanceErrorAlert + maxDistance + " " + distUnit ) ;
478
493
return ;
479
494
}
480
495
}
481
496
else {
482
497
if ( locationset [ 0 ] [ 0 ] > settings . distanceAlert ) {
483
- alert ( "Unfortunately, our closest location is more than " + settings . distanceAlert + " miles away." ) ;
498
+ alert ( settings . distanceErrorAlert + settings . distanceAlert + " " + distUnit ) ;
484
499
}
485
500
}
486
501
487
502
//Create the map with jQuery
488
503
$ ( function ( ) {
489
504
490
- var storeDistance , storeName , storeAddress1 , storeAddress2 , storeCity , storeState , storeZip , storePhone , storeWeb , storeHours1 , storeHours2 , storeHours3 , storeDescription ;
505
+ var storeDistance , storeName , storeAddress1 , storeAddress2 , storeCity , storeState , storeZip , storePhone , storeWeb , storeHours1 , storeHours2 , storeHours3 , storeDescription , storeCat ;
491
506
492
507
//Instead of repeating the same thing twice below
493
508
function create_location_variables ( loopcount )
@@ -505,6 +520,7 @@ $.fn.storeLocator = function(options) {
505
520
storeHours1 = locationset [ loopcount ] [ 11 ] ;
506
521
storeHours2 = locationset [ loopcount ] [ 12 ] ;
507
522
storeHours3 = locationset [ loopcount ] [ 13 ] ;
523
+ storeCat = locationset [ loopcount ] [ 14 ] ;
508
524
}
509
525
510
526
//There are less variables for KML files
@@ -529,18 +545,18 @@ $.fn.storeLocator = function(options) {
529
545
var distLength ;
530
546
if ( storeDistance <= 1 ) {
531
547
if ( settings . lengthUnit === "km" ) {
532
- distLength = "kilometer" ;
548
+ distLength = settings . kilometerLang ;
533
549
}
534
550
else {
535
- distLength = "mile" ;
551
+ distLength = settings . mileLang ;
536
552
}
537
553
}
538
554
else {
539
555
if ( settings . lengthUnit === "km" ) {
540
- distLength = "kilometers" ;
556
+ distLength = settings . kilometersLang ;
541
557
}
542
558
else {
543
- distLength = "miles" ;
559
+ distLength = settings . milesLang ;
544
560
}
545
561
}
546
562
@@ -589,7 +605,8 @@ $.fn.storeLocator = function(options) {
589
605
"hours2" : storeHours2 ,
590
606
"hours3" : storeHours3 ,
591
607
"length" : distLength ,
592
- "origin" : origin
608
+ "origin" : origin ,
609
+ "category" : storeCat
593
610
}
594
611
]
595
612
} ;
@@ -623,15 +640,15 @@ $.fn.storeLocator = function(options) {
623
640
//Pop up the modal window
624
641
$ ( '#' + settings . overlayDiv ) . fadeIn ( ) ;
625
642
//Close modal when close icon is clicked and when background overlay is clicked
626
- $ ( document ) . on ( 'click' , '#' + settings . modalCloseIconDiv + ', #' + settings . overlayDiv , function ( ) {
643
+ $ ( document ) . on ( 'click.' + prefix , '#' + settings . modalCloseIconDiv + ', #' + settings . overlayDiv , function ( ) {
627
644
modalClose ( ) ;
628
645
} ) ;
629
646
//Prevent clicks within the modal window from closing the entire thing
630
- $ ( document ) . on ( 'click' , '#' + settings . modalWindowDiv , function ( e ) {
647
+ $ ( document ) . on ( 'click.' + prefix , '#' + settings . modalWindowDiv , function ( e ) {
631
648
e . stopPropagation ( ) ;
632
649
} ) ;
633
650
//Close modal when escape key is pressed
634
- $ ( document ) . keyup ( function ( e ) {
651
+ $ ( document ) . on ( 'keyup.' + prefix , function ( e ) {
635
652
if ( e . keyCode === 27 ) {
636
653
modalClose ( ) ;
637
654
}
@@ -687,7 +704,7 @@ $.fn.storeLocator = function(options) {
687
704
{
688
705
var letter = String . fromCharCode ( "A" . charCodeAt ( 0 ) + y ) ;
689
706
var point = new google . maps . LatLng ( locationset [ y ] [ 2 ] , locationset [ y ] [ 3 ] ) ;
690
- marker = createMarker ( point , locationset [ y ] [ 1 ] , locationset [ y ] [ 4 ] , letter ) ;
707
+ marker = createMarker ( point , locationset [ y ] [ 1 ] , locationset [ y ] [ 4 ] , letter , locationset [ y ] [ 14 ] ) ;
691
708
marker . set ( "id" , y ) ;
692
709
markers [ y ] = marker ;
693
710
if ( ( settings . fullMapStart === true && firstRun === true ) || settings . zoomLevel === 0 ) {
@@ -722,7 +739,7 @@ $.fn.storeLocator = function(options) {
722
739
}
723
740
724
741
//Handle clicks from the list
725
- $ ( document ) . on ( 'click' , '#' + settings . listDiv + ' li' , function ( ) {
742
+ $ ( document ) . on ( 'click.' + prefix , '#' + settings . listDiv + ' li' , function ( ) {
726
743
var markerId = $ ( this ) . data ( 'markerid' ) ;
727
744
728
745
var selectedMarker = markers [ markerId ] ;
@@ -749,7 +766,7 @@ $.fn.storeLocator = function(options) {
749
766
$ ( "#" + settings . listDiv + " ul li:odd" ) . css ( 'background' , "#" + settings . listColor2 ) ;
750
767
751
768
//Custom marker function - alphabetical
752
- function createMarker ( point , name , address , letter ) {
769
+ function createMarker ( point , name , address , letter , type ) {
753
770
//Set up pin icon with the Google Charts API for all of our markers
754
771
var pinImage = new google . maps . MarkerImage ( "http://chart.apis.google.com/chart?chst=d_map_pin_letter&chld=" + letter + "|" + settings . pinColor + "|" + settings . pinTextColor ,
755
772
new google . maps . Size ( 21 , 34 ) ,
0 commit comments