jquery-addresspicker-rails 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2013 YOURNAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,3 @@
1
+ = JQueryAddressPickerRails
2
+
3
+ This project rocks and uses MIT-LICENSE.
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
@@ -0,0 +1,5 @@
1
+ module JQueryAddressPickerRails
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace JQueryAddressPickerRails
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ module JQueryAddressPickerRails
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,4 @@
1
+ require "jquery-addresspicker-rails/engine"
2
+
3
+ module JQueryAddressPickerRails
4
+ end
@@ -0,0 +1,239 @@
1
+ /*
2
+ * jQuery UI addresspicker @VERSION
3
+ *
4
+ * Copyright 2010, AUTHORS.txt (http://jqueryui.com/about)
5
+ * Dual licensed under the MIT or GPL Version 2 licenses.
6
+ * http://jquery.org/license
7
+ *
8
+ * http://docs.jquery.com/UI/Progressbar
9
+ *
10
+ * Depends:
11
+ * jquery.ui.core.js
12
+ * jquery.ui.widget.js
13
+ * jquery.ui.autocomplete.js
14
+ */
15
+ (function( $, undefined ) {
16
+
17
+ $.widget( "ui.addresspicker", {
18
+ options: {
19
+ appendAddressString: "",
20
+ draggableMarker: true,
21
+ regionBias: null,
22
+ updateCallback: null,
23
+ reverseGeocode: false,
24
+ mapOptions: {
25
+ zoom: 5,
26
+ center: new google.maps.LatLng(46, 2),
27
+ scrollwheel: false,
28
+ mapTypeId: google.maps.MapTypeId.ROADMAP
29
+ },
30
+ elements: {
31
+ map: false,
32
+ lat: false,
33
+ lng: false,
34
+ street_number: false,
35
+ route: false,
36
+ locality: false,
37
+ sublocality: false,
38
+ administrative_area_level_2: false,
39
+ administrative_area_level_1: false,
40
+ country: false,
41
+ postal_code: false,
42
+ type: false
43
+
44
+ }
45
+ },
46
+
47
+ marker: function() {
48
+ return this.gmarker;
49
+ },
50
+
51
+ map: function() {
52
+ return this.gmap;
53
+ },
54
+
55
+ updatePosition: function() {
56
+ this._updatePosition(this.gmarker.getPosition());
57
+ },
58
+
59
+ reloadPosition: function() {
60
+ this.gmarker.setVisible(true);
61
+ this.gmarker.setPosition(new google.maps.LatLng(this.lat.val(), this.lng.val()));
62
+ this.gmap.setCenter(this.gmarker.getPosition());
63
+ },
64
+
65
+ selected: function() {
66
+ return this.selectedResult;
67
+ },
68
+
69
+ _create: function() {
70
+ this.geocoder = new google.maps.Geocoder();
71
+ this.element.autocomplete({
72
+ source: $.proxy(this._geocode, this),
73
+ focus: $.proxy(this._focusAddress, this),
74
+ select: $.proxy(this._selectAddress, this)
75
+ });
76
+
77
+ this.lat = $(this.options.elements.lat);
78
+ this.lng = $(this.options.elements.lng);
79
+ this.street_number = $(this.options.elements.street_number);
80
+ this.route = $(this.options.elements.route);
81
+ this.locality = $(this.options.elements.locality);
82
+ this.sublocality = $(this.options.elements.sublocality);
83
+ this.administrative_area_level_2 = $(this.options.elements.administrative_area_level_2);
84
+ this.administrative_area_level_1 = $(this.options.elements.administrative_area_level_1);
85
+ this.country = $(this.options.elements.country);
86
+ this.postal_code = $(this.options.elements.postal_code);
87
+ this.type = $(this.options.elements.type);
88
+ if (this.options.elements.map) {
89
+ this.mapElement = $(this.options.elements.map);
90
+ this._initMap();
91
+ }
92
+ },
93
+
94
+ _initMap: function() {
95
+ if (this.lat && this.lat.val()) {
96
+ this.options.mapOptions.center = new google.maps.LatLng(this.lat.val(), this.lng.val());
97
+ }
98
+
99
+ this.gmap = new google.maps.Map(this.mapElement[0], this.options.mapOptions);
100
+ this.gmarker = new google.maps.Marker({
101
+ position: this.options.mapOptions.center,
102
+ map:this.gmap,
103
+ draggable: this.options.draggableMarker});
104
+ google.maps.event.addListener(this.gmarker, 'dragend', $.proxy(this._markerMoved, this));
105
+ this.gmarker.setVisible(false);
106
+ },
107
+
108
+ _updatePosition: function(location) {
109
+ if (this.lat) {
110
+ this.lat.val(location.lat());
111
+ }
112
+ if (this.lng) {
113
+ this.lng.val(location.lng());
114
+ }
115
+ },
116
+
117
+ _addressParts: {street_number: null, route: null, locality: null, sublocality: null,
118
+ administrative_area_level_2: null, administrative_area_level_1: null,
119
+ country: null, postal_code:null, type: null},
120
+
121
+ _updateAddressParts: function(geocodeResult){
122
+
123
+ parsedResult = this._parseGeocodeResult(geocodeResult);
124
+
125
+ for (addressPart in this._addressParts){
126
+ if (this[addressPart]){
127
+ this[addressPart].val(parsedResult[addressPart]);
128
+ }
129
+ }
130
+ },
131
+
132
+ _updateAddressPartsViaReverseGeocode: function(location){
133
+ var latLng = new google.maps.LatLng(location.lat(), location.lng());
134
+
135
+ this.geocoder.geocode({'latLng': latLng}, $.proxy(function(results, status){
136
+ if (status == google.maps.GeocoderStatus.OK)
137
+
138
+ this._updateAddressParts(results[0]);
139
+ this.element.val(results[0].formatted_address);
140
+ this.selectedResult = results[0];
141
+
142
+ if (this.options.updateCallback) {
143
+ this.options.updateCallback(this.selectedResult, this._parseGeocodeResult(this.selectedResult));
144
+ }
145
+ }, this));
146
+ },
147
+
148
+ _parseGeocodeResult: function(geocodeResult){
149
+
150
+ var parsed = {lat: geocodeResult.geometry.location.lat(),
151
+ lng: geocodeResult.geometry.location.lng()};
152
+
153
+ for (var addressPart in this._addressParts){
154
+ parsed[addressPart] = this._findInfo(geocodeResult, addressPart);
155
+ }
156
+
157
+ parsed.type = geocodeResult.types[0];
158
+
159
+ return parsed;
160
+ },
161
+
162
+ _markerMoved: function() {
163
+ this._updatePosition(this.gmarker.getPosition());
164
+
165
+ if (this.options.reverseGeocode){
166
+ this._updateAddressPartsViaReverseGeocode(this.gmarker.getPosition());
167
+ }
168
+ },
169
+
170
+ // Autocomplete source method: fill its suggests with google geocoder results
171
+ _geocode: function(request, response) {
172
+ var address = request.term, self = this;
173
+ this.geocoder.geocode({
174
+ 'address': address + this.options.appendAddressString,
175
+ 'region': this.options.regionBias
176
+ }, function(results, status) {
177
+ if (status == google.maps.GeocoderStatus.OK) {
178
+ for (var i = 0; i < results.length; i++) {
179
+ results[i].label = results[i].formatted_address;
180
+ };
181
+ }
182
+ response(results);
183
+ })
184
+ },
185
+
186
+ _findInfo: function(result, type) {
187
+ for (var i = 0; i < result.address_components.length; i++) {
188
+ var component = result.address_components[i];
189
+ if (component.types.indexOf(type) !=-1) {
190
+ return component.long_name;
191
+ }
192
+ }
193
+ return false;
194
+ },
195
+
196
+ _focusAddress: function(event, ui) {
197
+ var address = ui.item;
198
+ if (!address) {
199
+ return;
200
+ }
201
+
202
+ if (this.gmarker) {
203
+ this.gmarker.setPosition(address.geometry.location);
204
+ this.gmarker.setVisible(true);
205
+
206
+ this.gmap.fitBounds(address.geometry.viewport);
207
+ }
208
+
209
+ this._updatePosition(address.geometry.location);
210
+
211
+ this._updateAddressParts(address);
212
+
213
+ },
214
+
215
+ _selectAddress: function(event, ui) {
216
+ this.selectedResult = ui.item;
217
+ if (this.options.updateCallback) {
218
+ this.options.updateCallback(this.selectedResult, this._parseGeocodeResult(this.selectedResult));
219
+ }
220
+ }
221
+ });
222
+
223
+ $.extend( $.ui.addresspicker, {
224
+ version: "@VERSION"
225
+ });
226
+
227
+ // make IE think it doesn't suck
228
+ if(!Array.indexOf){
229
+ Array.prototype.indexOf = function(obj){
230
+ for(var i=0; i<this.length; i++){
231
+ if(this[i]==obj){
232
+ return i;
233
+ }
234
+ }
235
+ return -1;
236
+ }
237
+ }
238
+
239
+ })( jQuery );
metadata ADDED
@@ -0,0 +1,84 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jquery-addresspicker-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Fábio Luiz Nery de Miranda
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-06-03 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rails
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 3.2.13
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 3.2.13
30
+ - !ruby/object:Gem::Dependency
31
+ name: jquery-rails
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description: ''
47
+ email:
48
+ - fabio@miranti.net.br
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - lib/jquery-addresspicker-rails/engine.rb
54
+ - lib/jquery-addresspicker-rails/version.rb
55
+ - lib/jquery-addresspicker-rails.rb
56
+ - vendor/assets/javascripts/jquery.ui.addresspicker.js
57
+ - MIT-LICENSE
58
+ - Rakefile
59
+ - README.rdoc
60
+ homepage: https://github.com/fabiolnm/jquery-addresspicker-rails
61
+ licenses: []
62
+ post_install_message:
63
+ rdoc_options: []
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ! '>='
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ requirements: []
79
+ rubyforge_project:
80
+ rubygems_version: 1.8.23
81
+ signing_key:
82
+ specification_version: 3
83
+ summary: Assets for https://github.com/sgruhier/jquery-addresspicker
84
+ test_files: []