"use strict";var _createClass=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)}}return function(Constructor,protoProps,staticProps){if(protoProps)defineProperties(Constructor.prototype,protoProps);if(staticProps)defineProperties(Constructor,staticProps);return Constructor}}();function _toConsumableArray(arr){if(Array.isArray(arr)){for(var i=0,arr2=Array(arr.length);i<arr.length;i++){arr2[i]=arr[i]}return arr2}else{return Array.from(arr)}}function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function")}}(function(define){define(["jquery"],function($){"use strict";var InputTag=function(){_createClass(InputTag,[{key:"elem",get:function get(){return $(this.options.elem)}},{key:"copyData",get:function get(){return[].concat(_toConsumableArray(this.options.data))}}]);function InputTag(options){_classCallCheck(this,InputTag);this.options={elem:".layui-tag-input",theme:["layui-bg-red","layui-bg-orange","layui-bg-green","layui-bg-cyan","layui-bg-blue","layui-bg-black"],data:[],removeKeyNum:8,createKeyNum:13,permanentData:[]};this.render(options)}_createClass(InputTag,[{key:"render",value:function render(options){this.init(options);this.listen()}},{key:"init",value:function init(options){var spans="",that=this;this.options=$.extend(this.options,options);!this.elem.attr("placeholder")&&this.elem.attr("placeholder","添加标签");$.each(this.options.data,function(index,item){spans+=that.spanHtml(item)});this.elem.before(spans)}},{key:"listen",value:function listen(){var that=this;this.elem.parent().on("click","a",function(){that.removeItem($(this).parent("span"))});this.elem.parent().on("click",function(){that.elem.focus()});this.elem.keydown(function(event){var keyNum=event.keyCode?event.keyCode:event.which;if(keyNum===that.options.removeKeyNum){if(!that.elem.val().trim()){var closeItems=that.elem.parent().find("a");if(closeItems.length){that.removeItem($(closeItems[closeItems.length-1]).parent("span"));event.preventDefault()}}}else if(keyNum===that.options.createKeyNum){that.createItem();event.preventDefault()}})}},{key:"createItem",value:function createItem(){var value=this.elem.val().trim();if(this.options.beforeCreate&&typeof this.options.beforeCreate==="function"){var modifiedValue=this.options.beforeCreate(this.copyData,value);if(typeof modifiedValue=="string"&&modifiedValue){value=modifiedValue}else{value=""}}if(value){if(!this.options.data.includes(value)){this.options.data.push(value);this.elem.before(this.spanHtml(value));this.onChange(value,"create")}}this.elem.val("")}},{key:"removeItem",value:function removeItem(target){var that=this;var closeSpan=target.remove(),closeSpanText=$(closeSpan).children("span").text();var value=that.options.data.splice($.inArray(closeSpanText,that.options.data),1);value.length===1&&that.onChange(value[0],"remove")}},{key:"randomColor",value:function randomColor(){return this.options.theme[Math.floor(Math.random()*this.options.theme.length)]}},{key:"spanHtml",value:function spanHtml(value){return'<span class="layui-tag layui-anim-fadein '+this.randomColor()+'">'+"<span>"+value+"</span>"+(this.options.permanentData.includes(value)?"":'<a href="#" title="删除标签">&times;</a>')+"</span>"}},{key:"onChange",value:function onChange(value,type){this.options.onChange&&typeof this.options.onChange==="function"&&this.options.onChange(this.copyData,value,type)}},{key:"getData",value:function getData(){return this.copyData}},{key:"clearData",value:function clearData(){this.options.data=[];this.elem.prevAll("span.layui-tag").remove()}}]);return InputTag}();return{render:function render(options){return new InputTag(options)}}})})(typeof define==="function"&&define.amd?define:function(deps,factory){var MOD_NAME="inputTag";if(typeof module!=="undefined"&&module.exports){module.exports=factory(require("jquery"))}else if(window.layui&&layui.define){layui.define("jquery",function(exports){exports(MOD_NAME,factory(layui.jquery))})}else{window[MOD_NAME]=factory(window.jQuery)}});layui.link("/static/plugins/lay-module/inputTags/inputTags.css?v=7");