text: !function(t){t.fn.baigoSubmit=function(e){"use strict";if(this.length<1)return this;var a=t(this);a.submit(function(t){t.preventDefault()});var s=t.extend(!0,{ajax_url:"",timeout:3e4,class_msg:{submitting:"bg-msg-submitting",err:"bg-msg-err",success:"bg-msg-success"},msg_text:{submitting:"Submitting ...",err:"Error"},selector:{submit_btn:'[type="submit"]',empty_input:":password",jump_link:".bg-jump"},modal:{selector:{modal:".bg-submit-modal",msg:".bg-msg",extra:".bg-extra",close:".bg-close",ok:".bg-ok"},btn_text:{close:"Close",ok:"OK"},tpl:'<div class="modal fade bg-submit-modal"><div class="modal-dialog modal-dialog-centered"><div class="modal-content"><div class="modal-body"><div class="bg-msg mb-2"></div><div class="bg-extra mb-2"></div><div class="bg-jump"></div></div><div class="modal-footer"><button type="button" class="btn btn-outline-secondary btn-sm bg-close" data-dismiss="modal">Close</button><a href="#" class="btn btn-primary btn-sm bg-ok">OK</a></div></div></div></div>',delay:5e3},replaces:"",jump:{url:"",text:"",attach_key:"",separator:"",equal:"",delay:3e3}},e),o=s.modal.selector;t(o.modal).length<1&&t("body").append(s.modal.tpl),t(o.modal+" "+o.msg).addClass(s.class_msg.submitting),t(o.modal+" "+o.msg).html(s.msg_text.submitting),t(o.modal+" "+o.close).text(s.modal.btn_text.close),t(o.modal+" "+o.ok).text(s.modal.btn_text.ok),t(o.modal+" "+o.ok).hide();var l={jumpUrl:function(t){var e="";if(s.jump.url.length>0&&s.jump.text.length>0){var a="",o="";e=s.jump.url,s.jump.attach_key.length>0&&void 0!==t&&(a=void 0!==s.jump.separator&&s.jump.separator.length>0?s.jump.separator:e.indexOf("?")?"&":"?",o=void 0!==s.jump.equal&&s.jump.equal.length>0?s.jump.equal:"=",e+=a+s.jump.attach_key+o+t)}return e},output:function(e,u,m,r,n){switch(e){case"pre":l.modalOutput("submitting","submitting",s.msg_text.submitting),t(o.modal).modal("show"),a.find(s.selector.submit_btn).attr("disabled",!0);break;case"err":l.modalOutput("err","err",s.msg_text.err+"! "+m);break;case"success":var d,c,g="",p="",b="<span>";void 0!==u&&null!==u||(u="x"),"y"==u.substr(0,1)?(d="success",c="success",(p=l.jumpUrl(r)).length>0&&(c="submitting")):(d="err",c="err",g=" "+u),void 0!==m&&(b=m+g),b+="</span>",l.modalOutput(d,c,b,n),g.length<1&&(a.find(s.selector.empty_input).val(""),p.length>0&&i.jump(p,s.jump.text));break;default:t(o.modal).modal("hide"),a.find(s.selector.submit_btn).removeAttr("disabled")}},modalOutput:function(e,a,l,i){t(o.modal+" "+o.msg).removeClass(s.class_msg.submitting+" "+s.class_msg.err+" "+s.class_msg.success),void 0!==s.class_msg[e]&&t(o.modal+" "+o.msg).addClass(s.class_msg[e]),void 0!==l&&l.length>0&&t(o.modal+" "+o.msg).html(l),void 0!==i&&i.length>0&&t(o.modal+" "+o.extra).html(i)},replaceResult:function(e){"object"==typeof s.replaces?t.each(s.replaces,function(a,s){if("object"==typeof s){var o=a;if(void 0!==s.param&&s.param.length>0&&(o=s.param),void 0!==e[o]){var l="#"+a,i="value";void 0!==s.selector&&s.selector.length>0&&(l=s.selector),void 0!==s.attr&&s.attr.length>0&&(i=s.attr),t(l).attr(i,e[o])}}else"string"==typeof s&&void 0!==e[s]&&t("#"+s).val(e[s])}):"string"==typeof s.replaces&&void 0!==e[s.replaces]&&t("#"+s.replaces).val(e[s.replaces])},submitFunc:function(e){var o;void 0!==s.ajax_url&&""!=s.ajax_url||(s.ajax_url=a.attr("action")),o=s.ajax_url.indexOf("?")>0?"&":"?",t.ajax({url:s.ajax_url+o+(new Date).getTime()+"at"+Math.random(),type:"post",dataType:"json",data:t(a).serialize(),timeout:s.timeout,beforeSend:function(){l.output("pre")},error:function(t){l.output("err","",t.status+" "+t.statusText),setTimeout(function(){l.output()},s.modal.delay)},success:function(t){var a;void 0!==t[s.jump.attach_key]&&(a=t[s.jump.attach_key]),l.replaceResult(t),void 0===t.rcode&&(t.rcode="x"),void 0===t.msg&&"undefined"!=t.err_message&&(t.msg=t.err_message),void 0===t.msg&&(t.msg="Unknow"),void 0===t.extra&&(t.extra=""),l.output("success",t.rcode,t.msg,a,t.extra),e&&e instanceof Function&&e(t),setTimeout(function(){l.output()},s.modal.delay)}})}},i={formSubmit:function(t,e){void 0!==t&&!1!==t&&(s.ajax_url=t),l.submitFunc(function(t){e&&e instanceof Function&&e(t)})},jump:function(e,a){void 0!==e&&e.length>0&&(t(o.modal+" "+o.ok).attr("href",e),t(o.modal+" "+o.ok).show(),(void 0===a||a.length<1)&&(a=e),t(s.selector.jump_link).html('<a href="'+e+'">'+a+"</a>"),setTimeout(function(){window.location.href=e},s.jump.delay))},ajaxUrl:function(t){void 0!==t&&(s.ajax_url=t)}};return i}}(jQuery);