Socket
Socket
Sign inDemoInstall

mobile-select

Package Overview
Dependencies
0
Maintainers
1
Versions
28
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.2.0-beta.1 to 1.2.0-beta.2

5

dist/mobile-select.es.js
/*
* mobile-select v1.2.0-beta.1
* mobile-select v1.2.0-beta.2
* Homepage: https://github.com/onlyhom/mobile-select

@@ -182,3 +182,4 @@ * Released under the MIT License.

destroy() {
this.registerEvents("remove"), this.mobileSelect.parentNode.removeChild(this.mobileSelect);
var t, e;
this.registerEvents("remove"), (e = (t = this.mobileSelect) == null ? void 0 : t.parentNode) == null || e.removeChild(this.mobileSelect);
}

@@ -185,0 +186,0 @@ getOptionsHtmlStr(t) {

/*
* mobile-select v1.2.0-beta.1
* mobile-select v1.2.0-beta.2
* Homepage: https://github.com/onlyhom/mobile-select

@@ -274,3 +274,4 @@ * Released under the MIT License.

value: function destroy() {
this.registerEvents("remove"), this.mobileSelect.parentNode.removeChild(this.mobileSelect);
var t, e;
this.registerEvents("remove"), (e = (t = this.mobileSelect) == null ? void 0 : t.parentNode) == null || e.removeChild(this.mobileSelect);
}

@@ -277,0 +278,0 @@ }, {

4

dist/mobile-select.iife.min.js
/*
* mobile-select v1.2.0-beta.1
* mobile-select v1.2.0-beta.2
* Homepage: https://github.com/onlyhom/mobile-select

@@ -7,2 +7,2 @@ * Released under the MIT License.

*/
"use strict";function _defineProperty(obj,key,value){return key in obj?Object.defineProperty(obj,key,{value:value,enumerable:!0,configurable:!0,writable:!0}):obj[key]=value,obj}function _toConsumableArray(arr){return _arrayWithoutHoles(arr)||_iterableToArray(arr)||_unsupportedIterableToArray(arr)||_nonIterableSpread()}function _nonIterableSpread(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _iterableToArray(iter){if("undefined"!=typeof Symbol&&null!=iter[Symbol.iterator]||null!=iter["@@iterator"])return Array.from(iter)}function _arrayWithoutHoles(arr){if(Array.isArray(arr))return _arrayLikeToArray(arr)}function _slicedToArray(arr,i){return _arrayWithHoles(arr)||_iterableToArrayLimit(arr,i)||_unsupportedIterableToArray(arr,i)||_nonIterableRest()}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _unsupportedIterableToArray(o,minLen){if(o){if("string"==typeof o)return _arrayLikeToArray(o,minLen);var n=Object.prototype.toString.call(o).slice(8,-1);return"Map"===(n="Object"===n&&o.constructor?o.constructor.name:n)||"Set"===n?Array.from(o):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?_arrayLikeToArray(o,minLen):void 0}}function _arrayLikeToArray(arr,len){(null==len||len>arr.length)&&(len=arr.length);for(var i=0,arr2=new Array(len);i<len;i++)arr2[i]=arr[i];return arr2}function _iterableToArrayLimit(arr,i){var _i=null==arr?null:"undefined"!=typeof Symbol&&arr[Symbol.iterator]||arr["@@iterator"];if(null!=_i){var _s,_e,_arr=[],_n=!0,_d=!1;try{for(_i=_i.call(arr);!(_n=(_s=_i.next()).done)&&(_arr.push(_s.value),!i||_arr.length!==i);_n=!0);}catch(err){_d=!0,_e=err}finally{try{_n||null==_i.return||_i.return()}finally{if(_d)throw _e}}return _arr}}function _arrayWithHoles(arr){if(Array.isArray(arr))return arr}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||!1,descriptor.configurable=!0,"value"in descriptor&&(descriptor.writable=!0),Object.defineProperty(target,descriptor.key,descriptor)}}function _createClass(Constructor,protoProps,staticProps){return protoProps&&_defineProperties(Constructor.prototype,protoProps),staticProps&&_defineProperties(Constructor,staticProps),Object.defineProperty(Constructor,"prototype",{writable:!1}),Constructor}function _typeof(obj){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(obj){return typeof obj}:function(obj){return obj&&"function"==typeof Symbol&&obj.constructor===Symbol&&obj!==Symbol.prototype?"symbol":typeof obj})(obj)}var MobileSelect=function(){function h(a,l,f){D(a,"symbol"!=_typeof(l)?l+"":l,f)}var C=Object.defineProperty,D=function(a,l,f){return l in a?C(a,l,{enumerable:!0,configurable:!0,writable:!0,value:f}):a[l]=f},a=function(){function l(t){_classCallCheck(this,l),h(this,"mobileSelect"),h(this,"trigger"),h(this,"wheel"),h(this,"slider"),h(this,"wheels"),h(this,"panel"),h(this,"ensureBtn"),h(this,"cancelBtn"),h(this,"grayLayer"),h(this,"popUp"),h(this,"initPosition"),h(this,"initColWidth"),h(this,"connector"),h(this,"wheelsData"),h(this,"displayJson"),h(this,"curValue"),h(this,"curIndexArr"),h(this,"isCascade"),h(this,"isJsonType"),h(this,"startY"),h(this,"moveEndY"),h(this,"moveY"),h(this,"preMoveY"),h(this,"offsetY"),h(this,"offsetSum"),h(this,"oversizeBorder"),h(this,"enableClickStatus"),h(this,"isPC"),h(this,"optionHeight"),h(this,"curDistance"),h(this,"cascadeJsonData"),h(this,"keyMap"),h(this,"eventHandleMap"),h(this,"initDeepCount"),h(this,"config"),l.checkRequiredConfig(t)&&(this.config=Object.assign({},l.defaultConfig,t),this.wheelsData=t.wheels,this.isJsonType=!1,this.cascadeJsonData=[],this.displayJson=[],this.curValue=[],this.curIndexArr=[],this.isCascade=!1,this.startY,this.moveEndY,this.moveY,this.preMoveY,this.offsetY=0,this.offsetSum=0,this.oversizeBorder,this.curDistance=[],this.enableClickStatus=!1,this.isPC=!0,this.optionHeight=0,this.initPosition=t.position||[],this.initColWidth=t.colWidth||[],this.init())}return _createClass(l,[{key:"init",value:function(){var _this=this,t=this.config;if(this.isJsonType=l.checkDataType(this.wheelsData),this.renderComponent(this.wheelsData),this.checkTriggerAvailable()){if(this.wheel=this.mobileSelect.getElementsByClassName("ms-wheel"),this.slider=this.mobileSelect.getElementsByClassName("ms-select-container"),this.panel=this.mobileSelect.querySelector(".ms-panel"),this.wheels=this.mobileSelect.querySelector(".ms-wheels"),this.ensureBtn=this.mobileSelect.querySelector(".ms-ensure"),this.cancelBtn=this.mobileSelect.querySelector(".ms-cancel"),this.grayLayer=this.mobileSelect.querySelector(".ms-gray-layer"),this.popUp=this.mobileSelect.querySelector(".ms-content"),this.optionHeight=this.mobileSelect.querySelector("li").offsetHeight,t.initValue&&t.triggerDisplayValue&&(this.trigger.innerText=t.initValue),this.setStyle(t),this.isPC=l.checkIsPC(),this.isCascade=this.checkCascade(),this.isCascade&&this.initCascade(),t.initValue&&(this.initPosition=this.getPositionByValue()),this.initPosition.length<this.slider.length)for(var e=this.slider.length-this.initPosition.length,i=0;i<e;i++)this.initPosition.push(0);this.isCascade?this.initPosition.forEach(function(e,i){_this.checkRange(i,_this.initPosition)}):this.setCurDistance(this.initPosition),this.eventHandleMap={cancelBtn:{event:"click",fn:function(){var i,e;_this.hide(),null!=(i=(e=_this.config).cancel)&&i.call(e,_this.curIndexArr,_this.curValue,_this),null!=(e=(i=_this.config).onCancel)&&e.call(i,_this.curValue,_this.curIndexArr,_this)}},ensureBtn:{event:"click",fn:function(){_this.hide(),_this.optionHeight||(_this.optionHeight=_this.mobileSelect.querySelector("li").offsetHeight);for(var s,i,e="",o=0;o<_this.wheel.length;o++)o==_this.wheel.length-1?e+=_this.getInnerText(o):e+=_this.getInnerText(o)+_this.config.connector;t.triggerDisplayValue&&(_this.trigger.innerText=e),_this.curIndexArr=_this.getIndexArr(),_this.curValue=_this.getCurValue(),null!=(s=(i=_this.config).callback)&&s.call(i,_this.curIndexArr,_this.curValue,_this),null!=(i=(s=_this.config).onChange)&&i.call(s,_this.curValue,_this.curIndexArr,_this)}},trigger:{event:"click",fn:function(){_this.show()}},grayLayer:{event:"click",fn:function(){return _this.hide()}},popUp:{event:"click",fn:function(e){return e.stopPropagation()}},panel:{event:["touchstart","touchend","touchmove"],fn:function(e){return _this.touch(e)}}},this.isPC&&(this.eventHandleMap.panel.event=["mousedown","mousemove","mouseup"]),this.registerEvents("add"),this.fixRowStyle(),t.autoFocus&&this.show()}}},{key:"checkTriggerAvailable",value:function(){var t=this.config;return this.trigger=t.trigger instanceof HTMLElement?t.trigger:document.querySelector(t.trigger),!!this.trigger||(l.log("error","trigger HTMLElement does not found on your document."),!1)}},{key:"getPositionByValue",value:function(){var r,_this2=this,_this$config=this.config,t=_this$config.keyMap,e=_this$config.connector,_this$config=_this$config.initValue,_this$config=(null==_this$config?void 0:_this$config.split(e))||[];return this.isJsonType?(r=null==(e=this.wheelsData[0])?void 0:e.data,_this$config.reduce(function(o,g){var c=null==r?void 0:r.findIndex(function(d){return d[t.value]==g});return o.push(c<0?0:c),r=null==(c=r[c])?void 0:c[t.childs],o},[])):_this$config.reduce(function(r,o,g){g=null==(g=null==(g=_this2.wheelsData[g])?void 0:g.data)?void 0:g.findIndex(function(m){return m==o});return r.push(g<0?0:g),r},[])}},{key:"setTitle",value:function(t){this.mobileSelect.querySelector(".ms-title").innerHTML=t}},{key:"setStyle",value:function(t){var _e2;t.ensureBtnColor&&(this.ensureBtn.style.color=t.ensureBtnColor),t.cancelBtnColor&&(this.cancelBtn.style.color=t.cancelBtnColor),t.titleColor&&(this.mobileSelect.querySelector(".ms-title").style.color=t.titleColor),t.textColor&&(this.panel=this.mobileSelect.querySelector(".ms-panel"),this.panel.style.color=t.textColor),t.titleBgColor&&(this.mobileSelect.querySelector(".ms-btn-bar").style.backgroundColor=t.titleBgColor),t.bgColor&&(this.panel=this.mobileSelect.querySelector(".ms-panel"),_e2=this.mobileSelect.querySelector(".ms-shadow-mask"),this.panel.style.backgroundColor=t.bgColor,_e2.style.background="linear-gradient(to bottom, "+t.bgColor+", rgba(255, 255, 255, 0), "+t.bgColor+")"),"number"==typeof t.maskOpacity&&(this.mobileSelect.querySelector(".ms-gray-layer").style.background="rgba(0, 0, 0, "+t.maskOpacity+")")}},{key:"show",value:function(){var t,e;this.mobileSelect.classList.add("ms-show"),"function"==typeof this.config.onShow&&null!=(e=(t=this.config).onShow)&&e.call(t)}},{key:"hide",value:function(){var t,e;this.mobileSelect.classList.remove("ms-show"),"function"==typeof this.config.onHide&&null!=(e=(t=this.config).onHide)&&e.call(t)}},{key:"registerEvents",value:function(t){for(var _this3=this,_i=0,_Object$entries=Object.entries(this.eventHandleMap);_i<_Object$entries.length;_i++)!function(){var _Object$entries$_i=_slicedToArray(_Object$entries[_i],2),e=_Object$entries$_i[0],i=_Object$entries$_i[1];"string"==typeof i.event?_this3[e]["".concat(t,"EventListener")](i.event,i.fn,{passive:!1}):i.event.forEach(function(s){_this3[e]["".concat(t,"EventListener")](s,i.fn,{passive:!1})})}()}},{key:"destroy",value:function(){this.registerEvents("remove"),this.mobileSelect.parentNode.removeChild(this.mobileSelect)}},{key:"getOptionsHtmlStr",value:function(t){var e=this.config.keyMap,i="";if(this.isJsonType)for(var s=0;s<t.length;s++){var n=t[s][e.id],r=t[s][e.value];i+='<li data-id="'.concat(n,'">').concat(r,"</li>")}else for(var _s2=0;_s2<t.length;_s2++)i+="<li>"+t[_s2]+"</li>";return i}},{key:"renderComponent",value:function(t){this.mobileSelect=document.createElement("div"),this.mobileSelect.className="ms-mobile-select",this.mobileSelect.innerHTML='<div class="ms-gray-layer"></div>\n <div class="ms-content">\n <div class="ms-btn-bar">\n <div class="ms-fix-width">\n <div class="ms-cancel">'.concat(this.config.cancelBtnText,'</div> \n <div class="ms-title">').concat(this.config.title||"",'</div>\n <div class="ms-ensure">').concat(this.config.ensureBtnText,'</div>\n </div>\n </div>\n <div class="ms-panel">\n <div class="ms-fix-width">\n <div class="ms-wheels"></div>\n <div class="ms-select-line"></div>\n <div class="ms-shadow-mask"></div>\n </div>\n </div>'),document.body.appendChild(this.mobileSelect);for(var e="",i=0;i<t.length;i++)e=(e+='<div class="ms-wheel"><ul class="ms-select-container" data-index="'.concat(i,'">'))+this.getOptionsHtmlStr(t[i].data)+"</ul></div>";this.mobileSelect.querySelector(".ms-wheels").innerHTML=e}},{key:"reRenderWheels",value:function(){var t=this.wheel.length-this.displayJson.length;if(0<t)for(var e=0;e<t;e++)this.wheels.removeChild(this.wheel[this.wheel.length-1]);for(var i,_e4=0;_e4<this.displayJson.length;_e4++)this.wheel[_e4]?this.slider[_e4].innerHTML=this.getOptionsHtmlStr(this.displayJson[_e4]):((i=document.createElement("div")).className="ms-wheel",i.innerHTML='<ul class="ms-select-container" data-index="'.concat(_e4,'">').concat(this.getOptionsHtmlStr(this.displayJson[_e4]),"</ul>"),this.wheels.appendChild(i))}},{key:"checkCascade",value:function(){var e,t=this.config.keyMap;if(this.isJsonType)for(var i=this.wheelsData[0].data,s=0;s<i.length;s++)if(t.childs in i[s]&&0<(null==(e=i[s][t.childs])?void 0:e.length))return this.cascadeJsonData=this.wheelsData[0].data,!0;return!1}},{key:"initCascade",value:function(){this.displayJson.push(this.cascadeJsonData),0<this.initPosition.length?(this.initDeepCount=0,this.initCheckArrDeep(this.cascadeJsonData[this.initPosition[0]])):this.checkArrDeep(this.cascadeJsonData[0]),this.reRenderWheels()}},{key:"initCheckArrDeep",value:function(t){var e,i;t&&(e=this.config.keyMap).childs in t&&0<t[e.childs].length&&(this.displayJson.push(t[e.childs]),this.initDeepCount++,(i=t[e.childs][this.initPosition[this.initDeepCount]])?this.initCheckArrDeep(i):this.checkArrDeep(t[e.childs][0]))}},{key:"checkArrDeep",value:function(t){var e;!t||(e=this.config.keyMap).childs in t&&0<t[e.childs].length&&(this.displayJson.push(t[e.childs]),this.checkArrDeep(t[e.childs][0]))}},{key:"checkRange",value:function(t,e){for(var r,n,i=this.displayJson.length-1-t,s=this.config.keyMap,o=0;o<i;o++)this.displayJson.pop();for(var _o=0;_o<=t;_o++)n=0==_o?this.cascadeJsonData[e[0]]:null==(r=null==n?void 0:n[s.childs])?void 0:r[e[_o]];this.checkArrDeep(n),this.reRenderWheels(),this.fixRowStyle(),this.setCurDistance(this.resetPosition(t,e))}},{key:"resetPosition",value:function(t,e){var i=_toConsumableArray(e);if(this.slider.length>e.length)for(var s=this.slider.length-e.length,n=0;n<s;n++)i.push(0);else if(this.slider.length<e.length){s=e.length-this.slider.length;for(var _n2=0;_n2<s;_n2++)i.pop()}for(var _n3=t+1;_n3<i.length;_n3++)i[_n3]=0;return i}},{key:"updateWheels",value:function(t){if(this.isCascade){if(this.cascadeJsonData=t,this.displayJson=[],this.initCascade(),this.initPosition.length<this.slider.length)for(var e=this.slider.length-this.initPosition.length,i=0;i<e;i++)this.initPosition.push(0);this.setCurDistance(this.initPosition),this.fixRowStyle()}}},{key:"updateWheel",value:function(t,e){var i;this.isCascade?l.log("error","'updateWheel()' not support cascade json data, please use 'updateWheels()' instead to update the whole data source"):(i="",i+=this.getOptionsHtmlStr(e),this.wheelsData[t]=this.isJsonType?{data:e}:e,this.slider[t].innerHTML=i)}},{key:"fixRowStyle",value:function(){var e,_this4=this;if(this.initColWidth.length&&this.initColWidth.length===this.wheel.length)e=this.initColWidth.reduce(function(i,s){return i+s},0),this.initColWidth.forEach(function(i,s){_this4.wheel[s].style.width=(i/e*100).toFixed(2)+"%"});else for(var t=(100/this.wheel.length).toFixed(2),_e5=0;_e5<this.wheel.length;_e5++)this.wheel[_e5].style.width=t+"%"}},{key:"getIndex",value:function(t){return Math.round((2*this.optionHeight-t)/this.optionHeight)}},{key:"getIndexArr",value:function(){for(var t=[],e=0;e<this.curDistance.length;e++)t.push(this.getIndex(this.curDistance[e]));return t}},{key:"getCurValue",value:function(){var t=[],e=this.getIndexArr(),i=this.config.keyMap;if(this.isCascade)for(var s=0;s<this.wheel.length;s++){var _t$push,n=this.displayJson[s][e[s]];n&&t.push((_defineProperty(_t$push={},i.id,n[i.id]),_defineProperty(_t$push,i.value,n[i.value]),_t$push))}else if(this.isJsonType)for(var _s3=0;_s3<this.curDistance.length;_s3++)t.push(this.wheelsData[_s3].data[this.getIndex(this.curDistance[_s3])]);else for(var _s4=0;_s4<this.curDistance.length;_s4++)t.push(this.getInnerText(_s4));return t}},{key:"getValue",value:function(){return this.curValue}},{key:"calcDistance",value:function(t){return 2*this.optionHeight-t*this.optionHeight}},{key:"setCurDistance",value:function(t){for(var e=[],i=0;i<this.slider.length;i++)e.push(this.calcDistance(t[i])),this.movePosition(this.slider[i],e[i]);this.curDistance=e}},{key:"fixPosition",value:function(t){return-(this.getIndex(t)-2)*this.optionHeight}},{key:"movePosition",value:function(t,e){t.style.transform="translate3d(0,"+e+"px, 0)"}},{key:"locatePosition",value:function(t,e){this.curDistance[t]=this.calcDistance(e),this.movePosition(this.slider[t],this.curDistance[t]),this.isCascade&&this.checkRange(t,this.getIndexArr())}},{key:"updateCurDistance",value:function(t,e){this.curDistance[e]=parseInt(t.style.transform.split(",")[1])}},{key:"getInnerText",value:function(t){var e=this.slider[t].getElementsByTagName("li").length,i=this.getIndex(this.curDistance[t]);return e<=i?i=e-1:i<0&&(i=0),(null==(e=this.slider[t].getElementsByTagName("li")[i])?void 0:e.innerText)||""}},{key:"touch",value:function(t){var r,y,_this5=this,i=(t.composedPath&&t.composedPath())[1],s=parseInt(i.getAttribute("data-index")||"0");switch(t.type){case"touchstart":case"mousedown":i.style.transition="none 0s ease-out",this.startY=Math.floor((t instanceof TouchEvent?t.touches[0]:t).clientY),this.preMoveY=this.startY,"mousedown"===t.type&&(this.enableClickStatus=!0);break;case"touchend":case"mouseup":i.style.transition="transform 0.18s ease-out",this.moveEndY=Math.floor((t instanceof TouchEvent?t.changedTouches[0]:t).clientY),this.offsetSum=this.moveEndY-this.startY,this.oversizeBorder=-(i.getElementsByTagName("li").length-3)*this.optionHeight,0==this.offsetSum?2!=(y=Math.floor((window.innerHeight-this.moveEndY)/40))&&(y=this.curDistance[s]+(y-2)*this.optionHeight)<=2*this.optionHeight&&y>=this.oversizeBorder&&(this.curDistance[s]=y,this.movePosition(i,this.curDistance[s]),null!=(r=(y=this.config).transitionEnd)&&r.call(y,this.getIndexArr(),this.getCurValue(),this),null!=(y=(r=this.config).onTransitionEnd)&&y.call(r,this.getCurValue(),this.getIndexArr(),this)):(this.updateCurDistance(i,s),this.curDistance[s]=this.fixPosition(this.curDistance[s]),this.movePosition(i,this.curDistance[s]),this.curDistance[s]+this.offsetSum>2*this.optionHeight?(this.curDistance[s]=2*this.optionHeight,setTimeout(function(){_this5.movePosition(i,_this5.curDistance[s])},100)):this.curDistance[s]+this.offsetSum<this.oversizeBorder&&(this.curDistance[s]=this.oversizeBorder,setTimeout(function(){_this5.movePosition(i,_this5.curDistance[s])},100)),null!=(r=(y=this.config).transitionEnd)&&r.call(y,this.getIndexArr(),this.getCurValue(),this),null!=(y=(r=this.config).onTransitionEnd)&&y.call(r,this.getCurValue(),this.getIndexArr(),this)),"mouseup"===t.type&&(this.enableClickStatus=!1),this.isCascade&&this.checkRange(s,this.getIndexArr());break;case"touchmove":case"mousemove":if(t.preventDefault(),"mousemove"===t.type&&!this.enableClickStatus)break;this.moveY=Math.floor((t instanceof TouchEvent?t.touches[0]:t).clientY),this.offsetY=(this.moveY-this.preMoveY)*this.config.scrollSpeed,this.updateCurDistance(i,s),this.curDistance[s]=this.curDistance[s]+this.offsetY,this.movePosition(i,this.curDistance[s]),this.preMoveY=this.moveY}}}],[{key:"checkIsPC",value:function(){return!Boolean(navigator.userAgent.toLowerCase().match(/ipad|iphone os|midp|rv:1.2.3.4|ucweb|android|windows ce|windows mobile/))}},{key:"checkDataType",value:function(t){return"object"==_typeof(null==(t=null==(t=t[0])?void 0:t.data)?void 0:t[0])}},{key:"checkRequiredConfig",value:function(t){var i,e=l.REQUIRED_PARAMS;if(!t)return i=e.map(function(s){return"'".concat(s,"'")}),l.log("error","missing required param ".concat(i.join(" and "),".")),!1;for(var _i2=0;_i2<e.length;_i2++){var s=e[_i2];if(!t[s])return l.log("error","missing required param '".concat(s,"'.")),!1}return!0}},{key:"log",value:function(t,e){null!=(t=console[t])&&t.call(console,"[mobile-select]: ".concat(e))}}]),l}();return h(a,"defaultConfig",{keyMap:{id:"id",value:"value",childs:"childs"},position:[],colWidth:[],title:"",connector:" ",ensureBtnText:"确认",cancelBtnText:"取消",triggerDisplayValue:!0,scrollSpeed:1}),h(a,"REQUIRED_PARAMS",["trigger","wheels"]),a}();
"use strict";function _defineProperty(obj,key,value){return key in obj?Object.defineProperty(obj,key,{value:value,enumerable:!0,configurable:!0,writable:!0}):obj[key]=value,obj}function _toConsumableArray(arr){return _arrayWithoutHoles(arr)||_iterableToArray(arr)||_unsupportedIterableToArray(arr)||_nonIterableSpread()}function _nonIterableSpread(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _iterableToArray(iter){if("undefined"!=typeof Symbol&&null!=iter[Symbol.iterator]||null!=iter["@@iterator"])return Array.from(iter)}function _arrayWithoutHoles(arr){if(Array.isArray(arr))return _arrayLikeToArray(arr)}function _slicedToArray(arr,i){return _arrayWithHoles(arr)||_iterableToArrayLimit(arr,i)||_unsupportedIterableToArray(arr,i)||_nonIterableRest()}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _unsupportedIterableToArray(o,minLen){if(o){if("string"==typeof o)return _arrayLikeToArray(o,minLen);var n=Object.prototype.toString.call(o).slice(8,-1);return"Map"===(n="Object"===n&&o.constructor?o.constructor.name:n)||"Set"===n?Array.from(o):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?_arrayLikeToArray(o,minLen):void 0}}function _arrayLikeToArray(arr,len){(null==len||len>arr.length)&&(len=arr.length);for(var i=0,arr2=new Array(len);i<len;i++)arr2[i]=arr[i];return arr2}function _iterableToArrayLimit(arr,i){var _i=null==arr?null:"undefined"!=typeof Symbol&&arr[Symbol.iterator]||arr["@@iterator"];if(null!=_i){var _s,_e,_arr=[],_n=!0,_d=!1;try{for(_i=_i.call(arr);!(_n=(_s=_i.next()).done)&&(_arr.push(_s.value),!i||_arr.length!==i);_n=!0);}catch(err){_d=!0,_e=err}finally{try{_n||null==_i.return||_i.return()}finally{if(_d)throw _e}}return _arr}}function _arrayWithHoles(arr){if(Array.isArray(arr))return arr}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||!1,descriptor.configurable=!0,"value"in descriptor&&(descriptor.writable=!0),Object.defineProperty(target,descriptor.key,descriptor)}}function _createClass(Constructor,protoProps,staticProps){return protoProps&&_defineProperties(Constructor.prototype,protoProps),staticProps&&_defineProperties(Constructor,staticProps),Object.defineProperty(Constructor,"prototype",{writable:!1}),Constructor}function _typeof(obj){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(obj){return typeof obj}:function(obj){return obj&&"function"==typeof Symbol&&obj.constructor===Symbol&&obj!==Symbol.prototype?"symbol":typeof obj})(obj)}var MobileSelect=function(){function h(a,l,f){D(a,"symbol"!=_typeof(l)?l+"":l,f)}var C=Object.defineProperty,D=function(a,l,f){return l in a?C(a,l,{enumerable:!0,configurable:!0,writable:!0,value:f}):a[l]=f},a=function(){function l(t){_classCallCheck(this,l),h(this,"mobileSelect"),h(this,"trigger"),h(this,"wheel"),h(this,"slider"),h(this,"wheels"),h(this,"panel"),h(this,"ensureBtn"),h(this,"cancelBtn"),h(this,"grayLayer"),h(this,"popUp"),h(this,"initPosition"),h(this,"initColWidth"),h(this,"connector"),h(this,"wheelsData"),h(this,"displayJson"),h(this,"curValue"),h(this,"curIndexArr"),h(this,"isCascade"),h(this,"isJsonType"),h(this,"startY"),h(this,"moveEndY"),h(this,"moveY"),h(this,"preMoveY"),h(this,"offsetY"),h(this,"offsetSum"),h(this,"oversizeBorder"),h(this,"enableClickStatus"),h(this,"isPC"),h(this,"optionHeight"),h(this,"curDistance"),h(this,"cascadeJsonData"),h(this,"keyMap"),h(this,"eventHandleMap"),h(this,"initDeepCount"),h(this,"config"),l.checkRequiredConfig(t)&&(this.config=Object.assign({},l.defaultConfig,t),this.wheelsData=t.wheels,this.isJsonType=!1,this.cascadeJsonData=[],this.displayJson=[],this.curValue=[],this.curIndexArr=[],this.isCascade=!1,this.startY,this.moveEndY,this.moveY,this.preMoveY,this.offsetY=0,this.offsetSum=0,this.oversizeBorder,this.curDistance=[],this.enableClickStatus=!1,this.isPC=!0,this.optionHeight=0,this.initPosition=t.position||[],this.initColWidth=t.colWidth||[],this.init())}return _createClass(l,[{key:"init",value:function(){var _this=this,t=this.config;if(this.isJsonType=l.checkDataType(this.wheelsData),this.renderComponent(this.wheelsData),this.checkTriggerAvailable()){if(this.wheel=this.mobileSelect.getElementsByClassName("ms-wheel"),this.slider=this.mobileSelect.getElementsByClassName("ms-select-container"),this.panel=this.mobileSelect.querySelector(".ms-panel"),this.wheels=this.mobileSelect.querySelector(".ms-wheels"),this.ensureBtn=this.mobileSelect.querySelector(".ms-ensure"),this.cancelBtn=this.mobileSelect.querySelector(".ms-cancel"),this.grayLayer=this.mobileSelect.querySelector(".ms-gray-layer"),this.popUp=this.mobileSelect.querySelector(".ms-content"),this.optionHeight=this.mobileSelect.querySelector("li").offsetHeight,t.initValue&&t.triggerDisplayValue&&(this.trigger.innerText=t.initValue),this.setStyle(t),this.isPC=l.checkIsPC(),this.isCascade=this.checkCascade(),this.isCascade&&this.initCascade(),t.initValue&&(this.initPosition=this.getPositionByValue()),this.initPosition.length<this.slider.length)for(var e=this.slider.length-this.initPosition.length,i=0;i<e;i++)this.initPosition.push(0);this.isCascade?this.initPosition.forEach(function(e,i){_this.checkRange(i,_this.initPosition)}):this.setCurDistance(this.initPosition),this.eventHandleMap={cancelBtn:{event:"click",fn:function(){var i,e;_this.hide(),null!=(i=(e=_this.config).cancel)&&i.call(e,_this.curIndexArr,_this.curValue,_this),null!=(e=(i=_this.config).onCancel)&&e.call(i,_this.curValue,_this.curIndexArr,_this)}},ensureBtn:{event:"click",fn:function(){_this.hide(),_this.optionHeight||(_this.optionHeight=_this.mobileSelect.querySelector("li").offsetHeight);for(var s,i,e="",o=0;o<_this.wheel.length;o++)o==_this.wheel.length-1?e+=_this.getInnerText(o):e+=_this.getInnerText(o)+_this.config.connector;t.triggerDisplayValue&&(_this.trigger.innerText=e),_this.curIndexArr=_this.getIndexArr(),_this.curValue=_this.getCurValue(),null!=(s=(i=_this.config).callback)&&s.call(i,_this.curIndexArr,_this.curValue,_this),null!=(i=(s=_this.config).onChange)&&i.call(s,_this.curValue,_this.curIndexArr,_this)}},trigger:{event:"click",fn:function(){_this.show()}},grayLayer:{event:"click",fn:function(){return _this.hide()}},popUp:{event:"click",fn:function(e){return e.stopPropagation()}},panel:{event:["touchstart","touchend","touchmove"],fn:function(e){return _this.touch(e)}}},this.isPC&&(this.eventHandleMap.panel.event=["mousedown","mousemove","mouseup"]),this.registerEvents("add"),this.fixRowStyle(),t.autoFocus&&this.show()}}},{key:"checkTriggerAvailable",value:function(){var t=this.config;return this.trigger=t.trigger instanceof HTMLElement?t.trigger:document.querySelector(t.trigger),!!this.trigger||(l.log("error","trigger HTMLElement does not found on your document."),!1)}},{key:"getPositionByValue",value:function(){var r,_this2=this,_this$config=this.config,t=_this$config.keyMap,e=_this$config.connector,_this$config=_this$config.initValue,_this$config=(null==_this$config?void 0:_this$config.split(e))||[];return this.isJsonType?(r=null==(e=this.wheelsData[0])?void 0:e.data,_this$config.reduce(function(o,g){var c=null==r?void 0:r.findIndex(function(d){return d[t.value]==g});return o.push(c<0?0:c),r=null==(c=r[c])?void 0:c[t.childs],o},[])):_this$config.reduce(function(r,o,g){g=null==(g=null==(g=_this2.wheelsData[g])?void 0:g.data)?void 0:g.findIndex(function(m){return m==o});return r.push(g<0?0:g),r},[])}},{key:"setTitle",value:function(t){this.mobileSelect.querySelector(".ms-title").innerHTML=t}},{key:"setStyle",value:function(t){var _e2;t.ensureBtnColor&&(this.ensureBtn.style.color=t.ensureBtnColor),t.cancelBtnColor&&(this.cancelBtn.style.color=t.cancelBtnColor),t.titleColor&&(this.mobileSelect.querySelector(".ms-title").style.color=t.titleColor),t.textColor&&(this.panel=this.mobileSelect.querySelector(".ms-panel"),this.panel.style.color=t.textColor),t.titleBgColor&&(this.mobileSelect.querySelector(".ms-btn-bar").style.backgroundColor=t.titleBgColor),t.bgColor&&(this.panel=this.mobileSelect.querySelector(".ms-panel"),_e2=this.mobileSelect.querySelector(".ms-shadow-mask"),this.panel.style.backgroundColor=t.bgColor,_e2.style.background="linear-gradient(to bottom, "+t.bgColor+", rgba(255, 255, 255, 0), "+t.bgColor+")"),"number"==typeof t.maskOpacity&&(this.mobileSelect.querySelector(".ms-gray-layer").style.background="rgba(0, 0, 0, "+t.maskOpacity+")")}},{key:"show",value:function(){var t,e;this.mobileSelect.classList.add("ms-show"),"function"==typeof this.config.onShow&&null!=(e=(t=this.config).onShow)&&e.call(t)}},{key:"hide",value:function(){var t,e;this.mobileSelect.classList.remove("ms-show"),"function"==typeof this.config.onHide&&null!=(e=(t=this.config).onHide)&&e.call(t)}},{key:"registerEvents",value:function(t){for(var _this3=this,_i=0,_Object$entries=Object.entries(this.eventHandleMap);_i<_Object$entries.length;_i++)!function(){var _Object$entries$_i=_slicedToArray(_Object$entries[_i],2),e=_Object$entries$_i[0],i=_Object$entries$_i[1];"string"==typeof i.event?_this3[e]["".concat(t,"EventListener")](i.event,i.fn,{passive:!1}):i.event.forEach(function(s){_this3[e]["".concat(t,"EventListener")](s,i.fn,{passive:!1})})}()}},{key:"destroy",value:function(){var t;this.registerEvents("remove"),null!=(t=null==(t=this.mobileSelect)?void 0:t.parentNode)&&t.removeChild(this.mobileSelect)}},{key:"getOptionsHtmlStr",value:function(t){var e=this.config.keyMap,i="";if(this.isJsonType)for(var s=0;s<t.length;s++){var n=t[s][e.id],r=t[s][e.value];i+='<li data-id="'.concat(n,'">').concat(r,"</li>")}else for(var _s2=0;_s2<t.length;_s2++)i+="<li>"+t[_s2]+"</li>";return i}},{key:"renderComponent",value:function(t){this.mobileSelect=document.createElement("div"),this.mobileSelect.className="ms-mobile-select",this.mobileSelect.innerHTML='<div class="ms-gray-layer"></div>\n <div class="ms-content">\n <div class="ms-btn-bar">\n <div class="ms-fix-width">\n <div class="ms-cancel">'.concat(this.config.cancelBtnText,'</div> \n <div class="ms-title">').concat(this.config.title||"",'</div>\n <div class="ms-ensure">').concat(this.config.ensureBtnText,'</div>\n </div>\n </div>\n <div class="ms-panel">\n <div class="ms-fix-width">\n <div class="ms-wheels"></div>\n <div class="ms-select-line"></div>\n <div class="ms-shadow-mask"></div>\n </div>\n </div>'),document.body.appendChild(this.mobileSelect);for(var e="",i=0;i<t.length;i++)e=(e+='<div class="ms-wheel"><ul class="ms-select-container" data-index="'.concat(i,'">'))+this.getOptionsHtmlStr(t[i].data)+"</ul></div>";this.mobileSelect.querySelector(".ms-wheels").innerHTML=e}},{key:"reRenderWheels",value:function(){var t=this.wheel.length-this.displayJson.length;if(0<t)for(var e=0;e<t;e++)this.wheels.removeChild(this.wheel[this.wheel.length-1]);for(var i,_e4=0;_e4<this.displayJson.length;_e4++)this.wheel[_e4]?this.slider[_e4].innerHTML=this.getOptionsHtmlStr(this.displayJson[_e4]):((i=document.createElement("div")).className="ms-wheel",i.innerHTML='<ul class="ms-select-container" data-index="'.concat(_e4,'">').concat(this.getOptionsHtmlStr(this.displayJson[_e4]),"</ul>"),this.wheels.appendChild(i))}},{key:"checkCascade",value:function(){var e,t=this.config.keyMap;if(this.isJsonType)for(var i=this.wheelsData[0].data,s=0;s<i.length;s++)if(t.childs in i[s]&&0<(null==(e=i[s][t.childs])?void 0:e.length))return this.cascadeJsonData=this.wheelsData[0].data,!0;return!1}},{key:"initCascade",value:function(){this.displayJson.push(this.cascadeJsonData),0<this.initPosition.length?(this.initDeepCount=0,this.initCheckArrDeep(this.cascadeJsonData[this.initPosition[0]])):this.checkArrDeep(this.cascadeJsonData[0]),this.reRenderWheels()}},{key:"initCheckArrDeep",value:function(t){var e,i;t&&(e=this.config.keyMap).childs in t&&0<t[e.childs].length&&(this.displayJson.push(t[e.childs]),this.initDeepCount++,(i=t[e.childs][this.initPosition[this.initDeepCount]])?this.initCheckArrDeep(i):this.checkArrDeep(t[e.childs][0]))}},{key:"checkArrDeep",value:function(t){var e;!t||(e=this.config.keyMap).childs in t&&0<t[e.childs].length&&(this.displayJson.push(t[e.childs]),this.checkArrDeep(t[e.childs][0]))}},{key:"checkRange",value:function(t,e){for(var r,n,i=this.displayJson.length-1-t,s=this.config.keyMap,o=0;o<i;o++)this.displayJson.pop();for(var _o=0;_o<=t;_o++)n=0==_o?this.cascadeJsonData[e[0]]:null==(r=null==n?void 0:n[s.childs])?void 0:r[e[_o]];this.checkArrDeep(n),this.reRenderWheels(),this.fixRowStyle(),this.setCurDistance(this.resetPosition(t,e))}},{key:"resetPosition",value:function(t,e){var i=_toConsumableArray(e);if(this.slider.length>e.length)for(var s=this.slider.length-e.length,n=0;n<s;n++)i.push(0);else if(this.slider.length<e.length){s=e.length-this.slider.length;for(var _n2=0;_n2<s;_n2++)i.pop()}for(var _n3=t+1;_n3<i.length;_n3++)i[_n3]=0;return i}},{key:"updateWheels",value:function(t){if(this.isCascade){if(this.cascadeJsonData=t,this.displayJson=[],this.initCascade(),this.initPosition.length<this.slider.length)for(var e=this.slider.length-this.initPosition.length,i=0;i<e;i++)this.initPosition.push(0);this.setCurDistance(this.initPosition),this.fixRowStyle()}}},{key:"updateWheel",value:function(t,e){var i;this.isCascade?l.log("error","'updateWheel()' not support cascade json data, please use 'updateWheels()' instead to update the whole data source"):(i="",i+=this.getOptionsHtmlStr(e),this.wheelsData[t]=this.isJsonType?{data:e}:e,this.slider[t].innerHTML=i)}},{key:"fixRowStyle",value:function(){var e,_this4=this;if(this.initColWidth.length&&this.initColWidth.length===this.wheel.length)e=this.initColWidth.reduce(function(i,s){return i+s},0),this.initColWidth.forEach(function(i,s){_this4.wheel[s].style.width=(i/e*100).toFixed(2)+"%"});else for(var t=(100/this.wheel.length).toFixed(2),_e5=0;_e5<this.wheel.length;_e5++)this.wheel[_e5].style.width=t+"%"}},{key:"getIndex",value:function(t){return Math.round((2*this.optionHeight-t)/this.optionHeight)}},{key:"getIndexArr",value:function(){for(var t=[],e=0;e<this.curDistance.length;e++)t.push(this.getIndex(this.curDistance[e]));return t}},{key:"getCurValue",value:function(){var t=[],e=this.getIndexArr(),i=this.config.keyMap;if(this.isCascade)for(var s=0;s<this.wheel.length;s++){var _t$push,n=this.displayJson[s][e[s]];n&&t.push((_defineProperty(_t$push={},i.id,n[i.id]),_defineProperty(_t$push,i.value,n[i.value]),_t$push))}else if(this.isJsonType)for(var _s3=0;_s3<this.curDistance.length;_s3++)t.push(this.wheelsData[_s3].data[this.getIndex(this.curDistance[_s3])]);else for(var _s4=0;_s4<this.curDistance.length;_s4++)t.push(this.getInnerText(_s4));return t}},{key:"getValue",value:function(){return this.curValue}},{key:"calcDistance",value:function(t){return 2*this.optionHeight-t*this.optionHeight}},{key:"setCurDistance",value:function(t){for(var e=[],i=0;i<this.slider.length;i++)e.push(this.calcDistance(t[i])),this.movePosition(this.slider[i],e[i]);this.curDistance=e}},{key:"fixPosition",value:function(t){return-(this.getIndex(t)-2)*this.optionHeight}},{key:"movePosition",value:function(t,e){t.style.transform="translate3d(0,"+e+"px, 0)"}},{key:"locatePosition",value:function(t,e){this.curDistance[t]=this.calcDistance(e),this.movePosition(this.slider[t],this.curDistance[t]),this.isCascade&&this.checkRange(t,this.getIndexArr())}},{key:"updateCurDistance",value:function(t,e){this.curDistance[e]=parseInt(t.style.transform.split(",")[1])}},{key:"getInnerText",value:function(t){var e=this.slider[t].getElementsByTagName("li").length,i=this.getIndex(this.curDistance[t]);return e<=i?i=e-1:i<0&&(i=0),(null==(e=this.slider[t].getElementsByTagName("li")[i])?void 0:e.innerText)||""}},{key:"touch",value:function(t){var r,y,_this5=this,i=(t.composedPath&&t.composedPath())[1],s=parseInt(i.getAttribute("data-index")||"0");switch(t.type){case"touchstart":case"mousedown":i.style.transition="none 0s ease-out",this.startY=Math.floor((t instanceof TouchEvent?t.touches[0]:t).clientY),this.preMoveY=this.startY,"mousedown"===t.type&&(this.enableClickStatus=!0);break;case"touchend":case"mouseup":i.style.transition="transform 0.18s ease-out",this.moveEndY=Math.floor((t instanceof TouchEvent?t.changedTouches[0]:t).clientY),this.offsetSum=this.moveEndY-this.startY,this.oversizeBorder=-(i.getElementsByTagName("li").length-3)*this.optionHeight,0==this.offsetSum?2!=(y=Math.floor((window.innerHeight-this.moveEndY)/40))&&(y=this.curDistance[s]+(y-2)*this.optionHeight)<=2*this.optionHeight&&y>=this.oversizeBorder&&(this.curDistance[s]=y,this.movePosition(i,this.curDistance[s]),null!=(r=(y=this.config).transitionEnd)&&r.call(y,this.getIndexArr(),this.getCurValue(),this),null!=(y=(r=this.config).onTransitionEnd)&&y.call(r,this.getCurValue(),this.getIndexArr(),this)):(this.updateCurDistance(i,s),this.curDistance[s]=this.fixPosition(this.curDistance[s]),this.movePosition(i,this.curDistance[s]),this.curDistance[s]+this.offsetSum>2*this.optionHeight?(this.curDistance[s]=2*this.optionHeight,setTimeout(function(){_this5.movePosition(i,_this5.curDistance[s])},100)):this.curDistance[s]+this.offsetSum<this.oversizeBorder&&(this.curDistance[s]=this.oversizeBorder,setTimeout(function(){_this5.movePosition(i,_this5.curDistance[s])},100)),null!=(r=(y=this.config).transitionEnd)&&r.call(y,this.getIndexArr(),this.getCurValue(),this),null!=(y=(r=this.config).onTransitionEnd)&&y.call(r,this.getCurValue(),this.getIndexArr(),this)),"mouseup"===t.type&&(this.enableClickStatus=!1),this.isCascade&&this.checkRange(s,this.getIndexArr());break;case"touchmove":case"mousemove":if(t.preventDefault(),"mousemove"===t.type&&!this.enableClickStatus)break;this.moveY=Math.floor((t instanceof TouchEvent?t.touches[0]:t).clientY),this.offsetY=(this.moveY-this.preMoveY)*this.config.scrollSpeed,this.updateCurDistance(i,s),this.curDistance[s]=this.curDistance[s]+this.offsetY,this.movePosition(i,this.curDistance[s]),this.preMoveY=this.moveY}}}],[{key:"checkIsPC",value:function(){return!Boolean(navigator.userAgent.toLowerCase().match(/ipad|iphone os|midp|rv:1.2.3.4|ucweb|android|windows ce|windows mobile/))}},{key:"checkDataType",value:function(t){return"object"==_typeof(null==(t=null==(t=t[0])?void 0:t.data)?void 0:t[0])}},{key:"checkRequiredConfig",value:function(t){var i,e=l.REQUIRED_PARAMS;if(!t)return i=e.map(function(s){return"'".concat(s,"'")}),l.log("error","missing required param ".concat(i.join(" and "),".")),!1;for(var _i2=0;_i2<e.length;_i2++){var s=e[_i2];if(!t[s])return l.log("error","missing required param '".concat(s,"'.")),!1}return!0}},{key:"log",value:function(t,e){null!=(t=console[t])&&t.call(console,"[mobile-select]: ".concat(e))}}]),l}();return h(a,"defaultConfig",{keyMap:{id:"id",value:"value",childs:"childs"},position:[],colWidth:[],title:"",connector:" ",ensureBtnText:"确认",cancelBtnText:"取消",triggerDisplayValue:!0,scrollSpeed:1}),h(a,"REQUIRED_PARAMS",["trigger","wheels"]),a}();
/*
* mobile-select v1.2.0-beta.1
* mobile-select v1.2.0-beta.2
* Homepage: https://github.com/onlyhom/mobile-select

@@ -7,3 +7,3 @@ * Released under the MIT License.

*/
(function(a,o){typeof exports=="object"&&typeof module<"u"?module.exports=o(require("./style/mobile-select.css")):typeof define=="function"&&define.amd?define(["./style/mobile-select.css"],o):(a=typeof globalThis<"u"?globalThis:a||self,a.MobileSelect=o())})(this,function(){"use strict";var C=Object.defineProperty;var D=(a,o,g)=>o in a?C(a,o,{enumerable:!0,configurable:!0,writable:!0,value:g}):a[o]=g;var h=(a,o,g)=>(D(a,typeof o!="symbol"?o+"":o,g),g);const o=class{constructor(e){h(this,"mobileSelect");h(this,"trigger");h(this,"wheel");h(this,"slider");h(this,"wheels");h(this,"panel");h(this,"ensureBtn");h(this,"cancelBtn");h(this,"grayLayer");h(this,"popUp");h(this,"initPosition");h(this,"initColWidth");h(this,"connector");h(this,"wheelsData");h(this,"displayJson");h(this,"curValue");h(this,"curIndexArr");h(this,"isCascade");h(this,"isJsonType");h(this,"startY");h(this,"moveEndY");h(this,"moveY");h(this,"preMoveY");h(this,"offsetY");h(this,"offsetSum");h(this,"oversizeBorder");h(this,"enableClickStatus");h(this,"isPC");h(this,"optionHeight");h(this,"curDistance");h(this,"cascadeJsonData");h(this,"keyMap");h(this,"eventHandleMap");h(this,"initDeepCount");h(this,"config");!o.checkRequiredConfig(e)||(this.config=Object.assign({},o.defaultConfig,e),this.wheelsData=e.wheels,this.isJsonType=!1,this.cascadeJsonData=[],this.displayJson=[],this.curValue=[],this.curIndexArr=[],this.isCascade=!1,this.startY,this.moveEndY,this.moveY,this.preMoveY,this.offsetY=0,this.offsetSum=0,this.oversizeBorder,this.curDistance=[],this.enableClickStatus=!1,this.isPC=!0,this.optionHeight=0,this.initPosition=e.position||[],this.initColWidth=e.colWidth||[],this.init())}init(){const{config:e}=this;if(this.isJsonType=o.checkDataType(this.wheelsData),this.renderComponent(this.wheelsData),!!this.checkTriggerAvailable()){if(this.wheel=this.mobileSelect.getElementsByClassName("ms-wheel"),this.slider=this.mobileSelect.getElementsByClassName("ms-select-container"),this.panel=this.mobileSelect.querySelector(".ms-panel"),this.wheels=this.mobileSelect.querySelector(".ms-wheels"),this.ensureBtn=this.mobileSelect.querySelector(".ms-ensure"),this.cancelBtn=this.mobileSelect.querySelector(".ms-cancel"),this.grayLayer=this.mobileSelect.querySelector(".ms-gray-layer"),this.popUp=this.mobileSelect.querySelector(".ms-content"),this.optionHeight=this.mobileSelect.querySelector("li").offsetHeight,e.initValue&&e.triggerDisplayValue&&(this.trigger.innerText=e.initValue),this.setStyle(e),this.isPC=o.checkIsPC(),this.isCascade=this.checkCascade(),this.isCascade&&this.initCascade(),e.initValue&&(this.initPosition=this.getPositionByValue()),this.initPosition.length<this.slider.length){let t=this.slider.length-this.initPosition.length;for(let i=0;i<t;i++)this.initPosition.push(0)}this.isCascade?this.initPosition.forEach((t,i)=>{this.checkRange(i,this.initPosition)}):this.setCurDistance(this.initPosition),this.eventHandleMap={cancelBtn:{event:"click",fn:()=>{var t,i,s,n;this.hide(),(i=(t=this.config).cancel)==null||i.call(t,this.curIndexArr,this.curValue,this),(n=(s=this.config).onCancel)==null||n.call(s,this.curValue,this.curIndexArr,this)}},ensureBtn:{event:"click",fn:()=>{var i,s,n,r;this.hide(),this.optionHeight||(this.optionHeight=this.mobileSelect.querySelector("li").offsetHeight);let t="";for(let l=0;l<this.wheel.length;l++)l==this.wheel.length-1?t+=this.getInnerText(l):t+=this.getInnerText(l)+this.config.connector;e.triggerDisplayValue&&(this.trigger.innerText=t),this.curIndexArr=this.getIndexArr(),this.curValue=this.getCurValue(),(s=(i=this.config).callback)==null||s.call(i,this.curIndexArr,this.curValue,this),(r=(n=this.config).onChange)==null||r.call(n,this.curValue,this.curIndexArr,this)}},trigger:{event:"click",fn:()=>{this.show()}},grayLayer:{event:"click",fn:()=>this.hide()},popUp:{event:"click",fn:t=>t.stopPropagation()},panel:{event:["touchstart","touchend","touchmove"],fn:t=>this.touch(t)}},this.isPC&&(this.eventHandleMap.panel.event=["mousedown","mousemove","mouseup"]),this.registerEvents("add"),this.fixRowStyle(),e.autoFocus&&this.show()}}static checkIsPC(){return!Boolean(navigator.userAgent.toLowerCase().match(/ipad|iphone os|midp|rv:1.2.3.4|ucweb|android|windows ce|windows mobile/))}static checkDataType(e){var t,i;return typeof((i=(t=e[0])==null?void 0:t.data)==null?void 0:i[0])=="object"}static checkRequiredConfig(e){const t=o.REQUIRED_PARAMS;if(!e){const i=t.map(s=>`'${s}'`);return o.log("error",`missing required param ${i.join(" and ")}.`),!1}for(let i=0;i<t.length;i++){const s=t[i];if(!e[s])return o.log("error",`missing required param '${s}'.`),!1}return!0}static log(e,t){var i;(i=console[e])==null||i.call(console,`[mobile-select]: ${t}`)}checkTriggerAvailable(){const{config:e}=this;return this.trigger=e.trigger instanceof HTMLElement?e.trigger:document.querySelector(e.trigger),this.trigger?!0:(o.log("error","trigger HTMLElement does not found on your document."),!1)}getPositionByValue(){var n;const{keyMap:e,connector:t,initValue:i}=this.config,s=(i==null?void 0:i.split(t))||[];if(this.isJsonType){let r=(n=this.wheelsData[0])==null?void 0:n.data;return s.reduce((l,f)=>{var u;const c=r==null?void 0:r.findIndex(d=>d[e.value]==f);return l.push(c<0?0:c),r=(u=r[c])==null?void 0:u[e.childs],l},[])}return s.reduce((r,l,f)=>{var u,d;const c=(d=(u=this.wheelsData[f])==null?void 0:u.data)==null?void 0:d.findIndex(m=>m==l);return r.push(c<0?0:c),r},[])}setTitle(e){this.mobileSelect.querySelector(".ms-title").innerHTML=e}setStyle(e){if(e.ensureBtnColor&&(this.ensureBtn.style.color=e.ensureBtnColor),e.cancelBtnColor&&(this.cancelBtn.style.color=e.cancelBtnColor),e.titleColor){const t=this.mobileSelect.querySelector(".ms-title");t.style.color=e.titleColor}if(e.textColor&&(this.panel=this.mobileSelect.querySelector(".ms-panel"),this.panel.style.color=e.textColor),e.titleBgColor){const t=this.mobileSelect.querySelector(".ms-btn-bar");t.style.backgroundColor=e.titleBgColor}if(e.bgColor){this.panel=this.mobileSelect.querySelector(".ms-panel");const t=this.mobileSelect.querySelector(".ms-shadow-mask");this.panel.style.backgroundColor=e.bgColor,t.style.background="linear-gradient(to bottom, "+e.bgColor+", rgba(255, 255, 255, 0), "+e.bgColor+")"}if(typeof e.maskOpacity=="number"){const t=this.mobileSelect.querySelector(".ms-gray-layer");t.style.background="rgba(0, 0, 0, "+e.maskOpacity+")"}}show(){var e,t;this.mobileSelect.classList.add("ms-show"),typeof this.config.onShow=="function"&&((t=(e=this.config).onShow)==null||t.call(e))}hide(){var e,t;this.mobileSelect.classList.remove("ms-show"),typeof this.config.onHide=="function"&&((t=(e=this.config).onHide)==null||t.call(e))}registerEvents(e){for(const[t,i]of Object.entries(this.eventHandleMap))typeof i.event=="string"?this[t][`${e}EventListener`](i.event,i.fn,{passive:!1}):i.event.forEach(s=>{this[t][`${e}EventListener`](s,i.fn,{passive:!1})})}destroy(){this.registerEvents("remove"),this.mobileSelect.parentNode.removeChild(this.mobileSelect)}getOptionsHtmlStr(e){const{keyMap:t}=this.config;let i="";if(this.isJsonType)for(let s=0;s<e.length;s++){const n=e[s][t.id],r=e[s][t.value];i+=`<li data-id="${n}">${r}</li>`}else for(let s=0;s<e.length;s++)i+="<li>"+e[s]+"</li>";return i}renderComponent(e){this.mobileSelect=document.createElement("div"),this.mobileSelect.className="ms-mobile-select",this.mobileSelect.innerHTML=`<div class="ms-gray-layer"></div>
(function(a,o){typeof exports=="object"&&typeof module<"u"?module.exports=o(require("./style/mobile-select.css")):typeof define=="function"&&define.amd?define(["./style/mobile-select.css"],o):(a=typeof globalThis<"u"?globalThis:a||self,a.MobileSelect=o())})(this,function(){"use strict";var C=Object.defineProperty;var D=(a,o,g)=>o in a?C(a,o,{enumerable:!0,configurable:!0,writable:!0,value:g}):a[o]=g;var h=(a,o,g)=>(D(a,typeof o!="symbol"?o+"":o,g),g);const o=class{constructor(e){h(this,"mobileSelect");h(this,"trigger");h(this,"wheel");h(this,"slider");h(this,"wheels");h(this,"panel");h(this,"ensureBtn");h(this,"cancelBtn");h(this,"grayLayer");h(this,"popUp");h(this,"initPosition");h(this,"initColWidth");h(this,"connector");h(this,"wheelsData");h(this,"displayJson");h(this,"curValue");h(this,"curIndexArr");h(this,"isCascade");h(this,"isJsonType");h(this,"startY");h(this,"moveEndY");h(this,"moveY");h(this,"preMoveY");h(this,"offsetY");h(this,"offsetSum");h(this,"oversizeBorder");h(this,"enableClickStatus");h(this,"isPC");h(this,"optionHeight");h(this,"curDistance");h(this,"cascadeJsonData");h(this,"keyMap");h(this,"eventHandleMap");h(this,"initDeepCount");h(this,"config");!o.checkRequiredConfig(e)||(this.config=Object.assign({},o.defaultConfig,e),this.wheelsData=e.wheels,this.isJsonType=!1,this.cascadeJsonData=[],this.displayJson=[],this.curValue=[],this.curIndexArr=[],this.isCascade=!1,this.startY,this.moveEndY,this.moveY,this.preMoveY,this.offsetY=0,this.offsetSum=0,this.oversizeBorder,this.curDistance=[],this.enableClickStatus=!1,this.isPC=!0,this.optionHeight=0,this.initPosition=e.position||[],this.initColWidth=e.colWidth||[],this.init())}init(){const{config:e}=this;if(this.isJsonType=o.checkDataType(this.wheelsData),this.renderComponent(this.wheelsData),!!this.checkTriggerAvailable()){if(this.wheel=this.mobileSelect.getElementsByClassName("ms-wheel"),this.slider=this.mobileSelect.getElementsByClassName("ms-select-container"),this.panel=this.mobileSelect.querySelector(".ms-panel"),this.wheels=this.mobileSelect.querySelector(".ms-wheels"),this.ensureBtn=this.mobileSelect.querySelector(".ms-ensure"),this.cancelBtn=this.mobileSelect.querySelector(".ms-cancel"),this.grayLayer=this.mobileSelect.querySelector(".ms-gray-layer"),this.popUp=this.mobileSelect.querySelector(".ms-content"),this.optionHeight=this.mobileSelect.querySelector("li").offsetHeight,e.initValue&&e.triggerDisplayValue&&(this.trigger.innerText=e.initValue),this.setStyle(e),this.isPC=o.checkIsPC(),this.isCascade=this.checkCascade(),this.isCascade&&this.initCascade(),e.initValue&&(this.initPosition=this.getPositionByValue()),this.initPosition.length<this.slider.length){let t=this.slider.length-this.initPosition.length;for(let i=0;i<t;i++)this.initPosition.push(0)}this.isCascade?this.initPosition.forEach((t,i)=>{this.checkRange(i,this.initPosition)}):this.setCurDistance(this.initPosition),this.eventHandleMap={cancelBtn:{event:"click",fn:()=>{var t,i,s,n;this.hide(),(i=(t=this.config).cancel)==null||i.call(t,this.curIndexArr,this.curValue,this),(n=(s=this.config).onCancel)==null||n.call(s,this.curValue,this.curIndexArr,this)}},ensureBtn:{event:"click",fn:()=>{var i,s,n,r;this.hide(),this.optionHeight||(this.optionHeight=this.mobileSelect.querySelector("li").offsetHeight);let t="";for(let l=0;l<this.wheel.length;l++)l==this.wheel.length-1?t+=this.getInnerText(l):t+=this.getInnerText(l)+this.config.connector;e.triggerDisplayValue&&(this.trigger.innerText=t),this.curIndexArr=this.getIndexArr(),this.curValue=this.getCurValue(),(s=(i=this.config).callback)==null||s.call(i,this.curIndexArr,this.curValue,this),(r=(n=this.config).onChange)==null||r.call(n,this.curValue,this.curIndexArr,this)}},trigger:{event:"click",fn:()=>{this.show()}},grayLayer:{event:"click",fn:()=>this.hide()},popUp:{event:"click",fn:t=>t.stopPropagation()},panel:{event:["touchstart","touchend","touchmove"],fn:t=>this.touch(t)}},this.isPC&&(this.eventHandleMap.panel.event=["mousedown","mousemove","mouseup"]),this.registerEvents("add"),this.fixRowStyle(),e.autoFocus&&this.show()}}static checkIsPC(){return!Boolean(navigator.userAgent.toLowerCase().match(/ipad|iphone os|midp|rv:1.2.3.4|ucweb|android|windows ce|windows mobile/))}static checkDataType(e){var t,i;return typeof((i=(t=e[0])==null?void 0:t.data)==null?void 0:i[0])=="object"}static checkRequiredConfig(e){const t=o.REQUIRED_PARAMS;if(!e){const i=t.map(s=>`'${s}'`);return o.log("error",`missing required param ${i.join(" and ")}.`),!1}for(let i=0;i<t.length;i++){const s=t[i];if(!e[s])return o.log("error",`missing required param '${s}'.`),!1}return!0}static log(e,t){var i;(i=console[e])==null||i.call(console,`[mobile-select]: ${t}`)}checkTriggerAvailable(){const{config:e}=this;return this.trigger=e.trigger instanceof HTMLElement?e.trigger:document.querySelector(e.trigger),this.trigger?!0:(o.log("error","trigger HTMLElement does not found on your document."),!1)}getPositionByValue(){var n;const{keyMap:e,connector:t,initValue:i}=this.config,s=(i==null?void 0:i.split(t))||[];if(this.isJsonType){let r=(n=this.wheelsData[0])==null?void 0:n.data;return s.reduce((l,f)=>{var u;const c=r==null?void 0:r.findIndex(d=>d[e.value]==f);return l.push(c<0?0:c),r=(u=r[c])==null?void 0:u[e.childs],l},[])}return s.reduce((r,l,f)=>{var u,d;const c=(d=(u=this.wheelsData[f])==null?void 0:u.data)==null?void 0:d.findIndex(m=>m==l);return r.push(c<0?0:c),r},[])}setTitle(e){this.mobileSelect.querySelector(".ms-title").innerHTML=e}setStyle(e){if(e.ensureBtnColor&&(this.ensureBtn.style.color=e.ensureBtnColor),e.cancelBtnColor&&(this.cancelBtn.style.color=e.cancelBtnColor),e.titleColor){const t=this.mobileSelect.querySelector(".ms-title");t.style.color=e.titleColor}if(e.textColor&&(this.panel=this.mobileSelect.querySelector(".ms-panel"),this.panel.style.color=e.textColor),e.titleBgColor){const t=this.mobileSelect.querySelector(".ms-btn-bar");t.style.backgroundColor=e.titleBgColor}if(e.bgColor){this.panel=this.mobileSelect.querySelector(".ms-panel");const t=this.mobileSelect.querySelector(".ms-shadow-mask");this.panel.style.backgroundColor=e.bgColor,t.style.background="linear-gradient(to bottom, "+e.bgColor+", rgba(255, 255, 255, 0), "+e.bgColor+")"}if(typeof e.maskOpacity=="number"){const t=this.mobileSelect.querySelector(".ms-gray-layer");t.style.background="rgba(0, 0, 0, "+e.maskOpacity+")"}}show(){var e,t;this.mobileSelect.classList.add("ms-show"),typeof this.config.onShow=="function"&&((t=(e=this.config).onShow)==null||t.call(e))}hide(){var e,t;this.mobileSelect.classList.remove("ms-show"),typeof this.config.onHide=="function"&&((t=(e=this.config).onHide)==null||t.call(e))}registerEvents(e){for(const[t,i]of Object.entries(this.eventHandleMap))typeof i.event=="string"?this[t][`${e}EventListener`](i.event,i.fn,{passive:!1}):i.event.forEach(s=>{this[t][`${e}EventListener`](s,i.fn,{passive:!1})})}destroy(){var e,t;this.registerEvents("remove"),(t=(e=this.mobileSelect)==null?void 0:e.parentNode)==null||t.removeChild(this.mobileSelect)}getOptionsHtmlStr(e){const{keyMap:t}=this.config;let i="";if(this.isJsonType)for(let s=0;s<e.length;s++){const n=e[s][t.id],r=e[s][t.value];i+=`<li data-id="${n}">${r}</li>`}else for(let s=0;s<e.length;s++)i+="<li>"+e[s]+"</li>";return i}renderComponent(e){this.mobileSelect=document.createElement("div"),this.mobileSelect.className="ms-mobile-select",this.mobileSelect.innerHTML=`<div class="ms-gray-layer"></div>
<div class="ms-content">

@@ -10,0 +10,0 @@ <div class="ms-btn-bar">

@@ -6,3 +6,3 @@ {

"private": false,
"version": "1.2.0-beta.1",
"version": "1.2.0-beta.2",
"main": "dist/mobile-select.umd.js",

@@ -9,0 +9,0 @@ "module": "dist/mobile-select.es.js",

<p align="center"><img width="130" src="https://github.com/onlyhom/img-folder/blob/master/png/m_logo_orange.png?raw=true"></p>
<h1 align="center" >Mobile Select</h1>
<h1 align="center">Mobile Select</h1>
<p align="center">

@@ -55,12 +55,9 @@ <a href="https://github.com/onlyhom/mobileSelect.js/blob/master/LICENSE" title="LICENSE"><img src="https://img.shields.io/github/license/CKGrafico/Papanasi.svg?logo=creative%20commons&color=8FBFA9&logoColor=FFFFFF" alt="MIT license" /></a>

## Getting started
## 📚 Setup and scripts
### Installation
#### script include:
#### Method1:
Using CDN:
```html
<link rel="stylesheet" type="text/css" href="https://unpkg.com/mobile-select@latest/dist/style/mobile-select.css" />
<script type="text/javascript" src="https://unpkg.com/mobile-select@latest/dist/mobile-select.iife.min.js" ></script>
<link rel="stylesheet" type="text/css" href="dist/style/mobile-select.css" />
<script type="text/javascript" src="dist/mobile-select.iife.min.js" ></script>
```

@@ -72,3 +69,3 @@

#### Method2:
#### npm/pnpm/yarn:

@@ -99,3 +96,3 @@ Using npm:

## Getting Started
## 📗 Quick Start

@@ -102,0 +99,0 @@ #### ①Ordinary array format - Non-cascade

@@ -43,16 +43,32 @@ <p align="center"><img width="130" src="https://github.com/onlyhom/img-folder/blob/master/png/m_logo_orange.png?raw=true"></p>

```html
<link rel="stylesheet" type="text/css" href="dist/style/mobile-select.css" />
<script type="text/javascript" src="dist/mobile-select.iife.js" ></script>
<link rel="stylesheet" type="text/css" href="https://unpkg.com/mobile-select@latest/dist/style/mobile-select.css" />
<script type="text/javascript" src="https://unpkg.com/mobile-select@latest/dist/mobile-select.iife.min.js" ></script>
```
CDN
CDN Path:
> https://unpkg.com/mobile-select@latest/dist/
> https://cdn.jsdelivr.net/npm/mobile-select@latest/dist/
#### 方式二 npm:
```
#### 方式二 npm/pnpm/yarn导入:
Using npm:
```shell
npm install mobile-select
```
在你的 js 文件中 import:
Using pnpm:
```shell
pnpm add mobile-select
```
Using Yarn:
```shell
yarn add mobile-select
```
在你的js文件中 import:
```javascript

@@ -59,0 +75,0 @@ import MobileSelect from "mobile-select";

@@ -6,3 +6,3 @@ {

"private": false,
"version": "1.2.0-beta.1",
"version": "1.2.0-beta.2",
"main": "dist/mobile-select.umd.js",

@@ -9,0 +9,0 @@ "module": "dist/mobile-select.es.js",

<p align="center"><img width="130" src="https://github.com/onlyhom/img-folder/blob/master/png/m_logo_orange.png?raw=true"></p>
<h1 align="center" >Mobile Select</h1>
<h1 align="center">Mobile Select</h1>
<p align="center">

@@ -55,12 +55,9 @@ <a href="https://github.com/onlyhom/mobileSelect.js/blob/master/LICENSE" title="LICENSE"><img src="https://img.shields.io/github/license/CKGrafico/Papanasi.svg?logo=creative%20commons&color=8FBFA9&logoColor=FFFFFF" alt="MIT license" /></a>

## Getting started
## 📚 Setup and scripts
### Installation
#### script include:
#### Method1:
Using CDN:
```html
<link rel="stylesheet" type="text/css" href="https://unpkg.com/mobile-select@latest/dist/style/mobile-select.css" />
<script type="text/javascript" src="https://unpkg.com/mobile-select@latest/dist/mobile-select.iife.min.js" ></script>
<link rel="stylesheet" type="text/css" href="dist/style/mobile-select.css" />
<script type="text/javascript" src="dist/mobile-select.iife.min.js" ></script>
```

@@ -72,3 +69,3 @@

#### Method2:
#### npm/pnpm/yarn:

@@ -99,3 +96,3 @@ Using npm:

## Getting Started
## 📗 Quick Start

@@ -102,0 +99,0 @@ #### ①Ordinary array format - Non-cascade

@@ -380,3 +380,3 @@ import {

this.registerEvents("remove");
this.mobileSelect.parentNode.removeChild(this.mobileSelect);
this.mobileSelect?.parentNode?.removeChild(this.mobileSelect);
}

@@ -383,0 +383,0 @@

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc