diff --git a/.jshintrc b/.jshintrc
index 0a30119..7eb3a49 100644
--- a/.jshintrc
+++ b/.jshintrc
@@ -1,13 +1,13 @@
-{
- "boss": true,
- "curly": true,
- "eqeqeq": true,
- "eqnull": true,
- "expr": true,
- "immed": true,
- "noarg": true,
- "onevar": true,
- "quotmark": "double",
- "unused": true,
- "node": true
-}
\ No newline at end of file
+{
+ "boss": true,
+ "curly": true,
+ "eqeqeq": true,
+ "eqnull": true,
+ "expr": true,
+ "immed": true,
+ "noarg": true,
+ "onevar": true,
+ "quotmark": "double",
+ "unused": true,
+ "node": true
+}
diff --git a/Gruntfile.js b/Gruntfile.js
index 7e23067..2403940 100644
--- a/Gruntfile.js
+++ b/Gruntfile.js
@@ -1,67 +1,69 @@
-module.exports = function(grunt) {
-
- grunt.initConfig({
-
- // Import package manifest
- pkg: grunt.file.readJSON("flagstrap.jquery.json"),
-
- // Banner definitions
- meta: {
- banner: "/*\n" +
- " * <%= pkg.title || pkg.name %> - v<%= pkg.version %>\n" +
- " * <%= pkg.description %>\n" +
- " * <%= pkg.homepage %>\n" +
- " *\n" +
- " * Made by <%= pkg.author.name %>\n" +
- " * Under <%= pkg.licenses[0].type %> License\n" +
- " */\n"
- },
-
- // Concat definitions
- concat: {
- dist: {
- src: ["src/jquery.flagstrap.js"],
- dest: "dist/js/jquery.flagstrap.js"
- },
- options: {
- banner: "<%= meta.banner %>"
- }
- },
-
- // Lint definitions
- jshint: {
- files: ["src/jquery.boilerplate.js"],
- options: {
- jshintrc: ".jshintrc"
- }
- },
-
- // Minify definitions
- uglify: {
- my_target: {
- src: ["dist/js/jquery.flagstrap.js"],
- dest: "dist/js/jquery.flagstrap.min.js"
- },
- options: {
- banner: "<%= meta.banner %>"
- }
- },
-
- // watch for changes to source
- // Better than calling grunt a million times
- // (call 'grunt watch')
- watch: {
- files: ['src/*'],
- tasks: ['default']
- }
-
- });
-
- grunt.loadNpmTasks("grunt-contrib-concat");
- grunt.loadNpmTasks("grunt-contrib-jshint");
- grunt.loadNpmTasks("grunt-contrib-uglify");
- grunt.loadNpmTasks("grunt-contrib-watch");
-
- grunt.registerTask("default", ["jshint", "concat", "uglify"]);
-
-};
\ No newline at end of file
+module.exports = function(grunt) {
+
+ grunt.initConfig({
+
+ // Import package manifest
+ pkg: grunt.file.readJSON("flagstrap.jquery.json"),
+
+ // Banner definitions
+ meta: {
+ banner: "/*\n" +
+ " * <%= pkg.title || pkg.name %> - v<%= pkg.version %>\n" +
+ " * <%= pkg.description %>\n" +
+ " * <%= pkg.homepage %>\n" +
+ " *\n" +
+ " * Made by <%= pkg.author.name %>\n" +
+ " * Under <%= pkg.licenses[0].type %> License\n" +
+ " */\n"
+ },
+
+ // Concat definitions
+ concat: {
+ dist: {
+ src: ["src/jquery.flagstrap.js"],
+ dest: "dist/js/jquery.flagstrap.js"
+ },
+ options: {
+ banner: "<%= meta.banner %>"
+ }
+ },
+
+ // Lint definitions
+ jshint: {
+ files: ["src/jquery.flagstrap.js"],
+ path: "src/jquery.flagstrap.js",
+ options: {
+ jshintrc: ".jshintrc",
+ reporterOutput: ""
+ }
+ },
+
+ // Minify definitions
+ uglify: {
+ my_target: {
+ src: ["dist/js/jquery.flagstrap.js"],
+ dest: "dist/js/jquery.flagstrap.min.js"
+ },
+ options: {
+ banner: "<%= meta.banner %>"
+ }
+ },
+
+ // watch for changes to source
+ // Better than calling grunt a million times
+ // (call 'grunt watch')
+ watch: {
+ files: ['src/*'],
+ tasks: ['default']
+ }
+
+ });
+
+ grunt.loadNpmTasks("grunt-contrib-concat");
+ grunt.loadNpmTasks("grunt-contrib-jshint");
+ grunt.loadNpmTasks("grunt-contrib-uglify");
+ grunt.loadNpmTasks("grunt-contrib-watch");
+
+ grunt.registerTask("default", ["jshint", "concat", "uglify"]);
+
+};
diff --git a/README.md b/README.md
index 9db61d3..183428b 100644
--- a/README.md
+++ b/README.md
@@ -1,172 +1,188 @@
-# Flagstrap
-
-A lightwieght jQuery plugin for creating Bootstrap 3 compatible country select boxes with flags.
-
-
-
-###Demo
-http://blazeworx.github.io/flagstrap
-
-###Usage
-
-####Basic
-
-```html
-
-```
-
-```html
-
-```
-
-####Options
-
-#####Using Data Attributes
-This example will create a Flagstrap Dropdown giving the input field the name of `country` with all countries available and `Germany` pre selected and in a `scrollable` dropdown with `max-height` of `250px`.
-
-```html
-
-```
-
-```html
-
-```
-
-#####Using Instance Options
-This example will create a Flagstrap Dropdown giving the input field the name of `country` with only `Australia`, `USA` and `Canada` as available options and no pre selection.
-
-```html
-
-```
-
-```html
-
-```
-
-### Options
-
-
-
- Name
- Type
- Default
- Description
-
-
-
-
- inputName
- string
- uniquely generated
- the `name` attribute for the actual `select` input
-
-
- inputId
- string
- uniquely generated
- the `id` attribute for the actual `select` input
-
-
- buttonSize
- string
- "btn-md"
- The bootstrap button size `class` for this drop down
-
-
- buttonType
- string
- "btn-default"
- The bootstrap button type `class` for this drop down
-
-
- labelMargin
- string
- "20px"
- The `margin` between `flag` and `text label`
-
-
- scrollable
- boolean
- false
- Scrollable or full height drop down
-
-
- scrollableHeight
- string
- "250px"
- `max-height` for the scrollable drop down
-
-
- countries (optional)
- object
- (all)
- Only show specific countries Example: {"GB": "United Kingdom", "US": "United States"} will only show the USA and UK.
-
-
- onSelect (optional)
- function
- null
- This callback gets called each time the select is changed. It receives two parameters, the new value, and the select element.
-
-
- placeholder
- bool|object
- {value: "", text: "Please select a country"}
- Set the placeholder value and text. To disable the placeholder define as (boolean) false.
-
-
-
-
-### Contributors
-
-This project was created by Alex Carter. I owe many thanks to the following people who have helped make flagstrap even better.
-
-* [Matthew Machuga](https://github.com/machuga)
-* [TJ Miller](https://github.com/sixlive)
+# Flagstrap
+
+A lightwieght jQuery plugin for creating Bootstrap 3 compatible country select boxes with flags.
+
+
+
+###Demo
+http://blazeworx.github.io/flagstrap
+
+###Usage
+
+####Basic
+
+```html
+
+```
+
+```html
+
+```
+
+####Options
+
+#####Using Data Attributes
+This example will create a Flagstrap Dropdown giving the input field the name of `country` with all countries available and `Germany` pre selected and in a `scrollable` dropdown with `max-height` of `250px`.
+
+```html
+
+```
+
+```html
+
+```
+
+#####Using Instance Options
+This example will create a Flagstrap Dropdown giving the input field the name of `country` with only `Australia`, `USA` and `Canada` as available options and no pre selection.
+
+```html
+
+```
+
+```html
+
+```
+
+This example will create a Flagstrap Dropdown using an array of objects instead, giving the plugin users the possibility to specify the order of the countries. Arrays can be sorted but objects not.
+
+United states will be first in the list in this case.
+
+```html
+
+```
+
+### Options
+
+
+
+ Name
+ Type
+ Default
+ Description
+
+
+
+
+ inputName
+ string
+ uniquely generated
+ the `name` attribute for the actual `select` input
+
+
+ inputId
+ string
+ uniquely generated
+ the `id` attribute for the actual `select` input
+
+
+ buttonSize
+ string
+ "btn-md"
+ The bootstrap button size `class` for this drop down
+
+
+ buttonType
+ string
+ "btn-default"
+ The bootstrap button type `class` for this drop down
+
+
+ labelMargin
+ string
+ "20px"
+ The `margin` between `flag` and `text label`
+
+
+ scrollable
+ boolean
+ false
+ Scrollable or full height drop down
+
+
+ scrollableHeight
+ string
+ "250px"
+ `max-height` for the scrollable drop down
+
+
+ countries (optional)
+ object
+ (all)
+ Only show specific countries Example: {"GB": "United Kingdom", "US": "United States"} will only show the USA and UK.
+
+
+ onSelect (optional)
+ function
+ null
+ This callback gets called each time the select is changed. It receives two parameters, the new value, and the select element.
+
+
+ placeholder
+ bool|object
+ {value: "", text: "Please select a country"}
+ Set the placeholder value and text. To disable the placeholder define as (boolean) false.
+
+
+
+
+### Contributors
+
+This project was created by Alex Carter. I owe many thanks to the following people who have helped make flagstrap even better.
+
+* [Matthew Machuga](https://github.com/machuga)
+* [TJ Miller](https://github.com/sixlive)
diff --git a/dist/js/jquery.flagstrap.js b/dist/js/jquery.flagstrap.js
index bbe1e0b..33de3ed 100644
--- a/dist/js/jquery.flagstrap.js
+++ b/dist/js/jquery.flagstrap.js
@@ -1,458 +1,487 @@
-/*
- * FlagStrap - v1.0
- * A lightwieght jQuery plugin for creating Bootstrap 3 compatible country select boxes with flags.
- * http://www.blazeworx.com/flagstrap
- *
- * Made by Alex Carter
- * Under MIT License
- */
-(function ($) {
-
- var defaults = {
- buttonSize: "btn-md",
- buttonType: "btn-default",
- labelMargin: "10px",
- scrollable: true,
- scrollableHeight: "250px",
- placeholder: {
- value: '',
- text: 'Please select country'
- }
- };
-
- var countries = {
- "AF": "Afghanistan",
- "AL": "Albania",
- "DZ": "Algeria",
- "AS": "American Samoa",
- "AD": "Andorra",
- "AO": "Angola",
- "AI": "Anguilla",
- "AG": "Antigua and Barbuda",
- "AR": "Argentina",
- "AM": "Armenia",
- "AW": "Aruba",
- "AU": "Australia",
- "AT": "Austria",
- "AZ": "Azerbaijan",
- "BS": "Bahamas",
- "BH": "Bahrain",
- "BD": "Bangladesh",
- "BB": "Barbados",
- "BY": "Belarus",
- "BE": "Belgium",
- "BZ": "Belize",
- "BJ": "Benin",
- "BM": "Bermuda",
- "BT": "Bhutan",
- "BO": "Bolivia, Plurinational State of",
- "BA": "Bosnia and Herzegovina",
- "BW": "Botswana",
- "BV": "Bouvet Island",
- "BR": "Brazil",
- "IO": "British Indian Ocean Territory",
- "BN": "Brunei Darussalam",
- "BG": "Bulgaria",
- "BF": "Burkina Faso",
- "BI": "Burundi",
- "KH": "Cambodia",
- "CM": "Cameroon",
- "CA": "Canada",
- "CV": "Cape Verde",
- "KY": "Cayman Islands",
- "CF": "Central African Republic",
- "TD": "Chad",
- "CL": "Chile",
- "CN": "China",
- "CO": "Colombia",
- "KM": "Comoros",
- "CG": "Congo",
- "CD": "Congo, the Democratic Republic of the",
- "CK": "Cook Islands",
- "CR": "Costa Rica",
- "CI": "C" + "ô" + "te d'Ivoire",
- "HR": "Croatia",
- "CU": "Cuba",
- "CW": "Cura" + "ç" + "ao",
- "CY": "Cyprus",
- "CZ": "Czech Republic",
- "DK": "Denmark",
- "DJ": "Djibouti",
- "DM": "Dominica",
- "DO": "Dominican Republic",
- "EC": "Ecuador",
- "EG": "Egypt",
- "SV": "El Salvador",
- "GQ": "Equatorial Guinea",
- "ER": "Eritrea",
- "EE": "Estonia",
- "ET": "Ethiopia",
- "FK": "Falkland Islands (Malvinas)",
- "FO": "Faroe Islands",
- "FJ": "Fiji",
- "FI": "Finland",
- "FR": "France",
- "GF": "French Guiana",
- "PF": "French Polynesia",
- "TF": "French Southern Territories",
- "GA": "Gabon",
- "GM": "Gambia",
- "GE": "Georgia",
- "DE": "Germany",
- "GH": "Ghana",
- "GI": "Gibraltar",
- "GR": "Greece",
- "GL": "Greenland",
- "GD": "Grenada",
- "GP": "Guadeloupe",
- "GU": "Guam",
- "GT": "Guatemala",
- "GG": "Guernsey",
- "GN": "Guinea",
- "GW": "Guinea-Bissau",
- "GY": "Guyana",
- "HT": "Haiti",
- "HM": "Heard Island and McDonald Islands",
- "VA": "Holy See (Vatican City State)",
- "HN": "Honduras",
- "HK": "Hong Kong",
- "HU": "Hungary",
- "IS": "Iceland",
- "IN": "India",
- "ID": "Indonesia",
- "IR": "Iran, Islamic Republic of",
- "IQ": "Iraq",
- "IE": "Ireland",
- "IM": "Isle of Man",
- "IL": "Israel",
- "IT": "Italy",
- "JM": "Jamaica",
- "JP": "Japan",
- "JE": "Jersey",
- "JO": "Jordan",
- "KZ": "Kazakhstan",
- "KE": "Kenya",
- "KI": "Kiribati",
- "KP": "Korea, Democratic People's Republic of",
- "KR": "Korea, Republic of",
- "KW": "Kuwait",
- "KG": "Kyrgyzstan",
- "LA": "Lao People's Democratic Republic",
- "LV": "Latvia",
- "LB": "Lebanon",
- "LS": "Lesotho",
- "LR": "Liberia",
- "LY": "Libya",
- "LI": "Liechtenstein",
- "LT": "Lithuania",
- "LU": "Luxembourg",
- "MO": "Macao",
- "MK": "Macedonia, the former Yugoslav Republic of",
- "MG": "Madagascar",
- "MW": "Malawi",
- "MY": "Malaysia",
- "MV": "Maldives",
- "ML": "Mali",
- "MT": "Malta",
- "MH": "Marshall Islands",
- "MQ": "Martinique",
- "MR": "Mauritania",
- "MU": "Mauritius",
- "YT": "Mayotte",
- "MX": "Mexico",
- "FM": "Micronesia, Federated States of",
- "MD": "Moldova, Republic of",
- "MC": "Monaco",
- "MN": "Mongolia",
- "ME": "Montenegro",
- "MS": "Montserrat",
- "MA": "Morocco",
- "MZ": "Mozambique",
- "MM": "Myanmar",
- "NA": "Namibia",
- "NR": "Nauru",
- "NP": "Nepal",
- "NL": "Netherlands",
- "NC": "New Caledonia",
- "NZ": "New Zealand",
- "NI": "Nicaragua",
- "NE": "Niger",
- "NG": "Nigeria",
- "NU": "Niue",
- "NF": "Norfolk Island",
- "MP": "Northern Mariana Islands",
- "NO": "Norway",
- "OM": "Oman",
- "PK": "Pakistan",
- "PW": "Palau",
- "PS": "Palestinian Territory, Occupied",
- "PA": "Panama",
- "PG": "Papua New Guinea",
- "PY": "Paraguay",
- "PE": "Peru",
- "PH": "Philippines",
- "PN": "Pitcairn",
- "PL": "Poland",
- "PT": "Portugal",
- "PR": "Puerto Rico",
- "QA": "Qatar",
- "RE": "R" + "é" + "union",
- "RO": "Romania",
- "RU": "Russian Federation",
- "RW": "Rwanda",
- "SH": "Saint Helena, Ascension and Tristan da Cunha",
- "KN": "Saint Kitts and Nevis",
- "LC": "Saint Lucia",
- "MF": "Saint Martin (French part)",
- "PM": "Saint Pierre and Miquelon",
- "VC": "Saint Vincent and the Grenadines",
- "WS": "Samoa",
- "SM": "San Marino",
- "ST": "Sao Tome and Principe",
- "SA": "Saudi Arabia",
- "SN": "Senegal",
- "RS": "Serbia",
- "SC": "Seychelles",
- "SL": "Sierra Leone",
- "SG": "Singapore",
- "SX": "Sint Maarten (Dutch part)",
- "SK": "Slovakia",
- "SI": "Slovenia",
- "SB": "Solomon Islands",
- "SO": "Somalia",
- "ZA": "South Africa",
- "GS": "South Georgia and the South Sandwich Islands",
- "SS": "South Sudan",
- "ES": "Spain",
- "LK": "Sri Lanka",
- "SD": "Sudan",
- "SR": "Suriname",
- "SZ": "Swaziland",
- "SE": "Sweden",
- "CH": "Switzerland",
- "SY": "Syrian Arab Republic",
- "TW": "Taiwan, Province of China",
- "TJ": "Tajikistan",
- "TZ": "Tanzania, United Republic of",
- "TH": "Thailand",
- "TL": "Timor-Leste",
- "TG": "Togo",
- "TK": "Tokelau",
- "TO": "Tonga",
- "TT": "Trinidad and Tobago",
- "TN": "Tunisia",
- "TR": "Turkey",
- "TM": "Turkmenistan",
- "TC": "Turks and Caicos Islands",
- "TV": "Tuvalu",
- "UG": "Uganda",
- "UA": "Ukraine",
- "AE": "United Arab Emirates",
- "GB": "United Kingdom",
- "US": "United States",
- "UM": "United States Minor Outlying Islands",
- "UY": "Uruguay",
- "UZ": "Uzbekistan",
- "VU": "Vanuatu",
- "VE": "Venezuela, Bolivarian Republic of",
- "VN": "Viet Nam",
- "VG": "Virgin Islands, British",
- "VI": "Virgin Islands, U.S.",
- "WF": "Wallis and Futuna",
- "EH": "Western Sahara",
- "YE": "Yemen",
- "ZM": "Zambia",
- "ZW": "Zimbabwe"
- };
-
- $.flagStrap = function (element, options, i) {
-
- var plugin = this;
-
- var uniqueId = generateId(8);
-
- plugin.countries = {};
- plugin.selected = {value: null, text: null};
- plugin.settings = {inputName: 'country-' + uniqueId};
-
- var $container = $(element);
- var htmlSelectId = 'flagstrap-' + uniqueId;
- var htmlSelect = '#' + htmlSelectId;
-
- plugin.init = function () {
-
- // Merge in global settings then merge in individual settings via data attributes
- plugin.countries = countries;
-
- // Initialize Settings, priority: defaults, init options, data attributes
- plugin.countries = countries;
- plugin.settings = $.extend({}, defaults, options, $container.data());
-
- if (undefined !== plugin.settings.countries) {
- plugin.countries = plugin.settings.countries;
- }
-
- if (undefined !== plugin.settings.inputId) {
- htmlSelectId = plugin.settings.inputId;
- htmlSelect = '#' + htmlSelectId;
- }
-
- // Build HTML Select, Construct the drop down button, Assemble the drop down list items element and insert
- $container
- .addClass('flagstrap')
- .append(buildHtmlSelect)
- .append(buildDropDownButton)
- .append(buildDropDownButtonItemList);
-
- // Check to see if the onSelect callback method is assigned / callable, bind the change event for broadcast
- if (plugin.settings.onSelect !== undefined && plugin.settings.onSelect instanceof Function) {
- $(htmlSelect).change(function (event) {
- var element = this;
- options.onSelect($(element).val(), element);
- });
- }
-
- // Hide the actual HTML select
- $(htmlSelect).hide();
-
- };
-
- var buildHtmlSelect = function () {
- var htmlSelectElement = $(' ').attr('id', htmlSelectId).attr('name', plugin.settings.inputName);
-
- $.each(plugin.countries, function (code, country) {
- var optionAttributes = {value: code};
- if (plugin.settings.selectedCountry !== undefined) {
- if (plugin.settings.selectedCountry === code) {
- optionAttributes = {value: code, selected: "selected"};
- plugin.selected = {value: code, text: country}
- }
- }
- htmlSelectElement.append($('', optionAttributes).text(country));
- });
-
- if (plugin.settings.placeholder !== false) {
- htmlSelectElement.prepend($(' ', {
- value: plugin.settings.placeholder.value,
- text: plugin.settings.placeholder.text
- }));
- }
-
- return htmlSelectElement;
- };
-
- var buildDropDownButton = function () {
-
- var selectedText = $(htmlSelect).find('option').first().text();
- var selectedValue = $(htmlSelect).find('option').first().val();
-
- selectedText = plugin.selected.text || selectedText;
- selectedValue = plugin.selected.value || selectedValue;
-
- if (selectedValue !== plugin.settings.placeholder.value) {
- var $selectedLabel = $(' ').addClass('flagstrap-icon flagstrap-' + selectedValue.toLowerCase()).css('margin-right', plugin.settings.labelMargin);
- } else {
- var $selectedLabel = $(' ').addClass('flagstrap-icon flagstrap-placeholder');
- }
-
- var buttonLabel = $(' ')
- .addClass('flagstrap-selected-' + uniqueId)
- .html($selectedLabel)
- .append(selectedText);
-
- var button = $(' ')
- .attr('type', 'button')
- .attr('data-toggle', 'dropdown')
- .attr('id', 'flagstrap-drop-down-' + uniqueId)
- .addClass('btn ' + plugin.settings.buttonType + ' ' + plugin.settings.buttonSize + ' dropdown-toggle')
- .html(buttonLabel);
-
- $(' ')
- .addClass('caret')
- .css('margin-left', plugin.settings.labelMargin)
- .insertAfter(buttonLabel);
-
- return button;
-
- };
-
- var buildDropDownButtonItemList = function () {
- var items = $('')
- .attr('id', 'flagstrap-drop-down-' + uniqueId + '-list')
- .attr('aria-labelled-by', 'flagstrap-drop-down-' + uniqueId)
- .addClass('dropdown-menu');
-
- if (plugin.settings.scrollable) {
- items.css('height', 'auto')
- .css('max-height', plugin.settings.scrollableHeight)
- .css('overflow-x', 'hidden');
- }
-
- // Populate the bootstrap dropdown item list
- $(htmlSelect).find('option').each(function () {
-
- // Get original select option values and labels
- var text = $(this).text();
- var value = $(this).val();
-
- // Build the flag icon
- if (value !== plugin.settings.placeholder.value) {
- var flagIcon = $(' ').addClass('flagstrap-icon flagstrap-' + value.toLowerCase()).css('margin-right', plugin.settings.labelMargin);
- } else {
- var flagIcon = null;
- }
-
-
- // Build a clickable drop down option item, insert the flag and label, attach click event
- var flagStrapItem = $(' ')
- .attr('data-val', $(this).val())
- .html(flagIcon)
- .append(text)
- .on('click', function (e) {
- $(htmlSelect).find('option').removeAttr('selected');
- $(htmlSelect).find('option[value="' + $(this).data('val') + '"]').attr("selected", "selected");
- $(htmlSelect).trigger('change');
- $('.flagstrap-selected-' + uniqueId).html($(this).html());
- e.preventDefault();
- });
-
- // Make it a list item
- var listItem = $(' ').prepend(flagStrapItem);
-
- // Append it to the drop down item list
- items.append(listItem);
-
- });
-
- return items;
- };
-
- function generateId(length) {
- var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz'.split('');
-
- if (!length) {
- length = Math.floor(Math.random() * chars.length);
- }
-
- var str = '';
- for (var i = 0; i < length; i++) {
- str += chars[Math.floor(Math.random() * chars.length)];
- }
- return str;
- }
-
- plugin.init();
-
- };
-
- $.fn.flagStrap = function (options) {
-
- return this.each(function (i) {
- if ($(this).data('flagStrap') === undefined) {
- $(this).data('flagStrap', new $.flagStrap(this, options, i));
- }
- });
-
- }
-
-})(jQuery);
+/*
+ * FlagStrap - v1.0
+ * A lightwieght jQuery plugin for creating Bootstrap 3 compatible country select boxes with flags.
+ * http://www.blazeworx.com/flagstrap
+ *
+ * Made by Alex Carter
+ * Under MIT License
+ */
+(function ($) {
+
+ var defaults = {
+ buttonSize: "btn-md",
+ buttonType: "btn-default",
+ labelMargin: "10px",
+ scrollable: true,
+ scrollableHeight: "250px",
+ placeholder: {
+ value: "",
+ text: "Please select country"
+ }
+ };
+
+ var countries = {
+ "AF": "Afghanistan",
+ "AL": "Albania",
+ "DZ": "Algeria",
+ "AS": "American Samoa",
+ "AD": "Andorra",
+ "AO": "Angola",
+ "AI": "Anguilla",
+ "AG": "Antigua and Barbuda",
+ "AR": "Argentina",
+ "AM": "Armenia",
+ "AW": "Aruba",
+ "AU": "Australia",
+ "AT": "Austria",
+ "AZ": "Azerbaijan",
+ "BS": "Bahamas",
+ "BH": "Bahrain",
+ "BD": "Bangladesh",
+ "BB": "Barbados",
+ "BY": "Belarus",
+ "BE": "Belgium",
+ "BZ": "Belize",
+ "BJ": "Benin",
+ "BM": "Bermuda",
+ "BT": "Bhutan",
+ "BO": "Bolivia, Plurinational State of",
+ "BA": "Bosnia and Herzegovina",
+ "BW": "Botswana",
+ "BV": "Bouvet Island",
+ "BR": "Brazil",
+ "IO": "British Indian Ocean Territory",
+ "BN": "Brunei Darussalam",
+ "BG": "Bulgaria",
+ "BF": "Burkina Faso",
+ "BI": "Burundi",
+ "KH": "Cambodia",
+ "CM": "Cameroon",
+ "CA": "Canada",
+ "CV": "Cape Verde",
+ "KY": "Cayman Islands",
+ "CF": "Central African Republic",
+ "TD": "Chad",
+ "CL": "Chile",
+ "CN": "China",
+ "CO": "Colombia",
+ "KM": "Comoros",
+ "CG": "Congo",
+ "CD": "Congo, the Democratic Republic of the",
+ "CK": "Cook Islands",
+ "CR": "Costa Rica",
+ "CI": "C" + "ô" + "te d\"Ivoire",
+ "HR": "Croatia",
+ "CU": "Cuba",
+ "CW": "Cura" + "ç" + "ao",
+ "CY": "Cyprus",
+ "CZ": "Czech Republic",
+ "DK": "Denmark",
+ "DJ": "Djibouti",
+ "DM": "Dominica",
+ "DO": "Dominican Republic",
+ "EC": "Ecuador",
+ "EG": "Egypt",
+ "SV": "El Salvador",
+ "GQ": "Equatorial Guinea",
+ "ER": "Eritrea",
+ "EE": "Estonia",
+ "ET": "Ethiopia",
+ "FK": "Falkland Islands (Malvinas)",
+ "FO": "Faroe Islands",
+ "FJ": "Fiji",
+ "FI": "Finland",
+ "FR": "France",
+ "GF": "French Guiana",
+ "PF": "French Polynesia",
+ "TF": "French Southern Territories",
+ "GA": "Gabon",
+ "GM": "Gambia",
+ "GE": "Georgia",
+ "DE": "Germany",
+ "GH": "Ghana",
+ "GI": "Gibraltar",
+ "GR": "Greece",
+ "GL": "Greenland",
+ "GD": "Grenada",
+ "GP": "Guadeloupe",
+ "GU": "Guam",
+ "GT": "Guatemala",
+ "GG": "Guernsey",
+ "GN": "Guinea",
+ "GW": "Guinea-Bissau",
+ "GY": "Guyana",
+ "HT": "Haiti",
+ "HM": "Heard Island and McDonald Islands",
+ "VA": "Holy See (Vatican City State)",
+ "HN": "Honduras",
+ "HK": "Hong Kong",
+ "HU": "Hungary",
+ "IS": "Iceland",
+ "IN": "India",
+ "ID": "Indonesia",
+ "IR": "Iran, Islamic Republic of",
+ "IQ": "Iraq",
+ "IE": "Ireland",
+ "IM": "Isle of Man",
+ "IL": "Israel",
+ "IT": "Italy",
+ "JM": "Jamaica",
+ "JP": "Japan",
+ "JE": "Jersey",
+ "JO": "Jordan",
+ "KZ": "Kazakhstan",
+ "KE": "Kenya",
+ "KI": "Kiribati",
+ "KP": "Korea, Democratic People\"s Republic of",
+ "KR": "Korea, Republic of",
+ "KW": "Kuwait",
+ "KG": "Kyrgyzstan",
+ "LA": "Lao People\"s Democratic Republic",
+ "LV": "Latvia",
+ "LB": "Lebanon",
+ "LS": "Lesotho",
+ "LR": "Liberia",
+ "LY": "Libya",
+ "LI": "Liechtenstein",
+ "LT": "Lithuania",
+ "LU": "Luxembourg",
+ "MO": "Macao",
+ "MK": "Macedonia, the former Yugoslav Republic of",
+ "MG": "Madagascar",
+ "MW": "Malawi",
+ "MY": "Malaysia",
+ "MV": "Maldives",
+ "ML": "Mali",
+ "MT": "Malta",
+ "MH": "Marshall Islands",
+ "MQ": "Martinique",
+ "MR": "Mauritania",
+ "MU": "Mauritius",
+ "YT": "Mayotte",
+ "MX": "Mexico",
+ "FM": "Micronesia, Federated States of",
+ "MD": "Moldova, Republic of",
+ "MC": "Monaco",
+ "MN": "Mongolia",
+ "ME": "Montenegro",
+ "MS": "Montserrat",
+ "MA": "Morocco",
+ "MZ": "Mozambique",
+ "MM": "Myanmar",
+ "NA": "Namibia",
+ "NR": "Nauru",
+ "NP": "Nepal",
+ "NL": "Netherlands",
+ "NC": "New Caledonia",
+ "NZ": "New Zealand",
+ "NI": "Nicaragua",
+ "NE": "Niger",
+ "NG": "Nigeria",
+ "NU": "Niue",
+ "NF": "Norfolk Island",
+ "MP": "Northern Mariana Islands",
+ "NO": "Norway",
+ "OM": "Oman",
+ "PK": "Pakistan",
+ "PW": "Palau",
+ "PS": "Palestinian Territory, Occupied",
+ "PA": "Panama",
+ "PG": "Papua New Guinea",
+ "PY": "Paraguay",
+ "PE": "Peru",
+ "PH": "Philippines",
+ "PN": "Pitcairn",
+ "PL": "Poland",
+ "PT": "Portugal",
+ "PR": "Puerto Rico",
+ "QA": "Qatar",
+ "RE": "R" + "é" + "union",
+ "RO": "Romania",
+ "RU": "Russian Federation",
+ "RW": "Rwanda",
+ "SH": "Saint Helena, Ascension and Tristan da Cunha",
+ "KN": "Saint Kitts and Nevis",
+ "LC": "Saint Lucia",
+ "MF": "Saint Martin (French part)",
+ "PM": "Saint Pierre and Miquelon",
+ "VC": "Saint Vincent and the Grenadines",
+ "WS": "Samoa",
+ "SM": "San Marino",
+ "ST": "Sao Tome and Principe",
+ "SA": "Saudi Arabia",
+ "SN": "Senegal",
+ "RS": "Serbia",
+ "SC": "Seychelles",
+ "SL": "Sierra Leone",
+ "SG": "Singapore",
+ "SX": "Sint Maarten (Dutch part)",
+ "SK": "Slovakia",
+ "SI": "Slovenia",
+ "SB": "Solomon Islands",
+ "SO": "Somalia",
+ "ZA": "South Africa",
+ "GS": "South Georgia and the South Sandwich Islands",
+ "SS": "South Sudan",
+ "ES": "Spain",
+ "LK": "Sri Lanka",
+ "SD": "Sudan",
+ "SR": "Suriname",
+ "SZ": "Swaziland",
+ "SE": "Sweden",
+ "CH": "Switzerland",
+ "SY": "Syrian Arab Republic",
+ "TW": "Taiwan, Province of China",
+ "TJ": "Tajikistan",
+ "TZ": "Tanzania, United Republic of",
+ "TH": "Thailand",
+ "TL": "Timor-Leste",
+ "TG": "Togo",
+ "TK": "Tokelau",
+ "TO": "Tonga",
+ "TT": "Trinidad and Tobago",
+ "TN": "Tunisia",
+ "TR": "Turkey",
+ "TM": "Turkmenistan",
+ "TC": "Turks and Caicos Islands",
+ "TV": "Tuvalu",
+ "UG": "Uganda",
+ "UA": "Ukraine",
+ "AE": "United Arab Emirates",
+ "GB": "United Kingdom",
+ "US": "United States",
+ "UM": "United States Minor Outlying Islands",
+ "UY": "Uruguay",
+ "UZ": "Uzbekistan",
+ "VU": "Vanuatu",
+ "VE": "Venezuela, Bolivarian Republic of",
+ "VN": "Viet Nam",
+ "VG": "Virgin Islands, British",
+ "VI": "Virgin Islands, U.S.",
+ "WF": "Wallis and Futuna",
+ "EH": "Western Sahara",
+ "YE": "Yemen",
+ "ZM": "Zambia",
+ "ZW": "Zimbabwe"
+ };
+
+ $.flagStrap = function (element, options) {
+
+ var plugin = this;
+
+ var uniqueId = generateId(8);
+
+ plugin.countries = {};
+ plugin.selected = {value: null, text: null};
+ plugin.settings = {inputName: "country-" + uniqueId};
+
+ var $container = $(element);
+ var htmlSelectId = "flagstrap-" + uniqueId;
+ var htmlSelect = "#" + htmlSelectId;
+
+ plugin.init = function () {
+
+ // Merge in global settings then merge in individual settings via data attributes
+ plugin.countries = countries;
+
+ // Initialize Settings, priority: defaults, init options, data attributes
+ plugin.settings = $.extend({}, defaults, options, $container.data());
+
+ if (undefined !== plugin.settings.countries) {
+ plugin.countries = plugin.settings.countries;
+ }
+
+ if (undefined !== plugin.settings.inputId) {
+ htmlSelectId = plugin.settings.inputId;
+ htmlSelect = "#" + htmlSelectId;
+ }
+
+ // Build HTML Select, Construct the drop down button, Assemble the drop down list items element and insert
+ $container
+ .addClass("flagstrap")
+ .append(buildHtmlSelect)
+ .append(buildDropDownButton)
+ .append(buildDropDownButtonItemList);
+
+ // Check to see if the onSelect callback method is assigned / callable, bind the change event for broadcast
+ if (plugin.settings.onSelect !== undefined && plugin.settings.onSelect instanceof Function) {
+ // $(htmlSelect).change(function (event) {
+ $(htmlSelect).change(function () {
+ var element = this;
+ options.onSelect($(element).val(), element);
+ });
+ }
+
+ // Hide the actual HTML select
+ $(htmlSelect).hide();
+ };
+
+ var buildHtmlSelect = function () {
+ var htmlSelectElement = $(" ").attr("id", htmlSelectId).attr("name", plugin.settings.inputName);
+
+ // check if countries is an array instead
+ if ($.isArray(plugin.countries)) {
+ var key, value, cObj, cObjKeys, optionAttributes;
+
+ // loop through each item in the countries array
+ for(var i=0; i", optionAttributes).text(value));
+ }
+ } else {
+ $.each(plugin.countries, function (code, country) {
+ var optionAttributes = {value: code};
+ if (plugin.settings.selectedCountry !== undefined) {
+ if (plugin.settings.selectedCountry === code) {
+ optionAttributes = {value: code, selected: "selected"};
+ plugin.selected = {value: code, text: country};
+ }
+ }
+ htmlSelectElement.append($("", optionAttributes).text(country));
+ });
+ }
+
+ if (plugin.settings.placeholder !== false) {
+ htmlSelectElement.prepend($(" ", {
+ value: plugin.settings.placeholder.value,
+ text: plugin.settings.placeholder.text
+ }));
+ }
+
+ return htmlSelectElement;
+ };
+
+ var buildDropDownButton = function () {
+
+ var selectedText = $(htmlSelect).find("option").first().text();
+ var selectedValue = $(htmlSelect).find("option").first().val();
+ var $selectedLabel;
+
+ selectedText = plugin.selected.text || selectedText;
+ selectedValue = plugin.selected.value || selectedValue;
+
+ if (selectedValue !== plugin.settings.placeholder.value) {
+ $selectedLabel = $(" ").addClass("flagstrap-icon flagstrap-" + selectedValue.toLowerCase()).css("margin-right", plugin.settings.labelMargin);
+ } else {
+ $selectedLabel = $(" ").addClass("flagstrap-icon flagstrap-placeholder");
+ }
+
+ var buttonLabel = $(" ")
+ .addClass("flagstrap-selected-" + uniqueId)
+ .html($selectedLabel)
+ .append(selectedText);
+
+ var button = $(" ")
+ .attr("type", "button")
+ .attr("data-toggle", "dropdown")
+ .attr("id", "flagstrap-drop-down-" + uniqueId)
+ .addClass("btn " + plugin.settings.buttonType + " " + plugin.settings.buttonSize + " dropdown-toggle")
+ .html(buttonLabel);
+
+ $(" ")
+ .addClass("caret")
+ .css("margin-left", plugin.settings.labelMargin)
+ .insertAfter(buttonLabel);
+
+ return button;
+
+ };
+
+ var buildDropDownButtonItemList = function () {
+ var items = $("")
+ .attr("id", "flagstrap-drop-down-" + uniqueId + "-list")
+ .attr("aria-labelled-by", "flagstrap-drop-down-" + uniqueId)
+ .addClass("dropdown-menu");
+
+ if (plugin.settings.scrollable) {
+ items.css("height", "auto")
+ .css("max-height", plugin.settings.scrollableHeight)
+ .css("overflow-x", "hidden");
+ }
+
+ // Populate the bootstrap dropdown item list
+ $(htmlSelect).find("option").each(function () {
+
+ // Get original select option values and labels
+ var text = $(this).text();
+ var value = $(this).val();
+ var flagIcon;
+
+ // Build the flag icon
+ if (value !== plugin.settings.placeholder.value) {
+ flagIcon = $(" ").addClass("flagstrap-icon flagstrap-" + value.toLowerCase()).css("margin-right", plugin.settings.labelMargin);
+ } else {
+ flagIcon = null;
+ }
+
+
+ // Build a clickable drop down option item, insert the flag and label, attach click event
+ var flagStrapItem = $(" ")
+ .attr("data-val", $(this).val())
+ .html(flagIcon)
+ .append(text)
+ .on("click", function (e) {
+ $(htmlSelect).find("option").removeAttr("selected");
+ $(htmlSelect).find("option[value=\"" + $(this).data("val") + "\"]").attr("selected", "selected");
+ $(htmlSelect).trigger("change");
+ $(".flagstrap-selected-" + uniqueId).html($(this).html());
+ e.preventDefault();
+ });
+
+ // Make it a list item
+ var listItem = $(" ").prepend(flagStrapItem);
+
+ // Append it to the drop down item list
+ items.append(listItem);
+
+ });
+
+ return items;
+ };
+
+ function generateId(length) {
+ var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz".split("");
+
+ if (!length) {
+ length = Math.floor(Math.random() * chars.length);
+ }
+
+ var str = "";
+ for (var i = 0; i < length; i++) {
+ str += chars[Math.floor(Math.random() * chars.length)];
+ }
+ return str;
+ }
+
+ plugin.init();
+
+ };
+
+ $.fn.flagStrap = function (options) {
+
+ return this.each(function (i) {
+ if ($(this).data("flagStrap") === undefined) {
+ $(this).data("flagStrap", new $.flagStrap(this, options, i));
+ }
+ });
+
+ };
+
+})(jQuery);
diff --git a/dist/js/jquery.flagstrap.min.js b/dist/js/jquery.flagstrap.min.js
index 7825459..59197d8 100644
--- a/dist/js/jquery.flagstrap.min.js
+++ b/dist/js/jquery.flagstrap.min.js
@@ -1,9 +1,9 @@
-/*
- * FlagStrap - v1.0
- * A lightwieght jQuery plugin for creating Bootstrap 3 compatible country select boxes with flags.
- * http://www.blazeworx.com/flagstrap
- *
- * Made by Alex Carter
- * Under MIT License
- */
-!function(a){var b={buttonSize:"btn-md",buttonType:"btn-default",labelMargin:"10px",scrollable:!0,scrollableHeight:"250px",placeholder:{value:"",text:"Please select country"}},c={AF:"Afghanistan",AL:"Albania",DZ:"Algeria",AS:"American Samoa",AD:"Andorra",AO:"Angola",AI:"Anguilla",AG:"Antigua and Barbuda",AR:"Argentina",AM:"Armenia",AW:"Aruba",AU:"Australia",AT:"Austria",AZ:"Azerbaijan",BS:"Bahamas",BH:"Bahrain",BD:"Bangladesh",BB:"Barbados",BY:"Belarus",BE:"Belgium",BZ:"Belize",BJ:"Benin",BM:"Bermuda",BT:"Bhutan",BO:"Bolivia, Plurinational State of",BA:"Bosnia and Herzegovina",BW:"Botswana",BV:"Bouvet Island",BR:"Brazil",IO:"British Indian Ocean Territory",BN:"Brunei Darussalam",BG:"Bulgaria",BF:"Burkina Faso",BI:"Burundi",KH:"Cambodia",CM:"Cameroon",CA:"Canada",CV:"Cape Verde",KY:"Cayman Islands",CF:"Central African Republic",TD:"Chad",CL:"Chile",CN:"China",CO:"Colombia",KM:"Comoros",CG:"Congo",CD:"Congo, the Democratic Republic of the",CK:"Cook Islands",CR:"Costa Rica",CI:"Côte d'Ivoire",HR:"Croatia",CU:"Cuba",CW:"Curaçao",CY:"Cyprus",CZ:"Czech Republic",DK:"Denmark",DJ:"Djibouti",DM:"Dominica",DO:"Dominican Republic",EC:"Ecuador",EG:"Egypt",SV:"El Salvador",GQ:"Equatorial Guinea",ER:"Eritrea",EE:"Estonia",ET:"Ethiopia",FK:"Falkland Islands (Malvinas)",FO:"Faroe Islands",FJ:"Fiji",FI:"Finland",FR:"France",GF:"French Guiana",PF:"French Polynesia",TF:"French Southern Territories",GA:"Gabon",GM:"Gambia",GE:"Georgia",DE:"Germany",GH:"Ghana",GI:"Gibraltar",GR:"Greece",GL:"Greenland",GD:"Grenada",GP:"Guadeloupe",GU:"Guam",GT:"Guatemala",GG:"Guernsey",GN:"Guinea",GW:"Guinea-Bissau",GY:"Guyana",HT:"Haiti",HM:"Heard Island and McDonald Islands",VA:"Holy See (Vatican City State)",HN:"Honduras",HK:"Hong Kong",HU:"Hungary",IS:"Iceland",IN:"India",ID:"Indonesia",IR:"Iran, Islamic Republic of",IQ:"Iraq",IE:"Ireland",IM:"Isle of Man",IL:"Israel",IT:"Italy",JM:"Jamaica",JP:"Japan",JE:"Jersey",JO:"Jordan",KZ:"Kazakhstan",KE:"Kenya",KI:"Kiribati",KP:"Korea, Democratic People's Republic of",KR:"Korea, Republic of",KW:"Kuwait",KG:"Kyrgyzstan",LA:"Lao People's Democratic Republic",LV:"Latvia",LB:"Lebanon",LS:"Lesotho",LR:"Liberia",LY:"Libya",LI:"Liechtenstein",LT:"Lithuania",LU:"Luxembourg",MO:"Macao",MK:"Macedonia, the former Yugoslav Republic of",MG:"Madagascar",MW:"Malawi",MY:"Malaysia",MV:"Maldives",ML:"Mali",MT:"Malta",MH:"Marshall Islands",MQ:"Martinique",MR:"Mauritania",MU:"Mauritius",YT:"Mayotte",MX:"Mexico",FM:"Micronesia, Federated States of",MD:"Moldova, Republic of",MC:"Monaco",MN:"Mongolia",ME:"Montenegro",MS:"Montserrat",MA:"Morocco",MZ:"Mozambique",MM:"Myanmar",NA:"Namibia",NR:"Nauru",NP:"Nepal",NL:"Netherlands",NC:"New Caledonia",NZ:"New Zealand",NI:"Nicaragua",NE:"Niger",NG:"Nigeria",NU:"Niue",NF:"Norfolk Island",MP:"Northern Mariana Islands",NO:"Norway",OM:"Oman",PK:"Pakistan",PW:"Palau",PS:"Palestinian Territory, Occupied",PA:"Panama",PG:"Papua New Guinea",PY:"Paraguay",PE:"Peru",PH:"Philippines",PN:"Pitcairn",PL:"Poland",PT:"Portugal",PR:"Puerto Rico",QA:"Qatar",RE:"Réunion",RO:"Romania",RU:"Russian Federation",RW:"Rwanda",SH:"Saint Helena, Ascension and Tristan da Cunha",KN:"Saint Kitts and Nevis",LC:"Saint Lucia",MF:"Saint Martin (French part)",PM:"Saint Pierre and Miquelon",VC:"Saint Vincent and the Grenadines",WS:"Samoa",SM:"San Marino",ST:"Sao Tome and Principe",SA:"Saudi Arabia",SN:"Senegal",RS:"Serbia",SC:"Seychelles",SL:"Sierra Leone",SG:"Singapore",SX:"Sint Maarten (Dutch part)",SK:"Slovakia",SI:"Slovenia",SB:"Solomon Islands",SO:"Somalia",ZA:"South Africa",GS:"South Georgia and the South Sandwich Islands",SS:"South Sudan",ES:"Spain",LK:"Sri Lanka",SD:"Sudan",SR:"Suriname",SZ:"Swaziland",SE:"Sweden",CH:"Switzerland",SY:"Syrian Arab Republic",TW:"Taiwan, Province of China",TJ:"Tajikistan",TZ:"Tanzania, United Republic of",TH:"Thailand",TL:"Timor-Leste",TG:"Togo",TK:"Tokelau",TO:"Tonga",TT:"Trinidad and Tobago",TN:"Tunisia",TR:"Turkey",TM:"Turkmenistan",TC:"Turks and Caicos Islands",TV:"Tuvalu",UG:"Uganda",UA:"Ukraine",AE:"United Arab Emirates",GB:"United Kingdom",US:"United States",UM:"United States Minor Outlying Islands",UY:"Uruguay",UZ:"Uzbekistan",VU:"Vanuatu",VE:"Venezuela, Bolivarian Republic of",VN:"Viet Nam",VG:"Virgin Islands, British",VI:"Virgin Islands, U.S.",WF:"Wallis and Futuna",EH:"Western Sahara",YE:"Yemen",ZM:"Zambia",ZW:"Zimbabwe"};a.flagStrap=function(d,e){function f(a){var b="0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz".split("");a||(a=Math.floor(Math.random()*b.length));for(var c="",d=0;a>d;d++)c+=b[Math.floor(Math.random()*b.length)];return c}var g=this,h=f(8);g.countries={},g.selected={value:null,text:null},g.settings={inputName:"country-"+h};var i=a(d),j="flagstrap-"+h,k="#"+j;g.init=function(){g.countries=c,g.countries=c,g.settings=a.extend({},b,e,i.data()),void 0!==g.settings.countries&&(g.countries=g.settings.countries),void 0!==g.settings.inputId&&(j=g.settings.inputId,k="#"+j),i.addClass("flagstrap").append(l).append(m).append(n),void 0!==g.settings.onSelect&&g.settings.onSelect instanceof Function&&a(k).change(function(){var b=this;e.onSelect(a(b).val(),b)}),a(k).hide()};var l=function(){var b=a(" ").attr("id",j).attr("name",g.settings.inputName);return a.each(g.countries,function(c,d){var e={value:c};void 0!==g.settings.selectedCountry&&g.settings.selectedCountry===c&&(e={value:c,selected:"selected"},g.selected={value:c,text:d}),b.append(a(" ",e).text(d))}),g.settings.placeholder!==!1&&b.prepend(a(" ",{value:g.settings.placeholder.value,text:g.settings.placeholder.text})),b},m=function(){var b=a(k).find("option").first().text(),c=a(k).find("option").first().val();if(b=g.selected.text||b,c=g.selected.value||c,c!==g.settings.placeholder.value)var d=a(" ").addClass("flagstrap-icon flagstrap-"+c.toLowerCase()).css("margin-right",g.settings.labelMargin);else var d=a(" ").addClass("flagstrap-icon flagstrap-placeholder");var e=a(" ").addClass("flagstrap-selected-"+h).html(d).append(b),f=a(" ").attr("type","button").attr("data-toggle","dropdown").attr("id","flagstrap-drop-down-"+h).addClass("btn "+g.settings.buttonType+" "+g.settings.buttonSize+" dropdown-toggle").html(e);return a(" ").addClass("caret").css("margin-left",g.settings.labelMargin).insertAfter(e),f},n=function(){var b=a("").attr("id","flagstrap-drop-down-"+h+"-list").attr("aria-labelled-by","flagstrap-drop-down-"+h).addClass("dropdown-menu");return g.settings.scrollable&&b.css("height","auto").css("max-height",g.settings.scrollableHeight).css("overflow-x","hidden"),a(k).find("option").each(function(){var c=a(this).text(),d=a(this).val();if(d!==g.settings.placeholder.value)var e=a(" ").addClass("flagstrap-icon flagstrap-"+d.toLowerCase()).css("margin-right",g.settings.labelMargin);else var e=null;var f=a(" ").attr("data-val",a(this).val()).html(e).append(c).on("click",function(b){a(k).find("option").removeAttr("selected"),a(k).find('option[value="'+a(this).data("val")+'"]').attr("selected","selected"),a(k).trigger("change"),a(".flagstrap-selected-"+h).html(a(this).html()),b.preventDefault()}),i=a(" ").prepend(f);b.append(i)}),b};g.init()},a.fn.flagStrap=function(b){return this.each(function(c){void 0===a(this).data("flagStrap")&&a(this).data("flagStrap",new a.flagStrap(this,b,c))})}}(jQuery);
\ No newline at end of file
+/*
+ * FlagStrap - v1.0
+ * A lightwieght jQuery plugin for creating Bootstrap 3 compatible country select boxes with flags.
+ * http://www.blazeworx.com/flagstrap
+ *
+ * Made by Alex Carter
+ * Under MIT License
+ */
+!function(a){var b={buttonSize:"btn-md",buttonType:"btn-default",labelMargin:"10px",scrollable:!0,scrollableHeight:"250px",placeholder:{value:"",text:"Please select country"}},c={AF:"Afghanistan",AL:"Albania",DZ:"Algeria",AS:"American Samoa",AD:"Andorra",AO:"Angola",AI:"Anguilla",AG:"Antigua and Barbuda",AR:"Argentina",AM:"Armenia",AW:"Aruba",AU:"Australia",AT:"Austria",AZ:"Azerbaijan",BS:"Bahamas",BH:"Bahrain",BD:"Bangladesh",BB:"Barbados",BY:"Belarus",BE:"Belgium",BZ:"Belize",BJ:"Benin",BM:"Bermuda",BT:"Bhutan",BO:"Bolivia, Plurinational State of",BA:"Bosnia and Herzegovina",BW:"Botswana",BV:"Bouvet Island",BR:"Brazil",IO:"British Indian Ocean Territory",BN:"Brunei Darussalam",BG:"Bulgaria",BF:"Burkina Faso",BI:"Burundi",KH:"Cambodia",CM:"Cameroon",CA:"Canada",CV:"Cape Verde",KY:"Cayman Islands",CF:"Central African Republic",TD:"Chad",CL:"Chile",CN:"China",CO:"Colombia",KM:"Comoros",CG:"Congo",CD:"Congo, the Democratic Republic of the",CK:"Cook Islands",CR:"Costa Rica",CI:'Côte d"Ivoire',HR:"Croatia",CU:"Cuba",CW:"Curaçao",CY:"Cyprus",CZ:"Czech Republic",DK:"Denmark",DJ:"Djibouti",DM:"Dominica",DO:"Dominican Republic",EC:"Ecuador",EG:"Egypt",SV:"El Salvador",GQ:"Equatorial Guinea",ER:"Eritrea",EE:"Estonia",ET:"Ethiopia",FK:"Falkland Islands (Malvinas)",FO:"Faroe Islands",FJ:"Fiji",FI:"Finland",FR:"France",GF:"French Guiana",PF:"French Polynesia",TF:"French Southern Territories",GA:"Gabon",GM:"Gambia",GE:"Georgia",DE:"Germany",GH:"Ghana",GI:"Gibraltar",GR:"Greece",GL:"Greenland",GD:"Grenada",GP:"Guadeloupe",GU:"Guam",GT:"Guatemala",GG:"Guernsey",GN:"Guinea",GW:"Guinea-Bissau",GY:"Guyana",HT:"Haiti",HM:"Heard Island and McDonald Islands",VA:"Holy See (Vatican City State)",HN:"Honduras",HK:"Hong Kong",HU:"Hungary",IS:"Iceland",IN:"India",ID:"Indonesia",IR:"Iran, Islamic Republic of",IQ:"Iraq",IE:"Ireland",IM:"Isle of Man",IL:"Israel",IT:"Italy",JM:"Jamaica",JP:"Japan",JE:"Jersey",JO:"Jordan",KZ:"Kazakhstan",KE:"Kenya",KI:"Kiribati",KP:'Korea, Democratic People"s Republic of',KR:"Korea, Republic of",KW:"Kuwait",KG:"Kyrgyzstan",LA:'Lao People"s Democratic Republic',LV:"Latvia",LB:"Lebanon",LS:"Lesotho",LR:"Liberia",LY:"Libya",LI:"Liechtenstein",LT:"Lithuania",LU:"Luxembourg",MO:"Macao",MK:"Macedonia, the former Yugoslav Republic of",MG:"Madagascar",MW:"Malawi",MY:"Malaysia",MV:"Maldives",ML:"Mali",MT:"Malta",MH:"Marshall Islands",MQ:"Martinique",MR:"Mauritania",MU:"Mauritius",YT:"Mayotte",MX:"Mexico",FM:"Micronesia, Federated States of",MD:"Moldova, Republic of",MC:"Monaco",MN:"Mongolia",ME:"Montenegro",MS:"Montserrat",MA:"Morocco",MZ:"Mozambique",MM:"Myanmar",NA:"Namibia",NR:"Nauru",NP:"Nepal",NL:"Netherlands",NC:"New Caledonia",NZ:"New Zealand",NI:"Nicaragua",NE:"Niger",NG:"Nigeria",NU:"Niue",NF:"Norfolk Island",MP:"Northern Mariana Islands",NO:"Norway",OM:"Oman",PK:"Pakistan",PW:"Palau",PS:"Palestinian Territory, Occupied",PA:"Panama",PG:"Papua New Guinea",PY:"Paraguay",PE:"Peru",PH:"Philippines",PN:"Pitcairn",PL:"Poland",PT:"Portugal",PR:"Puerto Rico",QA:"Qatar",RE:"Réunion",RO:"Romania",RU:"Russian Federation",RW:"Rwanda",SH:"Saint Helena, Ascension and Tristan da Cunha",KN:"Saint Kitts and Nevis",LC:"Saint Lucia",MF:"Saint Martin (French part)",PM:"Saint Pierre and Miquelon",VC:"Saint Vincent and the Grenadines",WS:"Samoa",SM:"San Marino",ST:"Sao Tome and Principe",SA:"Saudi Arabia",SN:"Senegal",RS:"Serbia",SC:"Seychelles",SL:"Sierra Leone",SG:"Singapore",SX:"Sint Maarten (Dutch part)",SK:"Slovakia",SI:"Slovenia",SB:"Solomon Islands",SO:"Somalia",ZA:"South Africa",GS:"South Georgia and the South Sandwich Islands",SS:"South Sudan",ES:"Spain",LK:"Sri Lanka",SD:"Sudan",SR:"Suriname",SZ:"Swaziland",SE:"Sweden",CH:"Switzerland",SY:"Syrian Arab Republic",TW:"Taiwan, Province of China",TJ:"Tajikistan",TZ:"Tanzania, United Republic of",TH:"Thailand",TL:"Timor-Leste",TG:"Togo",TK:"Tokelau",TO:"Tonga",TT:"Trinidad and Tobago",TN:"Tunisia",TR:"Turkey",TM:"Turkmenistan",TC:"Turks and Caicos Islands",TV:"Tuvalu",UG:"Uganda",UA:"Ukraine",AE:"United Arab Emirates",GB:"United Kingdom",US:"United States",UM:"United States Minor Outlying Islands",UY:"Uruguay",UZ:"Uzbekistan",VU:"Vanuatu",VE:"Venezuela, Bolivarian Republic of",VN:"Viet Nam",VG:"Virgin Islands, British",VI:"Virgin Islands, U.S.",WF:"Wallis and Futuna",EH:"Western Sahara",YE:"Yemen",ZM:"Zambia",ZW:"Zimbabwe"};a.flagStrap=function(d,e){function f(a){var b="0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz".split("");a||(a=Math.floor(Math.random()*b.length));for(var c="",d=0;d").attr("id",j).attr("name",g.settings.inputName);if(a.isArray(g.countries))for(var c,d,e,f,h,i=0;i",h).text(d));else a.each(g.countries,function(c,d){var e={value:c};void 0!==g.settings.selectedCountry&&g.settings.selectedCountry===c&&(e={value:c,selected:"selected"},g.selected={value:c,text:d}),b.append(a("",e).text(d))});return!1!==g.settings.placeholder&&b.prepend(a(" ",{value:g.settings.placeholder.value,text:g.settings.placeholder.text})),b},m=function(){var b,c=a(k).find("option").first().text(),d=a(k).find("option").first().val();c=g.selected.text||c,d=g.selected.value||d,b=d!==g.settings.placeholder.value?a(" ").addClass("flagstrap-icon flagstrap-"+d.toLowerCase()).css("margin-right",g.settings.labelMargin):a(" ").addClass("flagstrap-icon flagstrap-placeholder");var e=a(" ").addClass("flagstrap-selected-"+h).html(b).append(c),f=a(" ").attr("type","button").attr("data-toggle","dropdown").attr("id","flagstrap-drop-down-"+h).addClass("btn "+g.settings.buttonType+" "+g.settings.buttonSize+" dropdown-toggle").html(e);return a(" ").addClass("caret").css("margin-left",g.settings.labelMargin).insertAfter(e),f},n=function(){var b=a("").attr("id","flagstrap-drop-down-"+h+"-list").attr("aria-labelled-by","flagstrap-drop-down-"+h).addClass("dropdown-menu");return g.settings.scrollable&&b.css("height","auto").css("max-height",g.settings.scrollableHeight).css("overflow-x","hidden"),a(k).find("option").each(function(){var c,d=a(this).text(),e=a(this).val();c=e!==g.settings.placeholder.value?a(" ").addClass("flagstrap-icon flagstrap-"+e.toLowerCase()).css("margin-right",g.settings.labelMargin):null;var f=a(" ").attr("data-val",a(this).val()).html(c).append(d).on("click",function(b){a(k).find("option").removeAttr("selected"),a(k).find('option[value="'+a(this).data("val")+'"]').attr("selected","selected"),a(k).trigger("change"),a(".flagstrap-selected-"+h).html(a(this).html()),b.preventDefault()}),i=a(" ").prepend(f);b.append(i)}),b};g.init()},a.fn.flagStrap=function(b){return this.each(function(c){void 0===a(this).data("flagStrap")&&a(this).data("flagStrap",new a.flagStrap(this,b,c))})}}(jQuery);
\ No newline at end of file
diff --git a/package.json b/package.json
index e6cf10d..e548c6d 100644
--- a/package.json
+++ b/package.json
@@ -1,13 +1,14 @@
-{
- "private": true,
- "devDependencies": {
- "grunt": "~0.4.5",
- "grunt-cli": "~0.1.13",
- "grunt-contrib-concat": "~0.4.0",
- "grunt-contrib-jshint": "~0.10.0",
- "grunt-contrib-uglify": "~0.4.0",
- "grunt-contrib-watch": "^0.6.1"
- }
-}
-
-
+{
+ "private": true,
+ "devDependencies": {
+ "grunt": "~0.4.5",
+ "grunt-cli": "~0.1.13",
+ "grunt-contrib-concat": "~0.4.0",
+ "grunt-contrib-jshint": "~0.10.0",
+ "grunt-contrib-uglify": "~0.4.0",
+ "grunt-contrib-watch": "^0.6.1"
+ },
+ "scripts": {
+ "start": "grunt"
+ }
+}
diff --git a/sorted.png b/sorted.png
new file mode 100644
index 0000000..c97bba1
Binary files /dev/null and b/sorted.png differ
diff --git a/src/jquery.flagstrap.js b/src/jquery.flagstrap.js
index 0c6c76c..8408ecd 100644
--- a/src/jquery.flagstrap.js
+++ b/src/jquery.flagstrap.js
@@ -1,450 +1,479 @@
-(function ($) {
-
- var defaults = {
- buttonSize: "btn-md",
- buttonType: "btn-default",
- labelMargin: "10px",
- scrollable: true,
- scrollableHeight: "250px",
- placeholder: {
- value: '',
- text: 'Please select country'
- }
- };
-
- var countries = {
- "AF": "Afghanistan",
- "AL": "Albania",
- "DZ": "Algeria",
- "AS": "American Samoa",
- "AD": "Andorra",
- "AO": "Angola",
- "AI": "Anguilla",
- "AG": "Antigua and Barbuda",
- "AR": "Argentina",
- "AM": "Armenia",
- "AW": "Aruba",
- "AU": "Australia",
- "AT": "Austria",
- "AZ": "Azerbaijan",
- "BS": "Bahamas",
- "BH": "Bahrain",
- "BD": "Bangladesh",
- "BB": "Barbados",
- "BY": "Belarus",
- "BE": "Belgium",
- "BZ": "Belize",
- "BJ": "Benin",
- "BM": "Bermuda",
- "BT": "Bhutan",
- "BO": "Bolivia, Plurinational State of",
- "BA": "Bosnia and Herzegovina",
- "BW": "Botswana",
- "BV": "Bouvet Island",
- "BR": "Brazil",
- "IO": "British Indian Ocean Territory",
- "BN": "Brunei Darussalam",
- "BG": "Bulgaria",
- "BF": "Burkina Faso",
- "BI": "Burundi",
- "KH": "Cambodia",
- "CM": "Cameroon",
- "CA": "Canada",
- "CV": "Cape Verde",
- "KY": "Cayman Islands",
- "CF": "Central African Republic",
- "TD": "Chad",
- "CL": "Chile",
- "CN": "China",
- "CO": "Colombia",
- "KM": "Comoros",
- "CG": "Congo",
- "CD": "Congo, the Democratic Republic of the",
- "CK": "Cook Islands",
- "CR": "Costa Rica",
- "CI": "C" + "ô" + "te d'Ivoire",
- "HR": "Croatia",
- "CU": "Cuba",
- "CW": "Cura" + "ç" + "ao",
- "CY": "Cyprus",
- "CZ": "Czech Republic",
- "DK": "Denmark",
- "DJ": "Djibouti",
- "DM": "Dominica",
- "DO": "Dominican Republic",
- "EC": "Ecuador",
- "EG": "Egypt",
- "SV": "El Salvador",
- "GQ": "Equatorial Guinea",
- "ER": "Eritrea",
- "EE": "Estonia",
- "ET": "Ethiopia",
- "FK": "Falkland Islands (Malvinas)",
- "FO": "Faroe Islands",
- "FJ": "Fiji",
- "FI": "Finland",
- "FR": "France",
- "GF": "French Guiana",
- "PF": "French Polynesia",
- "TF": "French Southern Territories",
- "GA": "Gabon",
- "GM": "Gambia",
- "GE": "Georgia",
- "DE": "Germany",
- "GH": "Ghana",
- "GI": "Gibraltar",
- "GR": "Greece",
- "GL": "Greenland",
- "GD": "Grenada",
- "GP": "Guadeloupe",
- "GU": "Guam",
- "GT": "Guatemala",
- "GG": "Guernsey",
- "GN": "Guinea",
- "GW": "Guinea-Bissau",
- "GY": "Guyana",
- "HT": "Haiti",
- "HM": "Heard Island and McDonald Islands",
- "VA": "Holy See (Vatican City State)",
- "HN": "Honduras",
- "HK": "Hong Kong",
- "HU": "Hungary",
- "IS": "Iceland",
- "IN": "India",
- "ID": "Indonesia",
- "IR": "Iran, Islamic Republic of",
- "IQ": "Iraq",
- "IE": "Ireland",
- "IM": "Isle of Man",
- "IL": "Israel",
- "IT": "Italy",
- "JM": "Jamaica",
- "JP": "Japan",
- "JE": "Jersey",
- "JO": "Jordan",
- "KZ": "Kazakhstan",
- "KE": "Kenya",
- "KI": "Kiribati",
- "KP": "Korea, Democratic People's Republic of",
- "KR": "Korea, Republic of",
- "KW": "Kuwait",
- "KG": "Kyrgyzstan",
- "LA": "Lao People's Democratic Republic",
- "LV": "Latvia",
- "LB": "Lebanon",
- "LS": "Lesotho",
- "LR": "Liberia",
- "LY": "Libya",
- "LI": "Liechtenstein",
- "LT": "Lithuania",
- "LU": "Luxembourg",
- "MO": "Macao",
- "MK": "Macedonia, the former Yugoslav Republic of",
- "MG": "Madagascar",
- "MW": "Malawi",
- "MY": "Malaysia",
- "MV": "Maldives",
- "ML": "Mali",
- "MT": "Malta",
- "MH": "Marshall Islands",
- "MQ": "Martinique",
- "MR": "Mauritania",
- "MU": "Mauritius",
- "YT": "Mayotte",
- "MX": "Mexico",
- "FM": "Micronesia, Federated States of",
- "MD": "Moldova, Republic of",
- "MC": "Monaco",
- "MN": "Mongolia",
- "ME": "Montenegro",
- "MS": "Montserrat",
- "MA": "Morocco",
- "MZ": "Mozambique",
- "MM": "Myanmar",
- "NA": "Namibia",
- "NR": "Nauru",
- "NP": "Nepal",
- "NL": "Netherlands",
- "NC": "New Caledonia",
- "NZ": "New Zealand",
- "NI": "Nicaragua",
- "NE": "Niger",
- "NG": "Nigeria",
- "NU": "Niue",
- "NF": "Norfolk Island",
- "MP": "Northern Mariana Islands",
- "NO": "Norway",
- "OM": "Oman",
- "PK": "Pakistan",
- "PW": "Palau",
- "PS": "Palestinian Territory, Occupied",
- "PA": "Panama",
- "PG": "Papua New Guinea",
- "PY": "Paraguay",
- "PE": "Peru",
- "PH": "Philippines",
- "PN": "Pitcairn",
- "PL": "Poland",
- "PT": "Portugal",
- "PR": "Puerto Rico",
- "QA": "Qatar",
- "RE": "R" + "é" + "union",
- "RO": "Romania",
- "RU": "Russian Federation",
- "RW": "Rwanda",
- "SH": "Saint Helena, Ascension and Tristan da Cunha",
- "KN": "Saint Kitts and Nevis",
- "LC": "Saint Lucia",
- "MF": "Saint Martin (French part)",
- "PM": "Saint Pierre and Miquelon",
- "VC": "Saint Vincent and the Grenadines",
- "WS": "Samoa",
- "SM": "San Marino",
- "ST": "Sao Tome and Principe",
- "SA": "Saudi Arabia",
- "SN": "Senegal",
- "RS": "Serbia",
- "SC": "Seychelles",
- "SL": "Sierra Leone",
- "SG": "Singapore",
- "SX": "Sint Maarten (Dutch part)",
- "SK": "Slovakia",
- "SI": "Slovenia",
- "SB": "Solomon Islands",
- "SO": "Somalia",
- "ZA": "South Africa",
- "GS": "South Georgia and the South Sandwich Islands",
- "SS": "South Sudan",
- "ES": "Spain",
- "LK": "Sri Lanka",
- "SD": "Sudan",
- "SR": "Suriname",
- "SZ": "Swaziland",
- "SE": "Sweden",
- "CH": "Switzerland",
- "SY": "Syrian Arab Republic",
- "TW": "Taiwan, Province of China",
- "TJ": "Tajikistan",
- "TZ": "Tanzania, United Republic of",
- "TH": "Thailand",
- "TL": "Timor-Leste",
- "TG": "Togo",
- "TK": "Tokelau",
- "TO": "Tonga",
- "TT": "Trinidad and Tobago",
- "TN": "Tunisia",
- "TR": "Turkey",
- "TM": "Turkmenistan",
- "TC": "Turks and Caicos Islands",
- "TV": "Tuvalu",
- "UG": "Uganda",
- "UA": "Ukraine",
- "AE": "United Arab Emirates",
- "GB": "United Kingdom",
- "US": "United States",
- "UM": "United States Minor Outlying Islands",
- "UY": "Uruguay",
- "UZ": "Uzbekistan",
- "VU": "Vanuatu",
- "VE": "Venezuela, Bolivarian Republic of",
- "VN": "Viet Nam",
- "VG": "Virgin Islands, British",
- "VI": "Virgin Islands, U.S.",
- "WF": "Wallis and Futuna",
- "EH": "Western Sahara",
- "YE": "Yemen",
- "ZM": "Zambia",
- "ZW": "Zimbabwe"
- };
-
- $.flagStrap = function (element, options, i) {
-
- var plugin = this;
-
- var uniqueId = generateId(8);
-
- plugin.countries = {};
- plugin.selected = {value: null, text: null};
- plugin.settings = {inputName: 'country-' + uniqueId};
-
- var $container = $(element);
- var htmlSelectId = 'flagstrap-' + uniqueId;
- var htmlSelect = '#' + htmlSelectId;
-
- plugin.init = function () {
-
- // Merge in global settings then merge in individual settings via data attributes
- plugin.countries = countries;
-
- // Initialize Settings, priority: defaults, init options, data attributes
- plugin.countries = countries;
- plugin.settings = $.extend({}, defaults, options, $container.data());
-
- if (undefined !== plugin.settings.countries) {
- plugin.countries = plugin.settings.countries;
- }
-
- if (undefined !== plugin.settings.inputId) {
- htmlSelectId = plugin.settings.inputId;
- htmlSelect = '#' + htmlSelectId;
- }
-
- // Build HTML Select, Construct the drop down button, Assemble the drop down list items element and insert
- $container
- .addClass('flagstrap')
- .append(buildHtmlSelect)
- .append(buildDropDownButton)
- .append(buildDropDownButtonItemList);
-
- // Check to see if the onSelect callback method is assigned / callable, bind the change event for broadcast
- if (plugin.settings.onSelect !== undefined && plugin.settings.onSelect instanceof Function) {
- $(htmlSelect).change(function (event) {
- var element = this;
- options.onSelect($(element).val(), element);
- });
- }
-
- // Hide the actual HTML select
- $(htmlSelect).hide();
-
- };
-
- var buildHtmlSelect = function () {
- var htmlSelectElement = $(' ').attr('id', htmlSelectId).attr('name', plugin.settings.inputName);
-
- $.each(plugin.countries, function (code, country) {
- var optionAttributes = {value: code};
- if (plugin.settings.selectedCountry !== undefined) {
- if (plugin.settings.selectedCountry === code) {
- optionAttributes = {value: code, selected: "selected"};
- plugin.selected = {value: code, text: country}
- }
- }
- htmlSelectElement.append($(' ', optionAttributes).text(country));
- });
-
- if (plugin.settings.placeholder !== false) {
- htmlSelectElement.prepend($(' ', {
- value: plugin.settings.placeholder.value,
- text: plugin.settings.placeholder.text
- }));
- }
-
- return htmlSelectElement;
- };
-
- var buildDropDownButton = function () {
-
- var selectedText = $(htmlSelect).find('option').first().text();
- var selectedValue = $(htmlSelect).find('option').first().val();
-
- selectedText = plugin.selected.text || selectedText;
- selectedValue = plugin.selected.value || selectedValue;
-
- if (selectedValue !== plugin.settings.placeholder.value) {
- var $selectedLabel = $(' ').addClass('flagstrap-icon flagstrap-' + selectedValue.toLowerCase()).css('margin-right', plugin.settings.labelMargin);
- } else {
- var $selectedLabel = $(' ').addClass('flagstrap-icon flagstrap-placeholder');
- }
-
- var buttonLabel = $(' ')
- .addClass('flagstrap-selected-' + uniqueId)
- .html($selectedLabel)
- .append(selectedText);
-
- var button = $(' ')
- .attr('type', 'button')
- .attr('data-toggle', 'dropdown')
- .attr('id', 'flagstrap-drop-down-' + uniqueId)
- .addClass('btn ' + plugin.settings.buttonType + ' ' + plugin.settings.buttonSize + ' dropdown-toggle')
- .html(buttonLabel);
-
- $(' ')
- .addClass('caret')
- .css('margin-left', plugin.settings.labelMargin)
- .insertAfter(buttonLabel);
-
- return button;
-
- };
-
- var buildDropDownButtonItemList = function () {
- var items = $('')
- .attr('id', 'flagstrap-drop-down-' + uniqueId + '-list')
- .attr('aria-labelled-by', 'flagstrap-drop-down-' + uniqueId)
- .addClass('dropdown-menu');
-
- if (plugin.settings.scrollable) {
- items.css('height', 'auto')
- .css('max-height', plugin.settings.scrollableHeight)
- .css('overflow-x', 'hidden');
- }
-
- // Populate the bootstrap dropdown item list
- $(htmlSelect).find('option').each(function () {
-
- // Get original select option values and labels
- var text = $(this).text();
- var value = $(this).val();
-
- // Build the flag icon
- if (value !== plugin.settings.placeholder.value) {
- var flagIcon = $(' ').addClass('flagstrap-icon flagstrap-' + value.toLowerCase()).css('margin-right', plugin.settings.labelMargin);
- } else {
- var flagIcon = null;
- }
-
-
- // Build a clickable drop down option item, insert the flag and label, attach click event
- var flagStrapItem = $(' ')
- .attr('data-val', $(this).val())
- .html(flagIcon)
- .append(text)
- .on('click', function (e) {
- $(htmlSelect).find('option').removeAttr('selected');
- $(htmlSelect).find('option[value="' + $(this).data('val') + '"]').attr("selected", "selected");
- $(htmlSelect).trigger('change');
- $('.flagstrap-selected-' + uniqueId).html($(this).html());
- e.preventDefault();
- });
-
- // Make it a list item
- var listItem = $(' ').prepend(flagStrapItem);
-
- // Append it to the drop down item list
- items.append(listItem);
-
- });
-
- return items;
- };
-
- function generateId(length) {
- var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz'.split('');
-
- if (!length) {
- length = Math.floor(Math.random() * chars.length);
- }
-
- var str = '';
- for (var i = 0; i < length; i++) {
- str += chars[Math.floor(Math.random() * chars.length)];
- }
- return str;
- }
-
- plugin.init();
-
- };
-
- $.fn.flagStrap = function (options) {
-
- return this.each(function (i) {
- if ($(this).data('flagStrap') === undefined) {
- $(this).data('flagStrap', new $.flagStrap(this, options, i));
- }
- });
-
- }
-
-})(jQuery);
+(function ($) {
+
+ var defaults = {
+ buttonSize: "btn-md",
+ buttonType: "btn-default",
+ labelMargin: "10px",
+ scrollable: true,
+ scrollableHeight: "250px",
+ placeholder: {
+ value: "",
+ text: "Please select country"
+ }
+ };
+
+ var countries = {
+ "AF": "Afghanistan",
+ "AL": "Albania",
+ "DZ": "Algeria",
+ "AS": "American Samoa",
+ "AD": "Andorra",
+ "AO": "Angola",
+ "AI": "Anguilla",
+ "AG": "Antigua and Barbuda",
+ "AR": "Argentina",
+ "AM": "Armenia",
+ "AW": "Aruba",
+ "AU": "Australia",
+ "AT": "Austria",
+ "AZ": "Azerbaijan",
+ "BS": "Bahamas",
+ "BH": "Bahrain",
+ "BD": "Bangladesh",
+ "BB": "Barbados",
+ "BY": "Belarus",
+ "BE": "Belgium",
+ "BZ": "Belize",
+ "BJ": "Benin",
+ "BM": "Bermuda",
+ "BT": "Bhutan",
+ "BO": "Bolivia, Plurinational State of",
+ "BA": "Bosnia and Herzegovina",
+ "BW": "Botswana",
+ "BV": "Bouvet Island",
+ "BR": "Brazil",
+ "IO": "British Indian Ocean Territory",
+ "BN": "Brunei Darussalam",
+ "BG": "Bulgaria",
+ "BF": "Burkina Faso",
+ "BI": "Burundi",
+ "KH": "Cambodia",
+ "CM": "Cameroon",
+ "CA": "Canada",
+ "CV": "Cape Verde",
+ "KY": "Cayman Islands",
+ "CF": "Central African Republic",
+ "TD": "Chad",
+ "CL": "Chile",
+ "CN": "China",
+ "CO": "Colombia",
+ "KM": "Comoros",
+ "CG": "Congo",
+ "CD": "Congo, the Democratic Republic of the",
+ "CK": "Cook Islands",
+ "CR": "Costa Rica",
+ "CI": "C" + "ô" + "te d\"Ivoire",
+ "HR": "Croatia",
+ "CU": "Cuba",
+ "CW": "Cura" + "ç" + "ao",
+ "CY": "Cyprus",
+ "CZ": "Czech Republic",
+ "DK": "Denmark",
+ "DJ": "Djibouti",
+ "DM": "Dominica",
+ "DO": "Dominican Republic",
+ "EC": "Ecuador",
+ "EG": "Egypt",
+ "SV": "El Salvador",
+ "GQ": "Equatorial Guinea",
+ "ER": "Eritrea",
+ "EE": "Estonia",
+ "ET": "Ethiopia",
+ "FK": "Falkland Islands (Malvinas)",
+ "FO": "Faroe Islands",
+ "FJ": "Fiji",
+ "FI": "Finland",
+ "FR": "France",
+ "GF": "French Guiana",
+ "PF": "French Polynesia",
+ "TF": "French Southern Territories",
+ "GA": "Gabon",
+ "GM": "Gambia",
+ "GE": "Georgia",
+ "DE": "Germany",
+ "GH": "Ghana",
+ "GI": "Gibraltar",
+ "GR": "Greece",
+ "GL": "Greenland",
+ "GD": "Grenada",
+ "GP": "Guadeloupe",
+ "GU": "Guam",
+ "GT": "Guatemala",
+ "GG": "Guernsey",
+ "GN": "Guinea",
+ "GW": "Guinea-Bissau",
+ "GY": "Guyana",
+ "HT": "Haiti",
+ "HM": "Heard Island and McDonald Islands",
+ "VA": "Holy See (Vatican City State)",
+ "HN": "Honduras",
+ "HK": "Hong Kong",
+ "HU": "Hungary",
+ "IS": "Iceland",
+ "IN": "India",
+ "ID": "Indonesia",
+ "IR": "Iran, Islamic Republic of",
+ "IQ": "Iraq",
+ "IE": "Ireland",
+ "IM": "Isle of Man",
+ "IL": "Israel",
+ "IT": "Italy",
+ "JM": "Jamaica",
+ "JP": "Japan",
+ "JE": "Jersey",
+ "JO": "Jordan",
+ "KZ": "Kazakhstan",
+ "KE": "Kenya",
+ "KI": "Kiribati",
+ "KP": "Korea, Democratic People\"s Republic of",
+ "KR": "Korea, Republic of",
+ "KW": "Kuwait",
+ "KG": "Kyrgyzstan",
+ "LA": "Lao People\"s Democratic Republic",
+ "LV": "Latvia",
+ "LB": "Lebanon",
+ "LS": "Lesotho",
+ "LR": "Liberia",
+ "LY": "Libya",
+ "LI": "Liechtenstein",
+ "LT": "Lithuania",
+ "LU": "Luxembourg",
+ "MO": "Macao",
+ "MK": "Macedonia, the former Yugoslav Republic of",
+ "MG": "Madagascar",
+ "MW": "Malawi",
+ "MY": "Malaysia",
+ "MV": "Maldives",
+ "ML": "Mali",
+ "MT": "Malta",
+ "MH": "Marshall Islands",
+ "MQ": "Martinique",
+ "MR": "Mauritania",
+ "MU": "Mauritius",
+ "YT": "Mayotte",
+ "MX": "Mexico",
+ "FM": "Micronesia, Federated States of",
+ "MD": "Moldova, Republic of",
+ "MC": "Monaco",
+ "MN": "Mongolia",
+ "ME": "Montenegro",
+ "MS": "Montserrat",
+ "MA": "Morocco",
+ "MZ": "Mozambique",
+ "MM": "Myanmar",
+ "NA": "Namibia",
+ "NR": "Nauru",
+ "NP": "Nepal",
+ "NL": "Netherlands",
+ "NC": "New Caledonia",
+ "NZ": "New Zealand",
+ "NI": "Nicaragua",
+ "NE": "Niger",
+ "NG": "Nigeria",
+ "NU": "Niue",
+ "NF": "Norfolk Island",
+ "MP": "Northern Mariana Islands",
+ "NO": "Norway",
+ "OM": "Oman",
+ "PK": "Pakistan",
+ "PW": "Palau",
+ "PS": "Palestinian Territory, Occupied",
+ "PA": "Panama",
+ "PG": "Papua New Guinea",
+ "PY": "Paraguay",
+ "PE": "Peru",
+ "PH": "Philippines",
+ "PN": "Pitcairn",
+ "PL": "Poland",
+ "PT": "Portugal",
+ "PR": "Puerto Rico",
+ "QA": "Qatar",
+ "RE": "R" + "é" + "union",
+ "RO": "Romania",
+ "RU": "Russian Federation",
+ "RW": "Rwanda",
+ "SH": "Saint Helena, Ascension and Tristan da Cunha",
+ "KN": "Saint Kitts and Nevis",
+ "LC": "Saint Lucia",
+ "MF": "Saint Martin (French part)",
+ "PM": "Saint Pierre and Miquelon",
+ "VC": "Saint Vincent and the Grenadines",
+ "WS": "Samoa",
+ "SM": "San Marino",
+ "ST": "Sao Tome and Principe",
+ "SA": "Saudi Arabia",
+ "SN": "Senegal",
+ "RS": "Serbia",
+ "SC": "Seychelles",
+ "SL": "Sierra Leone",
+ "SG": "Singapore",
+ "SX": "Sint Maarten (Dutch part)",
+ "SK": "Slovakia",
+ "SI": "Slovenia",
+ "SB": "Solomon Islands",
+ "SO": "Somalia",
+ "ZA": "South Africa",
+ "GS": "South Georgia and the South Sandwich Islands",
+ "SS": "South Sudan",
+ "ES": "Spain",
+ "LK": "Sri Lanka",
+ "SD": "Sudan",
+ "SR": "Suriname",
+ "SZ": "Swaziland",
+ "SE": "Sweden",
+ "CH": "Switzerland",
+ "SY": "Syrian Arab Republic",
+ "TW": "Taiwan, Province of China",
+ "TJ": "Tajikistan",
+ "TZ": "Tanzania, United Republic of",
+ "TH": "Thailand",
+ "TL": "Timor-Leste",
+ "TG": "Togo",
+ "TK": "Tokelau",
+ "TO": "Tonga",
+ "TT": "Trinidad and Tobago",
+ "TN": "Tunisia",
+ "TR": "Turkey",
+ "TM": "Turkmenistan",
+ "TC": "Turks and Caicos Islands",
+ "TV": "Tuvalu",
+ "UG": "Uganda",
+ "UA": "Ukraine",
+ "AE": "United Arab Emirates",
+ "GB": "United Kingdom",
+ "US": "United States",
+ "UM": "United States Minor Outlying Islands",
+ "UY": "Uruguay",
+ "UZ": "Uzbekistan",
+ "VU": "Vanuatu",
+ "VE": "Venezuela, Bolivarian Republic of",
+ "VN": "Viet Nam",
+ "VG": "Virgin Islands, British",
+ "VI": "Virgin Islands, U.S.",
+ "WF": "Wallis and Futuna",
+ "EH": "Western Sahara",
+ "YE": "Yemen",
+ "ZM": "Zambia",
+ "ZW": "Zimbabwe"
+ };
+
+ $.flagStrap = function (element, options) {
+
+ var plugin = this;
+
+ var uniqueId = generateId(8);
+
+ plugin.countries = {};
+ plugin.selected = {value: null, text: null};
+ plugin.settings = {inputName: "country-" + uniqueId};
+
+ var $container = $(element);
+ var htmlSelectId = "flagstrap-" + uniqueId;
+ var htmlSelect = "#" + htmlSelectId;
+
+ plugin.init = function () {
+
+ // Merge in global settings then merge in individual settings via data attributes
+ plugin.countries = countries;
+
+ // Initialize Settings, priority: defaults, init options, data attributes
+ plugin.settings = $.extend({}, defaults, options, $container.data());
+
+ if (undefined !== plugin.settings.countries) {
+ plugin.countries = plugin.settings.countries;
+ }
+
+ if (undefined !== plugin.settings.inputId) {
+ htmlSelectId = plugin.settings.inputId;
+ htmlSelect = "#" + htmlSelectId;
+ }
+
+ // Build HTML Select, Construct the drop down button, Assemble the drop down list items element and insert
+ $container
+ .addClass("flagstrap")
+ .append(buildHtmlSelect)
+ .append(buildDropDownButton)
+ .append(buildDropDownButtonItemList);
+
+ // Check to see if the onSelect callback method is assigned / callable, bind the change event for broadcast
+ if (plugin.settings.onSelect !== undefined && plugin.settings.onSelect instanceof Function) {
+ // $(htmlSelect).change(function (event) {
+ $(htmlSelect).change(function () {
+ var element = this;
+ options.onSelect($(element).val(), element);
+ });
+ }
+
+ // Hide the actual HTML select
+ $(htmlSelect).hide();
+ };
+
+ var buildHtmlSelect = function () {
+ var htmlSelectElement = $(" ").attr("id", htmlSelectId).attr("name", plugin.settings.inputName);
+
+ // check if countries is an array instead
+ if ($.isArray(plugin.countries)) {
+ var key, value, cObj, cObjKeys, optionAttributes;
+
+ // loop through each item in the countries array
+ for(var i=0; i", optionAttributes).text(value));
+ }
+ } else {
+ $.each(plugin.countries, function (code, country) {
+ var optionAttributes = {value: code};
+ if (plugin.settings.selectedCountry !== undefined) {
+ if (plugin.settings.selectedCountry === code) {
+ optionAttributes = {value: code, selected: "selected"};
+ plugin.selected = {value: code, text: country};
+ }
+ }
+ htmlSelectElement.append($("", optionAttributes).text(country));
+ });
+ }
+
+ if (plugin.settings.placeholder !== false) {
+ htmlSelectElement.prepend($(" ", {
+ value: plugin.settings.placeholder.value,
+ text: plugin.settings.placeholder.text
+ }));
+ }
+
+ return htmlSelectElement;
+ };
+
+ var buildDropDownButton = function () {
+
+ var selectedText = $(htmlSelect).find("option").first().text();
+ var selectedValue = $(htmlSelect).find("option").first().val();
+ var $selectedLabel;
+
+ selectedText = plugin.selected.text || selectedText;
+ selectedValue = plugin.selected.value || selectedValue;
+
+ if (selectedValue !== plugin.settings.placeholder.value) {
+ $selectedLabel = $(" ").addClass("flagstrap-icon flagstrap-" + selectedValue.toLowerCase()).css("margin-right", plugin.settings.labelMargin);
+ } else {
+ $selectedLabel = $(" ").addClass("flagstrap-icon flagstrap-placeholder");
+ }
+
+ var buttonLabel = $(" ")
+ .addClass("flagstrap-selected-" + uniqueId)
+ .html($selectedLabel)
+ .append(selectedText);
+
+ var button = $(" ")
+ .attr("type", "button")
+ .attr("data-toggle", "dropdown")
+ .attr("id", "flagstrap-drop-down-" + uniqueId)
+ .addClass("btn " + plugin.settings.buttonType + " " + plugin.settings.buttonSize + " dropdown-toggle")
+ .html(buttonLabel);
+
+ $(" ")
+ .addClass("caret")
+ .css("margin-left", plugin.settings.labelMargin)
+ .insertAfter(buttonLabel);
+
+ return button;
+
+ };
+
+ var buildDropDownButtonItemList = function () {
+ var items = $("")
+ .attr("id", "flagstrap-drop-down-" + uniqueId + "-list")
+ .attr("aria-labelled-by", "flagstrap-drop-down-" + uniqueId)
+ .addClass("dropdown-menu");
+
+ if (plugin.settings.scrollable) {
+ items.css("height", "auto")
+ .css("max-height", plugin.settings.scrollableHeight)
+ .css("overflow-x", "hidden");
+ }
+
+ // Populate the bootstrap dropdown item list
+ $(htmlSelect).find("option").each(function () {
+
+ // Get original select option values and labels
+ var text = $(this).text();
+ var value = $(this).val();
+ var flagIcon;
+
+ // Build the flag icon
+ if (value !== plugin.settings.placeholder.value) {
+ flagIcon = $(" ").addClass("flagstrap-icon flagstrap-" + value.toLowerCase()).css("margin-right", plugin.settings.labelMargin);
+ } else {
+ flagIcon = null;
+ }
+
+
+ // Build a clickable drop down option item, insert the flag and label, attach click event
+ var flagStrapItem = $(" ")
+ .attr("data-val", $(this).val())
+ .html(flagIcon)
+ .append(text)
+ .on("click", function (e) {
+ $(htmlSelect).find("option").removeAttr("selected");
+ $(htmlSelect).find("option[value=\"" + $(this).data("val") + "\"]").attr("selected", "selected");
+ $(htmlSelect).trigger("change");
+ $(".flagstrap-selected-" + uniqueId).html($(this).html());
+ e.preventDefault();
+ });
+
+ // Make it a list item
+ var listItem = $(" ").prepend(flagStrapItem);
+
+ // Append it to the drop down item list
+ items.append(listItem);
+
+ });
+
+ return items;
+ };
+
+ function generateId(length) {
+ var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz".split("");
+
+ if (!length) {
+ length = Math.floor(Math.random() * chars.length);
+ }
+
+ var str = "";
+ for (var i = 0; i < length; i++) {
+ str += chars[Math.floor(Math.random() * chars.length)];
+ }
+ return str;
+ }
+
+ plugin.init();
+
+ };
+
+ $.fn.flagStrap = function (options) {
+
+ return this.each(function (i) {
+ if ($(this).data("flagStrap") === undefined) {
+ $(this).data("flagStrap", new $.flagStrap(this, options, i));
+ }
+ });
+
+ };
+
+})(jQuery);