gmaps-autocomplete-rails 0.1.2.1 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (32) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +265 -50
  3. data/gmaps-autocomplete-rails.gemspec +7 -32
  4. data/vendor/assets/javascripts/gmaps-auto-complete.js +297 -0
  5. metadata +20 -63
  6. data/.document +0 -5
  7. data/.rspec +0 -1
  8. data/CHANGELOG +0 -6
  9. data/Gemfile.lock +0 -109
  10. data/Rakefile +0 -49
  11. data/VERSION +0 -1
  12. data/spec/index.html +0 -64
  13. data/spec/init.js +0 -4
  14. data/spec/jquery-ui/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
  15. data/spec/jquery-ui/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
  16. data/spec/jquery-ui/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
  17. data/spec/jquery-ui/images/ui-bg_glass_75_dadada_1x400.png +0 -0
  18. data/spec/jquery-ui/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
  19. data/spec/jquery-ui/images/ui-bg_glass_75_ffffff_1x400.png +0 -0
  20. data/spec/jquery-ui/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
  21. data/spec/jquery-ui/images/ui-bg_inset-soft_95_fef1ec_1x100.png +0 -0
  22. data/spec/jquery-ui/images/ui-icons_222222_256x240.png +0 -0
  23. data/spec/jquery-ui/images/ui-icons_2e83ff_256x240.png +0 -0
  24. data/spec/jquery-ui/images/ui-icons_454545_256x240.png +0 -0
  25. data/spec/jquery-ui/images/ui-icons_888888_256x240.png +0 -0
  26. data/spec/jquery-ui/images/ui-icons_cd0a0a_256x240.png +0 -0
  27. data/spec/jquery-ui/images/ui-icons_f6cf3b_256x240.png +0 -0
  28. data/spec/jquery-ui/jquery-ui-1.8.16.custom.css +0 -1320
  29. data/spec/jquery-ui/jquery.ui.1.8.16.ie.css +0 -6
  30. data/spec/main.css +0 -89
  31. data/spec/spec_helper.rb +0 -12
  32. data/vendor/assets/javascripts/gmaps-autocomplete.js +0 -300
