geo_contrast 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +0 -0
- data/README.md +31 -0
- data/lib/geo_contrast/version.rb +3 -0
- data/lib/geo_contrast.rb +6 -0
- data/vendor/assets/javascripts/geo_contrast.js +280 -0
- metadata +91 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 381617d86fb5ddf5ceb5dfee09cf062ff804d4f1
|
4
|
+
data.tar.gz: 41e8f1994fefb73b5e536d69c49445a549ecac49
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 20f03db9381dbd6a2c35626af2514c41a51c2a6db36bf3708c56196ee7e9fe9dd8111c4713602157c29ba493763dff8a7c52212ed00be2e816097293e7e6cc61
|
7
|
+
data.tar.gz: c70f8ca7ad3fb52c90969f02fed2cd7dc976351d76c1757bed6a950405c9b52b4a5f1a7424b961dd1bed7e6a07733d13bb8c81e2e3549c10cf29b7935e6e6ae3
|
data/MIT-LICENSE
ADDED
File without changes
|
data/README.md
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# GeoContrast
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'geo_contrast'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install geo_contrast
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
TODO: Write usage instructions here
|
24
|
+
|
25
|
+
## Contributing
|
26
|
+
|
27
|
+
1. Fork it ( https://github.com/[my-github-username]/geo_contrast/fork )
|
28
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
29
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
30
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
31
|
+
5. Create a new Pull Request
|
data/lib/geo_contrast.rb
ADDED
@@ -0,0 +1,280 @@
|
|
1
|
+
/*
|
2
|
+
geoContrast v1.0
|
3
|
+
|
4
|
+
https://github.com/lucasfogliarini/geoContrast
|
5
|
+
*/
|
6
|
+
$(function(){
|
7
|
+
window.geoContrast = {
|
8
|
+
options_default: {
|
9
|
+
options_gmaps: {//api: http://goo.gl/x3h6o3
|
10
|
+
//types: ['geocode','(regions)','(cities)', 'establishment']
|
11
|
+
},
|
12
|
+
format: 'short',//formatted
|
13
|
+
gmaps_through_pin: true,
|
14
|
+
assign_through_tab: true,
|
15
|
+
assigned:{
|
16
|
+
input_title: '',
|
17
|
+
pin_title: 'Click to open on Google Maps.',
|
18
|
+
pin_img: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABmJLR0QA/wD/AP+gvaeTAAABBUlEQVQ4jZXTTyuEURQG8F9T/mzGNCjh4yghG8N3MDtZKd+ApfJ12GomZIVEKDakZMHGvBZz3rwz7jt46nTuuc95ntu573v5iWE00cZLRAvrGEr092AWJ8hK4hgzZeJRnEXjHRqYjFjBVXCnGEkZbBbE9QRfx330bKQM2kE2ol7GDa6xFHtr0XOUMngLshp1flqG29irRf2aiyoFg07kLMFV+rhOPwGXkeciN/GIh1jDfOSL1AjbccK59CWO+x5rK2UwjQ+9n7GKMawWxO+YShnAvvKfKI+9MjFM4HmA+ClGGYhF3VvuF39i4Tdxjt2Ewc5fxXRf5GFBfBB7/0JN9xm3Yp3EF8CeW3oneDAyAAAAAElFTkSuQmCC'
|
19
|
+
},
|
20
|
+
unassigned:{
|
21
|
+
input_title: '',
|
22
|
+
pin_title: 'Location not assigned.',
|
23
|
+
pin_img: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABmJLR0QA/wD/AP+gvaeTAAACE0lEQVQ4jY2QQWsTURSFv5dMm2xCQFwILoqhIIolJDMpxKAU3WqxQqDoyh8gIhUXVsSNUKobK/QP1J2ICxXqwpWU0sKbgWI2GhzqQqgUoUToi9N5181MmaZFvKv7zj3nvHuuYqBGR0cL5XL5NnATGEngTeClMeZFp9P5k+Wr7KNarZ50HOetiHwDnkdR9BnAcZyxfD5/R0RGrLWTQRD8OGQwMTFR7PV6a8CS1vpZug1At9vtA3ied19Epnd2dpoptm/ged5dEbmktb7aarVKxphZYDsZHy8Wi09WVlZ6ruu+Bz5orRcAnEyCG9baGQBjzL3h4eH51dXVXwDNZvNYv9+fAR4rpZ6KyBywAJBL1SJyJo5jnfQ2FQNk+0KhoIGz6XvfAJBSqZQDUEpl8fQDBbC3t3fg8FniV2NM6rxVq9Wa6aDRaJwHtgCsteeAL+kse4NlYApY01ov1uv1W57nXQGI47jr+/5issk1EVlORfvrjI+Pn4rj2I+i6PTGxsbPwQgAruuWga611guCYPNAhPX19RB4NTQ09OAocVKPROR1Kh68AdbaWeB6kvlA1ev1C0BbKfUwi6tBYq1Wu5jL5ZYAV2u9DdBoNE5Ya7WITPu+/+mfBknWOWCsUqlMAoRh+E5EAq31oXhHGrTb7XwYhm+A70Bkra34vj8F2P8yAGi1WqXd3d2PSikxxlzudDq/j+L9BaBN8gpKSjbcAAAAAElFTkSuQmCC'
|
24
|
+
}
|
25
|
+
}
|
26
|
+
}
|
27
|
+
$.fn.geoContrast = function(options){
|
28
|
+
var $inputs = this;
|
29
|
+
for (var i = 0; i < $inputs.length; i++){
|
30
|
+
var current = $inputs[i];
|
31
|
+
var $current = $(current);
|
32
|
+
//props
|
33
|
+
current.index = i;
|
34
|
+
current.options = $.extend(true,'¬¬',window.geoContrast.options_default,options);
|
35
|
+
current.autocomplete_gmaps = new google.maps.places.Autocomplete(current, current.options.options_gmaps);
|
36
|
+
current.geocoder = new google.maps.Geocoder();
|
37
|
+
current.autocomplete_gmaps.geocontrast = current;//accessibility
|
38
|
+
current.$pin = $('<span class="pin_geocontrast"/>');
|
39
|
+
current.$bounds = $('<input class="bounds_geocontrast" type="hidden" />');
|
40
|
+
current.$lat = $('<input class="lat_geocontrast" type="hidden" />');
|
41
|
+
current.$lng = $('<input class="lng_geocontrast" type="hidden" />');
|
42
|
+
current.$formatted = $('<input class="formatted_geocontrast" type="hidden" />');
|
43
|
+
//endprops
|
44
|
+
|
45
|
+
//methods
|
46
|
+
current.toggle = function(state){
|
47
|
+
var input_title, pin, pin_title;
|
48
|
+
|
49
|
+
if (state){
|
50
|
+
pin_img = this.options.assigned.pin_img;
|
51
|
+
pin_title = this.options.assigned.pin_title;
|
52
|
+
input_title = this.options.assigned.input_title;
|
53
|
+
if(input_title){
|
54
|
+
this.title = input_title;
|
55
|
+
}
|
56
|
+
}
|
57
|
+
else{
|
58
|
+
this.place_info = undefined;
|
59
|
+
this.sync_coords();
|
60
|
+
this.sync_bounds();
|
61
|
+
this.$formatted.val("");
|
62
|
+
pin_img = this.options.unassigned.pin_img;
|
63
|
+
pin_title = this.options.unassigned.pin_title;
|
64
|
+
input_title = this.options.unassigned.input_title;
|
65
|
+
}
|
66
|
+
this.$pin.css('background','no-repeat url('+pin_img+')');
|
67
|
+
this.$pin.attr('title',pin_title);
|
68
|
+
this.title = input_title;
|
69
|
+
}
|
70
|
+
|
71
|
+
current.assigned = function(){
|
72
|
+
return this.place_info !== undefined && this.place_info.formatted_address !== undefined;
|
73
|
+
}
|
74
|
+
|
75
|
+
current.bounds_assigned = function(){
|
76
|
+
return this.assigned() && this.place_info.geometry.bounds !== undefined;
|
77
|
+
}
|
78
|
+
|
79
|
+
current.sync_coords = function(){
|
80
|
+
try{
|
81
|
+
var lat;
|
82
|
+
var lng;
|
83
|
+
if(this.assigned()) {
|
84
|
+
lat = this.place_info.geometry.location.lat();
|
85
|
+
lng = this.place_info.geometry.location.lng();
|
86
|
+
}
|
87
|
+
this.$lat.val(lat);
|
88
|
+
this.$lng.val(lng);
|
89
|
+
} catch(ex){
|
90
|
+
throw ex;
|
91
|
+
}
|
92
|
+
}
|
93
|
+
|
94
|
+
current.sync_bounds = function(){
|
95
|
+
try{
|
96
|
+
if (this.$bounds !== undefined){
|
97
|
+
var bounds;
|
98
|
+
if (this.bounds_assigned()){
|
99
|
+
bounds = this.place_info.geometry.bounds.toUrlValue();
|
100
|
+
}else if(this.assigned()){
|
101
|
+
bounds = "0,0,0,0";
|
102
|
+
}
|
103
|
+
this.$bounds.val(bounds);
|
104
|
+
}
|
105
|
+
} catch(ex){
|
106
|
+
throw ex;
|
107
|
+
}
|
108
|
+
}
|
109
|
+
|
110
|
+
current.sync = function(){
|
111
|
+
var assigned = this.assigned();
|
112
|
+
if(assigned){
|
113
|
+
this.place_info.formatted_address = geoContrast.format_address(this.place_info.address_components);
|
114
|
+
switch(this.options.format){
|
115
|
+
case 'short':
|
116
|
+
this.value = this.place_info.name;
|
117
|
+
this.$formatted[0].value = this.place_info.formatted_address;
|
118
|
+
break;
|
119
|
+
case 'formatted':
|
120
|
+
this.value = this.place_info.formatted_address;
|
121
|
+
break;
|
122
|
+
}
|
123
|
+
this.sync_coords();
|
124
|
+
this.sync_bounds();
|
125
|
+
}
|
126
|
+
this.toggle(assigned);
|
127
|
+
}
|
128
|
+
|
129
|
+
current.find_address = function(address, call){
|
130
|
+
if(address !== ""){
|
131
|
+
var geocontrast = this;
|
132
|
+
this.geocoder.geocode({"address": address }, function(results) {
|
133
|
+
if (results.length > 0) {
|
134
|
+
geocontrast.place_info = results[0];
|
135
|
+
var addresses = geocontrast.place_info.address_components.filter(function(each){
|
136
|
+
return each.types[0] != "street_number";
|
137
|
+
});
|
138
|
+
geocontrast.place_info.name = addresses[0].long_name;
|
139
|
+
if (call !== undefined) {
|
140
|
+
call.call(geocontrast);
|
141
|
+
};
|
142
|
+
}
|
143
|
+
});
|
144
|
+
}
|
145
|
+
}
|
146
|
+
|
147
|
+
current.append_bounds = function(bounds_name){
|
148
|
+
bounds_name = bounds_name ? bounds_name : "bounds";
|
149
|
+
this.$bounds.prop('name',bounds_name);
|
150
|
+
$(this).before(this.$bounds);
|
151
|
+
}
|
152
|
+
|
153
|
+
current.append_coords = function(lat_name,lng_name){
|
154
|
+
lat_name = lat_name ? lat_name : "latitude";
|
155
|
+
lng_name = lng_name ? lng_name : "longitude";
|
156
|
+
lat_name = geoContrast.remake_name(this,function(args){
|
157
|
+
args.attribute = lat_name;
|
158
|
+
});
|
159
|
+
|
160
|
+
lng_name = geoContrast.remake_name(this,function(args){
|
161
|
+
args.attribute = lng_name;
|
162
|
+
});
|
163
|
+
|
164
|
+
this.$lat.prop('name',lat_name);
|
165
|
+
this.$lng.prop('name',lng_name);
|
166
|
+
|
167
|
+
$(this).before(this.$lng);
|
168
|
+
$(this).before(this.$lat);
|
169
|
+
}
|
170
|
+
|
171
|
+
current.first_hint = function(){
|
172
|
+
var eq = this.index;
|
173
|
+
return $('.pac-container:eq('+eq+') > :first').text();
|
174
|
+
}
|
175
|
+
//endmethods
|
176
|
+
|
177
|
+
//init
|
178
|
+
$current = $(current);
|
179
|
+
$current.addClass('geocontrast');
|
180
|
+
$current.css('padding-right','20px');
|
181
|
+
$current.after(current.$pin);
|
182
|
+
|
183
|
+
current.$pin.css({
|
184
|
+
position:'absolute',
|
185
|
+
left: current.offsetLeft + current.offsetWidth - 18,
|
186
|
+
top: current.offsetTop + ((current.offsetHeight - 16) / 2),
|
187
|
+
height: '16px',
|
188
|
+
width: '16px',
|
189
|
+
cursor: 'pointer'
|
190
|
+
});
|
191
|
+
|
192
|
+
if (current.options.format == "short") {
|
193
|
+
$current.before(current.$formatted);
|
194
|
+
var name = geoContrast.remake_name(current,function(args){
|
195
|
+
args.attribute += "_formatted";
|
196
|
+
});
|
197
|
+
current.$formatted.attr("name", name);
|
198
|
+
};
|
199
|
+
|
200
|
+
google.maps.event.addListener(current.autocomplete_gmaps, 'place_changed', function(){
|
201
|
+
this.geocontrast.place_info = this.getPlace();
|
202
|
+
this.geocontrast.place_info.geometry.bounds = this.geocontrast.place_info.geometry.viewport;//:/
|
203
|
+
this.geocontrast.sync();
|
204
|
+
});
|
205
|
+
|
206
|
+
$(document).on('input','.geocontrast',function(){
|
207
|
+
if(this.assigned()){
|
208
|
+
this.toggle(false);
|
209
|
+
}
|
210
|
+
});
|
211
|
+
|
212
|
+
$(document).on('keydown','.geocontrast',function(e){
|
213
|
+
switch(e.keyCode){
|
214
|
+
case 9:
|
215
|
+
if (this.options.assign_through_tab){
|
216
|
+
this.find_address(this.first_hint(), function(){
|
217
|
+
this.sync();
|
218
|
+
});
|
219
|
+
}
|
220
|
+
break;
|
221
|
+
case 13:
|
222
|
+
e.preventDefault();
|
223
|
+
break;
|
224
|
+
}
|
225
|
+
});
|
226
|
+
|
227
|
+
$(document).on('click','.pin_geocontrast',function(){
|
228
|
+
var input = $(this).prev()[0];
|
229
|
+
if (input.assigned() && input.options.gmaps_through_pin){
|
230
|
+
window.open('https://www.google.com.br/maps/place/'+input.place_info.formatted_address);
|
231
|
+
}
|
232
|
+
});
|
233
|
+
current.toggle(false);
|
234
|
+
current.find_address($current.data('find-address'),function(){
|
235
|
+
this.sync();
|
236
|
+
});
|
237
|
+
//endinit
|
238
|
+
}
|
239
|
+
return $inputs;
|
240
|
+
}
|
241
|
+
|
242
|
+
window.geoContrast.remake_name = function(input, delegate){
|
243
|
+
var args = {
|
244
|
+
attribute: input.name
|
245
|
+
}, attr_bracket
|
246
|
+
var first_bracket = input.name.indexOf('[');
|
247
|
+
if (first_bracket > 0){
|
248
|
+
attr_bracket = input.name.slice(first_bracket);
|
249
|
+
args.attribute = input.name.slice(first_bracket+1,-1);
|
250
|
+
}
|
251
|
+
delegate(args);
|
252
|
+
return first_bracket > 0 ? input.name.replace(attr_bracket,"["+args.attribute+"]") : args.attribute;
|
253
|
+
}
|
254
|
+
|
255
|
+
window.geoContrast.format_address = function(address_components){
|
256
|
+
var route, street_number, neighborhood, locality, area_lvl_1, country;
|
257
|
+
for (var i = 0; i < address_components.length; i++) {
|
258
|
+
route = address_components[i].types[0] == "route" ? address_components[i] : route;
|
259
|
+
street_number = address_components[i].types[0] == "street_number" ? address_components[i] : street_number;
|
260
|
+
neighborhood = address_components[i].types[0] == "neighborhood" ? address_components[i] : neighborhood;
|
261
|
+
locality = address_components[i].types[0] == "locality" ? address_components[i] : locality;
|
262
|
+
area_lvl_1 = address_components[i].types[0] == "administrative_area_level_1" ? address_components[i] : area_lvl_1;
|
263
|
+
country = address_components[i].types[0] == "country" ? address_components[i] : country;
|
264
|
+
};
|
265
|
+
var route_street_number, neighborhood_locality, area_lvl_1_country, format;
|
266
|
+
|
267
|
+
route_street_number = route ? route.long_name : "";
|
268
|
+
route_street_number += street_number ? ", " + street_number.long_name : "";
|
269
|
+
|
270
|
+
neighborhood_locality = neighborhood ? neighborhood.long_name + ', ' : "";
|
271
|
+
neighborhood_locality += locality ? locality.long_name : "";
|
272
|
+
|
273
|
+
area_lvl_1_country = neighborhood_locality ? area_lvl_1.short_name + ", " : area_lvl_1 ? area_lvl_1.long_name + ", " : "";
|
274
|
+
area_lvl_1_country += country ? country.long_name : "";
|
275
|
+
format = route_street_number ? route_street_number + ' - ' : '';
|
276
|
+
format += neighborhood_locality ? neighborhood_locality + ' - ' : '';
|
277
|
+
format += area_lvl_1_country ? area_lvl_1_country : '';
|
278
|
+
return format;
|
279
|
+
}
|
280
|
+
});
|
metadata
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: geo_contrast
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- CODELAND
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-12-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: jquery-rails
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: This description sucks and should be fixed
|
56
|
+
email:
|
57
|
+
- contato@codeland.com.br
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- MIT-LICENSE
|
63
|
+
- README.md
|
64
|
+
- lib/geo_contrast.rb
|
65
|
+
- lib/geo_contrast/version.rb
|
66
|
+
- vendor/assets/javascripts/geo_contrast.js
|
67
|
+
homepage: https://github.com/codelandev/geocontrast
|
68
|
+
licenses:
|
69
|
+
- MIT
|
70
|
+
metadata: {}
|
71
|
+
post_install_message:
|
72
|
+
rdoc_options: []
|
73
|
+
require_paths:
|
74
|
+
- lib
|
75
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '0'
|
80
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
requirements: []
|
86
|
+
rubyforge_project:
|
87
|
+
rubygems_version: 2.2.2
|
88
|
+
signing_key:
|
89
|
+
specification_version: 4
|
90
|
+
summary: This summary sucks and should be fixed
|
91
|
+
test_files: []
|