diff --git a/locationpicker.jquery.js b/locationpicker.jquery.js index 88b3def..b002eb5 100644 --- a/locationpicker.jquery.js +++ b/locationpicker.jquery.js @@ -116,10 +116,12 @@ function setupInputListenersInput(inputBinding, gmapContext) { if (inputBinding) { - inputBinding.radiusInput.on("change", function() { - gmapContext.radius = $(this).val(); - GmUtility.setPosition(gmapContext, gmapContext.location); - }); + if (inputBinding.radiusInput){ + inputBinding.radiusInput.on("change", function() { + gmapContext.radius = $(this).val(); + GmUtility.setPosition(gmapContext, gmapContext.location); + }); + } if (inputBinding.locationNameInput && gmapContext.settings.enableAutocomplete) { gmapContext.autocomplete = new google.maps.places.Autocomplete(inputBinding.locationNameInput.get(0)); google.maps.event.addListener(gmapContext.autocomplete, 'place_changed', function() { @@ -195,7 +197,7 @@ if (isPluginApplied(this)) return; // Plug-in initialization is required // Defaults - var settings = $.extend($.fn.locationpicker.defaults, options ); + var settings = $.extend({}, $.fn.locationpicker.defaults, options ); // Initialize var gmapContext = new GMapContext(this, { zoom: settings.zoom, @@ -209,18 +211,18 @@ locationName: settings.locationName, settings: settings }); - $(this).data("locationpicker", gmapContext); + $target.data("locationpicker", gmapContext); // Subscribe GMap events google.maps.event.addListener(gmapContext.marker, "dragend", function(event) { - GmUtility.setPosition(gmapContext, gmapContext.marker.position, function(){ + GmUtility.setPosition(gmapContext, gmapContext.marker.position, function(context){ var currentLocation = GmUtility.locationFromLatLng(gmapContext.location); - settings.onchanged(currentLocation, gmapContext.radius, true); - updateInputValues(settings.inputBinding, gmapContext); + context.settings.onchanged(currentLocation, context.radius, true); + updateInputValues(gmapContext.settings.inputBinding, gmapContext); }); }); - GmUtility.setPosition(gmapContext, new google.maps.LatLng(settings.location.latitude, settings.location.longitude), function(){ + GmUtility.setPosition(gmapContext, new google.maps.LatLng(settings.location.latitude, settings.location.longitude), function(context){ updateInputValues(settings.inputBinding, gmapContext); - settings.oninitialized($target); + context.settings.oninitialized($target); }); // Set up input bindings if needed setupInputListenersInput(settings.inputBinding, gmapContext); @@ -246,4 +248,4 @@ } -}( jQuery )); \ No newline at end of file +}( jQuery ));