geocomplete_rails 1.6.4 → 1.6.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0c98206237b7f337a6ae95ed9634d8f63b3f8ce7
4
- data.tar.gz: c6896d1fda94b8b229ffbca47c20631bf44ac697
3
+ metadata.gz: 3001815772a7bda654b34a52508fee477b1d26f4
4
+ data.tar.gz: 5bc8b2ee07cfeef68500314517627047cd0877b9
5
5
  SHA512:
6
- metadata.gz: d5261f258b4613d5b737a0a5b9841c25a13b9d70e5320e40f11aec2fd28ef75c77af89d06b73afb2327a806048c2d7c33a8abcd2f93496f51b49eb9091f53f5c
7
- data.tar.gz: c3e32fdbd8828e8a5912186befd3102fa414b4db74e1bef86ba81487896df3e3d8640258f5148267ab56509f81ef2014f0f943553a7274b21de5a30de1ff420e
6
+ metadata.gz: c65350dbc608ffb8215c85392ea98c8a45c952dc8cd1dd4f98057ae2f690c347c45f4cd837b5f6e0ab9c2d220f0a3f99ffd4aa67e1d53404fb72947e99d82d98
7
+ data.tar.gz: e3302072241edfb27a01c4aaa5cc5799fe0dbe6231a8009359b7ee0ec32f81890e781feca226c836ddb75e87b7bcd93a85e8a644e4fd5916cc2303a21594e17a
@@ -1,5 +1,5 @@
1
1
  /**
2
- * jQuery Geocoding and Places Autocomplete Plugin - V 1.6.4
2
+ * jQuery Geocoding and Places Autocomplete Plugin - V 1.6.5
3
3
  *
4
4
  * @author Martin Kleppe <kleppe@ubilabs.net>, 2014
5
5
  * @author Ubilabs http://ubilabs.net, 2014
@@ -19,6 +19,7 @@
19
19
  //
20
20
  // * `map` - Might be a selector, an jQuery object or a DOM element. Default is `false` which shows no map.
21
21
  // * `details` - The container that should be populated with data. Defaults to `false` which ignores the setting.
22
+ // * 'detailsScope' - Allows you to scope the 'details' container and have multiple geocomplete fields on one page. Must be a parent of the input. Default is 'null'
22
23
  // * `location` - Location to initialize the map on. Might be an address `string` or an `array` with [latitude, longitude] or a `google.maps.LatLng`object. Default is `false` which shows a blank map.
23
24
  // * `bounds` - Whether to snap geocode search to map bounds. Default: `true` if false search globally. Alternatively pass a custom `LatLngBounds object.
24
25
  // * `autoselect` - Automatically selects the highlighted item or the first item from the suggestions list on Enter.
@@ -34,6 +35,7 @@
34
35
  // * `types` - An array containing one or more of the supported types for the places request. Default: `['geocode']` See the full list [here](http://code.google.com/apis/maps/documentation/javascript/places.html#place_search_requests).
35
36
  // * `blur` - Trigger geocode when input loses focus.
36
37
  // * `geocodeAfterResult` - If blur is set to true, choose whether to geocode if user has explicitly selected a result before blur.
38
+ // * `restoreValueAfterBlur` - Restores the input's value upon blurring. Default is `false` which ignores the setting.
37
39
 
38
40
  var defaults = {
39
41
  bounds: true,
@@ -41,6 +43,7 @@
41
43
  map: false,
42
44
  details: false,
43
45
  detailsAttribute: "name",
46
+ detailsScope: null,
44
47
  autoselect: true,
45
48
  location: false,
46
49
 
@@ -57,7 +60,8 @@
57
60
  maxZoom: 16,
58
61
  types: ['geocode'],
59
62
  blur: false,
60
- geocodeAfterResult: false
63
+ geocodeAfterResult: false,
64
+ restoreValueAfterBlur: false
61
65
  };
62
66
 
63
67
  // See: [Geocoding Types](https://developers.google.com/maps/documentation/geocoding/#Types)
@@ -122,6 +126,20 @@
122
126
  $.proxy(this.mapClicked, this)
123
127
  );
124
128
 
129
+ // add dragend even listener on the map
130
+ google.maps.event.addListener(
131
+ this.map,
132
+ 'dragend',
133
+ $.proxy(this.mapDragged, this)
134
+ );
135
+
136
+ // add idle even listener on the map
137
+ google.maps.event.addListener(
138
+ this.map,
139
+ 'idle',
140
+ $.proxy(this.mapIdle, this)
141
+ );
142
+
125
143
  google.maps.event.addListener(
126
144
  this.map,
127
145
  'zoom_changed',
@@ -184,14 +202,14 @@
184
202
  );
185
203
 
186
204
  // Prevent parent form from being submitted if user hit enter.
187
- this.$input.keypress(function(event){
205
+ this.$input.on('keypress.' + this._name, function(event){
188
206
  if (event.keyCode === 13){ return false; }
189
207
  });
190
208
 
191
209
  // Assume that if user types anything after having selected a result,
192
210
  // the selected location is not valid any more.
193
211
  if (this.options.geocodeAfterResult === true){
194
- this.$input.bind('keypress', $.proxy(function(){
212
+ this.$input.bind('keypress.' + this._name, $.proxy(function(){
195
213
  if (event.keyCode != 9 && this.selected === true){
196
214
  this.selected = false;
197
215
  }
@@ -199,18 +217,28 @@
199
217
  }
200
218
 
201
219
  // Listen for "geocode" events and trigger find action.
202
- this.$input.bind("geocode", $.proxy(function(){
220
+ this.$input.bind('geocode.' + this._name, $.proxy(function(){
203
221
  this.find();
204
222
  }, this));
205
223
 
224
+ // Saves the previous input value
225
+ this.$input.bind('geocode:result.' + this._name, $.proxy(function(){
226
+ this.lastInputVal = this.$input.val();
227
+ }, this));
228
+
206
229
  // Trigger find action when input element is blurred out and user has
207
230
  // not explicitly selected a result.
208
231
  // (Useful for typing partial location and tabbing to the next field
209
232
  // or clicking somewhere else.)
210
233
  if (this.options.blur === true){
211
- this.$input.blur($.proxy(function(){
212
- if (this.options.geocodeAfterResult === true && this.selected === true){ return; }
213
- this.find();
234
+ this.$input.on('blur.' + this._name, $.proxy(function(){
235
+ if (this.options.geocodeAfterResult === true && this.selected === true) { return; }
236
+
237
+ if (this.options.restoreValueAfterBlur === true && this.selected === true) {
238
+ setTimeout($.proxy(this.restoreLastValue, this), 0);
239
+ } else {
240
+ this.find();
241
+ }
214
242
  }, this));
215
243
  }
216
244
  },
@@ -221,8 +249,13 @@
221
249
  initDetails: function(){
222
250
  if (!this.options.details){ return; }
223
251
 
224
- var $details = $(this.options.details),
225
- attribute = this.options.detailsAttribute,
252
+ if(this.options.detailsScope) {
253
+ var $details = $(this.input).parents(this.options.detailsScope).find(this.options.details);
254
+ } else {
255
+ var $details = $(this.options.details);
256
+ }
257
+
258
+ var attribute = this.options.detailsAttribute,
226
259
  details = {};
227
260
 
228
261
  function setDetail(value){
@@ -269,6 +302,20 @@
269
302
  }
270
303
  },
271
304
 
305
+ destroy: function(){
306
+ if (this.map) {
307
+ google.maps.event.clearInstanceListeners(this.map);
308
+ google.maps.event.clearInstanceListeners(this.marker);
309
+ }
310
+
311
+ this.autocomplete.unbindAll();
312
+ google.maps.event.clearInstanceListeners(this.autocomplete);
313
+ google.maps.event.clearInstanceListeners(this.input);
314
+ this.$input.removeData();
315
+ this.$input.off(this._name);
316
+ this.$input.unbind('.' + this._name);
317
+ },
318
+
272
319
  // Look up a given address. If no `address` was specified it uses
273
320
  // the current value of the input.
274
321
  find: function(address){
@@ -280,6 +327,10 @@
280
327
  // Requests details about a given location.
281
328
  // Additionally it will bias the requests to the provided bounds.
282
329
  geocode: function(request){
330
+ // Don't geocode if the requested address is empty
331
+ if (!request.address) {
332
+ return;
333
+ }
283
334
  if (this.options.bounds && !request.bounds){
284
335
  if (this.options.bounds === true){
285
336
  request.bounds = this.map && this.map.getBounds();
@@ -321,6 +372,11 @@
321
372
  return firstResult;
322
373
  },
323
374
 
375
+ // Restores the input value using the previous value if it exists
376
+ restoreLastValue: function() {
377
+ if (this.lastInputVal){ this.$input.val(this.lastInputVal); }
378
+ },
379
+
324
380
  // Handles the geocode response. If more than one results was found
325
381
  // it triggers the "geocode:multiple" events. If there was an error
326
382
  // the "geocode:error" event is fired.
@@ -451,11 +507,21 @@
451
507
  this.trigger("geocode:click", event.latLng);
452
508
  },
453
509
 
510
+ // Fire the "geocode:mapdragged" event and pass the current position of the map center.
511
+ mapDragged: function(event) {
512
+ this.trigger("geocode:mapdragged", this.map.getCenter());
513
+ },
514
+
515
+ // Fire the "geocode:idle" event and pass the current position of the map center.
516
+ mapIdle: function(event) {
517
+ this.trigger("geocode:idle", this.map.getCenter());
518
+ },
519
+
454
520
  mapZoomed: function(event) {
455
521
  this.trigger("geocode:zoom", this.map.getZoom());
456
522
  },
457
523
 
458
- // Restore the old position of the marker to the last now location.
524
+ // Restore the old position of the marker to the last knwon location.
459
525
  resetMarker: function(){
460
526
  this.marker.setPosition(this.data.location);
461
527
  this.setDetail(this.details.lat, this.data.location.lat());
@@ -1,3 +1,3 @@
1
1
  module GeocompleteRails
2
- VERSION = "1.6.4"
2
+ VERSION = "1.6.5"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: geocomplete_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.4
4
+ version: 1.6.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Guy Israeli
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-01-19 00:00:00.000000000 Z
12
+ date: 2015-07-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -89,7 +89,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
89
89
  version: '0'
90
90
  requirements: []
91
91
  rubyforge_project:
92
- rubygems_version: 2.4.5
92
+ rubygems_version: 2.4.6
93
93
  signing_key:
94
94
  specification_version: 4
95
95
  summary: jQuery Geocoding and Places Autocomplete Plugin