@@ -0,0 +1,297 @@
1
+ var GmapsCompleter, GmapsCompleterDefaultAssist,
2
+ __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
3
+
4
+ GmapsCompleter = (function() {
5
+ GmapsCompleter.prototype.geocoder = null;
6
+
7
+ GmapsCompleter.prototype.map = null;
8
+
9
+ GmapsCompleter.prototype.marker = null;
10
+
11
+ GmapsCompleter.prototype.inputField = null;
12
+
13
+ GmapsCompleter.prototype.errorField = null;
14
+
15
+ GmapsCompleter.prototype.positionOutputter = null;
16
+
17
+ GmapsCompleter.prototype.updateUI = null;
18
+
19
+ GmapsCompleter.prototype.updateMap = null;
20
+
21
+ GmapsCompleter.prototype.region = null;
22
+
23
+ GmapsCompleter.prototype.country = null;
24
+
25
+ GmapsCompleter.prototype.debugOn = false;
26
+
27
+ GmapsCompleter.prototype.mapElem = null;
28
+
29
+ GmapsCompleter.prototype.zoomLevel = 2;
30
+
31
+ GmapsCompleter.prototype.mapType = null;
32
+
33
+ GmapsCompleter.prototype.pos = [0, 0];
34
+
35
+ GmapsCompleter.prototype.inputField = '#gmaps-input-address';
36
+
37
+ GmapsCompleter.prototype.errorField = '#gmaps-error';
38
+
39
+ function GmapsCompleter(opts) {
40
+ this.keyDownHandler = __bind(this.keyDownHandler, this);
41
+ this.performGeocode = __bind(this.performGeocode, this);
42
+ this.init(opts);
43
+ }
44
+
45
+ GmapsCompleter.prototype.init = function(opts) {
46
+ var callOpts, completerAssistClass, error, lat, latlng, lng, mapElem, mapOptions, mapType, pos, self, zoomLevel;
47
+ opts = opts || {};
48
+ callOpts = $.extend(true, {}, opts);
49
+ this.debugOn = opts['debugOn'];
50
+ this.debug('init(opts)', opts);
51
+ completerAssistClass = opts['assist'];
52
+ try {
53
+ this.assist = new completerAssistClass;
54
+ } catch (_error) {
55
+ error = _error;
56
+ this.debug('assist error', error, opts['assist']);
57
+ }
58
+ this.assist || (this.assist = new GmapsCompleterDefaultAssist);
59
+ this.defaultOptions = opts['defaultOptions'] || this.assist.options;
60
+ opts = $.extend(true, {}, this.defaultOptions, opts);
61
+ this.positionOutputter = opts['positionOutputter'] || this.assist.positionOutputter;
62
+ this.updateUI = opts['updateUI'] || this.assist.updateUI;
63
+ this.updateMap = opts['updateMap'] || this.assist.updateMap;
64
+ this.geocodeErrorMsg = opts['geocodeErrorMsg'] || this.assist.geocodeErrorMsg;
65
+ this.geocodeErrorMsg = opts['geocodeErrorMsg'] || this.assist.geocodeErrorMsg;
66
+ this.noAddressFoundMsg = opts['noAddressFoundMsg'] || this.assist.noAddressFoundMsg;
67
+ pos = opts['pos'];
68
+ lat = pos[0];
69
+ lng = pos[1];
70
+ mapType = opts['mapType'];
71
+ mapElem = null;
72
+ this.mapElem = $("gmaps-canvas");
73
+ if (opts['mapElem']) {
74
+ this.mapElem = $(opts['mapElem']).get(0);
75
+ }
76
+ this.mapType = google.maps.MapTypeId.ROADMAP;
77
+ zoomLevel = opts['zoomLevel'];
78
+ this.inputField = opts['inputField'];
79
+ this.errorField = opts['#gmaps-error'];
80
+ this.debugOn = opts['debugOn'];
81
+ this.debug('called with opts', callOpts);
82
+ this.debug('final completerAssist', this.completerAssist);
83
+ this.debug('defaultOptions', this.defaultOptions);
84
+ this.debug('options after merge with defaults', opts);
85
+ latlng = new google.maps.LatLng(lat, lng);
86
+ this.debug('lat,lng', latlng);
87
+ mapOptions = {
88
+ zoom: zoomLevel,
89
+ center: latlng,
90
+ mapTypeId: mapType
91
+ };
92
+ this.debug('map options', mapOptions);
93
+ this.geocoder = new google.maps.Geocoder();
94
+ self = this;
95
+ if (typeof this.mapElem === 'undefined') {
96
+ this.showError("Map element " + opts['mapElem'] + " could not be resolved!");
97
+ }
98
+ this.debug('mapElem', this.mapElem);
99
+ if (!this.mapElem) {
100
+ return;
101
+ }
102
+ this.map = new google.maps.Map(this.mapElem, mapOptions);
103
+ if (!this.map) {
104
+ return;
105
+ }
106
+ this.marker = new google.maps.Marker({
107
+ map: this.map,
108
+ draggable: true
109
+ });
110
+ return self.addMapListeners(this.marker, this.map);
111
+ };
112
+
113
+ GmapsCompleter.prototype.debug = function(label, obj) {
114
+ if (!this.debugOn) {
115
+ return;
116
+ }
117
+ return console.log(label, obj);
118
+ };
119
+
120
+ GmapsCompleter.prototype.addMapListeners = function(marker, map) {
121
+ var self;
122
+ self = this;
123
+ google.maps.event.addListener(marker, 'dragend', function() {
124
+ return self.geocodeLookup('latLng', marker.getPosition());
125
+ });
126
+ return google.maps.event.addListener(map, 'click', function(event) {
127
+ marker.setPosition(event.latLng);
128
+ return self.geocodeLookup('latLng', event.latLng);
129
+ });
130
+ };
131
+
132
+ GmapsCompleter.prototype.geocodeLookup = function(type, value, update) {
133
+ var request;
134
+ this.update || (this.update = false);
135
+ request = {};
136
+ request[type] = value;
137
+ return this.geocoder.geocode(request, this.performGeocode);
138
+ };
139
+
140
+ GmapsCompleter.prototype.performGeocode = function(results, status) {
141
+ this.debug('performGeocode', status);
142
+ $(this.errorField).html('');
143
+ if (status === google.maps.GeocoderStatus.OK) {
144
+ return this.geocodeSuccess(results);
145
+ } else {
146
+ return this.geocodeFailure(type, value);
147
+ }
148
+ };
149
+
150
+ GmapsCompleter.prototype.geocodeSuccess = function(results) {
151
+ this.debug('geocodeSuccess', results);
152
+ if (results[0]) {
153
+ this.updateUI(results[0].formatted_address, results[0].geometry.location);
154
+ if (this.update) {
155
+ return this.updateMap(results[0].geometry);
156
+ }
157
+ } else {
158
+ return this.showError(this.geocodeErrorMsg());
159
+ }
160
+ };
161
+
162
+ GmapsCompleter.prototype.geocodeFailure = function(type, value) {
163
+ this.debug('geocodeFailure', type);
164
+ if (type === 'address') {
165
+ return this.showError(this.invalidAddressMsg(value));
166
+ } else {
167
+ this.showError(this.noAddressFoundMsg());
168
+ return this.updateUI('', value);
169
+ }
170
+ };
171
+
172
+ GmapsCompleter.prototype.showError = function(msg) {
173
+ $(this.errorField).html(msg);
174
+ $(this.errorField).show();
175
+ return setTimeout(function() {
176
+ return $(this.errorField).hide();
177
+ }, 1000);
178
+ };
179
+
180
+ GmapsCompleter.prototype.autoCompleteInit = function(opts) {
181
+ var autocompleteOpts, defaultAutocompleteOpts, self;
182
+ opts = opts || {};
183
+ this.region = opts['region'] || this.defaultOptions['region'];
184
+ this.country = opts['country'] || this.defaultOptions['country'];
185
+ this.debug('region', this.region);
186
+ self = this;
187
+ autocompleteOpts = opts['autocomplete'] || {};
188
+ defaultAutocompleteOpts = {
189
+ select: function(event, ui) {
190
+ self.updateUI(ui.item.value, ui.item.geocode.geometry.location);
191
+ return self.updateMap(ui.item.geocode.geometry);
192
+ },
193
+ source: function(request, response) {
194
+ var address, geocodeOpts, region, region_postfix;
195
+ region_postfix = '';
196
+ region = self.region;
197
+ if (region) {
198
+ region_postfix = ', ' + region;
199
+ }
200
+ address = request.term + region_postfix;
201
+ self.debug('geocode address', address);
202
+ geocodeOpts = {
203
+ 'address': address
204
+ };
205
+ return self.geocoder.geocode(geocodeOpts, function(results, status) {
206
+ return response($.map(results, function(item) {
207
+ var uiAddress;
208
+ uiAddress = item.formatted_address.replace(", " + self.country, '');
209
+ return {
210
+ label: uiAddress,
211
+ value: uiAddress,
212
+ geocode: item
213
+ };
214
+ }));
215
+ });
216
+ }
217
+ };
218
+ autocompleteOpts = $.extend(true, defaultAutocompleteOpts, autocompleteOpts);
219
+ $(this.inputField).autocomplete(autocompleteOpts);
220
+ return $(this.inputField).bind('keydown', this.keyDownHandler);
221
+ };
222
+
223
+ GmapsCompleter.prototype.keyDownHandler = function(event) {
224
+ if (event.keyCode === 13) {
225
+ this.geocodeLookup('address', $(this.inputField).val(), true);
226
+ return $(this.inputField).autocomplete("disable");
227
+ } else {
228
+ return $(this.inputField).autocomplete("enable");
229
+ }
230
+ };
231
+
232
+ return GmapsCompleter;
233
+
234
+ })();
235
+
236
+ GmapsCompleterDefaultAssist = (function() {
237
+ function GmapsCompleterDefaultAssist() {}
238
+
239
+ GmapsCompleterDefaultAssist.prototype.options = {
240
+ mapElem: '#gmaps-canvas',
241
+ zoomLevel: 2,
242
+ mapType: google.maps.MapTypeId.ROADMAP,
243
+ pos: [0, 0],
244
+ inputField: '#gmaps-input-address',
245
+ errorField: '#gmaps-error',
246
+ debugOn: true
247
+ };
248
+
249
+ GmapsCompleterDefaultAssist.prototype.updateMap = function(geometry) {
250
+ var map, marker;
251
+ map = this.map;
252
+ marker = this.marker;
253
+ if (map) {
254
+ map.fitBounds(geometry.viewport);
255
+ }
256
+ if (marker) {
257
+ return marker.setPosition(geometry.location);
258
+ }
259
+ };
260
+
261
+ GmapsCompleterDefaultAssist.prototype.updateUI = function(address, latLng) {
262
+ var country, inputField, updateAdr;
263
+ inputField = this.inputField;
264
+ country = this.country;
265
+ $(inputField).autocomplete('close');
266
+ this.debug('country', country);
267
+ updateAdr = address.replace(', ' + country, '');
268
+ updateAdr = address;
269
+ this.debug('updateAdr', updateAdr);
270
+ $(inputField).val(updateAdr);
271
+ return this.positionOutputter(latLng);
272
+ };
273
+
274
+ GmapsCompleterDefaultAssist.prototype.positionOutputter = function(latLng) {
275
+ $('#gmaps-output-latitude').html(latLng.lat());
276
+ return $('#gmaps-output-longitude').html(latLng.lng());
277
+ };
278
+
279
+ GmapsCompleterDefaultAssist.prototype.geocodeErrorMsg = function() {
280
+ return "Sorry, something went wrong. Try again!";
281
+ };
282
+
283
+ GmapsCompleterDefaultAssist.prototype.invalidAddressMsg = function(value) {
284
+ return "Sorry! We couldn't find " + value + ". Try a different search term, or click the map.";
285
+ };
286
+
287
+ GmapsCompleterDefaultAssist.prototype.noAddressFoundMsg = function() {
288
+ return "Woah... that's pretty remote! You're going to have to manually enter a place name.";
289
+ };
290
+
291
+ return GmapsCompleterDefaultAssist;
292
+
293
+ })();
294
+
295
+ window.GmapsCompleter = GmapsCompleter;
296
+
297
+ window.GmapsCompleterDefaultAssist = GmapsCompleterDefaultAssist;
metadata CHANGED
@@ -1,110 +1,97 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gmaps-autocomplete-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2.1
5
- prerelease:
4
+ version: 0.1.4
6
5
  platform: ruby
