-
Distpicker v2.0.7
+
Distpicker v2.0.8
A simple jQuery plugin for picking provinces, cities and districts of China.
diff --git a/docs/js/distpicker.js b/docs/js/distpicker.js
index abd8391..16b6c21 100644
--- a/docs/js/distpicker.js
+++ b/docs/js/distpicker.js
@@ -1,35 +1,46 @@
-/*! Distpicker v2.0.7 | (c) 2014-present Chen Fengyuan | MIT */
+/*! Distpicker v2.0.8 | (c) 2014-present Chen Fengyuan | MIT */
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('jquery')) :
typeof define === 'function' && define.amd ? define(['jquery'], factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.jQuery));
-}(this, (function ($) { 'use strict';
-
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
-
- var $__default = /*#__PURE__*/_interopDefaultLegacy($);
+})(this, (function ($) { 'use strict';
function _classCallCheck(instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
}
-
function _defineProperties(target, props) {
for (var i = 0; i < props.length; i++) {
var descriptor = props[i];
descriptor.enumerable = descriptor.enumerable || false;
descriptor.configurable = true;
if ("value" in descriptor) descriptor.writable = true;
- Object.defineProperty(target, descriptor.key, descriptor);
+ Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor);
}
}
-
function _createClass(Constructor, protoProps, staticProps) {
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
if (staticProps) _defineProperties(Constructor, staticProps);
+ Object.defineProperty(Constructor, "prototype", {
+ writable: false
+ });
return Constructor;
}
+ function _toPrimitive(input, hint) {
+ if (typeof input !== "object" || input === null) return input;
+ var prim = input[Symbol.toPrimitive];
+ if (prim !== undefined) {
+ var res = prim.call(input, hint || "default");
+ if (typeof res !== "object") return res;
+ throw new TypeError("@@toPrimitive must return a primitive value.");
+ }
+ return (hint === "string" ? String : Number)(input);
+ }
+ function _toPropertyKey(arg) {
+ var key = _toPrimitive(arg, "string");
+ return typeof key === "symbol" ? key : String(key);
+ }
var DEFAULTS = {
// Selects the districts automatically.
@@ -228,7 +239,6 @@
130533: '威县',
130534: '清河县',
130535: '临西县',
- 130571: '河北邢台经济开发区',
130581: '南宫市',
130582: '沙河市'
},
@@ -1105,19 +1115,18 @@
320507: '相城区',
320508: '姑苏区',
320509: '吴江区',
- 320571: '苏州工业园区',
320581: '常熟市',
320582: '张家港市',
320583: '昆山市',
320585: '太仓市'
},
320600: {
- 320602: '崇川区',
320612: '通州区',
+ 320613: '崇川区',
+ 320614: '海门区',
320623: '如东县',
320681: '启东市',
320682: '如皋市',
- 320684: '海门区',
320685: '海安市'
},
320700: {
@@ -1194,8 +1203,6 @@
},
330100: {
330102: '上城区',
- 330103: '下城区',
- 330104: '江干区',
330105: '拱墅区',
330106: '西湖区',
330108: '滨江区',
@@ -1203,6 +1210,8 @@
330110: '余杭区',
330111: '富阳区',
330112: '临安区',
+ 330113: '临平区',
+ 330114: '钱塘区',
330122: '桐庐县',
330127: '淳安县',
330182: '建德市'
@@ -1335,10 +1344,10 @@
},
340200: {
340202: '镜湖区',
- 340203: '弋江区',
340207: '鸠江区',
- 340221: '湾沚区',
- 340222: '繁昌区',
+ 340209: '弋江区',
+ 340210: '湾沚区',
+ 340212: '繁昌区',
340223: '南陵县',
340281: '无为市'
},
@@ -1500,14 +1509,13 @@
350322: '仙游县'
},
350400: {
- 350402: '梅列区',
- 350403: '三元区',
+ 350404: '三元区',
+ 350405: '沙县区',
350421: '明溪县',
350423: '清流县',
350424: '宁化县',
350425: '大田县',
350426: '尤溪县',
- 350427: '沙县',
350428: '将乐县',
350429: '泰宁县',
350430: '建宁县',
@@ -1530,15 +1538,15 @@
350600: {
350602: '芗城区',
350603: '龙文区',
+ 350604: '龙海区',
+ 350605: '长泰区',
350622: '云霄县',
350623: '漳浦县',
350624: '诏安县',
- 350625: '长泰县',
350626: '东山县',
350627: '南靖县',
350628: '平和县',
- 350629: '华安县',
- 350681: '龙海市'
+ 350629: '华安县'
},
350700: {
350702: '延平区',
@@ -1943,17 +1951,16 @@
410303: '西工区',
410304: '瀍河回族区',
410305: '涧西区',
- 410306: '吉利区',
+ 410307: '偃师区',
+ 410308: '孟津区',
410311: '洛龙区',
- 410322: '孟津县',
410323: '新安县',
410324: '栾川县',
410325: '嵩县',
410326: '汝阳县',
410327: '宜阳县',
410328: '洛宁县',
- 410329: '伊川县',
- 410381: '偃师市'
+ 410329: '伊川县'
},
410400: {
410402: '新华区',
@@ -2210,11 +2217,11 @@
421002: '沙市区',
421003: '荆州区',
421022: '公安县',
- 421023: '监利市',
421024: '江陵县',
421081: '石首市',
421083: '洪湖市',
- 421087: '松滋市'
+ 421087: '松滋市',
+ 421088: '监利市'
},
421100: {
421102: '黄州区',
@@ -2388,7 +2395,6 @@
431100: {
431102: '零陵区',
431103: '冷水滩区',
- 431121: '祁阳县',
431122: '东安县',
431123: '双牌县',
431124: '道县',
@@ -2396,7 +2402,8 @@
431126: '宁远县',
431127: '蓝山县',
431128: '新田县',
- 431129: '江华瑶族自治县'
+ 431129: '江华瑶族自治县',
+ 431181: '祁阳市'
},
431200: {
431202: '鹤城区',
@@ -2646,7 +2653,7 @@
450124: '马山县',
450125: '上林县',
450126: '宾阳县',
- 450127: '横县'
+ 450181: '横州市'
},
450200: {
450202: '城中区',
@@ -3135,10 +3142,10 @@
},
513400: {
513401: '西昌市',
+ 513402: '会理市',
513422: '木里藏族自治县',
513423: '盐源县',
513424: '德昌县',
- 513425: '会理县',
513426: '会东县',
513427: '宁南县',
513428: '普格县',
@@ -3178,7 +3185,7 @@
520200: {
520201: '钟山区',
520203: '六枝特区',
- 520221: '水城区',
+ 520204: '水城区',
520281: '盘州市'
},
520300: {
@@ -3208,12 +3215,12 @@
520500: {
520502: '七星关区',
520521: '大方县',
- 520522: '黔西县',
520523: '金沙县',
520524: '织金县',
520525: '纳雍县',
520526: '威宁彝族回族苗族自治县',
- 520527: '赫章县'
+ 520527: '赫章县',
+ 520581: '黔西市'
},
520600: {
520602: '碧江区',
@@ -3376,6 +3383,7 @@
},
532300: {
532301: '楚雄市',
+ 532302: '禄丰市',
532322: '双柏县',
532323: '牟定县',
532324: '南华县',
@@ -3383,8 +3391,7 @@
532326: '大姚县',
532327: '永仁县',
532328: '元谋县',
- 532329: '武定县',
- 532331: '禄丰县'
+ 532329: '武定县'
},
532500: {
532501: '个旧市',
@@ -3582,7 +3589,7 @@
610302: '渭滨区',
610303: '金台区',
610304: '陈仓区',
- 610322: '凤翔县',
+ 610305: '凤翔区',
610323: '岐山县',
610324: '扶风县',
610326: '眉县',
@@ -3672,8 +3679,8 @@
610925: '岚皋县',
610926: '平利县',
610927: '镇坪县',
- 610928: '旬阳县',
- 610929: '白河县'
+ 610929: '白河县',
+ 610981: '旬阳市'
},
611000: {
611002: '商州区',
@@ -3949,7 +3956,8 @@
659007: '双河市',
659008: '可克达拉市',
659009: '昆玉市',
- 659010: '胡杨河市'
+ 659010: '胡杨河市',
+ 659011: '新星市'
},
650100: {
650102: '天山区',
@@ -4060,8 +4068,8 @@
654200: {
654201: '塔城市',
654202: '乌苏市',
+ 654203: '沙湾市',
654221: '额敏县',
- 654223: '沙湾县',
654224: '托里县',
654225: '裕民县',
654226: '和布克赛尔蒙古自治县'
@@ -4105,6 +4113,9 @@
659010: {
659010: '胡杨河市'
},
+ 659011: {
+ 659011: '新星市'
+ },
810000: {
810100: '香港城区'
},
@@ -4151,31 +4162,27 @@
var PROVINCE = 'province';
var CITY = 'city';
var DISTRICT = 'district';
-
var Distpicker = /*#__PURE__*/function () {
function Distpicker(element, options) {
_classCallCheck(this, Distpicker);
-
- this.$element = $__default['default'](element);
- this.options = $__default['default'].extend({}, DEFAULTS, $__default['default'].isPlainObject(options) && options);
- this.placeholders = $__default['default'].extend({}, DEFAULTS);
+ this.$element = $(element);
+ this.options = $.extend({}, DEFAULTS, $.isPlainObject(options) && options);
+ this.placeholders = $.extend({}, DEFAULTS);
this.ready = false;
this.init();
}
-
_createClass(Distpicker, [{
key: "init",
value: function init() {
var _this = this;
-
var options = this.options;
var $selects = this.$element.find('select');
var length = $selects.length;
var data = {};
$selects.each(function (i, select) {
- return $__default['default'].extend(data, $__default['default'](select).data());
+ return $.extend(data, $(select).data());
});
- $__default['default'].each([PROVINCE, CITY, DISTRICT], function (i, type) {
+ $.each([PROVINCE, CITY, DISTRICT], function (i, type) {
if (data[type]) {
options[type] = data[type];
_this["$".concat(type)] = $selects.filter("[data-".concat(type, "]"));
@@ -4183,8 +4190,9 @@
_this["$".concat(type)] = length > i ? $selects.eq(i) : null;
}
});
- this.bind(); // Reset all the selects (after event binding)
+ this.bind();
+ // Reset all the selects (after event binding)
this.reset();
this.ready = true;
}
@@ -4192,17 +4200,14 @@
key: "bind",
value: function bind() {
var _this2 = this;
-
if (this.$province) {
- this.$province.on(EVENT_CHANGE, this.onChangeProvince = $__default['default'].proxy(function () {
+ this.$province.on(EVENT_CHANGE, this.onChangeProvince = $.proxy(function () {
_this2.output(CITY);
-
_this2.output(DISTRICT, true);
}, this));
}
-
if (this.$city) {
- this.$city.on(EVENT_CHANGE, this.onChangeCity = $__default['default'].proxy(function () {
+ this.$city.on(EVENT_CHANGE, this.onChangeCity = $.proxy(function () {
return _this2.output(DISTRICT, true);
}, this));
}
@@ -4213,7 +4218,6 @@
if (this.$province) {
this.$province.off(EVENT_CHANGE, this.onChangeProvince);
}
-
if (this.$city) {
this.$city.off(EVENT_CHANGE, this.onChangeCity);
}
@@ -4223,42 +4227,33 @@
value: function output(type) {
var triggerEvent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
var options = this.options,
- placeholders = this.placeholders;
+ placeholders = this.placeholders;
var $select = this["$".concat(type)];
-
if (!$select || !$select.length) {
return;
}
-
var code;
-
switch (type) {
case PROVINCE:
code = DEFAULT_CODE;
break;
-
case CITY:
code = this.$province && (this.$province.find(':selected').data('code') || '');
break;
-
case DISTRICT:
code = this.$city && (this.$city.find(':selected').data('code') || '');
break;
}
-
var districts = this.getDistricts(code);
var value = options[type];
var data = [];
var matched = false;
-
- if ($__default['default'].isPlainObject(districts)) {
- $__default['default'].each(districts, function (i, name) {
+ if ($.isPlainObject(districts)) {
+ $.each(districts, function (i, name) {
var selected = name === value || i === String(value);
-
if (selected) {
matched = true;
}
-
data.push({
name: name,
selected: selected,
@@ -4267,21 +4262,19 @@
});
});
}
-
if (!matched) {
var autoselect = options.autoselect || options.autoSelect;
-
if (data.length && (type === PROVINCE && autoselect > 0 || type === CITY && autoselect > 1 || type === DISTRICT && autoselect > 2)) {
data[0].selected = true;
- } // Save the unmatched value as a placeholder at the first output
-
+ }
+ // Save the unmatched value as a placeholder at the first output
if (!this.ready && value) {
placeholders[type] = value;
}
- } // Add placeholder option
-
+ }
+ // Add placeholder option
if (options.placeholder) {
data.unshift({
code: '',
@@ -4290,34 +4283,32 @@
selected: false
});
}
-
if (data.length) {
$select.html(this.getList(data));
} else {
$select.empty();
}
-
if (triggerEvent) {
$select.trigger(EVENT_CHANGE);
}
- } // eslint-disable-next-line class-methods-use-this
+ }
+ // eslint-disable-next-line class-methods-use-this
}, {
key: "getList",
value: function getList(data) {
var list = [];
- $__default['default'].each(data, function (i, n) {
+ $.each(data, function (i, n) {
var attrs = ["data-code=\"".concat(n.code, "\""), "data-text=\"".concat(n.name, "\""), "value=\"".concat(n.value, "\"")];
-
if (n.selected) {
attrs.push('selected');
}
-
list.push(""));
});
return list.join('');
- } // eslint-disable-next-line class-methods-use-this
+ }
+ // eslint-disable-next-line class-methods-use-this
}, {
key: "getDistricts",
value: function getDistricts() {
@@ -4343,43 +4334,35 @@
}], [{
key: "setDefaults",
value: function setDefaults(options) {
- $__default['default'].extend(DEFAULTS, $__default['default'].isPlainObject(options) && options);
+ $.extend(DEFAULTS, $.isPlainObject(options) && options);
}
}]);
-
return Distpicker;
}();
- if ($__default['default'].fn) {
- var AnotherDistpicker = $__default['default'].fn.distpicker;
-
- $__default['default'].fn.distpicker = function jQueryDistpicker(option) {
+ if ($.fn) {
+ var AnotherDistpicker = $.fn.distpicker;
+ $.fn.distpicker = function jQueryDistpicker(option) {
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
args[_key - 1] = arguments[_key];
}
-
var result;
this.each(function (i, element) {
- var $element = $__default['default'](element);
+ var $element = $(element);
var isDestroy = option === 'destroy';
var distpicker = $element.data(NAMESPACE);
-
if (!distpicker) {
if (isDestroy) {
return;
}
-
- var options = $__default['default'].extend({}, $element.data(), $__default['default'].isPlainObject(option) && option);
+ var options = $.extend({}, $element.data(), $.isPlainObject(option) && option);
distpicker = new Distpicker(element, options);
$element.data(NAMESPACE, distpicker);
}
-
if (typeof option === 'string') {
var fn = distpicker[option];
-
- if ($__default['default'].isFunction(fn)) {
+ if ($.isFunction(fn)) {
result = fn.apply(distpicker, args);
-
if (isDestroy) {
$element.removeData(NAMESPACE);
}
@@ -4388,20 +4371,17 @@
});
return typeof result === 'undefined' ? this : result;
};
-
- $__default['default'].fn.distpicker.Constructor = Distpicker;
- $__default['default'].fn.distpicker.setDefaults = Distpicker.setDefaults;
-
- $__default['default'].fn.distpicker.noConflict = function noConflict() {
- $__default['default'].fn.distpicker = AnotherDistpicker;
+ $.fn.distpicker.Constructor = Distpicker;
+ $.fn.distpicker.setDefaults = Distpicker.setDefaults;
+ $.fn.distpicker.noConflict = function noConflict() {
+ $.fn.distpicker = AnotherDistpicker;
return this;
};
}
-
if (WINDOW.document) {
- $__default['default'](function () {
- $__default['default']("[data-toggle=\"".concat(NAMESPACE, "\"]")).distpicker();
+ $(function () {
+ $("[data-toggle=\"".concat(NAMESPACE, "\"]")).distpicker();
});
}
-})));
+}));
diff --git a/package-lock.json b/package-lock.json
index f283645..d9d0132 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "distpicker",
- "version": "2.0.7",
+ "version": "2.0.8",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "distpicker",
- "version": "2.0.7",
+ "version": "2.0.8",
"license": "MIT",
"devDependencies": {
"@babel/core": "^7.20.7",
diff --git a/package.json b/package.json
index eeaf481..1102679 100644
--- a/package.json
+++ b/package.json
@@ -1,7 +1,7 @@
{
"name": "distpicker",
"description": "A simple jQuery plugin for picking provinces, cities and districts of China.",
- "version": "2.0.7",
+ "version": "2.0.8",
"main": "dist/distpicker.common.js",
"module": "dist/distpicker.esm.js",
"browser": "dist/distpicker.js",
diff --git a/src/districts.js b/src/districts.js
index cfdf960..a707f51 100644
--- a/src/districts.js
+++ b/src/districts.js
@@ -4088,5 +4088,5 @@ export default {
820106: '嘉模堂区',
820107: '路凼填海区',
820108: '圣方济各堂区',
- }
+ },
};