forked from ryanseddon/H5F
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathh5f.min.js
4 lines (4 loc) · 4.82 KB
/
h5f.min.js
1
2
3
4
/*! H5F - v1.0.0 - 2012-07-18
* https://github.com/ryanseddon/H5F/
* Copyright (c) 2012 Ryan Seddon; Licensed MIT */
var H5F=H5F||{};(function(a){var b=a.createElement("input"),c=/^[a-zA-Z0-9.!#$%&'*+-\/=?\^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/,d=/[a-z][\-\.+a-z]*:\/\//i,e=/^(input|select|textarea)$/i,f,g,h,i,j="",k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,A,B,C;k=function(a,b){var c=!a.nodeType||!1,d={validClass:"valid",invalidClass:"error",requiredClass:"required",placeholderClass:"placeholder"};if(typeof b=="object")for(var e in d)typeof b[e]=="undefined"&&(b[e]=d[e]);i=b||d;if(c)for(var f=0,g=a.length;f<g;f++)l(a[f]);else l(a)},l=function(a){var b=a.elements,c=b.length,d,e=!!a.attributes.novalidate;w(a,"invalid",n,!0),w(a,"blur",n,!0),w(a,"input",n,!0),w(a,"keyup",n,!0),w(a,"focus",n,!0),w(a,"submit",function(b){f=!0,!e&&!a.checkValidity()&&y(b)},!1);if(!q()){a.checkValidity=function(){return o(a)};while(c--)d=!!b[c].attributes.required,b[c].nodeName.toLowerCase()!=="fieldset"&&m(b[c])}},m=function(a){var b=a,c=v(b),d={type:b.getAttribute("type"),pattern:b.getAttribute("pattern"),placeholder:b.getAttribute("placeholder")},e=/^(email|url)$/i,f=/^(input|keyup)$/i,g=e.test(d.type)?d.type:d.pattern?d.pattern:!1,i=r(b,g),k=t(b,"step"),l=t(b,"min"),m=t(b,"max"),n=j!=="";b.checkValidity=function(){return o.call(this,b)},b.setCustomValidity=function(a){p.call(b,a)},b.validationMessage=j,b.validity={valueMissing:c,patternMismatch:i,rangeUnderflow:l,rangeOverflow:m,stepMismatch:k,customError:n,valid:!c&&!i&&!k&&!l&&!m&&!n},d.placeholder&&!f.test(h)&&s(b)},n=function(a){var b=z(a)||a,c=/^(input|keyup|focusin|focus)$/i,d=/^(submit|image|button|reset)$/i,f=!0;e.test(b.nodeName)&&!d.test(b.type)&&!d.test(b.nodeName)&&(h=a.type,q()||m(b),b.validity.valid&&b.value!==""||b.value!==b.getAttribute("placeholder")&&b.validity.valid?(B(b,[i.invalidClass,i.requiredClass]),A(b,i.validClass)):c.test(h)?b.validity.valueMissing&&B(b,[i.requiredClass,i.invalidClass,i.validClass]):b.validity.valueMissing?(B(b,[i.invalidClass,i.validClass]),A(b,i.requiredClass)):b.validity.valid||(B(b,[i.validClass,i.requiredClass]),A(b,i.invalidClass)),h==="input"&&f&&(x(b.form,"keyup",n,!0),f=!1))},o=function(a){var b,c,d,e,g=!1;if(a.nodeName.toLowerCase()==="form"){b=a.elements;for(var h=0,i=b.length;h<i;h++)c=b[h],d=!!c.attributes.required,e=!!c.attributes.pattern,c.nodeName.toLowerCase()!=="fieldset"&&(d||e&&d)&&(n(c),!c.validity.valid&&!g&&(f&&c.focus(),g=!0));return!g}return n(a),a.validity.valid},p=function(a){var b=this;j=a,b.validationMessage=j},q=function(){return C(b,"validity")&&C(b,"checkValidity")},r=function(a,b){if(b==="email")return!c.test(a.value);if(b==="url")return!d.test(a.value);if(!b)return!1;var e=a.getAttribute("placeholder"),f=a.value;return g=new RegExp("^(?:"+b+")$"),f===e?!0:f===""?!1:!g.test(a.value)},s=function(a){var c={placeholder:a.getAttribute("placeholder")},d=/^(focus|focusin|submit)$/i,e=/^(input|textarea)$/i,f=/^password$/i,g="placeholder"in b;!g&&e.test(a.nodeName)&&!f.test(a.type)&&(a.value===""&&!d.test(h)?(a.value=c.placeholder,w(a.form,"submit",function(){h="submit",s(a)},!0),A(a,i.placeholderClass)):a.value===c.placeholder&&d.test(h)&&(a.value="",B(a,i.placeholderClass)))},t=function(a,b){var c=parseInt(a.getAttribute("min"),10)||0,d=parseInt(a.getAttribute("max"),10)||!1,e=parseInt(a.getAttribute("step"),10)||1,f=parseInt(a.value,10),g=(f-c)%e;if(!!v(a)||!!isNaN(f))return a.getAttribute("type")==="number"?!0:!1;if(b==="step")return a.getAttribute("step")?g!==0:!1;if(b==="min")return a.getAttribute("min")?f<c:!1;if(b==="max")return a.getAttribute("max")?f>d:!1},u=function(a){var b=!!a.attributes.required;return b?v(a):!1},v=function(a){var b=a.getAttribute("placeholder"),c=!!a.attributes.required;return!(!c||a.value!==""&&a.value!==b)},w=function(a,b,c,d){C(window,"addEventListener")?a.addEventListener(b,c,d):C(window,"attachEvent")&&typeof window.event!="undefined"&&(b==="blur"?b="focusout":b==="focus"&&(b="focusin"),a.attachEvent("on"+b,c))},x=function(a,b,c,d){C(window,"removeEventListener")?a.removeEventListener(b,c,d):C(window,"detachEvent")&&typeof window.event!="undefined"&&a.detachEvent("on"+b,c)},y=function(a){a=a||window.event,a.stopPropagation&&a.preventDefault?(a.stopPropagation(),a.preventDefault()):(a.cancelBubble=!0,a.returnValue=!1)},z=function(a){return a=a||window.event,a.target||a.srcElement},A=function(a,b){var c;a.className?(c=new RegExp("(^|\\s)"+b+"(\\s|$)"),c.test(a.className)||(a.className+=" "+b)):a.className=b},B=function(a,b){var c,d,e=typeof b=="object"?b.length:1,f=e;if(a.className)if(a.className===b)a.className="";else while(e--)c=new RegExp("(^|\\s)"+(f>1?b[e]:b)+"(\\s|$)"),d=a.className.match(c),d&&d.length===3&&(a.className=a.className.replace(c,d[1]&&d[2]?" ":""))},C=function(a,b){var c=typeof a[b],d=new RegExp("^function|object$","i");return!!(d.test(c)&&a[b]||c==="unknown")},window.H5F={setup:k}})(document);