7
6
  authors:
8
7
  - Kristian Mandrup
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-03-04 00:00:00.000000000 Z
11
+ date: 2014-08-23 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rails
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - ">="
20
18
  - !ruby/object:Gem::Version
21
19
  version: 3.1.0
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - ">="
28
25
  - !ruby/object:Gem::Version
29
26
  version: 3.1.0
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: rspec
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - ">="
36
32
  - !ruby/object:Gem::Version
37
33
  version: 2.9.0
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - ">="
44
39
  - !ruby/object:Gem::Version
45
40
  version: 2.9.0
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: rdoc
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ! '>='
45
+ - - ">="
52
46
  - !ruby/object:Gem::Version
53
47
  version: '3.12'
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ! '>='
52
+ - - ">="
60
53
  - !ruby/object:Gem::Version
61
54
  version: '3.12'
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: bundler
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
- - - ! '>='
59
+ - - ">="
68
60
  - !ruby/object:Gem::Version
69
61
  version: 1.1.0
70
62
  type: :development
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
- - - ! '>='
66
+ - - ">="
76
67
  - !ruby/object:Gem::Version
77
68
  version: 1.1.0
78
69
  - !ruby/object:Gem::Dependency
79
70
  name: jeweler
80
71
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
72
  requirements:
83
- - - ! '>='
73
+ - - ">="
84
74
  - !ruby/object:Gem::Version
