[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/media/system/js/fields/ -> validate.min.js (source)

   1  const maxInt=2147483647,base=36,tMin=1,tMax=26,skew=38,damp=700,initialBias=72,initialN=128,delimiter="-",regexPunycode=/^xn--/,regexNonASCII=/[^\0-\x7E]/,regexSeparators=/[\x2E\u3002\uFF0E\uFF61]/g,errors={overflow:"Overflow: input needs wider integers to process","not-basic":"Illegal input >= 0x80 (not a basic code point)","invalid-input":"Invalid input"},baseMinusTMin=35,floor=Math.floor,stringFromCharCode=String.fromCharCode;function error(e){throw new RangeError(errors[e])}function map(e,t){const o=[];let s=e.length;for(;s--;)o[s]=t(e[s]);return o}function mapDomain(e,t){const o=e.split("@");let s="";o.length>1&&(s=o[0]+"@",e=o[1]);return s+map((e=e.replace(regexSeparators,".")).split("."),t).join(".")}function ucs2decode(e){const t=[];let o=0;const s=e.length;for(;o<s;){const r=e.charCodeAt(o++);if(r>=55296&&r<=56319&&o<s){const s=e.charCodeAt(o++);56320==(64512&s)?t.push(((1023&r)<<10)+(1023&s)+65536):(t.push(r),o--)}else t.push(r)}return t}const ucs2encode=e=>String.fromCodePoint(...e),basicToDigit=function(e){return e-48<10?e-22:e-65<26?e-65:e-97<26?e-97:36},digitToBasic=function(e,t){return e+22+75*(e<26)-((0!=t)<<5)},adapt=function(e,t,o){let s=0;for(e=o?floor(e/700):e>>1,e+=floor(e/t);e>455;s+=36)e=floor(e/35);return floor(s+36*e/(e+38))},decode=function(e){const t=[],o=e.length;let s=0,r=128,a=72,i=e.lastIndexOf("-");i<0&&(i=0);for(let o=0;o<i;++o)e.charCodeAt(o)>=128&&error("not-basic"),t.push(e.charCodeAt(o));for(let l=i>0?i+1:0;l<o;){let i=s;for(let t=1,r=36;;r+=36){l>=o&&error("invalid-input");const i=(n=e.charCodeAt(l++))-48<10?n-22:n-65<26?n-65:n-97<26?n-97:36;(i>=36||i>floor((maxInt-s)/t))&&error("overflow"),s+=i*t;const c=r<=a?1:r>=a+26?26:r-a;if(i<c)break;const d=36-c;t>floor(maxInt/d)&&error("overflow"),t*=d}const c=t.length+1;a=adapt(s-i,c,0==i),floor(s/c)>maxInt-r&&error("overflow"),r+=floor(s/c),s%=c,t.splice(s++,0,r)}var n;return String.fromCodePoint(...t)},encode=function(e){const t=[];let o=(e=ucs2decode(e)).length,s=128,r=0,a=72;for(const o of e)o<128&&t.push(stringFromCharCode(o));let i=t.length,n=i;for(i&&t.push("-");n<o;){let o=maxInt;for(const t of e)t>=s&&t<o&&(o=t);const l=n+1;o-s>floor((maxInt-r)/l)&&error("overflow"),r+=(o-s)*l,s=o;for(const o of e)if(o<s&&++r>maxInt&&error("overflow"),o==s){let e=r;for(let o=36;;o+=36){const s=o<=a?1:o>=a+26?26:o-a;if(e<s)break;const r=e-s,i=36-s;t.push(stringFromCharCode(digitToBasic(s+r%i,0))),e=floor(r/i)}t.push(stringFromCharCode(digitToBasic(e,0))),a=adapt(r,l,n==i),r=0,++n}++r,++s}return t.join("")},toUnicode=function(e){return mapDomain(e,(function(e){return regexPunycode.test(e)?decode(e.slice(4).toLowerCase()):e}))},toASCII=function(e){return mapDomain(e,(function(e){return regexNonASCII.test(e)?"xn--"+encode(e):e}))},punycode={version:"2.1.0",ucs2:{decode:ucs2decode,encode:ucs2encode},decode:decode,encode:encode,toASCII:toASCII,toUnicode:toUnicode};class JFormValidator{constructor(){this.customValidators={},this.handlers=[],this.handlers={},this.removeMarking=this.removeMarking.bind(this),this.inputEmail=()=>{const e=document.createElement("input");return e.setAttribute("type","email"),"text"!==e.type},this.setHandler("username",(e=>!/[<|>|"|'|%|;|(|)|&]/i.test(e))),this.setHandler("password",(e=>/^\S[\S ]{2,98}\S$/.test(e))),this.setHandler("numeric",(e=>/^(\d|-)?(\d|,)*\.?\d*$/.test(e))),this.setHandler("email",(e=>{const t=punycode.toASCII(e);return/^[a-zA-Z0-9.!#$%&’*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/.test(t)}));[].slice.call(document.querySelectorAll("form")).forEach((e=>{e.classList.contains("form-validate")&&this.attachToForm(e)}))}get custom(){return this.customValidators}set custom(e){this.customValidators=e}setHandler(e,t,o){const s=""===o||o;this.handlers[e]={enabled:s,exec:t}}markValid(e){const t=e.form.querySelector(`label[for="$e.id}"]`);let o;(e.classList.contains("required")||e.getAttribute("required"))&&t&&(o=t.querySelector("span.form-control-feedback")),e.classList.remove("form-control-danger"),e.classList.remove("invalid"),e.classList.add("form-control-success"),e.parentNode.classList.remove("has-danger"),e.parentNode.classList.add("has-success"),e.setAttribute("aria-invalid","false"),o&&o.parentNode.removeChild(o),t&&t.classList.remove("invalid")}markInvalid(e,t){const o=e.form.querySelector(`label[for="$e.id}"]`);let s;e.classList.remove("form-control-success"),e.classList.remove("valid"),e.classList.add("form-control-danger"),e.classList.add("invalid"),e.parentNode.classList.remove("has-success"),e.parentNode.classList.add("has-danger"),e.setAttribute("aria-invalid","true");const r=e.getAttribute("data-validation-text");if(o&&(s=o.querySelector("span.form-control-feedback")),!s){const e=document.createElement("span");e.classList.add("form-control-feedback"),e.innerHTML=t&&"checkbox"===t?null!==r?Joomla.sanitizeHtml(r):Joomla.sanitizeHtml(Joomla.Text._("JLIB_FORM_FIELD_REQUIRED_CHECK")):t&&"value"===t?null!==r?Joomla.sanitizeHtml(r):Joomla.sanitizeHtml(Joomla.Text._("JLIB_FORM_FIELD_REQUIRED_VALUE")):null!==r?Joomla.sanitizeHtml(r):Joomla.sanitizeHtml(Joomla.Text._("JLIB_FORM_FIELD_INVALID_VALUE")),o&&o.appendChild(e)}o&&o.classList.add("invalid")}removeMarking(e){let t;const o=e.form.querySelector(`label[for="$e.id}"]`);o&&(t=o.querySelector("span.form-control-feedback")),e.classList.remove("form-control-danger"),e.classList.remove("form-control-success"),e.classList.remove("invalid"),e.classList.add("valid"),e.parentNode.classList.remove("has-danger"),e.parentNode.classList.remove("has-success"),t&&o&&o.removeChild(t),o&&o.classList.remove("invalid")}handleResponse(e,t,o){const s=t.tagName.toLowerCase();("button"!==s&&void 0!==t.value||"fieldset"===s)&&(!1===e?this.markInvalid(t,o):this.markValid(t))}validate(e){let t;if("disabled"===e.getAttribute("disabled")||"none"===e.getAttribute("display"))return this.handleResponse(!0,e),!0;if(e.getAttribute("required")||e.classList.contains("required"))if(t=e.tagName.toLowerCase(),"fieldset"===t&&(e.classList.contains("radio")||e.classList.contains("checkboxes"))){if(null===e.querySelector("input:checked"))return this.handleResponse(!1,e,"checkbox"),!1}else{if("checkbox"===e.getAttribute("type")&&!0!==e.checked||"select"===t&&!e.value.length)return this.handleResponse(!1,e,"checkbox"),!1;if(!e.value||e.classList.contains("placeholder"))return this.handleResponse(!1,e,"value"),!1}const o=e.getAttribute("class")&&e.getAttribute("class").match(/validate-([a-zA-Z0-9_-]+)/)?e.getAttribute("class").match(/validate-([a-zA-Z0-9_-]+)/)[1]:"";if(e.getAttribute("pattern")&&""!==e.getAttribute("pattern")){if(e.value.length){const t=new RegExp(`^$e.getAttribute("pattern")}$`).test(e.value);return this.handleResponse(t,e,"empty"),t}return e.hasAttribute("required")||e.classList.contains("required")?(this.handleResponse(!1,e,"empty"),!1):(this.handleResponse(!0,e),!0)}return""===o?(this.handleResponse(!0,e),!0):o&&"none"!==o&&this.handlers[o]&&e.value&&!0!==this.handlers[o].exec(e.value,e)?(this.handleResponse(!1,e,"invalid_value"),!1):(this.handleResponse(!0,e),!0)}isValid(e){let t,o,s=!0;const r=[];return[].slice.call(e.querySelectorAll("input, textarea, select, button, fieldset")).forEach((e=>{!1===this.validate(e)&&(s=!1,r.push(e))})),Object.keys(this.customValidators).length&&Object.keys(this.customValidators).foreach((e=>{!0!==this.customValidators[e].exec()&&(s=!1)})),!s&&r.length>0&&(t=e.getAttribute("data-validation-text")?e.getAttribute("data-validation-text"):Joomla.Text._("JLIB_FORM_CONTAINS_INVALID_FIELDS"),o={error:[t]},Joomla.renderMessages(o)),s}attachToForm(e){[].slice.call(e.querySelectorAll("input, textarea, select, button, fieldset")).forEach((t=>{const o=t.tagName.toLowerCase();["input","textarea","select","fieldset"].indexOf(o)>-1&&t.classList.contains("required")&&t.setAttribute("required",""),"input"!==o&&"button"!==o||"submit"!==t.getAttribute("type")&&"image"!==t.getAttribute("type")?"button"===o||"input"===o&&"button"===t.getAttribute("type")||"fieldset"!==o&&(t.addEventListener("blur",(({target:e})=>this.validate(e))),t.addEventListener("focus",(({target:e})=>this.removeMarking(e))),t.classList.contains("validate-email")&&this.inputEmail&&t.setAttribute("type","email")):t.classList.contains("validate")&&t.addEventListener("click",(()=>this.isValid(e)))}))}}const initialize=()=>{document.formvalidator=new JFormValidator,document.removeEventListener("DOMContentLoaded",initialize)};document.addEventListener("DOMContentLoaded",initialize);


Generated: Wed Sep 7 05:41:13 2022 Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer