Skip to content

Commit

Permalink
0.4.0; closes #50
Browse files Browse the repository at this point in the history
  • Loading branch information
benkeen committed Jul 25, 2017
1 parent c67de03 commit 3d5cf43
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 34 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ That will then re-generate the minified files in your ./dist folder.

### Changelog

- `0.4.0` - Jul 25, 2017. Bug fix for blacklist/whitelisted fields in page with multiple other country-region-selectors
not listing the correct regions.
- `0.3.6` - Oct 31, 2016. Country data updated.
- `0.3.5` - July 4, 2016. Bug fix #40. Country data updated.
- `0.3.4` - July 4, 2016. Bug fix #37. Country data updated.
Expand Down
39 changes: 25 additions & 14 deletions dist/crs.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions dist/crs.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/jquery.crs.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/jquery.crs.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "country-region-selector",
"version": "0.3.6",
"description": "A simple, configurable JS script that lets you add a country dropdown that automatically updates a corresponding region dropdown in your forms.",
"version": "0.4.0",
"description": "A simple, configurable JS library that add a country dropdown that automatically updates a corresponding region dropdown in your forms.",
"main": "dist/crs.min.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
Expand Down
37 changes: 24 additions & 13 deletions source/source-crs.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
var _showEmptyCountryOption = true;
var _showEmptyRegionOption = true;
var _countries = [];
var _memoizedIndexes = {};

// included during grunt build step (run `grunt generate` on the command line)
//<%=__DATA__%>
Expand Down Expand Up @@ -137,24 +138,34 @@
// based on whitelist/blacklist, but that causes problems when there are multiple fields some with/without
// black/whitelists. Instead, this just memoizes the whitelist/blacklist for quick lookup
var _getCountrySubset = function (params) {

var i=0, countries = [];
if (params.whitelist) {
var whitelist = params.whitelist.split(",");
for (i=0; i<_data.length; i++) {
if (whitelist.indexOf(_data[i][1]) !== -1) {
countries.push(_data[i]);
var key = params.whitelist + "|" + params.blacklist;
var i=0;

if (!_memoizedIndexes.hasOwnProperty(key)) {
_memoizedIndexes[key] = [];
if (params.whitelist) {
var whitelist = params.whitelist.split(",");
for (i=0; i<_data.length; i++) {
if (whitelist.indexOf(_data[i][1]) !== -1) {
_memoizedIndexes[key].push(i);
}
}
}
} else if (params.blacklist) {
var blacklist = params.blacklist.split(",");
for (i=0; i<_data.length; i++) {
if (blacklist.indexOf(_data[i][1]) === -1) {
countries.push(_data[i]);
} else if (params.blacklist) {
var blacklist = params.blacklist.split(",");
for (i=0; i<_data.length; i++) {
if (blacklist.indexOf(_data[i][1]) === -1) {
_memoizedIndexes[key].push(i);
}
}
}
}

// now return the data in the memoized indexes
var countries = [];
for (i=0; i<_memoizedIndexes[key].length; i++) {
countries.push(_data[_memoizedIndexes[key][i]]);
}

return countries;
};

Expand Down

0 comments on commit 3d5cf43

Please sign in to comment.