📄 form.js
字号:
/*
* Copyright (c) 2001-2007, TIBCO Software Inc.
* Use, modification, and distribution subject to terms of license.
*/
jsx3.Class.defineClass("jsx3.net.Form",null,[jsx3.util.EventDispatcher],function(q,d){var Lc=jsx3.util.Logger.getLogger(q.jsxclass.getName());q.Je=0;q.Uf=250;q.zp=30000;q.METHOD_GET="get";q.METHOD_POST="post";q.xD="application/x-www-form-urlencoded";q.aG="multipart/form-data";q.EVENT_FILE_SELECTED="fileSelected";q.EVENT_ON_RESPONSE="onResponse";q.EVENT_ON_ERROR="onError";q.EVENT_ON_TIMEOUT="onTimeout";d.init=function(i,b,k){this.ge="jsx_httpform_"+q.Je++;if(i==-1){this.YA(b);}else{this.YA();this.setMethod(i!=null?i:q.METHOD_GET);this.setAction(b);this.setMultipart(k);}};q.newFromFragment=function(i){return new q(-1,i);};d.YA=function(e){var Jb=e;if(!Jb)Jb="<form method=\"get\" action=\"\"><input type=\"submit\"/></form>";var qc="<html><body class=\"jsx30form\">"+Jb+"</body></html>";jsx3.html.insertAdjacentHTML(document.body,"beforeEnd","<span id='"+this.ge+"_span' style='border:2px solid black;position:absolute;left:-50px;top:0px;width:10px;height:10px;overflow:hidden;'><iframe id='"+this.ge+"_frame' style='width:100%;height:100%;'></iframe></span>");this._l=document.getElementById(this.ge+"_l");this.io=this.eval(this.ge+"_frame");var X=this.io.document||this.io.contentDocument;if(X==null)throw new jsx3.Exception("No document in IFRAME.");X.open();X.write(qc);X.close();this.xp=X.getElementsByTagName("form")[0];if(e){if(this.xp==null)throw {description:"the HTML fragment did not contain a valid <form> tag: "+e};this.Re=this.xp.action;this.rG=this.xp.method;this.dC=this.xp.encoding&&this.xp.encoding.toLowerCase()==q.aG;}};d.getMethod=function(){return this.rG;};d.setMethod=function(p){p=p!=null?p.toLowerCase():q.METHOD_GET;this.rG=p;this.lD().setAttribute("method",p);};d.getAction=function(){return this.Re;};d.setAction=function(c){if(jsx3.CLASS_LOADER.FX){c=jsx3.app.Browser.getLocation().resolve(c).toString();}this.Re=c;this.lD().setAttribute("action",c);};d.getMultipart=function(){return this.dC;};d.setMultipart=function(l){this.dC=l;this.lD().setAttribute("encoding",l?q.aG:q.xD);};d.Ci=function(){return this._l;};d.fq=function(){return this.io;};d.lD=function(){return this.xp;};d.getField=function(f){var xb=this.lD().elements[f];return xb!=null&&typeof(xb)=="object"?xb.value:null;};d.getFields=function(){var lc=[];var yb=this.lD().elements;for(var Tb in yb){lc[Tb]=yb[Tb].name;}return lc;};d.setField=function(f,i,b){var tb=this.lD();var pb=tb.elements[f];if(pb==null||typeof(pb)!="object"){jsx3.html.insertAdjacentHTML(tb,"beforeEnd","<div>"+f+": <input type='text' name='"+f+"'/></div>");pb=tb.elements[f];}if(b&&pb.value){pb.value=pb.value+" "+i;}else{pb.value=i;}};d.removeField=function(m){var ac=this.lD();var K=ac.elements[m];if(K!=null&&K.parentNode)K.parentNode.parentNode.removeChild(K.parentNode);};d.addFileUploadField=function(i){var C=this.lD();var Nb=C.elements[i];if(Nb==null||typeof(Nb)!="object"){jsx3.html.insertAdjacentHTML(C,"beforeEnd","<div>"+i+": <input type='file' name='"+i+"'/></div>");Nb=C.elements[i];var E=this;Nb.onchange=function(){E.KF(i,Nb.value);};}else{throw new jsx3.Exception("Form already has field "+i+".");}};d.promptForFile=function(n){var hb=this.lD();var wc=hb.elements[n];if(wc!=null&&wc.type=="file"){if(jsx3.CLASS_LOADER.IE){wc.click();}else{if(jsx3.CLASS_LOADER.FX){Lc.warn("jsx3.net.Form does not support prompting file upload fields in Firefox.");wc.click();}}}else{throw new jsx3.Exception("Form does not have file upload field "+n+".");}};d.KF=function(f,g){this.publish({subject:q.EVENT_FILE_SELECTED,field:f,value:g});};d.Kq=function(){this.xp=null;this.publish({subject:q.EVENT_ON_RESPONSE});};d.we=function(i){this.xp=null;this.publish({subject:q.EVENT_ON_ERROR,message:i});};d.abort=function(){window.clearInterval(this.Uj);};if(jsx3.CLASS_LOADER.IE){d.send=function(m,g){if(m==null)m=q.Uf;if(g==null)g=q.zp;this.xp.submit();var gc=0;var x=g<=0?Number.MAX_VALUE:Math.ceil(g/m);var E=this;this.Uj=window.setInterval(function(){E.jD(++gc<x);},m);};d.jD=function(i){try{this.io.document.readyState=="";}catch(Kc){window.clearInterval(this.Uj);this.Uj=null;this.we("Form Response Security Error: "+jsx3.NativeError.wrap(Kc));return;}if(this.io.document.readyState=="complete"||this.io.document.readyState=="loaded"){window.clearInterval(this.Uj);this.Uj=null;this.Kq();}else{if(!i){window.clearInterval(this.Uj);this.Uj=null;this.destroy();this.publish({subject:q.EVENT_ON_TIMEOUT});}}};d.getResponseText=function(){var Bc=this.io.document;if(typeof(Bc.mimeType)!="unknown"){if(Bc.mimeType.indexOf("XML")==0){return Bc.XMLDocument.xml;}else{if(Bc.mimeType.indexOf("HTML")==0){return jsx3.html.getOuterHTML(this.io.document.childNodes[0]);}else{if(Bc.mimeType.indexOf("Text")==0){return this.io.document.childNodes[0].innerText;}}}}return this.io.document.body.innerHTML;};d.getResponseXML=function(){var Z=this.io.document;if(typeof(Z.mimeType)=="string"&&Z.mimeType.indexOf("XML")==0||Z.XMLDocument&&Z.XMLDocument.documentElement){var Jc=new jsx3.xml.Document();Jc.loadXML(Z.XMLDocument.documentElement.xml);return Jc;}else{var _b=null;if(Z.mimeType.indexOf("HTML")==0){_b=jsx3.html.getOuterHTML(this.io.document.childNodes[0]);}else{if(Z.mimeType.indexOf("Text")==0){_b=this.io.document.childNodes[0].innerText;}else{_b=this.io.document.body.innerHTML;}}var fc=new jsx3.xml.Document();fc.loadXML(_b);if(fc.hasError()){jsx3.util.Logger.doLog("HTFM06","Result not a valid XML document: "+fc.getError().description);return null;}return fc;}};}else{if(jsx3.CLASS_LOADER.FX){d.send=function(o,i){if(o==null)o=q.Uf;if(i==null)i=q.zp;var uc=this;this.io.onload=function(){uc.Lu();};try{this.xp.submit();}catch(Kc){this.we(jsx3.NativeError.wrap(Kc).toString());return;}this.Uj=window.setTimeout(function(){uc.Dl();},o*i);};d.Lu=function(){this.io.onload=null;if(this.Uj){window.clearTimeout(this.Uj);this.Uj=null;}try{var ec=" "+this.io.contentDocument.childNodes[0].innerHTML;}catch(Kc){this.publish({subject:q.EVENT_ON_ERROR,message:jsx3.NativeError.wrap(Kc).toString()});return;}this.Kq();};d.Dl=function(){this.io.onload=null;this.Uj=null;this.destroy();this.publish({subject:q.EVENT_ON_TIMEOUT});};d.getResponseText=function(){var cb=this.io.contentDocument;if(cb instanceof XMLDocument){return (new XMLSerializer()).serializeToString(cb);}else{if(cb instanceof HTMLDocument){return cb.childNodes[0].innerHTML;}else{Lc.warn("Unsupported document type: "+cb);return "";}}};d.getResponseXML=function(){var sb=this.io.contentDocument;if(sb instanceof XMLDocument){var Mb=(new XMLSerializer()).serializeToString(sb);return (new jsx3.xml.Document()).loadXML(Mb);}else{if(sb instanceof HTMLDocument){var Mb=sb.childNodes[0].innerHTML;return (new jsx3.xml.Document()).loadXML(Mb);}else{Lc.warn("Unsupported document type: "+sb);return (new jsx3.xml.Document()).loadXML("<html/>");}}};}}d.destroy=function(){var Mc=this.Ci();if(Mc!=null){Mc.parentNode.removeChild(Mc);this._l=null;this.io=null;this.xp=null;}else{jsx3.util.Logger.doLog("HTFM01","HttpForm probably already destroyed");}};d.reveal=function(e,p,m,i){if(e==null)e=10;if(p==null)p=10;if(m==null)m=Math.round(this._l.parentNode.offsetWidth/3);if(i==null)i=Math.round(this._l.parentNode.offsetHeight/3);var ub=this._l.style;ub.left=e+"px";ub.top=p+"px";ub.width=m+"px";ub.height=i+"px";ub.zIndex=30000;};d.conceal=function(){var vb=this._l.style;vb.left="-50px";vb.top="0px";vb.width="10px";vb.height="10px";vb.zIndex=0;};});jsx3.HttpForm=jsx3.net.Form;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -