multiple-select
Version:
Multiple select is a jQuery plugin to select multiple elements with checkboxes :).
11 lines (9 loc) • 4.32 kB
JavaScript
/**
* multiple-select - Multiple select is a jQuery plugin to select multiple elements with checkboxes :).
*
* @version v1.7.0
* @homepage http://multiple-select.wenzhixin.net.cn
* @author wenzhixin <wenzhixin2010@gmail.com> (http://wenzhixin.net.cn/)
* @license MIT
*/
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).MultipleSelect=t()}(this,(function(){"use strict";const e=window.jQuery;function t(e,t,i,s,n,l,r,a,u,o){"boolean"!=typeof r&&(u=a,a=r,r=!1);const h="function"==typeof i?i.options:i;let d;if(e&&e.render&&(h.render=e.render,h.staticRenderFns=e.staticRenderFns,h._compiled=!0,n&&(h.functional=!0)),s&&(h._scopeId=s),l?(d=function(e){(e=e||this.$vnode&&this.$vnode.ssrContext||this.parent&&this.parent.$vnode&&this.parent.$vnode.ssrContext)||"undefined"==typeof __VUE_SSR_CONTEXT__||(e=__VUE_SSR_CONTEXT__),t&&t.call(this,u(e)),e&&e._registeredComponents&&e._registeredComponents.add(l)},h._ssrRegister=d):t&&(d=r?function(e){t.call(this,o(e,this.$root.$options.shadowRoot))}:function(e){t.call(this,a(e))}),d)if(h.functional){const e=h.render;h.render=function(t,i){return d.call(i),e(t,i)}}else{const e=h.beforeCreate;h.beforeCreate=e?[].concat(e,d):[d]}return i}const i={name:"MultipleSelect",props:{value:{type:[String,Number,Array,Object],default:void 0},name:{type:String,default:void 0},multiple:{type:[Boolean,String],default:!1},disabled:{type:Boolean,default:!1},width:{type:[Number,String],default:void 0},size:{type:String,default:void 0},data:{type:[Array,Object],default(){}},options:{type:Object,default:()=>({})}},data(){return{currentValue:this.value}},watch:{value(){this.currentValue!==this.value&&(this.currentValue=this.value,this._initDefaultValue())},multiple(){this._initSelect()},disabled(){this.$nextTick((()=>{this.disabled?this.disable():this.enable()}))},width(){this._initSelectValue()},options:{handler(){this._initSelectValue()},deep:!0},data:{handler(){this._initSelectValue()},deep:!0}},beforeUpdate(){(this.slotDefault||this.slotDefault!==this.$slots.default)&&(this.slotDefault=this.$slots.default,this.$nextTick((()=>{this._refresh(),this._initSelectValue()})))},destroyed(){this.destroy(!0)},mounted(){this._refresh(),this.$select=e(this.$el).change((()=>{const e=this.getSelects();Array.isArray(this.currentValue)?this.currentValue=e:"number"==typeof this.currentValue?this.currentValue=e.length?+e[0]:void 0:this.currentValue=e.length?e[0]:void 0,this.$emit("input",this.currentValue),this.$emit("change",this.currentValue)})),this._hasInit&&this.$select.val()&&(void 0===this.currentValue||Array.isArray(this.currentValue)&&!this.currentValue.length)&&(this.currentValue=this.$select.val(),this.$emit("input",this.currentValue),this.$emit("change",this.currentValue));for(const t in e.fn.multipleSelect.defaults)/^on[A-Z]/.test(t)&&(e.fn.multipleSelect.defaults[t]=(...e)=>{this.$emit(t.replace(/([A-Z])/g,"-$1").toLowerCase(),...e)});this._initSelectValue()},methods:{_initSelectValue(){this._initSelect(),void 0===this.currentValue||Array.isArray(this.currentValue)&&!this.currentValue.length||this._initDefaultValue()},_initSelect(){const t={...(i=this.options,i?e.extend(!0,Array.isArray(i)?[]:{},i):i),single:!this.multiple,width:this.width,size:this.size,data:this.data};var i;this._hasInit?this.refreshOptions(t):(this.$select.multipleSelect(t),this._hasInit=!0)},_initDefaultValue(){this.$nextTick((()=>{try{this.setSelects(Array.isArray(this.currentValue)?this.currentValue:[this.currentValue],null,!0)}catch(e){}}))},...(()=>{const t={};for(const i of e.fn.multipleSelect.methods)t[i]=function(...e){return this.$select.multipleSelect(i,...e)};return t})(),_refresh(){if(this.$slots.default)for(const t of this.$slots.default)"OPTION"===t.elm.nodeName&&t.data.domProps&&t.data.domProps.value&&e(t.elm).data("value",t.data.domProps.value)},refresh(){this._refresh(),this.$select.multipleSelect("refresh")}}};var s=function(){var e=this,t=e.$createElement;return(e._self._c||t)("select",{attrs:{name:e.name,multiple:e.multiple,disabled:e.disabled}},[e._t("default")],2)};s._withStripped=!0;return t({render:s,staticRenderFns:[]},undefined,i,undefined,false,undefined,!1,void 0,void 0,void 0)}));