Global.js
Upload User: yatiankong
Upload Date: 2014-05-16
Package Size: 5604k
Code Size: 13k
Category:

Applet

Development Platform:

Java

  1. /*-=< base function >=-*/
  2. //HTMLElement.getElementById extend
  3. if(document && !document.getElementById){document.getElementById=function(id){
  4. if(document.all) return document.all(id); return null;}}
  5. /*
  6. function sleep(ms)
  7. {
  8.   var start = new Date().getTime();
  9.   var xh = new XMLHttpRequest();
  10.   while(new Date().getTime()-start<ms)
  11.   {
  12.     try{
  13.       xh.open("GET", "file:///c:\?mz="+ Math.random(), false);
  14.       xh.send(null);
  15.     }catch(ex){return;}
  16.   }
  17. }
  18. function Sleep(n){var start=new Date().getTime(); //for opera only
  19. while(true) if(new Date().getTime()-start>n) break;}
  20. */
  21. /*-=< HTMLElement >=-*/
  22. if("undefined"!=typeof HTMLDocument)
  23. {
  24.   if("undefined"==typeof HTMLDocument.prototype.createStyleSheet)
  25.   {
  26.     HTMLDocument.prototype.createStyleSheet=function(url)
  27.     {
  28.       var e;if(/[w-u4e00-u9fa5]+.w+(?|$)/.test(url))
  29.       {
  30.         e=document.createElement("LINK"); e.type="text/css";
  31.         e.rel="Stylesheet"; e.href=url;}else{
  32.         e=document.createElement("STYLE"); e.type="text/css";
  33.       }
  34.       document.getElementsByTagName("HEAD")[0].appendChild(e);
  35.       return e;
  36.     };
  37.   }
  38. }
  39. function searchByTagName(e, TAG)
  40. {
  41.   while(e!=null && e.tagName){if(e.tagName==TAG.toUpperCase())
  42.   return(e); e=e.parentNode; } return null;
  43. }
  44. function searchById(e, id)
  45. {
  46.   while(e = e.parentNode){if(e.id==id) return(e);} return null;
  47. }
  48. if(typeof(HTMLElement)!="undefined" && !window.opera)
  49. {
  50.   var t=HTMLElement.prototype
  51.   t.contains = function(obj)
  52.   {
  53.     if(obj==this)return true;
  54.     if(obj==null)return false; 
  55.     return this.contains(obj.parentNode); 
  56.   };
  57.   t.__defineGetter__("outerHTML",function()
  58.   {
  59.     var a=this.attributes, str="<"+this.tagName, i=0;for(;i<a.length;i++)
  60.     if(a[i].specified) str+=" "+a[i].name+'="'+a[i].value+'"';
  61.     if(!this.canHaveChildren) return str+" />";
  62.     return str+">"+this.innerHTML+"</"+this.tagName+">";
  63.   });
  64.   t.__defineSetter__("outerHTML",function(s)
  65.   {
  66.     var r = this.ownerDocument.createRange();
  67.     r.setStartBefore(this);
  68.     var df = r.createContextualFragment(s);
  69.     this.parentNode.replaceChild(df, this);
  70.     return s;
  71.   });
  72.   t.__defineGetter__("canHaveChildren",function()
  73.   {
  74.     return !/^(area|base|basefont|col|frame|hr|img|br|input|isindex|link|meta|param)$/.test(this.tagName.toLowerCase());
  75.   });
  76. };
  77. if("undefined"!=typeof HTMLElement)
  78. {
  79.   HTMLElement.prototype.getCssValue=function(prop)
  80.   {
  81.     if(!window.getComputedStyle) return null;
  82.     prop=prop.replace(/([A-Z])/g, "-$1").toLowerCase();
  83.     return window.getComputedStyle(this, "").getPropertyValue(prop);
  84.   };
  85. }
  86. if(!window.attachEvent && window.addEventListener)
  87. {
  88.   Window.prototype.attachEvent = HTMLDocument.prototype.attachEvent=
  89.   HTMLElement.prototype.attachEvent=function(en, func, cancelBubble)
  90.   {
  91.     var cb = cancelBubble ? true : false;
  92.     this.addEventListener(en.toLowerCase().substr(2), func, cb);
  93.   };
  94.   Window.prototype.detachEvent = HTMLDocument.prototype.detachEvent=
  95.   HTMLElement.prototype.detachEvent=function(en, func, cancelBubble)
  96.   {
  97.     var cb = cancelBubble ? true : false;
  98.     this.removeEventListener(en.toLowerCase().substr(2), func, cb);
  99.   };
  100. }
  101. if(typeof Event!="undefined" && !System.ie && !window.opera)
  102. {
  103.   var t=Event.prototype;
  104.   t.__defineSetter__("returnValue", function(b){if(!b)this.preventDefault();  return b;});
  105.   t.__defineSetter__("cancelBubble",function(b){if(b) this.stopPropagation(); return b;});
  106.   t.__defineGetter__("offsetX", function(){return this.layerX;});
  107.   t.__defineGetter__("offsetY", function(){return this.layerY;});
  108.   //t.__defineGetter__("srcElement", function(){var n=this.target; while (n.nodeType!=1)n=n.parentNode;return n;}); 
  109. }
  110. /*-=< Function >=-*/
  111. //apply and call
  112. if(typeof(Function.prototype.apply)!="function")
  113. {
  114.   Function.prototype.apply = function(obj, argu)
  115.   {
  116.     if(obj) obj.constructor.prototype.___caller = this;
  117.     for(var a=[], i=0; i<argu.length; i++) a[i] = "argu["+ i +"]";
  118.     var t = eval((obj ? "obj.___caller" : "this") +"("+ a.join(",") +");");
  119.     if(obj) delete obj.constructor.prototype.___caller; return t;};
  120.     Function.prototype.call = function(obj){
  121.     for(var a=[], i=1; i<arguments.length; i++) a[i-1]=arguments[i];
  122.     return this.apply(obj, a);
  123.   }; 
  124. }
  125. /*-=< Array >=-*/
  126. var t = Array.prototype;
  127. //[extended method] push  insert new item
  128. if(typeof(t.push)!="function")
  129. {
  130.   t.push = function()
  131.   {
  132.     for (var i=0; i<arguments.length; i++)
  133.       this[this.length] = arguments[i];
  134.     return this.length; 
  135.   };
  136. }
  137. //[extended method] shift  delete the first item
  138. if(typeof(t.shift)!="function")
  139. {
  140.   t.shift = function()
  141.   {
  142.     var mm = null;
  143.     if(this.length>0)
  144.     {
  145.       mm = this[0]; for(var i=1; i<this.length; i++)
  146.       this[i-1]=this[i]; this.length=this.length -1;
  147.     }
  148.     return mm;
  149.   };
  150. }
  151. //[extended method] unique  Delete repeated item
  152. t.Unique = function()
  153. {
  154.   for(var a={}, i=0; i<this.length; i++)
  155.   {
  156.     if("undefined"==typeof a[this[i]]) a[this[i]] = 1;
  157.   }
  158.   this.length=0;
  159.   for(i in a) this[this.length] = i; return this;
  160. };
  161. //[extended method] indexOf
  162. if(typeof(t.indexOf)!="function")
  163. {
  164.   t.indexOf=function(item, start)
  165.   {
  166.     start=start||0; if(start<0)start=Math.max(0,this.length+start);
  167.     for(var i=start;i<this.length;i++){if(this[i]===item)return i;}
  168.     return -1;
  169.   };
  170. }
  171. t.include=function(e){return this.indexOf(e)!=-1};
  172. t.remove=function(e)
  173. {
  174.   for(var i=0, a=[]; i<this.length; i++) if(this[i]!=e) a[a.length]=this[i];
  175.   return a;
  176. }
  177. /*-=< Date >=-*/
  178. //datetime format
  179. Date.prototype.format = function(format)
  180. {
  181.   var o = {
  182.     "M+" : this.getMonth()+1, //month
  183.     "d+" : this.getDate(),    //day
  184.     "h+" : this.getHours(),   //hour
  185.     "m+" : this.getMinutes(), //minute
  186.     "s+" : this.getSeconds(), //second
  187.     "q+" : Math.floor((this.getMonth()+3)/3),  //quarter
  188.     "S" : this.getMilliseconds() //millisecond
  189.   }
  190.   if(/(y+)/.test(format)) format=format.replace(RegExp.$1,
  191.     (this.getFullYear()+"").substr(4 - RegExp.$1.length));
  192.   for(var k in o)if(new RegExp("("+ k +")").test(format))
  193.     format = format.replace(RegExp.$1,
  194.       RegExp.$1.length==1 ? o[k] : 
  195.         ("00"+ o[k]).substr((""+ o[k]).length));
  196.   return format;
  197. };
  198. /*-=< Number >=-*/
  199. if(typeof(Number.prototype.toFixed)!="function")
  200. {
  201.     Number.prototype.toFixed = function(d)
  202.     {
  203.         var s=this+"";if(!d)d=0;
  204.         if(s.indexOf(".")==-1)s+=".";s+=new Array(d+1).join("0");
  205.         if (new RegExp("^(-|\+)?(\d+(\.\d{0,"+ (d+1) +"})?)\d*$").test(s))
  206.         {
  207.             var s="0"+ RegExp.$2, pm=RegExp.$1, a=RegExp.$3.length, b=true;
  208.             if (a==d+2){a=s.match(/d/g); if (parseInt(a[a.length-1])>4)
  209.             {
  210.                 for(var i=a.length-2; i>=0; i--) {a[i] = parseInt(a[i])+1;
  211.                 if(a[i]==10){a[i]=0; b=i!=1;} else break;}
  212.             }
  213.             s=a.join("").replace(new RegExp("(\d+)(\d{"+d+"})\d$"),"$1.$2");
  214.         }if(b)s=s.substr(1);return (pm+s).replace(/.$/, "");} return this+"";
  215.     };
  216. }
  217. if("undefined"==typeof(encodeURIComponent))encodeURIComponent=function(s){return escape(s);}
  218. /*-=< String >=-*/
  219. var t=String.prototype;
  220. t.trim=function(){return this.replace(/(^[st ]+)|([ st]+$)/g, "");};
  221. t.capitalize=function(){return this.charAt(0).toUpperCase() + this.substr(1);};
  222. t.getByteLength=function(){return this.replace(/[^x00-xff]/g, "mm").length;};
  223. t.getAttribute = function(attribute)
  224. {
  225.   if(new RegExp("(^|;)\s*"+attribute+"\s*:\s*([^;]*)\s*(;|$)","i").test(this))
  226.   return RegExp.$2.replace(/%3B/gi,";").replace(/%25/g,"%"); return null;
  227. };
  228. t.setAttribute = function(attribute, value)
  229. {
  230.   value=(""+value).replace(/%/g,"%25").replace(/;/g,"%3B").replace(/r|n/g,"");
  231.   return (attribute +":"+ value +";" + this);
  232. };
  233. t.deleteAttribute = function(attribute)
  234. {
  235.   return this.replace(new RegExp("\b\s*"+attribute+"\s*:\s*([^;]*)\s*(;|$)","gi"),"");
  236. };
  237. t.getQueryString = function(name)
  238. {
  239.   var reg = new RegExp("(^|&|\?)"+ name +"=([^&]*)(&|$)"), r;
  240.   if (r=this.match(reg)) return unescape(r[2]); return null;
  241. };
  242. t.sub = function(n)
  243. {
  244.   var r = /[^x00-xff]/g;
  245.   if(this.replace(r, "mm").length <= n) return this;
  246.   n = n - 3;
  247.   var m = Math.floor(n/2);
  248.   for(var i=m; i<this.length; i++)
  249.   {
  250.     if(this.substr(0, i).replace(r, "mm").length>=n)
  251.     {
  252.       return this.substr(0, i) +"...";
  253.     }
  254.   }
  255.   return this;
  256. };
  257. t.format=function()
  258. {
  259.   if(arguments.length==0) return this;
  260.   for(var s=this, i=0; i<arguments.length; i++)
  261.     s=s.replace(new RegExp("\{"+i+"\}","g"), arguments[i]);
  262.   return s;
  263. };
  264. String.format=function(str)
  265. {
  266.   if("string"!=typeof(str)||arguments.length<=1) return str;
  267.   for(var i=1; i<arguments.length; i++)
  268.     str=str.replace(new RegExp("\{"+(i-1)+"\}","g"), arguments[i]);
  269.   return str;
  270. };
  271. /*-=< Meizz Class >=-*/
  272. //NameSpace: System.MzBrowser
  273. System.MzBrowser=window["MzBrowser"]={};(function()
  274. {
  275.   if(MzBrowser.platform) return;
  276.   var ua = window.navigator.userAgent;
  277.   MzBrowser.platform = window.navigator.platform;
  278.   MzBrowser.firefox = ua.indexOf("Firefox")>0;
  279.   MzBrowser.opera = typeof(window.opera)=="object";
  280.   MzBrowser.ie = !MzBrowser.opera && ua.indexOf("MSIE")>0;
  281.   MzBrowser.mozilla = window.navigator.product == "Gecko";
  282.   MzBrowser.netscape= window.navigator.vendor=="Netscape";
  283.   MzBrowser.safari  = ua.indexOf("safari")>-1&&window.Dom;
  284.   if(MzBrowser.firefox) var re = /Firefox(s|/)(d+(.d+)?)/;
  285.   else if(MzBrowser.ie) var re = /MSIE( )(d+(.d+)?)/;
  286.   else if(MzBrowser.opera) var re = /Opera(s|/)(d+(.d+)?)/;
  287.   else if(MzBrowser.netscape) var re = /Netscape(s|/)(d+(.d+)?)/;
  288.   else if(MzBrowser.mozilla) var re = /rv(:)(d+(.d+)?)/;
  289.   if("undefined"!=typeof(re)&&re.test(ua))
  290.     MzBrowser.version = parseFloat(RegExp.$2);
  291. })();
  292. //alert(MzBrowser.version);
  293. /*-=< Extend >=-*/
  294. System.loadCssFile=function(cssPath, uniqueId)
  295. {
  296.   if(/w+.w+(?|$)/.test(cssPath))
  297.   {
  298.     if(!("string"==typeof uniqueId && uniqueId!=""))
  299.     uniqueId = "MzCss_"+ cssPath.replace(/W/g, "");
  300.     if(document.getElementById(uniqueId)) return;
  301.     var link  = document.createElement("LINK");
  302.     link.href = cssPath;
  303.     link.id   = uniqueId;
  304.     link.type = "text/css";
  305.     link.rel  = "Stylesheet";
  306.     uniqueId  = document.getElementsByTagName("HEAD")[0];
  307.     uniqueId.insertBefore(link, uniqueId.firstChild);
  308.   }
  309. };
  310. var t=window.MzElement=System.MzElement={};
  311. var $=t.check=function(e)
  312. {
  313.   if("object"==typeof e && !e.tagName) return null;
  314.   if("string"==typeof e && !(e=document.getElementById(e)))
  315.   return null; return e;
  316. };
  317. t.hide=function()
  318. {
  319.   for (var e=null, n=arguments.length, i=0; i<n; i++)
  320.   if(e=MzElement.check(arguments[i])) e.style.display="none";
  321. };
  322. t.show=function()
  323. {
  324.   for (var e=null, n=arguments.length, i=0; i<n; i++)
  325.   if(e=MzElement.check(arguments[i])) e.style.display="";
  326. };
  327. t.remove=function()
  328. {
  329.   for (var e=null, n=arguments.length, i=0; i<n; i++)
  330.   if(e=MzElement.check(arguments[i])) e.parentNode.removeChild(e);
  331. };
  332. t.realOffset=function(o)
  333. {
  334.   var e=o, x=y=l=t=0, doc=MzElement.body();
  335.   do{l+=e.offsetLeft||0; t+=e.offsetTop||0; e=e.offsetParent;}while(e);
  336.   do{x+=o.scrollLeft||0; y+=o.scrollTop||0; o=o.parentNode;}while(o);
  337.   return {"x":l-x+doc.scrollLeft, "y":t-y+doc.scrollTop};
  338. };
  339. t.body=function()
  340. {
  341.   var W, H, SL, ST;
  342.   var w=window, d=document, dd=d.documentElement;
  343.   if(w.innerWidth) W=w.innerWidth;
  344.   else if(dd&&dd.clientWidth) W=dd.clientWidth;
  345.   else if(d.body) W=d.body.clientWidth;
  346.   if(w.innerHeight) H=w.innerHeight;
  347.   else if(dd&&dd.clientHeight) H=dd.clientHeight; 
  348.   else if(d.body) H=d.body.clientHeight;
  349.   if(w.pageXOffset) SL=w.pageXOffset;
  350.   else if(dd&&dd.scrollLeft) SL=dd.scrollLeft;
  351.   else if(d.body) SL=d.body.scrollLeft;
  352.   if(w.pageYOffset) ST=w.pageYOffset;
  353.   else if(dd&&dd.scrollTop) ST=dd.scrollTop;
  354.   else if(d.body) ST=d.body.scrollTop;
  355.   return {"scrollTop":ST,"scrollLeft":SL,"clientWidth":W,"clientHeight":H};
  356. }
  357. t.hasClassName=function(element, className)
  358. {
  359.   if(!(element=MzElement.check(element))) return;
  360.   return element.className.split(" ").include(className);
  361. };
  362. t.addClassName=function(element, className)
  363. {
  364.   if(!(element=MzElement.check(element))) return;
  365.   var a=element.className.split(" ");
  366.   if(!a.include(className))a=a.concat(className);
  367.   element.className = a.join(" ").trim(); a=null;
  368. };
  369. t.removeClassName=function(element, className)
  370. {
  371.   if(!(element=MzElement.check(element))) return;
  372.   var r=new RegExp("(^| )"+ className +"( |$)", "g");
  373.   element.className=element.className.replace(r, "$2");
  374. };