/*
* @Author: layui-2
* @Date:   2018-08-31 11:40:42
* @Last Modified by:   yuege
* 根据inputTags修改
* @Last Modified time: 2020-09-04 14:07:38
*/
layui.define(["jquery","layer"],function(exports){"use strict";var $=layui.jquery,layer=layui.layer,inputTags={config:{},set:function(options){var that=this;that.config=$.extend({},that.config,options);return that},on:function(events,callback){return layui.onevent.call(this,MOD_NAME,events,callback)}},thisinputTags=function(){var that=this,options=that.config;return{config:options}},MOD_NAME="inputTags",Class=function(options){var that=this;that.config=$.extend({},that.config,inputTags.config,options);that.render()};Class.prototype.config={close:false,theme:"",content:[],aldaBtn:false};Class.prototype.init=function(){var that=this,spans="",options=that.config,span=document.createElement("span");$.each(options.content,function(index,item){spans+="<span><em>"+item+'</em><button type="button" class="close">×</button></span>'});options.elem.before(spans);that.events()};Class.prototype.render=function(){var that=this,options=that.config;options.elem=$(options.elem);that.enter()};Class.prototype.enter=function(){var that=this,spans="",options=that.config;options.elem.focus();options.elem.keypress(function(event){var keynum=event.keyCode?event.keyCode:event.which;if(keynum=="32"){var $val=options.elem.val().trim();if(!$val)return false;if(options.content.indexOf($val)==-1){options.content.push($val);that.render();spans="<span><em>"+$val+'</em><button type="button" class="close">×</button></span>';options.elem.before(spans);var content="";$.each(options.content,function(index,val){content+=val+","});options.elem.siblings('input[type="hidden"]').val($.trim(content,","))}options.done&&typeof options.done==="function"&&options.done($val);options.elem.val("")}})};Class.prototype.events=function(){var that=this,options=that.config;$(".tags").on("click",".close",function(){var ThisText=$(this).parent("span").find("em").text();options.content.splice($.inArray(ThisText,options.content),1);var content="";$.each(options.content,function(index,val){content+=val+","});$(this).parents("span").siblings('input[type="hidden"]').val($.trim(content,","));$(this).parent("span").remove()})};inputTags.render=function(options){var inst=new Class(options);inst.init();return thisinputTags.call(inst)};layui.link('/static/plugins/lay-module/inputTags/inputTags.css');
    exports("inputTags",inputTags)});