geo_select 0.0.2

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9acf55b7641fec1d01ce46e107be0586f266e7db
4
+ data.tar.gz: 75043f000b728dcf6e361ee1acc0fd0af7db6c6d
5
+ SHA512:
6
+ metadata.gz: d344a4a6e0d746a4ea1e2a0b4fcdb598e756ba8c6ac590b0fc81e6468a30af867dbc5007311f6fc75bb3e66dd865f197531c1ac474b0fcfca21c9a22951d34ea
7
+ data.tar.gz: dfa21706744d64ff63c4136743569e4ad485fbb9529c01c127317477c5018df670dad1dcebd8faf587c6616e96e6a5929cff1033bb16106c9f9c9620d81d1bef
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in geo_select.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Divyansh Kumar
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,51 @@
1
+ # GeoSelect
2
+
3
+ GeoSelect helps to auto-populate countries, states, regions and cities options to your select_tag form helper. It is based on http://geonames.org services.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'geo_select'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle install
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install geo_select
20
+
21
+ Must Add to application.js:
22
+
23
+ ```ruby
24
+ //= require geo_select
25
+ ```
26
+
27
+ ## Usage
28
+
29
+ ```ruby
30
+ <%= form_tag("/site/index") do %>
31
+ <%= label_tag 'name' %>
32
+ <%= select_tag(:country, nil, { class: 'geo-countries'}) %>
33
+
34
+ <%= label_tag 'name' %>
35
+ <%= select_tag(:state, nil, { class: 'geo-states' }) %>
36
+
37
+ <%= label_tag 'name' %>
38
+ <%= select_tag(:region, nil, { class: 'geo-regions' }) %>
39
+
40
+ <%= label_tag 'name' %>
41
+ <%= select_tag(:city, nil, { class: 'geo-cities' }) %>
42
+ <% end %>
43
+ ```
44
+
45
+ ## Contributing
46
+
47
+ 1. Fork it ( https://github.com/mrdivyansh/geo_select/fork )
48
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
49
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
50
+ 4. Push to the branch (`git push origin my-new-feature`)
51
+ 5. Create a new Pull Request
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,252 @@
1
+ window.geoSelect.unSort = [
2
+ ["Antarctica",6697173],
3
+ ["Bouvet Island",3371123],
4
+ ["French Southern Territories",1546748],
5
+ ["Heard Island and McDonald Islands",1547314],
6
+ ["South Georgia and South Sandwich Islands",3474415],
7
+ ["Algeria",2589581],
8
+ ["Angola",3351879],
9
+ ["Benin",2395170],
10
+ ["Botswana",933860],
11
+ ["Burkina Faso",2361809],
12
+ ["Burundi",433561],
13
+ ["Cameroon",2233387],
14
+ ["Cape Verde",3374766],
15
+ ["Central African Republic",239880],
16
+ ["Chad",2434508],
17
+ ["Comoros",921929],
18
+ ["Congo",2260494],
19
+ ["DR Congo",203312],
20
+ ["Djibouti",223816],
21
+ ["Egypt",357994],
22
+ ["Equatorial Guinea",2309096],
23
+ ["Eritrea",338010],
24
+ ["Ethiopia",337996],
25
+ ["Gabon",2400553],
26
+ ["Gambia",2413451],
27
+ ["Ghana",2300660],
28
+ ["Guinea",2420477],
29
+ ["Guinea-Bissau",2372248],
30
+ ["Ivory Coast",2287781],
31
+ ["Kenya",192950],
32
+ ["Lesotho",932692],
33
+ ["Liberia",2275384],
34
+ ["Libya",2215636],
35
+ ["Madagascar",1062947],
36
+ ["Malawi",927384],
37
+ ["Mali",2453866],
38
+ ["Mauritania",2378080],
39
+ ["Mauritius",934292],
40
+ ["Mayotte",1024031],
41
+ ["Morocco",2542007],
42
+ ["Mozambique",1036973],
43
+ ["Namibia",3355338],
44
+ ["Niger",2440476],
45
+ ["Nigeria",2328926],
46
+ ["Rwanda",49518],
47
+ ["Réunion",935317],
48
+ ["Saint Helena",3370751],
49
+ ["Senegal",2245662],
50
+ ["Seychelles",241170],
51
+ ["Sierra Leone",2403846],
52
+ ["Somalia",51537],
53
+ ["South Africa",953987],
54
+ ["South Sudan",7909807],
55
+ ["Sudan",366755],
56
+ ["Swaziland",934841],
57
+ ["São Tomé and Príncipe",2410758],
58
+ ["Tanzania",149590],
59
+ ["Togo",2363686],
60
+ ["Tunisia",2464461],
61
+ ["Uganda",226074],
62
+ ["Western Sahara",2461445],
63
+ ["Zambia",895949],
64
+ ["Zimbabwe",878675],
65
+ ["Argentina",3865483],
66
+ ["Bolivia",3923057],
67
+ ["Brazil",3469034],
68
+ ["Chile",3895114],
69
+ ["Colombia",3686110],
70
+ ["Ecuador",3658394],
71
+ ["Falkland Islands",3474414],
72
+ ["French Guiana",3381670],
73
+ ["Guyana",3378535],
74
+ ["Paraguay",3437598],
75
+ ["Peru",3932488],
76
+ ["Suriname",3382998],
77
+ ["Uruguay",3439705],
78
+ ["Venezuela",3625428],
79
+ ["Afghanistan",1149361],
80
+ ["Armenia",174982],
81
+ ["Azerbaijan",587116],
82
+ ["Bahrain",290291],
83
+ ["Bangladesh",1210997],
84
+ ["Bhutan",1252634],
85
+ ["British Indian Ocean Territory",1282588],
86
+ ["Brunei",1820814],
87
+ ["Cambodia",1831722],
88
+ ["China",1814991],
89
+ ["Christmas Island",2078138],
90
+ ["Cocos [Keeling] Islands",1547376],
91
+ ["Georgia",614540],
92
+ ["Hong Kong",1819730],
93
+ ["India",1269750],
94
+ ["Indonesia",1643084],
95
+ ["Iran",130758],
96
+ ["Iraq",99237],
97
+ ["Israel",294640],
98
+ ["Japan",1861060],
99
+ ["Jordan",248816],
100
+ ["Kazakhstan",1522867],
101
+ ["Kuwait",285570],
102
+ ["Kyrgyzstan",1527747],
103
+ ["Laos",1655842],
104
+ ["Lebanon",272103],
105
+ ["Macao",1821275],
106
+ ["Malaysia",1733045],
107
+ ["Maldives",1282028],
108
+ ["Mongolia",2029969],
109
+ ["Myanmar [Burma]",1327865],
110
+ ["Nepal",1282988],
111
+ ["North Korea",1873107],
112
+ ["Oman",286963],
113
+ ["Pakistan",1168579],
114
+ ["Palestine",6254930],
115
+ ["Philippines",1694008],
116
+ ["Qatar",289688],
117
+ ["Saudi Arabia",102358],
118
+ ["Singapore",1880251],
119
+ ["South Korea",1835841],
120
+ ["Sri Lanka",1227603],
121
+ ["Syria",163843],
122
+ ["Taiwan",1668284],
123
+ ["Tajikistan",1220409],
124
+ ["Thailand",1605651],
125
+ ["Turkey",298795],
126
+ ["Turkmenistan",1218197],
127
+ ["United Arab Emirates",290557],
128
+ ["Uzbekistan",1512440],
129
+ ["Vietnam",1562822],
130
+ ["Yemen",69543],
131
+ ["Anguilla",3573511],
132
+ ["Antigua and Barbuda",3576396],
133
+ ["Aruba",3577279],
134
+ ["Bahamas",3572887],
135
+ ["Barbados",3374084],
136
+ ["Belize",3582678],
137
+ ["Bermuda",3573345],
138
+ ["Bonaire, Sint Eustatius, and Saba",7626844],
139
+ ["British Virgin Islands",3577718],
140
+ ["Canada",6251999],
141
+ ["Cayman Islands",3580718],
142
+ ["Costa Rica",3624060],
143
+ ["Cuba",3562981],
144
+ ["Curaçao",7626836],
145
+ ["Dominica",3575830],
146
+ ["Dominican Republic",3508796],
147
+ ["El Salvador",3585968],
148
+ ["Greenland",3425505],
149
+ ["Grenada",3580239],
150
+ ["Guadeloupe",3579143],
151
+ ["Guatemala",3595528],
152
+ ["Haiti",3723988],
153
+ ["Honduras",3608932],
154
+ ["Jamaica",3489940],
155
+ ["Martinique",3570311],
156
+ ["Mexico",3996063],
157
+ ["Montserrat",3578097],
158
+ ["Nicaragua",3617476],
159
+ ["Panama",3703430],
160
+ ["Puerto Rico",4566966],
161
+ ["Saint Barthélemy",3578476],
162
+ ["Saint Kitts and Nevis",3575174],
163
+ ["Saint Lucia",3576468],
164
+ ["Saint Martin",3578421],
165
+ ["Saint Pierre and Miquelon",3424932],
166
+ ["Saint Vincent and the Grenadines",3577815],
167
+ ["Sint Maarten",7609695],
168
+ ["Trinidad and Tobago",3573591],
169
+ ["Turks and Caicos Islands",3576916],
170
+ ["U.S. Virgin Islands",4796775],
171
+ ["United States",6252001],
172
+ ["Albania",783754],
173
+ ["Andorra",3041565],
174
+ ["Austria",2782113],
175
+ ["Belarus",630336],
176
+ ["Belgium",2802361],
177
+ ["Bosnia and Herzegovina",3277605],
178
+ ["Bulgaria",732800],
179
+ ["Croatia",3202326],
180
+ ["Cyprus",146669],
181
+ ["Czech Republic",3077311],
182
+ ["Denmark",2623032],
183
+ ["Estonia",453733],
184
+ ["Faroe Islands",2622320],
185
+ ["Finland",660013],
186
+ ["France",3017382],
187
+ ["Germany",2921044],
188
+ ["Gibraltar",2411586],
189
+ ["Greece",390903],
190
+ ["Hungary",719819],
191
+ ["Iceland",2629691],
192
+ ["Ireland",2963597],
193
+ ["Italy",3175395],
194
+ ["Kosovo",831053],
195
+ ["Latvia",458258],
196
+ ["Liechtenstein",3042058],
197
+ ["Lithuania",597427],
198
+ ["Luxembourg",2960313],
199
+ ["Macedonia",718075],
200
+ ["Malta",2562770],
201
+ ["Moldova",617790],
202
+ ["Monaco",2993457],
203
+ ["Montenegro",3194884],
204
+ ["Netherlands",2750405],
205
+ ["Norway",3144096],
206
+ ["Poland",798544],
207
+ ["Portugal",2264397],
208
+ ["Romania",798549],
209
+ ["Russia",2017370],
210
+ ["San Marino",3168068],
211
+ ["Serbia",6290252],
212
+ ["Slovakia",3057568],
213
+ ["Slovenia",3190538],
214
+ ["Spain",2510769],
215
+ ["Svalbard and Jan Mayen",607072],
216
+ ["Sweden",2661886],
217
+ ["Switzerland",2658434],
218
+ ["Ukraine",690791],
219
+ ["United Kingdom",2635167],
220
+ ["Vatican City",3164670],
221
+ ["Åland",661882],
222
+ ["American Samoa",5880801],
223
+ ["Australia",2077456],
224
+ ["Cook Islands",1899402],
225
+ ["Coral Sea Islands Territory",2170371],
226
+ ["East Timor",1966436],
227
+ ["Fiji",2205218],
228
+ ["French Polynesia",4030656],
229
+ ["Guam",4043988],
230
+ ["Jervis Bay Territory",8335033],
231
+ ["Kiribati",4030945],
232
+ ["Marshall Islands",2080185],
233
+ ["Micronesia",2081918],
234
+ ["Nauru",2110425],
235
+ ["New Caledonia",2139685],
236
+ ["New Zealand",2186224],
237
+ ["Niue",4036232],
238
+ ["Norfolk Island",2155115],
239
+ ["Northern Mariana Islands",4041468],
240
+ ["Palau",1559582],
241
+ ["Papua New Guinea",2088628],
242
+ ["Pitcairn Islands",4030699],
243
+ ["Samoa",4034894],
244
+ ["Solomon Islands",2103350],
245
+ ["Territory of Ashmore and Cartier Islands",2077507],
246
+ ["Tokelau",4031074],
247
+ ["Tonga",4032283],
248
+ ["Tuvalu",2110297],
249
+ ["U.S. Minor Outlying Islands",5854968],
250
+ ["Vanuatu",2134431],
251
+ ["Wallis and Futuna",4034749]
252
+ ]
@@ -0,0 +1,14 @@
1
+ //= require 'utils'
2
+ //= require 'countriesUnSort'
3
+
4
+ $(function() {
5
+ $('.geo-countries').each(function() {
6
+ window.geoSelect.setCountryList(this);
7
+ });
8
+
9
+ $('.geo-countries, .geo-states, .geo-regions, .geo-cities').each(function() {
10
+ this.addEventListener("change", function(event) {
11
+ window.geoSelect.listChildren(event.target);
12
+ });
13
+ });
14
+ });
@@ -0,0 +1,68 @@
1
+
2
+
3
+ window.geoSelect = {
4
+ selectFieldOrder: ["geo-countries", "geo-states", "geo-regions", "geo-cities"],
5
+
6
+ wipeData: function (geonameObj) {
7
+ return [geonameObj["name"], geonameObj["geonameId"]];
8
+ },
9
+
10
+ childDisabler: function (element, callerValue) {
11
+ var disabled = element.options.length < 2;
12
+ var indexOfSelect = this.selectFieldOrder.indexOf(element.getAttribute('class'));
13
+ var disableFlag = false;
14
+ for (var i = indexOfSelect; i < this.selectFieldOrder.length; i++){
15
+ var element = $("." + this.selectFieldOrder[i]);
16
+ if(disabled){
17
+ element.html("<option value='"+callerValue+"'>"+callerValue+"</option>");
18
+ disableFlag = true;
19
+ }
20
+ else if(indexOfSelect != i)
21
+ element.html("<option value=''>Waiting for selection</option>");
22
+ element.attr("disabled", disabled);
23
+ }
24
+ },
25
+
26
+ addOptions: function (element, data, callerValue) {
27
+ element.options.length = 0;
28
+ var firstOptionHTML = (data.length > 0) ? (element.getAttribute('geo-default-option-HTML') || 'Select') : callerValue;
29
+ element.options[element.options.length] = new Option(firstOptionHTML, element.getAttribute('geo-default-option-value') || '');
30
+ for(var i = 0; i < data.length; i++){
31
+ element.options[element.options.length] = new Option(data[i][0], data[i][0])
32
+ element.options[element.options.length-1].setAttribute('geo-code', data[i][1]);
33
+ }
34
+ this.childDisabler(element, callerValue);
35
+ },
36
+
37
+ readCountries: function (element, variableName) {
38
+ var evalString = (variableName == "sort") ? "window.geoSelect.unSort.sort()" : "window.geoSelect.unSort";
39
+ this.addOptions(element, eval(evalString), "");
40
+ },
41
+
42
+ setCountryList: function (element) {
43
+ var variableName = (element.getAttribute('geo-sort') != undefined && element.getAttribute('geo-sort').toUpperCase() == 'CONTINENT') ? 'unSort' : 'sort';
44
+ this.readCountries(element, variableName);
45
+ },
46
+
47
+ listChildren: function (element) {
48
+ var elementsClass = null;
49
+ var selectedOption = element.options[element.selectedIndex];
50
+ var classValue = selectedOption.parentElement.getAttribute('class');
51
+ if (classValue == "geo-countries")
52
+ elementsClass = "geo-states";
53
+ else if (classValue == "geo-states")
54
+ elementsClass = "geo-regions";
55
+ else if(classValue == "geo-regions")
56
+ elementsClass = "geo-cities";
57
+ var startEvent = new CustomEvent('geoLoadingStart');
58
+ document.dispatchEvent(startEvent);
59
+ var endEvent = new CustomEvent('geoLoadingEnd');
60
+ $.getJSON("http://www.geonames.org/childrenJSON?geonameId=" + selectedOption.getAttribute('geo-code'), function(data){
61
+ var optionsData = data["geonames"] ? data["geonames"].map(window.geoSelect.wipeData).sort() : [];
62
+ $("." + elementsClass).each(function () {
63
+ window.geoSelect.addOptions(this, optionsData, element.value);
64
+ });
65
+ document.dispatchEvent(endEvent);
66
+ });
67
+ }
68
+ };
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'geo_select/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "geo_select"
8
+ spec.version = GeoSelect::VERSION
9
+ spec.authors = ["Divyansh Kumar"]
10
+ spec.email = ["mr.divyanshindore@gmail.com"]
11
+ spec.summary = %q{GeoSelect helps to auto-populate countries, states, regions and cities options to your select_tag form helper. It is based on http://geonames.org services.}
12
+ spec.homepage = "https://github.com/mrdivyansh/geo_select"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.7"
21
+ spec.add_development_dependency "rake", "~> 10.0"
22
+ spec.add_development_dependency "jquery-rails", "~> 3.0.0"
23
+ end
@@ -0,0 +1,6 @@
1
+ require "geo_select/version"
2
+ require "geo_select/engine"
3
+
4
+ module GeoSelect
5
+ # Your code goes here...
6
+ end
@@ -0,0 +1,4 @@
1
+ module GeoSelect
2
+ class Engine < Rails::Engine
3
+ end
4
+ end
@@ -0,0 +1,3 @@
1
+ module GeoSelect
2
+ VERSION = "0.0.2"
3
+ end
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: geo_select
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Divyansh Kumar
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-07-02 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: 3.0.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 3.0.0
55
+ description:
56
+ email:
57
+ - mr.divyanshindore@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - Gemfile
64
+ - LICENSE.txt
65
+ - README.md
66
+ - Rakefile
67
+ - app/assets/javascripts/countriesUnSort.js
68
+ - app/assets/javascripts/geo_select.js
69
+ - app/assets/javascripts/utils.js.erb
70
+ - geo_select.gemspec
71
+ - lib/geo_select.rb
72
+ - lib/geo_select/engine.rb
73
+ - lib/geo_select/version.rb
74
+ homepage: https://github.com/mrdivyansh/geo_select
75
+ licenses:
76
+ - MIT
77
+ metadata: {}
78
+ post_install_message:
79
+ rdoc_options: []
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ requirements: []
93
+ rubyforge_project:
94
+ rubygems_version: 2.4.5
95
+ signing_key:
96
+ specification_version: 4
97
+ summary: GeoSelect helps to auto-populate countries, states, regions and cities options
98
+ to your select_tag form helper. It is based on http://geonames.org services.
99
+ test_files: []