✏️ 正在编辑: form-chat.min.js
路径:
/srv/systems_dir/yuppiecred/public/scripts/form-chat.min.js
提示:
您可以编辑任何文件(包括二进制文件),但请注意不当修改可能导致文件损坏。
function SingleConvState(t){return this.input=t,this.answer="",this.next=!1,this}function ConvState(t,e,r,i,a){this.form=r,this.wrapper=t,this.current=e,this.answers={},this.parameters=i,this.originalFormHtml=a,this.scrollDown=function(){$(this.wrapper).find("#messages").stop().animate({scrollTop:$(this.wrapper).find("#messages")[0].scrollHeight},600)}.bind(this)}function enviarSimulacao(t){if(!t)return Swal.fire({title:"Atenção!",text:"Dados inexistentes.",icon:"warning"}),!1;urlParams=new URLSearchParams(window.location.search),t+="&utm_source="+urlParams.get("utm_source")+"&utm_campaign="+urlParams.get("utm_campaign")+"&utm_medium="+urlParams.get("utm_medium"),$(".full-loading").show(),$.ajax({type:"POST",dataType:"JSON",url:baseUrl+"/simulacao-aberta/save",data:t,success:function(t){return $("#conclusao").show(),t.error?($("#conclusao").html(t.content),!1):t.success?(trackEnvioSimulacao(),$("#conclusao").html(t.content),!1):void 0},error:function(){Swal.fire({title:"Atenção!",text:"Houve um erro durante o processamento.",icon:"warning"})},complete:function(){$(".full-loading").hide()}}),current_div=$("#chat"),next_div=$("#conclusao"),next_div.show(),current_div.animate({opacity:0},{step:function(t){opacity=1-t,current_div.css({display:"none",position:"relative"}),next_div.css({opacity:opacity})},duration:600})}function trackEnvioSimulacao(){"undefined"!=typeof fbq&&fbq("trackCustom","Envio Simulação")}SingleConvState.prototype.hasNext=function(){return this.next},ConvState.prototype.destroy=function(){return!!this.originalFormHtml&&($(this.wrapper).html(this.originalFormHtml),!0)},ConvState.prototype.newState=function(t){var e=$.extend(!0,{},{name:"",noAnswer:!1,required:!0,questions:["You forgot the question!"],type:"text",multiple:!1,selected:"",answers:[]},t);return e.element=$('<input type="text" name="'+e.name+'"/>'),new SingleConvState(e)},ConvState.prototype.next=function(){if(this.current.input.hasOwnProperty("callback")&&("string"==typeof this.current.input.callback?window[this.current.input.callback](this):this.current.input.callback(this)),this.current.hasNext()){if(this.current=this.current.next,this.current.input.hasOwnProperty("fork")&&this.current.input.hasOwnProperty("case")){if(this.answers.hasOwnProperty(this.current.input.fork)&&this.answers[this.current.input.fork].value!=this.current.input.case)return this.next();if(!this.answers.hasOwnProperty(this.current.input.fork))return this.next()}return!0}return!1},ConvState.prototype.printQuestion=function(){var t=this.current.input.questions,e=t[Math.floor(Math.random()*t.length)],r=e.match(/\{(.*?)\}(\:(\d)*)?/g);for(var i in r)if(r.hasOwnProperty(i)){var a=r[i].replace(/\{|\}/g,""),n=a,s=!1;if(-1!=a.indexOf(":")&&(n=n.split(":")[0],s=a.split(":")[1]),!1!==s){var p=this.answers[n].text.split(" ");e=p.length>=s?e.replace(r[i],p[s]):e.replace(r[i],this.answers[n].text)}else e=e.replace(r[i],this.answers[n].text)}var u=$(this.wrapper).find(".message.typing");setTimeout(function(){u.html(e),u.removeClass("typing").addClass("ready"),"select"==this.current.input.type&&this.printAnswers(this.current.input.answers,this.current.input.multiple),this.scrollDown(),this.current.input.hasOwnProperty("noAnswer")&&!0===this.current.input.noAnswer&&(this.next()?setTimeout(function(){var t=$('<div class="message to typing"><div class="typing_loader"></div></div>');$(this.wrapper).find("#messages").append(t),this.scrollDown(),this.printQuestion()}.bind(this),200):this.parameters.eventList.onSubmitForm(this)),$(this.wrapper).find(this.parameters.inputIdHashTagName).focus()}.bind(this),500)},ConvState.prototype.printAnswers=function(t,e){var r=!1;if(0!=this.wrapper.find("div.options").height()&&(r=!0),this.wrapper.find("div.options div.option").remove(),e){for(var i in t)if(t.hasOwnProperty(i)){var a=$('<div class="option">'+t[i].text+"</div>").data("answer",t[i]).click(function(t){Array.isArray(this.current.input.selected)||(this.current.input.selected=[]);var e=this.current.input.selected.indexOf($(t.target).data("answer").value);-1==e?(this.current.input.selected.push($(t.target).data("answer").value),$(t.target).addClass("selected")):(this.current.input.selected.splice(e,1),$(t.target).removeClass("selected")),this.wrapper.find(this.parameters.inputIdHashTagName).removeClass("error"),this.wrapper.find(this.parameters.inputIdHashTagName).val(""),this.current.input.selected.length>0?this.wrapper.find("button.submit").addClass("glow"):this.wrapper.find("button.submit").removeClass("glow")}.bind(this));this.wrapper.find("div.options").append(a),$(window).trigger("dragreset")}}else for(var i in t)if(t.hasOwnProperty(i)){a=$('<div class="option">'+t[i].text+"</div>").data("answer",t[i]).click(function(t){this.current.input.selected=$(t.target).data("answer").value,this.wrapper.find(this.parameters.inputIdHashTagName).removeClass("error"),this.wrapper.find(this.parameters.inputIdHashTagName).val(""),this.answerWith($(t.target).data("answer").text,$(t.target).data("answer")),this.wrapper.find("div.options div.option").remove()}.bind(this));this.wrapper.find("div.options").append(a),$(window).trigger("dragreset")}if(!r){var n=$(this.wrapper).find("div.options").height(),s=$(this.wrapper).find(".wrapper-messages").height();$(this.wrapper).find(".wrapper-messages").data("originalHeight",s),$(this.wrapper).find(".wrapper-messages").css({marginBottom:n,maxHeight:s-n})}"disable"==this.parameters.selectInputStyle?($(this.wrapper).find("#"+this.parameters.inputIdName).prop("disabled",!0),$(this.wrapper).find("#"+this.parameters.inputIdName).attr("placeholder",this.parameters.selectInputDisabledText)):"hide"==this.parameters.selectInputStyle&&(this.current.input.multiple?($(this.wrapper).find("#"+this.parameters.inputIdName).prop("disabled",!0),$(this.wrapper).find("#"+this.parameters.inputIdName).attr("placeholder",this.parameters.selectInputDisabledText)):($(this.wrapper).find("#"+this.parameters.inputIdName).css({display:"none"}),$(this.wrapper).find("#convForm button").css({display:"none"})))},ConvState.prototype.answerWith=function(t,e){this.current.input.hasOwnProperty("name")&&("string"==typeof e?("tel"==this.current.input.type&&(e=e.replace(/\s|\(|\)|-/g,"")),this.answers[this.current.input.name]={text:t,value:e},this.current.answer={text:t,value:e}):(this.answers[this.current.input.name]=e,this.current.answer=e),"select"!=this.current.input.type||this.current.input.multiple?$(this.current.input.element).val(e).change():$(this.current.input.element).val(e.value).change()),"password"==this.current.input.type&&(t=t.replace(/./g,"*"));var r=$('<div class="message from">'+t+"</div>");"select"==this.current.input.type&&"disable"==this.parameters.selectInputStyle?($(this.wrapper).find("#"+this.parameters.inputIdName).prop("disabled",!1),$(this.wrapper).find("#"+this.parameters.inputIdName).attr("placeholder",this.parameters.placeHolder),$(this.wrapper).find("#"+this.parameters.inputIdName).attr("inputmode",this.current.next.input.inputmode),$(this.wrapper).find("#"+this.parameters.inputIdName).attr("onkeypress",this.current.next.input.onkeypress)):"select"==this.current.input.type&&"hide"==this.parameters.selectInputStyle?this.current.input.multiple?($(this.wrapper).find("#"+this.parameters.inputIdName).prop("disabled",!1),$(this.wrapper).find("#"+this.parameters.inputIdName).attr("placeholder",this.parameters.placeHolder),$(this.wrapper).find("#"+this.parameters.inputIdName).attr("inputmode",this.current.next.input.inputmode),$(this.wrapper).find("#"+this.parameters.inputIdName).attr("onkeypress",this.current.next.input.onkeypress)):($(this.wrapper).find("#"+this.parameters.inputIdName).css({display:"block"}),$(this.wrapper).find("#convForm button").css({display:"block"}),$(this.wrapper).find("#"+this.parameters.inputIdName).attr("inputmode",this.current.next.input.inputmode),$(this.wrapper).find("#"+this.parameters.inputIdName).attr("onkeypress",this.current.next.input.onkeypress)):($(this.wrapper).find("#"+this.parameters.inputIdName).prop("disabled",!1),$(this.wrapper).find("#"+this.parameters.inputIdName).attr("placeholder",this.parameters.placeHolder),this.current.next.input.onkeypress&&!this.current.next.input.case?($(this.wrapper).find("#"+this.parameters.inputIdName).attr("inputmode",this.current.next.input.inputmode),$(this.wrapper).find("#"+this.parameters.inputIdName).attr("onkeypress",this.current.next.input.onkeypress)):($(this.wrapper).find("#"+this.parameters.inputIdName).removeAttr("inputmode"),$(this.wrapper).find("#"+this.parameters.inputIdName).removeAttr("onkeypress"),$(this.wrapper).find("#"+this.parameters.inputIdName).unmask())),$(this.wrapper).find("div.options div.option").remove();var i=$(this.wrapper).find("div.options").height(),a=$(this.wrapper).find(".wrapper-messages").data("originalHeight");$(this.wrapper).find(".wrapper-messages").css({marginBottom:i,maxHeight:a}),$(this.wrapper).find(this.parameters.inputIdHashTagName).focus(),e.hasOwnProperty("callback")&&(this.current.input.callback=e.callback),setTimeout(function(){$(this.wrapper).find("#messages").append(r),this.scrollDown()}.bind(this),100),$(this.form).append(this.current.input.element);var n=$('<div class="message to typing"><div class="typing_loader"></div></div>');setTimeout(function(){$(this.wrapper).find("#messages").append(n),this.scrollDown()}.bind(this),150),this.parameters.eventList.onInputSubmit(this,function(){this.next()?setTimeout(function(){this.printQuestion()}.bind(this),300):this.parameters.eventList.onSubmitForm(this)}.bind(this))},function(t){t.fn.convform=function(e){var r=this,i=t(r).html();t(this).addClass("conv-form-wrapper");var a=t.extend(!0,{},{placeHolder:"Digitar",typeInputUi:"input",timeOutFirstQuestion:1200,buttonClassStyle:"icon2-arrow",selectInputStyle:"show",selectInputDisabledText:"Selecione uma opção",eventList:{onSubmitForm:function(t){return sleep(3e3),enviarSimulacao(t.form.serialize()),!0},onInputSubmit:function(t,e){t.current.input.hasOwnProperty("callback")?"string"==typeof t.current.input.callback?window[t.current.input.callback](t,e):t.current.input.callback(t,e):e()}},formIdName:"convForm",inputIdName:"userInput",loadSpinnerVisible:"",buttonText:"▶"},e),n=t(this).find("input, select, textarea").map((function(){var e={};return t(this).attr("name")&&(e.name=t(this).attr("name")),t(this).attr("data-no-answer")&&(e.noAnswer=!0),t(this).attr("required")&&(e.required=!0),t(this).attr("type")&&(e.type=t(this).attr("type")),e.questions=t(this).attr("data-conv-question").split("|"),t(this).attr("data-pattern")&&(e.pattern=t(this).attr("data-pattern")),t(this).attr("data-inputmode")&&(e.inputmode=t(this).attr("data-inputmode")),t(this).attr("data-onkeypress")&&(e.onkeypress=t(this).attr("data-onkeypress")),t(this).attr("data-callback")&&(e.callback=t(this).attr("data-callback")),t(this).is("select")&&(e.type="select",e.answers=t(this).find("option").map((function(){var e={};return e.text=t(this).text(),e.value=t(this).val(),t(this).attr("data-callback")&&(e.callback=t(this).attr("data-callback")),e})).get(),t(this).prop("multiple")?(e.multiple=!0,e.selected=[]):(e.multiple=!1,e.selected="")),t(this).parent("div[data-conv-case]").length&&(e.case=t(this).parent("div[data-conv-case]").attr("data-conv-case"),e.fork=t(this).parent("div[data-conv-case]").parent("div[data-conv-fork]").attr("data-conv-fork")),e.element=this,t(this).detach(),e})).get();if(n.length){var s,p=t(r).find("form").hide();switch(a.inputIdHashTagName="#"+a.inputIdName,a.typeInputUi){case"input":s=t('<form id="'+a.formIdName+'" class="convFormDynamic"><div class="options dragscroll"></div><input id="'+a.inputIdName+'" type="text" placeholder="'+a.placeHolder+'" class="userInputDynamic"></><button type="submit" class="submit">'+a.buttonText+'</button><span class="clear"></span></form>');break;case"textarea":s=t('<form id="'+a.formIdName+'" class="convFormDynamic"><div class="options dragscroll"></div><textarea id="'+a.inputIdName+'" rows="1" placeholder="'+a.placeHolder+'" class="userInputDynamic"></textarea><button type="submit" class="submit">'+a.buttonText+'</button><span class="clear"></span></form>');break;default:return!1}t(r).append('<div class="wrapper-messages"><div class="spinLoader '+a.loadSpinnerVisible+' "></div><div id="messages"></div></div>'),t(r).append(s);var u=new SingleConvState(n[0]),o=new ConvState(r,u,p,a,i);for(var d in n)0!=d&&n.hasOwnProperty(d)&&(u.next=new SingleConvState(n[d]),u=u.next);return setTimeout((function(){t.when(t("div.spinLoader").addClass("hidden")).done((function(){var e=t('<div class="message to typing"><div class="typing_loader"></div></div>');t(o.wrapper).find("#messages").append(e),o.scrollDown(),o.printQuestion()}))}),a.timeOutFirstQuestion),t(s).find(a.inputIdHashTagName).keypress((function(e){if(13==e.which){var r=t(this).val();if(e.preventDefault(),"select"!=o.current.input.type||o.current.input.multiple)if("select"==o.current.input.type&&o.current.input.multiple){var i;if(""!=r.trim())(i=o.current.input.answers.filter((function(t){return-1!=t.text.toLowerCase().indexOf(r.toLowerCase())}))).length?-1==o.current.input.selected.indexOf(i[0].value)?(o.current.input.selected.push(i[0].value),o.wrapper.find(a.inputIdHashTagName).val("")):o.wrapper.find(a.inputIdHashTagName).val(""):o.wrapper.find(a.inputIdHashTagName).addClass("error");else o.current.input.selected.length&&t(this).parent("form").submit()}else""==r.trim()||o.wrapper.find(a.inputIdHashTagName).hasClass("error")?t(o.wrapper).find(a.inputIdHashTagName).focus():t(this).parent("form").submit();else if(o.current.input.required)o.wrapper.find("#userInputBot").addClass("error");else(i=o.current.input.answers.filter((function(t){return-1!=t.text.toLowerCase().indexOf(r.toLowerCase())}))).length?(o.current.input.selected=i[0],t(this).parent("form").submit()):o.wrapper.find(a.inputIdHashTagName).addClass("error")}autosize.update(t(o.wrapper).find(a.inputIdHashTagName))})).on("input",(function(e){if("select"==o.current.input.type){var r=t(this).val(),i=o.current.input.answers.filter((function(t){return-1!=t.text.toLowerCase().indexOf(r.toLowerCase())}));i.length?(o.wrapper.find(a.inputIdHashTagName).removeClass("error"),o.printAnswers(i,o.current.input.multiple)):o.wrapper.find(a.inputIdHashTagName).addClass("error")}else if(o.current.input.hasOwnProperty("pattern")){new RegExp(o.current.input.pattern,"i").test(t(this).val())?o.wrapper.find(a.inputIdHashTagName).removeClass("error"):o.wrapper.find(a.inputIdHashTagName).addClass("error")}})),t(s).find("button.submit").click((function(e){var r=t(o.wrapper).find(a.inputIdHashTagName).val();if(e.preventDefault(),"select"!=o.current.input.type||o.current.input.multiple)if("select"==o.current.input.type&&o.current.input.multiple){if(o.current.input.required&&0===o.current.input.selected.length)return!1;""!=r.trim()&&r!=a.placeHolder?(i=o.current.input.answers.filter((function(t){return-1!=t.text.toLowerCase().indexOf(r.toLowerCase())}))).length?-1==o.current.input.selected.indexOf(i[0].value)?(o.current.input.selected.push(i[0].value),o.wrapper.find(a.inputIdHashTagName).val("")):o.wrapper.find(a.inputIdHashTagName).val(""):o.wrapper.find(a.inputIdHashTagName).addClass("error"):o.current.input.selected.length&&(t(this).removeClass("glow"),t(this).parent("form").submit())}else""==r.trim()||o.wrapper.find(a.inputIdHashTagName).hasClass("error")?t(o.wrapper).find(a.inputIdHashTagName).focus():t(this).parent("form").submit();else{if(o.current.input.required&&!o.current.input.selected)return!1;var i;r==a.placeHolder&&(r=""),(i=o.current.input.answers.filter((function(t){return-1!=t.text.toLowerCase().indexOf(r.toLowerCase())}))).length?(o.current.input.selected=i[0],t(this).parent("form").submit()):o.wrapper.find(a.inputIdHashTagName).addClass("error")}autosize.update(t(o.wrapper).find(a.inputIdHashTagName))})),t(s).submit((function(e){e.preventDefault();var r=t(this).find(a.inputIdHashTagName).val();t(this).find(a.inputIdHashTagName).val(""),"select"==o.current.input.type?o.current.input.multiple?o.answerWith(o.current.input.selected.join(", "),o.current.input.selected):o.answerWith(o.current.input.selected.text,o.current.input.selected):o.answerWith(r,r)})),"function"==typeof autosize&&($textarea=t(o.wrapper).find(a.inputIdHashTagName),autosize($textarea)),o}return!1}}(jQuery);
💾 保存文件
← 返回文件管理器