You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

10 lines
10 KiB

11 months ago
/*!
* CityPicker v1.2.0
* https://github.com/tshi0912/citypicker
*
* Copyright (c) 2015-2018 Tao Shi
* Released under the MIT license
*
* Date: 2018-04-12T04:27:10.483Z
*/
!function(t){"function"==typeof define&&define.amd?define(["jquery","ChineseDistricts"],t):"object"==typeof exports?t(require("jquery"),require("ChineseDistricts")):t(jQuery,ChineseDistricts)}(function(t,e){"use strict";function i(e,s){this.$element=t(e),this.$dropdown=null,this.options=t.extend({},i.DEFAULTS,t.isPlainObject(s)&&s),this.active=!1,this.dems=[],this.needBlur=!1,this.init()}if("undefined"==typeof e)throw new Error('The file "city-picker.data.js" must be included first!');var s="citypicker",n="change."+s,c="province",o="city",d="district";i.prototype={constructor:i,init:function(){this.codeRender(),this.defineDems(),this.render(),this.bind(),this.active=!0},codeRender:function(){var e=this.$element.attr("code");void 0===e||""===e||isNaN(Number(e))||this.$element.val(t.fn.citypicker.getAddressbyCodeId(e))},render:function(){var e=this.getPosition(),i=this.$element.attr("placeholder")||this.options.placeholder,s='<span class="city-picker-span" style="'+this.getWidthStyle(e.width)+"height:"+e.height+"px;line-height:"+(e.height-1)+'px;">'+(i?'<span class="placeholder">'+i+"</span>":"")+'<span class="title"></span><div class="arrow"></div></span>',n='<div class="city-picker-dropdown" style="left:0px;top:100%;'+this.getWidthStyle(e.width,!0)+'"><div class="city-select-wrap"><div class="city-select-tab"><a class="active" data-count="province">省份</a>'+(this.includeDem("city")?'<a data-count="city">城市</a>':"")+(this.includeDem("district")?'<a data-count="district">区县</a>':"")+'</div><div class="city-select-content"><div class="city-select province" data-count="province"></div>'+(this.includeDem("city")?'<div class="city-select city" data-count="city"></div>':"")+(this.includeDem("district")?'<div class="city-select district" data-count="district"></div>':"")+"</div></div>";this.$element.addClass("city-picker-input"),this.$textspan=t(s).insertAfter(this.$element),this.$dropdown=t(n).insertAfter(this.$textspan);var c=this.$dropdown.find(".city-select");t.each(this.dems,t.proxy(function(t,e){this["$"+e]=c.filter("."+e)},this)),this.refresh()},refresh:function(e){var i=this.$dropdown.find(".city-select");i.data("item",null);var s=this.$element.val()||"";s=s.split("/"),t.each(this.dems,t.proxy(function(t,i){s[t]&&t<s.length?this.options[i]=s[t]:e&&(this.options[i]=""),this.output(i)},this)),this.tab(c),this.feedText(),this.feedVal()},defineDems:function(){var e=!1;t.each([c,o,d],t.proxy(function(t,i){e||this.dems.push(i),i===this.options.level&&(e=!0)},this))},includeDem:function(e){return t.inArray(e,this.dems)!==-1},getPosition:function(){var t,e,i,s,n;return t=this.$element.position(),s=this.getSize(this.$element),e=s.height,i=s.width,this.options.responsive&&(n=this.$element.offsetParent().width(),n&&(i/=n,i>.99&&(i=1),i=100*i+"%")),{top:t.top||0,left:t.left||0,height:e,width:i}},getSize:function(e){var i,s,n;return e.is(":visible")?n={width:e.outerWidth(),height:e.outerHeight()}:(i=t("<div />").appendTo(t("body")),i.css({position:"absolute !important",visibility:"hidden !important",display:"block !important"}),s=e.clone().appendTo(i),n={width:s.outerWidth(),height:s.outerHeight()},i.remove()),n},getWidthStyle:function(e,i){return this.options.responsive&&!t.isNumeric(e)?"width:"+e+";":"width:"+(i?Math.max(320,e):e)+"px;"},bind:function(){var e=this;t(document).on("click",this._mouteclick=function(i){var s,n,c,o=t(i.target);o.is(".city-picker-span")?n=o:o.is(".city-picker-span *")&&(n=o.parents(".city-picker-span")),o.is(".city-picker-input")&&(c=o),o.is(".city-picker-dropdown")?s=o:o.is(".city-picker-dropdown *")&&(s=o.parents(".city-picker-dropdown")),(!c&&!n&&!s||n&&n.get(0)!==e.$textspan.get(0)||c&&c.get(0)!==e.$element.get(0)||s&&s.get(0)!==e.$dropdown.get(0))&&e.close(!0)}),this.$element.on("change",this._changeElement=t.proxy(function(){this.close(!0),this.refresh(!0)},this)).on("focus",this._focusElement=t.proxy(function(){this.needBlur=!0,this.open()},this)).on("blur",this._blurElement=t.proxy(function(){this.needBlur&&(this.needBlur=!1,this.close(!0))},this)),this.$textspan.on("click",function(i