forked from EverexIO/Ethplorer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtilda-forms-1.0.min.js
1 lines (1 loc) · 13.6 KB
/
tilda-forms-1.0.min.js
1
!function($){$(document).ready(function(){$(".js-tilda-mask").each(function(){var e=$(this).data("tilda-mask"),r=$(this).data("tilda-mask-holder");e&&(r>""?$(this).mask(e,{placeholder:r}):$(this).mask(e))}),window.validateForm=function(e){var r=[];return e.find(".js-tilda-rule").each(function(){var e,t=$(this).data("tilda-req")||0,a=$(this).data("tilda-rule")||"none",i={},o=$(this).val(),n="";if(i.obj=$(this),i.type=[],o&&o.length>0&&(n=o.replace(/\s/g,""),o=o.trim()),1==t&&0==o.length&&0==n.length)i.type.push("req");else switch(a){case"email":e=/^[a-zA-Zёа-яЁА-Я0-9_\.\-\+]{1,64}@[a-zA-Zёа-яЁА-Я0-9][a-zA-Zёа-яЁА-Я0-9\.\-]{0,253}\.[a-zA-Zёа-яЁА-Я]{2,10}$/,o.length>0&&!o.match(e)&&i.type.push("email");break;case"url":e=/^((https?|ftp):\/\/)?[a-zA-Zёа-яЁА-Я0-9][a-zA-Zёа-яЁА-Я0-9\.\-]{0,253}\.[a-zA-Zёа-яЁА-Я]{2,10}\/?$/,o.length>0&&!o.match(e)&&i.type.push("url");break;case"phone":e=/^[0-9\(\)\-\+]+$/gi,n.length>0&&!n.match(e)&&i.type.push("phone");break;case"name":var e=/^([A-Za-zА-Яа-яЁё\s]{1,}((\-)?[A-Za-zА-Яа-яЁё\.\s](\')?){0,})*$/i;o.length>0&&!o.match(e)&&i.type.push("name");break;case"nameeng":var e=/^([A-Za-z\s]{1,}((\-)?[A-Za-z\.\s](\')?){0,})*$/i;o.length>0&&!o.match(e)&&i.type.push("nameeng");break;case"namerus":var e=/^([А-Яа-яЁё\s]{1,}((\-)?[А-Яа-яЁё\.\s](\')?){0,})*$/i;o.length>0&&!o.match(e)&&i.type.push("namerus");break;case"string":var e=/^[A-Za-zА-Яа-яЁё0-9,\.:;\"\'\`\-\_\+\?\!\%\$\@\*\&\^\s]$/i;o.length>0&&!o.match(e)&&i.type.push("string")}i.type&&i.type.length>0&&(r[r.length]=i)}),r};var $jallforms=$(".r").find(".js-form-proccess[data-formactiontype]");$jallforms.length>0&&$jallforms.each(function(){2==$(this).data("formactiontype")&&$(this).append('<div style="position: absolute; left: -5000px;"><input type="text" name="form-spec-comments" value="Its good" class="js-form-spec-comments" tabindex="-1" /></div>')}),$(".r").off("submit",".js-form-proccess"),$(".r").on("submit",".js-form-proccess",function(){var e=$(this).find("[type=submit]"),r=e.data("form-sending-status");return r&&3==r?(e.data("form-sending-status"),!0):($(this).find("[type=submit]").trigger("click"),!1)}),$(".r").off("click",".js-form-proccess [type=submit]"),$(".r").on("click",".js-form-proccess [type=submit]",function(event){event.preventDefault();var btnformsubmit=$(this),btnstatus=btnformsubmit.data("form-sending-status");if(btnstatus>="1")return!1;var $activeForm=$(this).closest("form");if(0==$activeForm.length)return!1;btnformsubmit.addClass("t-btn_sending"),btnformsubmit.data("form-sending-status","1"),btnformsubmit.data("submitform",$activeForm),$activeForm.find(".js-errorbox-all").hide(),$activeForm.find(".js-rule-error").hide(),$activeForm.find(".js-error-rule-all").html(""),$activeForm.find(".js-successbox").hide(),$activeForm.find(".js-error-control-box").removeClass("js-error-control-box"),$activeForm.removeClass("js-send-form-error"),$activeForm.removeClass("js-send-form-success");var arError=validateForm($activeForm),$blockinput="";if(arError&&arError.length>0){var clsInputBoxSelector=$activeForm.data("inputbox");clsInputBoxSelector||(clsInputBoxSelector=".blockinput");for(var i=0;i<arError.length;i++)if(arError[i]&&arError[i].obj)for(arError[i].obj.closest(clsInputBoxSelector).addClass("js-error-control-box"),j=0;j<arError[i].type.length;j++){error=arError[i].type[j];var $errItem=$activeForm.find(".js-rule-error-"+error);$errItem.length>0&&$errItem.css("display","block").show()}return arError.length>0&&$activeForm.find(".js-errorbox-all").css("display","block").show(),btnformsubmit.removeClass("t-btn_sending"),btnformsubmit.data("form-sending-status","0"),btnformsubmit.data("submitform",""),!1}var formtype=$activeForm.data("formactiontype");if(2==formtype&&$activeForm.find(".js-formaction-services").length>0){var $elemCookie=$activeForm.find("input[name=tildaspec-cookie]");return $elemCookie&&0!=$elemCookie.length||($activeForm.append('<input type="hidden" name="tildaspec-cookie" value="">'),$elemCookie=$activeForm.find("input[name=tildaspec-cookie]")),$elemCookie.length>0&&$elemCookie.val(document.cookie),$elemCookie=$activeForm.find("input[name=tildaspec-referer]"),$elemCookie&&0!=$elemCookie.length||($activeForm.append('<input type="hidden" name="tildaspec-referer" value="">'),$elemCookie=$activeForm.find("input[name=tildaspec-referer]")),$elemCookie.length>0&&$elemCookie.val(window.location.href),$activeForm.find(".js-form-spec-comments").val(""),$.ajax({type:"POST",url:"https://forms.tildacdn.com/procces/",data:$activeForm.serialize(),dataType:"json",success:function(json){var successurl=$activeForm.data("success-url"),successcallback=$activeForm.data("success-callback");if(btnformsubmit.removeClass("t-btn_sending"),btnformsubmit.data("form-sending-status","0"),btnformsubmit.data("submitform",""),json&&json.error){successurl="",successcallback="";var $errBox=$activeForm.find(".js-errorbox-all");$errBox&&0!=$errBox.length||($activeForm.prepend('<div class="js-errorbox-all"></div>'),$errBox=$activeForm.find(".js-errorbox-all"));var $allError=$errBox.find(".js-rule-error-all");$allError&&0!=$allError.length||($errBox.append('<p class="js-rule-error-all">'+json.error+"</p>"),$allError=$errBox.find(".js-rule-error-all")),$allError.html(json.error).show(),$errBox.show(),$activeForm.addClass("js-send-form-error")}else{$activeForm.find(".js-successbox").show(),$activeForm.addClass("js-send-form-success");var virtPage="/tilda/"+$activeForm.attr("id")+"/submitted/",virtTitle="Send data from form "+$activeForm.attr("id");window.Tilda&&"function"==typeof Tilda.sendEventToStatistics?(Tilda.sendEventToStatistics(virtPage,virtTitle,"",0),window.dataLayer&&window.dataLayer.push({event:"submit_"+$activeForm.attr("id")})):("undefined"!=typeof ga&&ga&&"tilda"!=window.mainTracker&&ga("send",{hitType:"pageview",page:virtPage,title:virtTitle}),window.mainMetrika>""&&window[window.mainMetrika]&&window[window.mainMetrika].hit(virtPage,{title:virtTitle,referer:window.location.href}),window.dataLayer&&window.dataLayer.push({event:"submit_"+$activeForm.attr("id")}));var formres={};if(json&&json.results&&json.results[0]){var str=json.results[0];str=str.split(":"),formres.tranid=""+str[0]+":"+str[1],formres.orderid=str[2]?str[2]:"0"}else formres.tranid="0",formres.orderid="0";$activeForm.data("tildaformresult",formres),successcallback&&successcallback.length>0?eval(successcallback+"($activeForm)"):successurl&&successurl.length>0&&setTimeout(function(){window.location.href=successurl},500),$activeForm.find("input[type=text]:visible").val(""),$activeForm.find("textarea:visible").html(""),$activeForm.find("textarea:visible").val(""),$activeForm.data("tildaformresult",{tranid:"0",orderid:"0"})}},error:function(e){btnformsubmit.removeClass("t-btn_sending"),btnformsubmit.data("form-sending-status","0"),btnformsubmit.data("submitform","");var r=$activeForm.find(".js-errorbox-all");r&&0!=r.length||($activeForm.prepend('<div class="js-errorbox-all"></div>'),r=$activeForm.find(".js-errorbox-all"));var t=r.find(".js-rule-error-all");t&&0!=t.length||(r.append('<p class="js-rule-error-all">Unknown error. Later, plaese try again.</p>'),t=r.find(".js-rule-error-all")),t.show(),r.show(),$activeForm.addClass("js-send-form-error")},timeout:15e3}),!1}return"y"==$activeForm.data("is-formajax")?($.ajax({type:"POST",url:$activeForm.attr("action"),data:$activeForm.serialize(),dataType:"text",success:function(e){var r,t=$activeForm.data("success-url");if(btnformsubmit.removeClass("t-btn_sending"),btnformsubmit.data("form-sending-status","0"),e&&e.length>0)if("{"==e.substring(0,1)){if(r=window.JSON&&window.JSON.parse?window.JSON.parse(e):$.parseJSON(e),r&&r.message)"OK"!=r.message&&$activeForm.find(".js-successbox").html(r.message);else if(r&&r.error){var a=$activeForm.find(".js-errorbox-all");a&&0!=a.length||($activeForm.prepend('<div class="js-errorbox-all"></div>'),a=$activeForm.find(".js-errorbox-all"));var i=a.find(".js-rule-error-all");return i&&0!=i.length||(a.append('<p class="js-rule-error-all">Unknown error. Later, plaese try again.</p>'),i=a.find(".js-rule-error-all")),i.html(r.error),i.show(),a.show(),$activeForm.addClass("js-send-form-error"),!1}}else $activeForm.find(".js-successbox").html(e);$activeForm.find(".js-successbox").show(),$activeForm.find("input[type=text]:visible").val(""),$activeForm.find("textarea:visible").html(""),$activeForm.find("textarea:visible").val(""),$activeForm.addClass("js-send-form-success");var o="/tilda/"+$activeForm.attr("id")+"/submitted/",n="Send data from form "+$activeForm.attr("id");window.Tilda&&"function"==typeof Tilda.sendEventToStatistics?Tilda.sendEventToStatistics(o,n,"",0):("undefined"!=typeof ga&&"tilda"!=window.mainTracker&&ga("send",{hitType:"pageview",page:o,title:n}),window.mainMetrika>""&&window[window.mainMetrika]&&window[window.mainMetrika].hit(o,{title:n,referer:window.location.href})),t&&t.length>0&&(window.location.href=t)},error:function(e){btnformsubmit.removeClass("t-btn_sending"),btnformsubmit.data("form-sending-status","0");var r=$activeForm.find(".js-errorbox-all");r&&0!=r.length||($activeForm.prepend('<div class="js-errorbox-all"></div>'),r=$activeForm.find(".js-errorbox-all"));var t=r.find(".js-rule-error-all");t&&0!=t.length||(r.append('<p class="js-rule-error-all"></p>'),t=r.find(".js-rule-error-all")),e&&e.responseText>""?t.html(e.responseText+". Later, plaese try again."):e&&e.statusText?t.html("Error - "+e.statusText+". Later, plaese try again."):t.html("Unknown error. Later, plaese try again."),t.show(),r.show(),$activeForm.addClass("js-send-form-error")},timeout:15e3}),event.preventDefault(),!1):(btnformsubmit.data("form-sending-status","3"),$activeForm.submit(),!0)})})}(jQuery),!function(e){"function"==typeof define&&define.amd?define(["jquery"],e):e("object"==typeof exports?require("jquery"):jQuery)}(function(e){var r,t=navigator.userAgent,a=/iphone/i.test(t),i=/chrome/i.test(t),o=/android/i.test(t);e.mask={definitions:{9:"[0-9]",a:"[A-Za-z]","*":"[A-Za-z0-9]"},autoclear:!0,dataName:"rawMaskFn",placeholder:"_"},e.fn.extend({caret:function(e,r){var t;return 0===this.length||this.is(":hidden")?void 0:"number"==typeof e?(r="number"==typeof r?r:e,this.each(function(){this.setSelectionRange?this.setSelectionRange(e,r):this.createTextRange&&(t=this.createTextRange(),t.collapse(!0),t.moveEnd("character",r),t.moveStart("character",e),t.select())})):(this[0].setSelectionRange?(e=this[0].selectionStart,r=this[0].selectionEnd):document.selection&&document.selection.createRange&&(t=document.selection.createRange(),e=0-t.duplicate().moveStart("character",-1e5),r=e+t.text.length),{begin:e,end:r})},unmask:function(){return this.trigger("unmask")},mask:function(t,n){var s,l,c,m,d,u,f,v;if(!t&&this.length>0){s=e(this[0]);var p=s.data(e.mask.dataName);return p?p():void 0}return n=e.extend({autoclear:e.mask.autoclear,placeholder:e.mask.placeholder,completed:null},n),l=e.mask.definitions,c=[],m=f=t.length,d=null,e.each(t.split(""),function(e,r){"?"==r?(f--,m=e):l[r]?(c.push(new RegExp(l[r])),null===d&&(d=c.length-1),m>e&&(u=c.length-1)):c.push(null)}),this.trigger("unmask").each(function(){function s(){if(n.completed){for(var e=d;u>=e;e++)if(c[e]&&E[e]===p(e))return;n.completed.call(C)}}function p(e){return n.placeholder.charAt(e<n.placeholder.length?e:0)}function h(e){for(;++e<f&&!c[e];);return e}function b(e){for(;--e>=0&&!c[e];);return e}function g(e,r){var t,a;if(!(0>e)){for(t=e,a=h(r);f>t;t++)if(c[t]){if(!(f>a&&c[t].test(E[a])))break;E[t]=E[a],E[a]=p(a),a=h(a)}x(),C.caret(Math.max(d,e))}}function $(e){var r,t,a,i;for(r=e,t=p(e);f>r;r++)if(c[r]){if(a=h(r),i=E[r],E[r]=t,!(f>a&&c[a].test(i)))break;t=i}}function j(){var e=C.val(),r=C.caret();if(v&&v.length&&v.length>e.length){for(T(!0);r.begin>0&&!c[r.begin-1];)r.begin--;if(0===r.begin)for(;r.begin<d&&!c[r.begin];)r.begin++;C.caret(r.begin,r.begin)}else{for(T(!0);r.begin<f&&!c[r.begin];)r.begin++;C.caret(r.begin,r.begin)}s()}function k(){T(),C.val()!=A&&C.change()}function w(e){if(!C.prop("readonly")){var r,t,i,o=e.which||e.keyCode;v=C.val(),8===o||46===o||a&&127===o?(r=C.caret(),t=r.begin,i=r.end,i-t===0&&(t=46!==o?b(t):i=h(t-1),i=46===o?h(i):i),F(t,i),g(t,i-1),e.preventDefault()):13===o?k.call(this,e):27===o&&(C.val(A),C.caret(0,T()),e.preventDefault())}}function y(r){if(!C.prop("readonly")){var t,a,i,n=r.which||r.keyCode,l=C.caret();if(!(r.ctrlKey||r.altKey||r.metaKey||32>n)&&n&&13!==n){if(l.end-l.begin!==0&&(F(l.begin,l.end),g(l.begin,l.end-1)),t=h(l.begin-1),f>t&&(a=String.fromCharCode(n),c[t].test(a))){if($(t),E[t]=a,x(),i=h(t),o){var m=function(){e.proxy(e.fn.caret,C,i)()};setTimeout(m,0)}else C.caret(i);l.begin<=u&&s()}r.preventDefault()}}}function F(e,r){var t;for(t=e;r>t&&f>t;t++)c[t]&&(E[t]=p(t))}function x(){C.val(E.join(""))}function T(e){var r,t,a,i=C.val(),o=-1;for(r=0,a=0;f>r;r++)if(c[r]){for(E[r]=p(r);a++<i.length;)if(t=i.charAt(a-1),c[r].test(t)){E[r]=t,o=r;break}if(a>i.length){F(r+1,f);break}}else E[r]===i.charAt(a)&&a++,m>r&&(o=r);return e?x():m>o+1?n.autoclear||E.join("")===S?(C.val()&&C.val(""),F(0,f)):x():(x(),C.val(C.val().substring(0,o+1))),m?r:d}var C=e(this),E=e.map(t.split(""),function(e,r){return"?"!=e?l[e]?p(r):e:void 0}),S=E.join(""),A=C.val();C.data(e.mask.dataName,function(){return e.map(E,function(e,r){return c[r]&&e!=p(r)?e:null}).join("")}),C.one("unmask",function(){C.off(".mask").removeData(e.mask.dataName)}).on("focus.mask",function(){if(!C.prop("readonly")){clearTimeout(r);var e;A=C.val(),e=T(),r=setTimeout(function(){C.get(0)===document.activeElement&&(x(),e==t.replace("?","").length?C.caret(0,e):C.caret(e))},10)}}).on("blur.mask",k).on("keydown.mask",w).on("keypress.mask",y).on("input.mask paste.mask",function(){C.prop("readonly")||setTimeout(function(){var e=T(!0);C.caret(e),s()},0)}),i&&o&&C.off("input.mask").on("input.mask",j),T()})}})});