11/*
2- * storeLocator v1.4.2 - jQuery Google Maps Store Locator Plugin
2+ * storeLocator v1.4.3 - jQuery Google Maps Store Locator Plugin
33* (c) Copyright 2013, Bjorn Holine (http://www.bjornblog.com)
44* Released under the MIT license
55* 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) {
5151 'callbackComplete' : null ,
5252 'callbackSuccess' : null ,
5353 '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'
5565 } , options ) ;
5666
5767 return this . each ( function ( ) {
@@ -101,6 +111,7 @@ $.fn.storeLocator = function(options) {
101111
102112 var userinput , olat , olng , marker , letter , storenum ;
103113 var locationset = [ ] ;
114+ var prefix = 'storeLocator' ;
104115
105116 //Add modal window divs if set
106117 if ( settings . modalWindow === true )
@@ -146,7 +157,7 @@ $.fn.storeLocator = function(options) {
146157 result . longitude = results [ 0 ] . geometry . location . lng ( ) ;
147158 callbackFunction ( result ) ;
148159 } else {
149- alert ( "Geocode was not successful for the following reason: " + status ) ;
160+ alert ( settings . geocodeErrorAlert + status ) ;
150161 callbackFunction ( null ) ;
151162 }
152163 } ) ;
@@ -166,7 +177,7 @@ $.fn.storeLocator = function(options) {
166177 callbackFunction ( result ) ;
167178 }
168179 } else {
169- alert ( "Geocode was not successful for the following reason: " + status ) ;
180+ alert ( settings . geocodeErrorAlert + status ) ;
170181 callbackFunction ( null ) ;
171182 }
172183 } ) ;
@@ -176,8 +187,7 @@ $.fn.storeLocator = function(options) {
176187 //Used to round miles to display
177188 function roundNumber ( num , dec )
178189 {
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 ) ;
181191 }
182192
183193 //If a default location is set
@@ -192,7 +202,7 @@ $.fn.storeLocator = function(options) {
192202 mapping ( settings . defaultLat , settings . defaultLng , originAddress ) ;
193203 } else {
194204 //Unable to geocode
195- alert ( 'Unable to find address' ) ;
205+ alert ( settings . addressErrorAlert ) ;
196206 }
197207 } ) ;
198208 }
@@ -224,15 +234,15 @@ $.fn.storeLocator = function(options) {
224234 mapping ( position . coords . latitude , position . coords . longitude , originAddress ) ;
225235 } else {
226236 //Unable to geocode
227- alert ( 'Unable to find address' ) ;
237+ alert ( settings . addressErrorAlert ) ;
228238 }
229239 } ) ;
230240 }
231241
232242 function autoGeocode_error ( error )
233243 {
234244 //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 ) ;
236246 }
237247
238248 //Set up the normal mapping
@@ -244,7 +254,7 @@ $.fn.storeLocator = function(options) {
244254 if ( userinput === "" )
245255 {
246256 //Show alert and stop processing
247- alert ( "The input box was blank." ) ;
257+ alert ( settings . blankInputAlert ) ;
248258 }
249259 else
250260 {
@@ -257,7 +267,7 @@ $.fn.storeLocator = function(options) {
257267 mapping ( olat , olng , userinput , distance ) ;
258268 } else {
259269 //Unable to geocode
260- alert ( 'ERROR! Unable to geocode address' ) ;
270+ alert ( settings . addressErrorAlert ) ;
261271 }
262272 } ) ;
263273 }
@@ -283,17 +293,17 @@ $.fn.storeLocator = function(options) {
283293
284294 //ASP.net or regular submission?
285295 if ( settings . noForm === true ) {
286- $ ( document ) . on ( 'click' , '#' + settings . formContainerDiv + ' #submit' , function ( e ) {
296+ $ ( document ) . on ( 'click.' + prefix , '#' + settings . formContainerDiv + ' #submit' , function ( e ) {
287297 get_form_values ( e ) ;
288298 } ) ;
289- $ ( document ) . keyup ( function ( e ) {
299+ $ ( document ) . on ( 'keyup.' + prefix , function ( e ) {
290300 if ( e . keyCode === 13 ) {
291301 get_form_values ( e ) ;
292302 }
293303 } ) ;
294304 }
295305 else {
296- $ ( document ) . on ( 'submit' , '#' + settings . formID , function ( e ) {
306+ $ ( document ) . on ( 'submit.' + prefix , '#' + settings . formID , function ( e ) {
297307 get_form_values ( e ) ;
298308 } ) ;
299309 }
@@ -380,20 +390,21 @@ $.fn.storeLocator = function(options) {
380390 var hours1 = this . hours1 ;
381391 var hours2 = this . hours2 ;
382392 var hours3 = this . hours3 ;
393+ var category = this . category ;
383394
384395 var distance = GeoCodeCalc . CalcDistance ( orig_lat , orig_lng , lat , lng , GeoCodeCalc . EarthRadius ) ;
385396
386397 //Create the array
387398 if ( settings . maxDistance === true && firstRun !== true ) {
388399 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 ] ;
390401 }
391402 else {
392403 return ;
393404 }
394405 }
395406 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 ] ;
397408 }
398409
399410 i ++ ;
@@ -444,20 +455,21 @@ $.fn.storeLocator = function(options) {
444455 var hours1 = $ ( this ) . attr ( 'hours1' ) ;
445456 var hours2 = $ ( this ) . attr ( 'hours2' ) ;
446457 var hours3 = $ ( this ) . attr ( 'hours3' ) ;
458+ var category = $ ( this ) . attr ( 'category' ) ;
447459
448460 var distance = GeoCodeCalc . CalcDistance ( orig_lat , orig_lng , lat , lng , GeoCodeCalc . EarthRadius ) ;
449461
450462 //Create the array
451463 if ( settings . maxDistance === true && firstRun !== true ) {
452464 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 ] ;
454466 }
455467 else {
456468 return ;
457469 }
458470 }
459471 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 ] ;
461473 }
462474
463475 i ++ ;
@@ -471,23 +483,26 @@ $.fn.storeLocator = function(options) {
471483 return ( ( x < y ) ? - 1 : ( ( x > y ) ? 1 : 0 ) ) ;
472484 } ) ;
473485
486+ //Get the length unit
487+ var distUnit = ( settings . lengthUnit === "km" ) ? settings . kilometersLang : settings . milesLang ;
488+
474489 //Check the closest marker
475490 if ( settings . maxDistance === true && firstRun !== true ) {
476491 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 ) ;
478493 return ;
479494 }
480495 }
481496 else {
482497 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 ) ;
484499 }
485500 }
486501
487502 //Create the map with jQuery
488503 $ ( function ( ) {
489504
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 ;
491506
492507 //Instead of repeating the same thing twice below
493508 function create_location_variables ( loopcount )
@@ -505,6 +520,7 @@ $.fn.storeLocator = function(options) {
505520 storeHours1 = locationset [ loopcount ] [ 11 ] ;
506521 storeHours2 = locationset [ loopcount ] [ 12 ] ;
507522 storeHours3 = locationset [ loopcount ] [ 13 ] ;
523+ storeCat = locationset [ loopcount ] [ 14 ] ;
508524 }
509525
510526 //There are less variables for KML files
@@ -529,18 +545,18 @@ $.fn.storeLocator = function(options) {
529545 var distLength ;
530546 if ( storeDistance <= 1 ) {
531547 if ( settings . lengthUnit === "km" ) {
532- distLength = "kilometer" ;
548+ distLength = settings . kilometerLang ;
533549 }
534550 else {
535- distLength = "mile" ;
551+ distLength = settings . mileLang ;
536552 }
537553 }
538554 else {
539555 if ( settings . lengthUnit === "km" ) {
540- distLength = "kilometers" ;
556+ distLength = settings . kilometersLang ;
541557 }
542558 else {
543- distLength = "miles" ;
559+ distLength = settings . milesLang ;
544560 }
545561 }
546562
@@ -589,7 +605,8 @@ $.fn.storeLocator = function(options) {
589605 "hours2" : storeHours2 ,
590606 "hours3" : storeHours3 ,
591607 "length" : distLength ,
592- "origin" : origin
608+ "origin" : origin ,
609+ "category" : storeCat
593610 }
594611 ]
595612 } ;
@@ -623,15 +640,15 @@ $.fn.storeLocator = function(options) {
623640 //Pop up the modal window
624641 $ ( '#' + settings . overlayDiv ) . fadeIn ( ) ;
625642 //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 ( ) {
627644 modalClose ( ) ;
628645 } ) ;
629646 //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 ) {
631648 e . stopPropagation ( ) ;
632649 } ) ;
633650 //Close modal when escape key is pressed
634- $ ( document ) . keyup ( function ( e ) {
651+ $ ( document ) . on ( 'keyup.' + prefix , function ( e ) {
635652 if ( e . keyCode === 27 ) {
636653 modalClose ( ) ;
637654 }
@@ -687,7 +704,7 @@ $.fn.storeLocator = function(options) {
687704 {
688705 var letter = String . fromCharCode ( "A" . charCodeAt ( 0 ) + y ) ;
689706 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 ] ) ;
691708 marker . set ( "id" , y ) ;
692709 markers [ y ] = marker ;
693710 if ( ( settings . fullMapStart === true && firstRun === true ) || settings . zoomLevel === 0 ) {
@@ -722,7 +739,7 @@ $.fn.storeLocator = function(options) {
722739 }
723740
724741 //Handle clicks from the list
725- $ ( document ) . on ( 'click' , '#' + settings . listDiv + ' li' , function ( ) {
742+ $ ( document ) . on ( 'click.' + prefix , '#' + settings . listDiv + ' li' , function ( ) {
726743 var markerId = $ ( this ) . data ( 'markerid' ) ;
727744
728745 var selectedMarker = markers [ markerId ] ;
@@ -749,7 +766,7 @@ $.fn.storeLocator = function(options) {
749766 $ ( "#" + settings . listDiv + " ul li:odd" ) . css ( 'background' , "#" + settings . listColor2 ) ;
750767
751768 //Custom marker function - alphabetical
752- function createMarker ( point , name , address , letter ) {
769+ function createMarker ( point , name , address , letter , type ) {
753770 //Set up pin icon with the Google Charts API for all of our markers
754771 var pinImage = new google . maps . MarkerImage ( "http://chart.apis.google.com/chart?chst=d_map_pin_letter&chld=" + letter + "|" + settings . pinColor + "|" + settings . pinTextColor ,
755772 new google . maps . Size ( 21 , 34 ) ,
0 commit comments