-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcustomform.min.js
1 lines (1 loc) · 4.14 KB
/
customform.min.js
1
function CustomForm(a){this.document=$(document),this.form=$(a),this.inputs=this.form.find("input[type=select], input[type=checkbox], input[type=radio]"),this.selects=this.form.find("select"),this.options=this.form.find("option"),this.customInputs=[],this.customSelects=[],this.customizeInputs(),this.customizeSelects(),this.document.bind("mouseup",$.proxy(this.clear,this))}CustomForm.prototype.clear=function(){var a=0,b=this.customInputs.length,c;for(a=0;a<b;a+=1)this.inputs[a].checked===!0?(c=this.customInputs[a].className.replace(/checked/g,""),c=c.trim(),c+=" checked",c=c.trim(),this.customInputs[a].className=c):(c=this.customInputs[a].className.replace(/checked/g,""),c=c.trim(),this.customInputs[a].className=c)},CustomForm.prototype.check=function(a){var b=a.currentTarget.nextSibling,c="",d="",e,f=this.inputs.length;if(b.checked===!0)c=a.currentTarget.className.replace(/checked/g,""),c.replace("click",""),a.currentTarget.className=c,b.checked=!1;else{if(b.type==="checkbox")c=a.currentTarget.className.replace(/checked/g,""),c=c.trim(),a.currentTarget.className=c+" checked";else{c=a.currentTarget.className.replace(/checked/g,""),c=c.trim(),a.currentTarget.className=c+" checked",d=b.name;for(e=0;e<f;e+=1)this.inputs[e].name===d&&this.inputs[e]!==b&&(c=this.customInputs[e].className.replace(/checked/g,""),c=c.trim(),this.customInputs[e].className=c)}b.checked=!0}c=a.currentTarget.className.replace(/click/g,""),c=c.trim(),a.currentTarget.className=c},CustomForm.prototype.customPushed=function(a){var b=a.currentTarget.nextSibling,c="";b.checked===!0?(c=a.currentTarget.className.replace(/checked/g,""),c=c.trim(),c+=" click",c=c.trim(),a.currentTarget.className=c):(c=a.currentTarget.className.replace(/checked/g,""),c=c.trim(),c+=" click checked",c=c.trim(),a.currentTarget.className=c)},CustomForm.prototype.choose=function(a){var b=a.currentTarget,c=b.getElementsByTagName("option"),d=0,e=0,f="",g="",h="",i=null;for(d=0,e=c.length;d<e;d+=1)c[d].selected===!0&&(f=a.currentTarget.name.replace(/\[/g,"_").replace(/\]/g,"_"),g=c[d].text,h="select-"+f,i=document.getElementById(h),i.innerHTML=g)},CustomForm.prototype.customizeInputs=function(){var a=0,b=0,c="",d=null;for(a=0,b=this.inputs.length;a<b;a+=1){c=this.inputs[a].type;if(c==="checkbox"||c==="radio")this.inputs[a].style.display="none",this.customInputs[a]=document.createElement("span"),this.customInputs[a].className=c,this.inputs[a].checked===!0&&(this.customInputs[a].className+=" checked"),d=this.inputs[a].parentElement,d.insertBefore(this.customInputs[a],this.inputs[a]),this.inputs[a].onchange=$.proxy(this.clear,this),this.inputs[a].disabled===!1?($(this.inputs[a]).bind("mouseup",$.proxy(this.check,this)),console.log(a,this.customInputs[a]),$(this.customInputs[a]).bind("mousedown",$.proxy(this.customPushed,this)),$(this.customInputs[a]).bind("mouseup",$.proxy(this.check,this))):this.customInputs[a].className+=" disabled"}},CustomForm.prototype.customizeSelects=function(){var a=0,b=0,c=null,d="",e=0,f=0,g="",h=null,i=null,j=0,k=0,l=null,m=document.getElementsByTagName("body")[0];for(a=0,b=this.selects.length;a<b;a+=1){this.selects[a].style.opacity=0,this.selects[a].style.filter="alpha(opacity=0)",c=this.selects[a].getElementsByTagName("option"),d=c[0].childNodes[0].nodeValue,i=document.createTextNode(d);for(e=0,f=c.length;e<f;e+=1)c[e].selected===!0&&(i=document.createTextNode(c[e].childNodes[0].nodeValue));this.customSelects[a]=document.createElement("span"),this.customSelects[a].className="select",g=this.selects[a].name.replace(/\[/g,"_").replace(/\]/g,"_"),this.customSelects[a].id="select-"+g,this.customSelects[a].appendChild(i),h=this.selects[a].parentElement,h.insertBefore(this.customSelects[a],this.selects[a]),l=this.selects[a].cloneNode(!0),m.appendChild(l),j=l.clientHeight,k=l.clientWidth,m.removeChild(l),h.style.position="relative",this.selects[a].style.position="absolute",this.selects[a].style.top="0px",this.selects[a].style.left="0px",this.customSelects[a].style.display="block",this.customSelects[a].style.height=j+"px",this.customSelects[a].style.width=k+"px",this.selects[a].disabled===!1?$(this.selects[a]).bind("change",$.proxy(this.choose,this)):this.selects[a].previousSibling.className+=" disabled"}}