Skip to content

Commit

Permalink
0.3.2; closes #36
Browse files Browse the repository at this point in the history
  • Loading branch information
benkeen committed May 15, 2016
1 parent ee3491f commit 8e57132
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 24 deletions.
25 changes: 15 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
## Country-Region-Selector

A feature you often need in forms is a connected country and region dropdown, where once the user selects a country,
the region field gets updated to show the appropriate list of regions (provinces/states/counties etc). It's very easy
to code all this, but it's kind of pain having to track down all the raw country-region data.
A feature you often need in forms is a connected country and region dropdown, where the region field gets automatically
updated when the user selects a country. It's very easy to code this of course, but it's a pain having to track down
all the raw country-region data.

That's what this script does. It lets you add this feature to your form without having to write any code or spend
mind-numbing hours on Wikipedia downloading and formatting the data. I did that. It wasn't pretty.
This script does all the legwork for you. It lets you add this feature to your form without having to write any code or
spend mind-numbing hours on Wikipedia downloading and formatting the data. I did that. It wasn't pretty.

The script comes in two flavours, both about **60KB**.
The script comes in two flavours:
- [standalone script](https://github.com/benkeen/country-region-selector/tree/master/dist/crs.min.js) (no dependencies, just plain JS)
- a [jQuery-dependent version](https://github.com/benkeen/country-region-selector/tree/master/dist/jquery.crs.min.js) (ever-so slightly smaller)
- a [jQuery-dependent version](https://github.com/benkeen/country-region-selector/tree/master/dist/jquery.crs.min.js)
(slightly smaller)

The reason the files are so large is that they contain all the country and region strings. If you know you're only going
to need a small subset of all countries, you can generate a custom build containing only that info. That will
substantially reduce the file size. See the Custom Builds section at the bottom of this page for more info on that.
The reason the files are so large (60K or more) is that they contain all the country and region strings. If you know
you're only going to need a small subset of all countries, you may want to generate a custom build containing only that
info. That will substantially reduce the file size. See the Custom Builds section at the bottom of this page for more info.


### Features
Expand Down Expand Up @@ -144,6 +145,9 @@ Just add whatever countries you want to include. To find the exact country names

This will generate new files in the `/dist` folder that you can use.

If the country name you're targeting contains a comma, just escape with with a single backslash, like so:
`grunt customBuild --countries="Côte d'Ivoire\, Republic of, Congo\, Republic of the (Brazzaville)"`


### Notes for Developers

Expand All @@ -162,6 +166,7 @@ That will then re-generate the minified files in your ./dist folder.

### Changelog

- `0.3.2` - May 15, 2016. More country shortcodes added - thanks [Ellen Hutchings](http://github.com/ellenhutchings)! Bug fixes
- `0.3.1` - Apr 30, 2016. Loads of new country shortcodes added - thanks [Ellen Hutchings](http://github.com/ellenhutchings)!
- `0.3.0` - Apr 28, 2016. Turkey region fix; source data moved to separate repo: https://github.com/benkeen/country-region-data
- `0.2.4` - Feb 11, 2016. South Africa data updated. Custom build option added to let you generate smaller JS files
Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "country-region-selector",
"version": "0.3.1",
"version": "0.3.2",
"main": "dist/crs.min.js",
"license": "MIT",
"ignore": [
Expand Down
4 changes: 2 additions & 2 deletions dist/crs.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/crs.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/jquery.crs.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/jquery.crs.min.js

Large diffs are not rendered by default.

17 changes: 15 additions & 2 deletions gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ module.exports = function(grunt) {
grunt.fail.fatal("Country list not passed. Example usage: `grunt customBuild --countries=Canada,United States`");
}

var targetCountries = countries.split(",");
// countries may contain commas in their names. Bit ugly, but simple. This swiches out those escaped commas
// and replaces them later
var commaReplaced = countries.replace(/\\,/g, '{COMMA}');
var targetCountries = _.map(commaReplaced.split(","), function (country) {
return country.replace(/\{COMMA\}/, ',').trim();
});

var countryData = [];
var foundCountryNames = [];
Expand All @@ -40,9 +45,17 @@ module.exports = function(grunt) {
_.each(missing, function (countryName) {
grunt.log.error("--", countryName);
});

// all good! Let the user know what bundle is being created, just to remove any ambiguity
} else {
grunt.log.writeln("");
grunt.log.writeln("Creating bundle with following countries:");
_.each(targetCountries, function (country) {
grunt.log.writeln("* " + country);
});
}

config.template.customBuild.options.data.__DATA__ = "\nvar _data = " + JSON.stringify(countryData)
config.template.customBuild.options.data.__DATA__ = "\nvar _data = " + JSON.stringify(countryData);
}


Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "country-region-dropdowns",
"version": "0.3.1",
"name": "country-region-selector",
"version": "0.3.2",
"description": "A simple, configurable JS script that lets you add a country dropdown that automatically updates a corresponding region dropdown in your forms.",
"main": "dist/crs.min.js",
"scripts": {
Expand All @@ -22,7 +22,7 @@
"url": "https://github.com/benkeen/country-region-dropdowns/issues"
},
"devDependencies": {
"country-region-data": "1.1.1",
"country-region-data": "1.2.0",
"grunt": "~0.4.1",
"grunt-contrib-uglify": "~0.3.2",
"grunt-template": "~0.2.3",
Expand Down

0 comments on commit 8e57132

Please sign in to comment.