Skip to content

Commit 2caabc7

Browse files
author
Dmitry Berezovsky
committed
Fixed issue with event subscription
1 parent 1752e96 commit 2caabc7

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

locationpicker.jquery.js

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,12 @@
116116

117117
function setupInputListenersInput(inputBinding, gmapContext) {
118118
if (inputBinding) {
119-
inputBinding.radiusInput.on("change", function() {
120-
gmapContext.radius = $(this).val();
121-
GmUtility.setPosition(gmapContext, gmapContext.location);
122-
});
119+
if (inputBinding.radiusInput){
120+
inputBinding.radiusInput.on("change", function() {
121+
gmapContext.radius = $(this).val();
122+
GmUtility.setPosition(gmapContext, gmapContext.location);
123+
});
124+
}
123125
if (inputBinding.locationNameInput && gmapContext.settings.enableAutocomplete) {
124126
gmapContext.autocomplete = new google.maps.places.Autocomplete(inputBinding.locationNameInput.get(0));
125127
google.maps.event.addListener(gmapContext.autocomplete, 'place_changed', function() {
@@ -195,7 +197,7 @@
195197
if (isPluginApplied(this)) return;
196198
// Plug-in initialization is required
197199
// Defaults
198-
var settings = $.extend($.fn.locationpicker.defaults, options );
200+
var settings = $.extend({}, $.fn.locationpicker.defaults, options );
199201
// Initialize
200202
var gmapContext = new GMapContext(this, {
201203
zoom: settings.zoom,
@@ -209,18 +211,18 @@
209211
locationName: settings.locationName,
210212
settings: settings
211213
});
212-
$(this).data("locationpicker", gmapContext);
214+
$target.data("locationpicker", gmapContext);
213215
// Subscribe GMap events
214216
google.maps.event.addListener(gmapContext.marker, "dragend", function(event) {
215-
GmUtility.setPosition(gmapContext, gmapContext.marker.position, function(){
217+
GmUtility.setPosition(gmapContext, gmapContext.marker.position, function(context){
216218
var currentLocation = GmUtility.locationFromLatLng(gmapContext.location);
217-
settings.onchanged(currentLocation, gmapContext.radius, true);
218-
updateInputValues(settings.inputBinding, gmapContext);
219+
context.settings.onchanged(currentLocation, context.radius, true);
220+
updateInputValues(gmapContext.settings.inputBinding, gmapContext);
219221
});
220222
});
221-
GmUtility.setPosition(gmapContext, new google.maps.LatLng(settings.location.latitude, settings.location.longitude), function(){
223+
GmUtility.setPosition(gmapContext, new google.maps.LatLng(settings.location.latitude, settings.location.longitude), function(context){
222224
updateInputValues(settings.inputBinding, gmapContext);
223-
settings.oninitialized($target);
225+
context.settings.oninitialized($target);
224226
});
225227
// Set up input bindings if needed
226228
setupInputListenersInput(settings.inputBinding, gmapContext);
@@ -246,4 +248,4 @@
246248

247249
}
248250

249-
}( jQuery ));
251+
}( jQuery ));

0 commit comments

Comments
 (0)