📄 mochikit.js
字号:
MochiKit.DateTime.EXPORT=["isoDate","isoTimestamp","toISOTime","toISOTimestamp","toISODate","americanDate","toPaddedAmericanDate","toAmericanDate"];MochiKit.DateTime.EXPORT_OK=[];MochiKit.DateTime.EXPORT_TAGS={":common":MochiKit.DateTime.EXPORT,":all":MochiKit.DateTime.EXPORT};MochiKit.DateTime.__new__=function(){var base=this.NAME+".";for(var k in this){var o=this[k];if(typeof (o)=="function"&&typeof (o.NAME)=="undefined"){try{o.NAME=base+k;}catch(e){}}}};MochiKit.DateTime.__new__();if(typeof (MochiKit.Base)!="undefined"){MochiKit.Base._exportSymbols(this,MochiKit.DateTime);}else{(function(_231,_232){if((typeof (JSAN)=="undefined"&&typeof (dojo)=="undefined")||(typeof (MochiKit.__compat__)=="boolean"&&MochiKit.__compat__)){var all=_232.EXPORT_TAGS[":all"];for(var i=0;i<all.length;i++){_231[all[i]]=_232[all[i]];}}})(this,MochiKit.DateTime);}if(typeof (dojo)!="undefined"){dojo.provide("MochiKit.Format");}if(typeof (MochiKit)=="undefined"){MochiKit={};}if(typeof (MochiKit.Format)=="undefined"){MochiKit.Format={};}MochiKit.Format.NAME="MochiKit.Format";MochiKit.Format.VERSION="1.3.1";MochiKit.Format.__repr__=function(){return "["+this.NAME+" "+this.VERSION+"]";};MochiKit.Format.toString=function(){return this.__repr__();};MochiKit.Format._numberFormatter=function(_233,_234,_235,_236,_237,_238,_239,_240,_241){return function(num){num=parseFloat(num);if(typeof (num)=="undefined"||num===null||isNaN(num)){return _233;}var _242=_234;var _243=_235;if(num<0){num=-num;}else{_242=_242.replace(/-/,"");}var me=arguments.callee;var fmt=MochiKit.Format.formatLocale(_236);if(_237){num=num*100;_243=fmt.percent+_243;}num=MochiKit.Format.roundToFixed(num,_238);var _245=num.split(/\./);var _246=_245[0];var frac=(_245.length==1)?"":_245[1];var res="";while(_246.length<_239){_246="0"+_246;}if(_240){while(_246.length>_240){var i=_246.length-_240;res=fmt.separator+_246.substring(i,_246.length)+res;_246=_246.substring(0,i);}}res=_246+res;if(_238>0){while(frac.length<_241){frac=frac+"0";}res=res+fmt.decimal+frac;}return _242+res+_243;};};MochiKit.Format.numberFormatter=function(_248,_249,_250){if(typeof (_249)=="undefined"){_249="";}var _251=_248.match(/((?:[0#]+,)?[0#]+)(?:\.([0#]+))?(%)?/);if(!_251){throw TypeError("Invalid pattern");}var _252=_248.substr(0,_251.index);var _253=_248.substr(_251.index+_251[0].length);if(_252.search(/-/)==-1){_252=_252+"-";}var _254=_251[1];var frac=(typeof (_251[2])=="string"&&_251[2]!="")?_251[2]:"";var _255=(typeof (_251[3])=="string"&&_251[3]!="");var tmp=_254.split(/,/);var _257;if(typeof (_250)=="undefined"){_250="default";}if(tmp.length==1){_257=null;}else{_257=tmp[1].length;}var _258=_254.length-_254.replace(/0/g,"").length;var _259=frac.length-frac.replace(/0/g,"").length;var _260=frac.length;var rval=MochiKit.Format._numberFormatter(_249,_252,_253,_250,_255,_260,_258,_257,_259);var m=MochiKit.Base;if(m){var fn=arguments.callee;var args=m.concat(arguments);rval.repr=function(){return [self.NAME,"(",map(m.repr,args).join(", "),")"].join("");};}return rval;};MochiKit.Format.formatLocale=function(_262){if(typeof (_262)=="undefined"||_262===null){_262="default";}if(typeof (_262)=="string"){var rval=MochiKit.Format.LOCALE[_262];if(typeof (rval)=="string"){rval=arguments.callee(rval);MochiKit.Format.LOCALE[_262]=rval;}return rval;}else{return _262;}};MochiKit.Format.twoDigitAverage=function(_263,_264){if(_264){var res=_263/_264;if(!isNaN(res)){return MochiKit.Format.twoDigitFloat(_263/_264);}}return "0";};MochiKit.Format.twoDigitFloat=function(_265){var sign=(_265<0?"-":"");var s=Math.floor(Math.abs(_265)*100).toString();if(s=="0"){return s;}if(s.length<3){while(s.charAt(s.length-1)=="0"){s=s.substring(0,s.length-1);}return sign+"0."+s;}var head=sign+s.substring(0,s.length-2);var tail=s.substring(s.length-2,s.length);if(tail=="00"){return head;}else{if(tail.charAt(1)=="0"){return head+"."+tail.charAt(0);}else{return head+"."+tail;}}};MochiKit.Format.lstrip=function(str,_270){str=str+"";if(typeof (str)!="string"){return null;}if(!_270){return str.replace(/^\s+/,"");}else{return str.replace(new RegExp("^["+_270+"]+"),"");}};MochiKit.Format.rstrip=function(str,_271){str=str+"";if(typeof (str)!="string"){return null;}if(!_271){return str.replace(/\s+$/,"");}else{return str.replace(new RegExp("["+_271+"]+$"),"");}};MochiKit.Format.strip=function(str,_272){var self=MochiKit.Format;return self.rstrip(self.lstrip(str,_272),_272);};MochiKit.Format.truncToFixed=function(_273,_274){_273=Math.floor(_273*Math.pow(10,_274));var res=(_273*Math.pow(10,-_274)).toFixed(_274);if(res.charAt(0)=="."){res="0"+res;}return res;};MochiKit.Format.roundToFixed=function(_275,_276){return MochiKit.Format.truncToFixed(_275+0.5*Math.pow(10,-_276),_276);};MochiKit.Format.percentFormat=function(_277){return MochiKit.Format.twoDigitFloat(100*_277)+"%";};MochiKit.Format.EXPORT=["truncToFixed","roundToFixed","numberFormatter","formatLocale","twoDigitAverage","twoDigitFloat","percentFormat","lstrip","rstrip","strip"];MochiKit.Format.LOCALE={en_US:{separator:",",decimal:".",percent:"%"},de_DE:{separator:".",decimal:",",percent:"%"},fr_FR:{separator:" ",decimal:",",percent:"%"},"default":"en_US"};MochiKit.Format.EXPORT_OK=[];MochiKit.Format.EXPORT_TAGS={":all":MochiKit.Format.EXPORT,":common":MochiKit.Format.EXPORT};MochiKit.Format.__new__=function(){var base=this.NAME+".";var k,v,o;for(k in this.LOCALE){o=this.LOCALE[k];if(typeof (o)=="object"){o.repr=function(){return this.NAME;};o.NAME=base+"LOCALE."+k;}}for(k in this){o=this[k];if(typeof (o)=="function"&&typeof (o.NAME)=="undefined"){try{o.NAME=base+k;}catch(e){}}}};MochiKit.Format.__new__();if(typeof (MochiKit.Base)!="undefined"){MochiKit.Base._exportSymbols(this,MochiKit.Format);}else{(function(_278,_279){if((typeof (JSAN)=="undefined"&&typeof (dojo)=="undefined")||(typeof (MochiKit.__compat__)=="boolean"&&MochiKit.__compat__)){var all=_279.EXPORT_TAGS[":all"];for(var i=0;i<all.length;i++){_278[all[i]]=_279[all[i]];}}})(this,MochiKit.Format);}if(typeof (dojo)!="undefined"){dojo.provide("MochiKit.Async");dojo.require("MochiKit.Base");}if(typeof (JSAN)!="undefined"){JSAN.use("MochiKit.Base",[]);}try{if(typeof (MochiKit.Base)=="undefined"){throw "";}}catch(e){throw "MochiKit.Async depends on MochiKit.Base!";}if(typeof (MochiKit.Async)=="undefined"){MochiKit.Async={};}MochiKit.Async.NAME="MochiKit.Async";MochiKit.Async.VERSION="1.3.1";MochiKit.Async.__repr__=function(){return "["+this.NAME+" "+this.VERSION+"]";};MochiKit.Async.toString=function(){return this.__repr__();};MochiKit.Async.Deferred=function(_280){this.chain=[];this.id=this._nextId();this.fired=-1;this.paused=0;this.results=[null,null];this.canceller=_280;this.silentlyCancelled=false;this.chained=false;};MochiKit.Async.Deferred.prototype={repr:function(){var _281;if(this.fired==-1){_281="unfired";}else{if(this.fired===0){_281="success";}else{_281="error";}}return "Deferred("+this.id+", "+_281+")";},toString:MochiKit.Base.forwardCall("repr"),_nextId:MochiKit.Base.counter(),cancel:function(){var self=MochiKit.Async;if(this.fired==-1){if(this.canceller){this.canceller(this);}else{this.silentlyCancelled=true;}if(this.fired==-1){this.errback(new self.CancelledError(this));}}else{if((this.fired===0)&&(this.results[0] instanceof self.Deferred)){this.results[0].cancel();}}},_pause:function(){this.paused++;},_unpause:function(){this.paused--;if((this.paused===0)&&(this.fired>=0)){this._fire();}},_continue:function(res){this._resback(res);this._unpause();},_resback:function(res){this.fired=((res instanceof Error)?1:0);this.results[this.fired]=res;this._fire();},_check:function(){if(this.fired!=-1){if(!this.silentlyCancelled){throw new MochiKit.Async.AlreadyCalledError(this);}this.silentlyCancelled=false;return;}},callback:function(res){this._check();if(res instanceof MochiKit.Async.Deferred){throw new Error("Deferred instances can only be chained if they are the result of a callback");}this._resback(res);},errback:function(res){this._check();var self=MochiKit.Async;if(res instanceof self.Deferred){throw new Error("Deferred instances can only be chained if they are the result of a callback");}if(!(res instanceof Error)){res=new self.GenericError(res);}this._resback(res);},addBoth:function(fn){if(arguments.length>1){fn=MochiKit.Base.partial.apply(null,arguments);}return this.addCallbacks(fn,fn);},addCallback:function(fn){if(arguments.length>1){fn=MochiKit.Base.partial.apply(null,arguments);}return this.addCallbacks(fn,null);},addErrback:function(fn){if(arguments.length>1){fn=MochiKit.Base.partial.apply(null,arguments);}return this.addCallbacks(null,fn);},addCallbacks:function(cb,eb){if(this.chained){throw new Error("Chained Deferreds can not be re-used");}this.chain.push([cb,eb]);if(this.fired>=0){this._fire();}return this;},_fire:function(){var _284=this.chain;var _285=this.fired;var res=this.results[_285];var self=this;var cb=null;while(_284.length>0&&this.paused===0){var pair=_284.shift();var f=pair[_285];if(f===null){continue;}try{res=f(res);_285=((res instanceof Error)?1:0);if(res instanceof MochiKit.Async.Deferred){cb=function(res){self._continue(res);};this._pause();}}catch(err){_285=1;if(!(err instanceof Error)){err=new MochiKit.Async.GenericError(err);}res=err;}}this.fired=_285;this.results[_285]=res;if(cb&&this.paused){res.addBoth(cb);res.chained=true;}}};MochiKit.Base.update(MochiKit.Async,{evalJSONRequest:function(){return eval("("+arguments[0].responseText+")");},succeed:function(_287){var d=new MochiKit.Async.Deferred();d.callback.apply(d,arguments);return d;},fail:function(_288){var d=new MochiKit.Async.Deferred();d.errback.apply(d,arguments);return d;},getXMLHttpRequest:function(){var self=arguments.callee;if(!self.XMLHttpRequest){var _289=[function(){return new XMLHttpRequest();},function(){return new ActiveXObject("Msxml2.XMLHTTP");},function(){return new ActiveXObject("Microsoft.XMLHTTP");},function(){return new ActiveXObject("Msxml2.XMLHTTP.4.0");},function(){throw new MochiKit.Async.BrowserComplianceError("Browser does not support XMLHttpRequest");}];for(var i=0;i<_289.length;i++){var func=_289[i];try{self.XMLHttpRequest=func;return func();}catch(e){}}}return self.XMLHttpRequest();},_nothing:function(){},_xhr_onreadystatechange:function(d){if(this.readyState==4){try{this.onreadystatechange=null;}catch(e){try{this.onreadystatechange=MochiKit.Async._nothing;}catch(e){}}var _290=null;try{_290=this.status;if(!_290&&MochiKit.Base.isNotEmpty(this.responseText)){_290=304;}}catch(e){}if(_290==200||_290==304){d.callback(this);}else{var err=new MochiKit.Async.XMLHttpRequestError(this,"Request failed");if(err.number){d.errback(err);}else{d.errback(err);}}}},_xhr_canceller:function(req){try{req.onreadystatechange=null;}catch(e){try{req.onreadystatechange=MochiKit.Async._nothing;}catch(e){}}req.abort();},sendXMLHttpRequest:function(req,_293){if(typeof (_293)=="undefined"||_293===null){_293="";}var m=MochiKit.Base;var self=MochiKit.Async;var d=new self.Deferred(m.partial(self._xhr_canceller,req));try{req.onreadystatechange=m.bind(self._xhr_onreadystatechange,req,d);req.send(_293);}catch(e){try{req.onreadystatechange=null;}catch(ignore){}d.errback(e);}return d;},doSimpleXMLHttpRequest:function(url){var self=MochiKit.Async;var req=self.getXMLHttpRequest();if(arguments.length>1){var m=MochiKit.Base;var qs=m.queryString.apply(null,m.extend(null,arguments,1));if(qs){url+="?"+qs;}}req.open("GET",url,true);return self.sendXMLHttpRequest(req);},loadJSONDoc:function(url){var self=MochiKit.Async;var d=self.doSimpleXMLHttpRequest.apply(self,arguments);d=d.addCallback(self.evalJSONRequest);return d;},wait:function(_296,_297){var d=new MochiKit.Async.Deferred();var m=MochiKit.Base;if(typeof (_297)!="undefined"){d.addCallback(function(){return _297;});}var _298=setTimeout(m.bind("callback",d),Math.floor(_296*1000));d.canceller=function(){try{clearTimeout(_298);}catch(e){}};return d;},callLater:function(_299,func){var m=MochiKit.Base;var _300=m.partial.apply(m,m.extend(null,arguments,1));return MochiKit.Async.wait(_299).addCallback(function(res){return _300();});}});MochiKit.Async.DeferredLock=function(){this.waiting=[];this.locked=false;this.id=this._nextId();};MochiKit.Async.DeferredLock.prototype={__class__:MochiKit.Async.DeferredLock,acquire:function(){d=new MochiKit.Async.Deferred();if(this.locked){this.waiting.push(d);}else{this.locked=true;d.callback(this);}return d;},release:function(){if(!this.locked){throw TypeError("Tried to release an unlocked DeferredLock");}this.locked=false;if(this.waiting.length>0){this.locked=true;this.waiting.shift().callback(this);}},_nextId:MochiKit.Base.counter(),repr:function(){var _301;if(this.locked){_301="locked, "+this.waiting.length+" waiting";}else{_301="unlocked";}return "DeferredLock("+this.id+", "+_301+")";
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -