jsframework.js
上传用户:yatiankong
上传日期:2014-05-16
资源大小:5604k
文件大小:9k
源码类别:

Applet

开发平台:

Java

  1. /*---------------------------------------------------------------------------*
  2. |  Subject: JavaScript Framework
  3. |  Author:  meizz
  4. |  Created: 2005-02-27
  5. |  Version: 2007-02-28
  6. |-----------------------------------
  7. |  MSN: huangfr@msn.com QQ:112889082 Copyright (c) meizz
  8. |  http://www.meizz.com/jsframework/ MIT-style license
  9. |  The above copyright notice and this permission notice shall be
  10. |  included in all copies or substantial portions of the Software
  11. *---------------------------------------------------------------------------*/
  12. window.System = function(){this.setHashCode();}
  13. System.debug=false; //false
  14. System._codebase={};
  15. try
  16. {
  17.   if (window!=parent && parent.System && parent.System._codebase)
  18.     System._codebase = parent.System._codebase;
  19.   else if ("undefined"!=typeof opener&&opener.System&&opener.System._codebase)
  20.     System._codebase = opener.System._codebase;
  21.   else if ("undefined"!=typeof dialogArguments && dialogArguments.System)
  22.     System._codebase = dialogArguments.System._codebase;
  23. }
  24. catch(ex){}
  25. System.MISSING_ARGUMENT="Missing argument";
  26. System.ARGUMENT_PARSE_ERROR="The argument cannot be parsed";
  27. System.NOT_SUPPORTED_XMLHTTP="Your browser do not support XMLHttp";
  28. System.FILE_NOT_FOUND="File not found";
  29. System.MISCODING="Maybe file encoding is not ANSI or UTF-8";
  30. System.NAMESPACE_ERROR=" nonstandard namespace";
  31. System.hashCounter=0;
  32. System.currentVersion="20070228_20";
  33. var t=document.getElementsByTagName("SCRIPT");
  34. t=(System.scriptElement=t[t.length-1]).src.replace(/\/g, "/");
  35. System.extend=function(d,s){for(var i in s)d[i]=s[i];return d;};
  36. System.path=(t.lastIndexOf("/")<0)?".":t.substring(0, t.lastIndexOf("/"));
  37. System.resourcePath=System.path +"/System/_resource";
  38. System.getUniqueId=function(){return "mz_"+(System.hashCounter++).toString(36);};
  39. System.toHashCode=function(e)
  40. {
  41.   if("undefined"!=typeof e.hashCode) return e.hashCode;
  42.   return e.hashCode=System.getUniqueId();
  43. };
  44. System.supportsXmlHttp=function()
  45. {
  46.   return "object"==typeof(System._xmlHttp||(System._xmlHttp=new XMLHttpRequest()));
  47. };
  48. System._getPrototype=function(namespace, argu)
  49. {
  50.   if("undefined"==typeof System._prototypes[namespace])return new System();
  51.   for(var a=[], i=0; i<argu.length; i++) a[i]="argu["+ i +"]";
  52.   return eval("new (System._prototypes['"+namespace+"'])("+a.join(",")+")");
  53. };
  54. System.ie=navigator.userAgent.indexOf("MSIE")>0 && !window.opera;
  55. System.ns=navigator.vendor=="Netscape";
  56. System.alert=function(msg){if(System.debug)alert(msg);};
  57. System._parseResponseText=function(s)
  58. {
  59.   if(null==s||"uFFFD"==s.charAt(0)){System.alert(System.MISCODING);return "";}
  60.   if("xef"==s.charAt(0))s=s.substr(3); //for firefox
  61.   return s.replace(/(^|n)s*//+s*((Using|Import|Include)(("|'))/g,"$1$2");
  62. };
  63. if(!window.XMLHttpRequest && window.ActiveXObject)
  64. {
  65.   window.XMLHttpRequest = function()
  66.   {
  67.     var msxmls=['MSXML3','MSXML2','Microsoft'];
  68.     for(var i=0;i<msxmls.length;i++)
  69.       try{return new ActiveXObject(msxmls[i]+'.XMLHTTP')} catch(ex){}
  70.     System._xmlHttp="mz"; throw new Error(System.NOT_SUPPORTED_XMLHTTP);
  71.   }
  72. }
  73. System.load = function(namespace, path)
  74. {
  75.   try
  76.   {
  77.     if(System.supportsXmlHttp()){path=System._mapPath(namespace, path);
  78.     var x=System._xmlHttp; x.open("GET",path,false); x.send(null);
  79.     if (x.readyState==4){if(x.status==0||/^file:/i.test(path))
  80.       return System._parseResponseText(x.responseText);
  81.     else if(x.status==200)return System._parseResponseText(x.responseText);
  82.     else if(x.status==404)System.alert(namespace+"n"+System.FILE_NOT_FOUND);
  83.     else throw new Error(x.status +": "+ x.statusText);}}
  84.     else System.alert(System.NOT_SUPPORTED_XMLHTTP);
  85.   }
  86.   catch(ex){System.alert(namespace+"n"+ex.message);}return "";
  87. };
  88. System._exist = function(namespace, path)
  89. {
  90.   if("undefined"==typeof System._existences[namespace]) return false;
  91.   return System._existences[namespace]==System._mapPath(namespace,path);
  92. };
  93. System._mapPath = function(namespace, path)
  94. {
  95.   if("string"==typeof path && path.length>3) return path;
  96.   var p=System.path +"/"+ namespace.replace(/./g,"/") +".js";
  97.   return p +(("undefined"==typeof path||path) ? "" : "?t="+ Math.random());
  98. };
  99. window.Using = function(namespace, path, rename)
  100. {
  101.   var N=namespace, C=N.substr(N.lastIndexOf(".")+1), code=N+".";
  102.   if(System._exist(N,path)){window[C]=System._prototypes[N];return}
  103.   if(!/((^|.)[w$]+)+$/.test(N))throw new Error(N+System.NAMESPACE_ERROR);
  104.   for(var s,e,i=code.indexOf("."); i>-1; i=code.indexOf(".", i+1)){
  105.   e=code.substring(0,i);s=(e.indexOf(".")==-1)?"window[""+e+""]":e;
  106.   if(e&&"undefined"==typeof(s)){eval(s+"=function(){return "
  107.     +"System._getPrototype(""+e+"", arguments)}");}}
  108.   if("string"!=typeof System._codebase[N]&&(code=System.load(N,path)))
  109.     System._codebase[N]=code+";rnSystem._prototypes['"+
  110.     N+"']=window['"+(rename||C)+"']="+C;code="";
  111.   System._existences[N]=System._mapPath(N, path);
  112.   if("string"==typeof (s=System._codebase[N]))try{(new Function(s))()}
  113.   catch(e){System.alert("Syntax error on load "+ N +"n"+ e.message);}
  114.   //alert(System._codebase[namespace])
  115. };
  116. window.Import=function(namespace,path,rename){Using(namespace,path,rename)};
  117. window.Instance=function(hashCode){return System._instances[hashCode]};
  118. window.Include=function(namespace, path)
  119. {
  120.   var N=namespace,code; if(System._exist(N, path)) return;
  121.   if(!/((^|.)[w$]+)+$/.test(N))throw new Error(N+System.NAMESPACE_ERROR);
  122.   if("string"!=typeof System._codebase[N])if(System.supportsXmlHttp()
  123.     && (code=System.load(N, path))) System._codebase[N]=code;
  124.   System._existences[N]=System._mapPath(N, path);
  125.   var B=("string"==typeof(System._codebase[N]));try{
  126.   if(window.execScript&&B)window.execScript(System._codebase[N]);else
  127.   {
  128.     var s=document.createElement("SCRIPT");s.type="text/javascript";
  129.     if(B)s.innerHTML="eval(System._codebase['"+N+"']);";
  130.     else s.src=System._existences[N]=System._mapPath(N,path);
  131.     document.getElementsByTagName("HEAD")[0].appendChild(s);
  132.     setTimeout(function(){s.parentNode.removeChild(s)},99);}
  133.   }catch(B){System.alert("Syntax error on include "+N+"n"+B.message);}
  134. };
  135. Function.READ=1;Function.WRITE=2;Function.READ_WRITE=3;
  136. Function.prototype.addProperty=function(name,initValue,r_w)
  137. {
  138.   var capital=name.charAt(0).toUpperCase()+name.substr(1);
  139.   r_w=r_w||Function.READ_WRITE; name="_"+name; var p=this.prototype;
  140.   if("undefined"!=typeof initValue) p[name]=initValue;
  141.   if(r_w&Function.READ) p["get"+ capital]=function(){return this[name];};
  142.   if(r_w&Function.WRITE) p["set"+ capital]=function(v){this[name]=v;};
  143. };
  144. Function.prototype.Extends=function(SuperClass,ClassName)
  145. {
  146.   var op=this.prototype, i, p=this.prototype=new SuperClass();
  147.   if(ClassName)p._className=ClassName; for(i in op)p[i]=op[i];
  148.   if(p.hashCode)delete System._instances[p.hashCode];return p;
  149. };
  150. System._instances={};
  151. System._prototypes=
  152. {
  153.   "System":System,
  154.   "System.Object":System,
  155.   "System.Event":System.Event
  156. };
  157. System._existences=
  158. {
  159.   "System":System._mapPath("System"),
  160.   "System.Event":System._mapPath("System.Event"),
  161.   "System.Object":System._mapPath("System.Object")
  162. };
  163. t=System.Extends(Object, "System"); System.Object = System;
  164. t.decontrol=function(){var t;if(t=this.hashCode)delete System._instances[t]};
  165. t.addEventListeners=function(type, handle)
  166. {
  167.   if("function"!=typeof handle)
  168.     throw new Error(this+" addEventListener: "+handle+" is not a function");
  169.   if(!this._listeners) this._listeners={};
  170.   var id=System.toHashCode(handle), t=this._listeners; 
  171.   if("object"!=typeof t[type]) t[type]={}; t[type][id]=handle;
  172. };
  173. t.removeEventListener=function(type, handle)
  174. {
  175.   if(!this._listeners)this._listeners={};var t=this._listeners;
  176.   if(!t[type]) return; var id=System.toHashCode(handle);
  177.   if( t[type][id])delete t[type][id];if(t[type])delete t[type];
  178. };
  179. t.dispatchEvent=function(evt)
  180. {
  181.   if(!this._listeners)this._listeners={};
  182.   var i, t =this._listeners, p =evt.type;
  183.   evt.target=evt.srcElement=evt.target||evt.srcElement||this;
  184.   evt.currentTarget=this; if(this[p])this[p](evt);
  185.   if("object"==typeof t[p]) for(i in t[p]) t[p][i].call(null, evt);
  186.   delete evt.target;delete evt.currentTarget;delete evt.srcElement;
  187.   return evt.returnValue;
  188. };
  189. t.setHashCode=function()
  190. {
  191.   System._instances[(this.hashCode=System.getUniqueId())]=this;
  192. };
  193. t.getHashCode=function()
  194. {
  195.   if(!this.hashCode)this.setHashCode(); return this.hashCode;
  196. };
  197. t.toString=function(){return "[object "+(this._className||"Object")+"]";};
  198. System.getType=function(e)
  199. {
  200.   if("object"!=typeof(e))return typeof(e);
  201.   if("[object Object]"==e)return "object";
  202.   if(/[objects+([^s]]+)]/.test(e))return RegExp.$1;
  203.   else return "object";
  204. };
  205. System.Event=function(type){this.type=type;};
  206. t=System.Event.Extends(System,"System.Event");
  207. t.returnValue=true;t.cancelBubble=false;
  208. t.target=t.currentTarget=t.srcElement=null;
  209. t.stopPropagation=function(){this.cancelBubble=true;};
  210. t.preventDefault =function(){this.returnValue=false;};
  211. if(System.ie && !System.debug) Include("System.Plugins.IE");//IE UserData
  212. if(window.opera) Include("System.Plugins.Opera"); //Opera support
  213. Include("System.Global");
  214. Include("Csdn.Common");