-
Notifications
You must be signed in to change notification settings - Fork 0
/
foxyforms-client.min.js
3 lines (2 loc) · 10.9 KB
/
foxyforms-client.min.js
1
2
3
/*! foxyforms-client 2018-02-02 */
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).foxyformsClient=e()}}(function(){return function e(t,r,n){function o(s,a){if(!r[s]){if(!t[s]){var d="function"==typeof require&&require;if(!a&&d)return d(s,!0);if(i)return i(s,!0);var u=new Error("Cannot find module '"+s+"'");throw u.code="MODULE_NOT_FOUND",u}var l=r[s]={exports:{}};t[s][0].call(l.exports,function(e){var r=t[s][1][e];return o(r||e)},l,l.exports,e,t,r,n)}return r[s].exports}for(var i="function"==typeof require&&require,s=0;s<n.length;s++)o(n[s]);return o}({"./lib/node/form":[function(e,t,r){var n=e("./validators.js"),o=function(e,t,r,n){var o="on"+t;if(e.addEventListener)e.addEventListener(t,function(t){e.event=t||window.event,r.apply(e,n)},!1);else if(e.attachEvent)e.attachEvent(o,function(t){e.event=t||window.event,r.apply(e,n)});else{var i=e[o];"function"!=typeof e[o]?e[o]=function(t){e.event=t||window.event,r.apply(e,n)}:e[o]=function(t){i&&i(),e.event=t||window.event,r.apply(e,n)}}},i=function(e,t){o(window,"load",e,t)},s=function(e,t,r,n){if(e&&"string"==typeof e){var i=document.getElementById(e);if(i)return o(i,t,r,n),i}return null},a=function(e){if("string"==typeof e&&(e={id:e}),"object"==typeof e&&e.id){var t=document.getElementById(e.id);if(t){if(void 0===e.required&&(e.required=!!t.getAttribute("foxyforms_required")||!!t.getAttribute("required")),e.value=t.value,void 0===e.type&&(e.type=t.getAttribute("foxyforms_type"),!e.type)){var r=t.getAttribute("type");switch(r){case"phone":case"phoneNA":case"tel":e.type="phone";break;case"email":e.type=r}}if(void 0===e.errorMessage){var n=t.getAttribute("foxyforms_error_message");n?e.errorMessage=n:(n=t.getAttribute("title"))&&(e.errorMessage=n)}}}return e},d=function(e,t){},u=function(e){},l=function(e,t,r){for(var n=null,o=0;o<e.length;o++){var i=e[o],s=document.getElementById(i.id);s&&(s.value=i.value,t&&(i.result?i.onSuccess&&"function"==typeof i.onSuccess?i.onSuccess(s):t.onFieldSuccess&&"function"==typeof t.onFieldSuccess?t.onFieldSuccess(s):u():(i.onError&&"function"==typeof i.onError?i.onError(i.error,s):t.onFieldError&&"function"==typeof t.onFieldError?t.onFieldError(i.error,s):d(i.error),!n&&r&&(n=s).focus())))}};r.postProcess=function(e){l(e)},r.parse=function(e,t){if("object"==typeof e)for(i=0;i<e.length;i++)e[i]=a(e[i]);else if("string"==typeof e){var r=e,n=document.getElementById(r);if(e=[],n){var o=[];"input"==n.nodeName.toLowerCase()?o.push(n):o=n.getElementsByTagName("input");for(var i=0;i<o.length;i++)if(r=o[i].getAttribute("id")){var s=a(r);s.type&&t.isTypeSupported(s.type)&&e.push(s)}}}return e},r.init=function(e,t){n.update(t),e&&"object"==typeof e&&i(function(e){for(var n=0;n<e.length;n++){var o=e[n];if(o&&"object"==typeof o&&o.id){var i=o.id,a="submit";if(o.buttonId&&(i=o.buttonId,a="click"),o.fields||(o.fields=o.id),o.fields=r.parse(o.fields,t),s(i,a,function(e){this.event&&(this.event.preventDefault?this.event.preventDefault():this.event.returnValue=!1),t.verify(e.fields,function(t,r){var n=document.getElementById(e.id);l(r,e,!0),t?e.onError&&"function"==typeof e.onError&&e.onError(t,n):e.onSuccess&&"function"==typeof e.onSuccess?e.onSuccess(n):n&&n.submit()})},[o]),o.enableOnBlurEvents)for(var d=0;d<o.fields.length;d++){var u=o.fields[d];s(u.id,"blur",function(e,r){t.verify([r],function(t,r){l(r,e,!1)})},[o,u])}}}},[e]),intialized=!0}},{"./validators.js":1}],"./lib/node/http-client":[function(e,t,r){var n=function(){for(var e=3,t=document.createElement("div"),r=t.getElementsByTagName("i");t.innerHTML="\x3c!--[if gt IE "+ ++e+"]><i></i><![endif]--\x3e",r[0];);return e>4?e:void 0}(),o=function(){if("undefined"==typeof window)throw new Error("no window object present");if(window.XMLHttpRequest)return window.XMLHttpRequest;if(window.ActiveXObject){for(var e=["Msxml2.XMLHTTP.6.0","Msxml2.XMLHTTP.3.0","Microsoft.XMLHTTP"],t=0;t<e.length;t++)try{var r=new window.ActiveXObject(e[t]);return function(){if(r){var n=r;return r=null,n}return new window.ActiveXObject(e[t])}}catch(e){}throw new Error("ajax not supported in this browser")}throw new Error("ajax not supported in this browser")}();r.request=function(e,t,r){try{if("object"!=typeof e)return void r("options object is required");var i,s=e.method?e.method:"GET",a=e.scheme+"://"+e.host+":"+e.port.toString()+e.path;if(n<8)r("Internet Explorer "+n.toString()+" is not supported");else if(8===n||9===n){var d=new XDomainRequest;d?(d.onerror=function(){r("XDomainRequest error")},d.ontimeout=function(){r("XDomainRequest timed out")},d.onload=function(){r(null,d.responseText)},d.timeout=1e4,d.open(s,a),d.send(t)):r("XDomainRequest undefined")}else{if((i=new o).open(s,a,!0),e.headers)for(var u in e.headers)i.setRequestHeader(u,e.headers[u]);i.send(t),i.onreadystatechange=function(){4==i.readyState&&(200==i.status?r(null,i.responseText):r("XMLHttpRequest error status: "+i.status))}}}catch(e){r(e.message)}}},{}],1:[function(e,t,r){r.update=function(e){window.jQuery&&function(t){t.validator&&(t.extend(t.validator,{addAsyncMethod:function(e,r,n){t.validator.addMethod(e,function(n,o,i){if(this.optional(o))return"dependency-mismatch";var s=this.previousValue(o);if(this.settings.messages[o.name]||(this.settings.messages[o.name]={}),s.originalMessage=this.settings.messages[o.name][e],this.settings.messages[o.name][e]=s.message,s.old===n)return s.valid;s.old=n;var a=this;return this.startRequest(o),{}[o.name]=n,r(n,o,function(r){a.settings.messages[o.name][e]=s.originalMessage;var i=!r;if(i){var d=a.formSubmitted;a.prepareElement(o),a.formSubmitted=d,a.successList.push(o),delete a.invalid[o.name],a.showErrors()}else{var u={},l=r||a.defaultMessage(o,e);u[o.name]=s.message=t.isFunction(l)?l(n):l,a.invalid[o.name]=!0,a.showErrors(u)}s.valid=i,a.stopRequest(o,i)},i),"pending"},n)}}),t.validator.addAsyncMethod("email",function(t,r,n){e.verify([r.id],function(e,t){var r=t[0].result?null:t[0].error.message;n(r)},"Please enter a valid email address.")}),t.validator.addAsyncMethod("phoneNA",function(t,r,n){e.verify([r.id],function(e,t){var r=t[0].result?null:t[0].error.message;n(r)},"Please enter a valid phone number.")}),t.validator.addAsyncMethod("tel",function(t,r,n){e.verify([r.id],function(e,t){var r=t[0].result?null:t[0].error.message;n(r)},"Please enter a valid phone number.")})),t.validationEngine&&(e.jQueryValidateEngineHandler=function(t,r,n,o,i){e.verify([t.attr("id")],function(e,t){i(t[0].result,t[0].error?t[0].error.message:null)})})}(window.jQuery)}},{}],2:[function(e,t,r){var n={cleanInputs:!0,ignoreServerErrors:!0,ignoreSoftBounces:!0,proxy:null,secure:!0},o={host:"api.foxyforms.com",port:80,sslPort:443,path:"/verify",loginPath:"/verify/login"},i=e("./lib/node/http-client"),s=e("./lib/node/form"),a=function(){var e={main:{badData:{code:300,message:"Invalid data passed to API"},badLogin:{code:302,message:"Invalid API login"},badToken:{code:303,message:"Invalid API token"},notValid:{code:304,message:"Validation failed"},required:{code:305,message:"Field is required"},serverComm:{code:500,message:"Unable to communicate with verification server"},serverData:{code:501,message:"Server returned bad data"},internal:{code:502,message:"Internal server error occurred"}},phone:{ok:{code:200,message:"Phone number is OK"},badType:{code:400,message:"Invalid data type passed - must be a string or number"},badFormat:{code:401,message:"Data entered is not a valid phone number - must be 10 digits"},notValid:{code:402,message:"Phone number is invalid"},wrongCountry:{code:403,message:"Phone number doesn't match the specified countries"},tollFree:{code:404,message:"Phone number is a toll-free number, which is not allowed"}},email:{ok:{code:200,message:"Email address is OK"},badType:{code:400,message:"Invalid data type passed - must be a string"},badFormat:{code:401,message:"Data entered is not a valid email address"},noMxRecords:{code:402,message:"No MX Records found for domain"},noResponse:{code:403,message:"Mail server failed to respond"},notValid:{code:404,message:"Email address rejected by mail server"}}};return{get:function(t,r){return{code:e[t][r].code,message:e[t][r].message}}}}(),d=function(e){if("object"==typeof e)for(var t in e)n[t]=e[t]},u=function(e,t,r){var o;n.proxy&&(void 0!==n.proxy.host&&(e.host=n.proxy.host),void 0!==n.proxy.port&&(e.port=n.proxy.port),void 0!==n.proxy.path&&(t.path=e.path,e.path=n.proxy.path)),o=JSON.stringify(t),e.method="POST",e.headers={"Content-Type":"application/json"},i.request(e,o,function(e,t){if(e){var n=a.get("main","serverComm");n.reason=e,r({result:!1,error:n})}else{var o=JSON.parse(t);r(o?o:{result:!1,error:a.get("main","serverData")})}})},l={phone:function(e){return{result:!0,value:e}},email:function(e){return{result:!0,value:e}}},f=function(e,t){if(e&&e.code==a.get("main","notValid").code)for(var r=0;r<t.length;r++)!t[r].result&&t[r].error&&t[r].errorMessage&&t[r].error.code>=400&&t[r].error.code<500&&(t[r].error.message=t[r].errorMessage);return t},c=function(e,t){for(var n=r.validateFields(e),o=[],i=0;i<n.fields.length;i++)null===n.fields[i].result&&o.push(n.fields[i]);o.length>0?r.verifyFields(o,function(e){var r=n.result?e.result?null:e.error:n.error;if(e.fields)for(var o=0;o<e.fields.length;o++)for(var i=0;i<n.fields.length;i++)if(n.fields[i].id===e.fields[o].id){n.fields[i]=e.fields[o];break}n.fields=f(r,n.fields),s.postProcess(n.fields),t(r,n.fields)}):(n.fields=f(n.error,n.fields),s.postProcess(n.fields),t(n.error,n.fields))};r.validateFields=function(e){var t=!0,r=null;if(e&&"object"==typeof e&&e.length)for(var n=0;n<e.length;n++){var o=e[n];if(o&&"object"==typeof o&&o.id&&o.type)if(e[n].result=null,void 0!==o.value&&o.value.length)if("function"==typeof l[o.type]){var i=l[o.type](o.value);if(!i.result){for(var s in i)e[n][s]=i[s];t=!1,r=a.get("main","notValid")}}else e[n].result=!0;else o.required?(e[n].result=!1,e[n].error=a.get("main","required"),t=!1,r=a.get("main","notValid")):e[n].result=!0;else r=a.get("main","badData"),t=!1}else r=a.get("main","badData"),t=!1;return{result:t,error:r,fields:e}},r.verifyFields=function(e,t){var r=!!n.secure;u({scheme:r?"https":"http",host:o.host,port:r?o.sslPort:o.port,path:o.path},{fields:e,options:n},function(r){if(!r.result&&r.error&&r.error.code>=500&&r.error.code<600){r.result=n.ignoreServerErrors,r.fields=e;for(var o=0;o<r.fields.length;o++)void 0!==r.fields[o].result&&null!==r.fields[o].result||(r.fields[o].result=n.ignoreServerErrors,r.fields[o].error=a.get("main","serverComm"))}t(r)})},r.login=function(e,t,r){u({scheme:n.secure?"https":"http",host:o.host,port:n.secure?o.sslPort:o.port,path:o.loginPath},{username:e,apiKey:t},r)},r.init=function(e,t){d(e),s.init(t,r)},r.verify=function(e,t){e=s.parse(e,r),c(e,t)},r.isTypeSupported=function(e){return!!l[e]},r.getError=function(e,t){return a.get(e,t)},r.isLocalValidationEnabled=function(){return!1}},{"./lib/node/form":"./lib/node/form","./lib/node/http-client":"./lib/node/http-client"}]},{},[2])(2)});