From c2e29c98bab114905b5fe76f257b7d7ce47ebfde Mon Sep 17 00:00:00 2001
From: Ben Keen
Date: Mon, 24 Mar 2014 20:08:39 -0700
Subject: [PATCH] Finished up script + doc
---
README.md | 16 +++++++++
example.html | 31 +++++++++++-----
gruntfile.js | 12 ++++++-
source/country-region-selector.js | 59 ++++++++++++++++++-------------
4 files changed, 85 insertions(+), 33 deletions(-)
diff --git a/README.md b/README.md
index c670591..5fe2a8c 100644
--- a/README.md
+++ b/README.md
@@ -54,6 +54,22 @@ If your form is used for people returning to it (e.g. "Edit Contact Info" or wha
region fields to be prefilled with the appropriate value on page load. To do that, just add a `data-default=""` attribute
to each element containing the country / region value last saved.
+### List of data-* attributes
+
+This lists all the available data-* attributes that you can add to the country/region fields to customize the appearance
+and behaviour.
+
+##### country fields
+
+- `data-region-id` - required. This should contain the ID of the region field that it's being mapped to.
+- `data-default-option` - optional. Default: "Select country". This determines the default, blank option display value.
+
+##### region fields
+- `data-blank-option` - before the user selects a country, there's a single
-
+
+
Example 2
-
- Custom default option texts for both the country and region dropdowns.
+
+ Custom default option texts for both the country and region dropdowns.
-
-
+
+
-
+
-
+
+
Example 3
+
+
+ The country dropdown values are by default the same as the display values: the full country names.
+ By adding the data-value="2-char" attribute to the country field, the values will be a 2-char
+ character code.
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/gruntfile.js b/gruntfile.js
index ec986a2..379c6d2 100644
--- a/gruntfile.js
+++ b/gruntfile.js
@@ -6,7 +6,17 @@ module.exports = function(grunt) {
grunt.loadNpmTasks('grunt-contrib-uglify');
var config = {
-
+ uglify: {
+ standalone: {
+ files: {
+ 'source/country-region-selector.min.js': 'source/country-region-selector.js'
+ },
+ options: {
+ report: "min",
+ compress: true
+ }
+ }
+ }
};
grunt.initConfig(config);
diff --git a/source/country-region-selector.js b/source/country-region-selector.js
index 212ef6c..36506a0 100644
--- a/source/country-region-selector.js
+++ b/source/country-region-selector.js
@@ -2,7 +2,9 @@
"use strict";
var _countryClass = "crs-country";
- var _regionClass = "crs-region";
+ var _defaultCountryStr = "Select country";
+ var _defaultRegionStr = "Select region";
+
var _data = [
{ c: "Afghanistan", cs: "AF", cl: "Badakhshan|Badghis|Baghlan|Balkh|Bamian|Farah|Faryab|Ghazni|Ghowr|Helmand|Herat|Jowzjan|Kabol|Kandahar|Kapisa|Konar|Kondoz|Laghman|Lowgar|Nangarhar|Nimruz|Oruzgan|Paktia|Paktika|Parvan|Samangan|Sar-e Pol|Takhar|Vardak|Zabol" },
@@ -247,8 +249,7 @@
var _init = function() {
- var countryDropdowns = document.getElementsByClassName("crs-country");
-
+ var countryDropdowns = document.getElementsByClassName(_countryClass);
for (var i=0; i