85
75
  version: 1.8.4
86
76
  type: :development
87
77
  prerelease: false
88
78
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
79
  requirements:
91
- - - ! '>='
80
+ - - ">="
92
81
  - !ruby/object:Gem::Version
93
82
  version: 1.8.4
94
83
  - !ruby/object:Gem::Dependency
95
84
  name: simplecov
96
85
  requirement: !ruby/object:Gem::Requirement
97
- none: false
98
86
  requirements:
99
- - - ! '>='
87
+ - - ">="
100
88
  - !ruby/object:Gem::Version
101
89
  version: '0.5'
102
90
  type: :development
103
91
  prerelease: false
104
92
  version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
93
  requirements:
107
- - - ! '>='
94
+ - - ">="
108
95
  - !ruby/object:Gem::Version
109
96
  version: '0.5'
110
97
  description: Easily add autocomplete geo-functionality to your Rails app :)
@@ -115,66 +102,36 @@ extra_rdoc_files:
115
102
  - LICENSE.txt
116
103
  - README.md
117
104
  files:
118
- - .document
119
- - .rspec
120
- - CHANGELOG
121
105
  - Gemfile
122
- - Gemfile.lock
123
106
  - LICENSE.txt
124
107
  - README.md
125
- - Rakefile
126
- - VERSION
127
108
  - gmaps-autocomplete-rails.gemspec
