XWWitPark/witpark_jzzs/xw_jzzs_web/public/lib/city-picker/city-picker.js

2 lines
10 KiB
JavaScript
Raw Normal View History

2024-09-12 00:10:00 +00:00
/* 2020-9-22 15:23:27 | 版权所有 军懋国兴 */
function _typeof(t){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}!function(t){"function"==typeof define&&define.amd?define(["jquery","ChineseDistricts"],t):"object"===("undefined"==typeof exports?"undefined":_typeof(exports))?t(require("jquery"),require("ChineseDistricts")):t(jQuery,ChineseDistricts)}(function(a,h){"use strict";if(void 0===h)throw new Error('The file "city-picker.data.js" must be included first!');var o="citypicker",s="change."+o,l="province",p="city",u="district";function d(t,e){this.$element=a(t),this.$dropdown=null,this.options=a.extend({},d.DEFAULTS,a.isPlainObject(e)&&e),this.active=!1,this.dems=[],this.needBlur=!1,this.init()}d.prototype={constructor:d,init:function(){this.codeRender(),this.defineDems(),this.render(),this.bind(),this.active=!0},codeRender:function(){var t=this.$element.attr("code");void 0===t||""===t||isNaN(Number(t))||this.$element.val(a.fn.citypicker.getAddressbyCodeId(t))},render:function(){var t=this.getPosition(),e=this.$element.attr("placeholder")||this.options.placeholder,i='<span class="city-picker-span" style="'+this.getWidthStyle(t.width)+"height:"+t.height+"px;line-height:"+(t.height-1)+'px;">'+(e?'<span class="placeholder">'+e+"</span>":"")+'<span class="title"></span><div class="arrow"></div></span>',s='<div class="city-picker-dropdown" style="left:0px;top:100%;'+this.getWidthStyle(t.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=a(i).insertAfter(this.$element),this.$dropdown=a(s).insertAfter(this.$textspan);var n=this.$dropdown.find(".city-select");a.each(this.dems,a.proxy(function(t,e){this["$"+e]=n.filter("."+e)},this)),this.refresh()},refresh:function(i){this.$dropdown.find(".city-select").data("item",null);var s=(s=this.$element.val()||"").split("/");a.each(this.dems,a.proxy(function(t,e){s[t]&&t<s.length?this.options[e]=s[t]:i&&(this.options[e]=""),this.output(e)},this)),this.tab(l),this.feedText(),this.feedVal()},defineDems:function(){var i=!1;a.each([l,p,u],a.proxy(function(t,e){i||this.dems.push(e),e===this.options.level&&(i=!0)},this))},includeDem:function(t){return-1!==a.inArray(t,this.dems)},getPosition:function(){var t,e=this.$element.position(),i=this.getSize(this.$element),s=i.height,n=i.width;return this.options.responsive&&(t=this.$element.offsetParent().width())&&(.99<(n/=t)&&(n=1),n=100*n+"%"),{top:e.top||0,left:e.left||0,height:s,width:n}},getSize:function(t){var e,i,s;return t.is(":visible")?s={width:t.outerWidth(),height:t.outerHeight()}:((e=a("<div />").appendTo(a("body"))).css({position:"absolute !important",visibility:"hidden !important",display:"block !important"}),s={width:(i=t.clone().appendTo(e)).outerWidth(),height:i.outerHeight()},e.remove()),s},getWidthStyle:function(t,e){return this.options.responsive&&!a.isNumeric(t)?"width:"+t+";":"width:"+(e?Math.max(320,t):t)+"px;"},bind:function(){var c=this;a(document).on("click",this._mouteclick=function(t){var e,i,s,n=a(t.target);n.is(".city-picker-span")?i=n:n.is(".city-picker-span *")&&(i=n.parents(".city-picker-span")),n.is(".city-picker-input")&&(s=n),n.is(".city-picker-dropdown")?e=n:n.is(".city-picker-dropdown *")&&(e=n.parents(".city-picker-dropdown")),(!s&&!i&&!e||i&&i.get(0)!==c.$textspan.get(0)||s&&s.get(0)!==c.$element.get(0)||e&&e.get(0)!==c.$dropdown.get(0))&&c.close(!0)}),this.$element.on("change",this._changeElement=a.proxy(function(){this.close