128
109
  - lib/gmaps-autocomplete-rails.rb
129
110
  - lib/gmaps-autocomplete/view_helper.rb
130
- - spec/index.html
131
- - spec/init.js
132
- - spec/jquery-ui/images/ui-bg_flat_0_aaaaaa_40x100.png
133
- - spec/jquery-ui/images/ui-bg_glass_55_fbf9ee_1x400.png
134
- - spec/jquery-ui/images/ui-bg_glass_65_ffffff_1x400.png
135
- - spec/jquery-ui/images/ui-bg_glass_75_dadada_1x400.png
136
- - spec/jquery-ui/images/ui-bg_glass_75_e6e6e6_1x400.png
137
- - spec/jquery-ui/images/ui-bg_glass_75_ffffff_1x400.png
138
- - spec/jquery-ui/images/ui-bg_highlight-soft_75_cccccc_1x100.png
139
- - spec/jquery-ui/images/ui-bg_inset-soft_95_fef1ec_1x100.png
140
- - spec/jquery-ui/images/ui-icons_222222_256x240.png
141
- - spec/jquery-ui/images/ui-icons_2e83ff_256x240.png
142
- - spec/jquery-ui/images/ui-icons_454545_256x240.png
143
- - spec/jquery-ui/images/ui-icons_888888_256x240.png
144
- - spec/jquery-ui/images/ui-icons_cd0a0a_256x240.png
145
- - spec/jquery-ui/images/ui-icons_f6cf3b_256x240.png
146
- - spec/jquery-ui/jquery-ui-1.8.16.custom.css
147
- - spec/jquery-ui/jquery.ui.1.8.16.ie.css
148
- - spec/main.css
149
- - spec/spec_helper.rb
150
- - vendor/assets/javascripts/gmaps-autocomplete.js
111
+ - vendor/assets/javascripts/gmaps-auto-complete.js
151
112
  homepage: http://github.com/kristianmandrup/gmaps-autocomplete-rails
152
113
  licenses:
153
114
  - MIT
115
+ metadata: {}
154
116
  post_install_message:
155
117
  rdoc_options: []
156
118
  require_paths:
157
119
  - lib
158
120
  required_ruby_version: !ruby/object:Gem::Requirement
159
- none: false
160
121
  requirements:
161
- - - ! '>='
122
+ - - ">="
162
123
  - !ruby/object:Gem::Version
163
124
  version: '0'
164
- segments:
165
- - 0
166
- hash: 3294242176316535928
167
125
  required_rubygems_version: !ruby/object:Gem::Requirement
168
- none: false
169
126
  requirements:
170
- - - ! '>='
127
+ - - ">="
171
128
  - !ruby/object:Gem::Version
172
129
  version: '0'
173
130
  requirements: []
174
131
  rubyforge_project:
175
- rubygems_version: 1.8.25
132
+ rubygems_version: 2.2.2
176
133
  signing_key:
177
- specification_version: 3
134
+ specification_version: 4
178
135
  summary: Google Maps v3 search with jQuery UI Autocomplete, ready for use with Rails
179
136
  asset pipeline
180
137
  test_files: []