PageRenderTime 25ms CodeModel.GetById 14ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 1ms

/Frameworks/Foundation/objj.platform/CPLog.j

http://github.com/jfahrenkrug/MapKit-HelloWorld
Unknown | 261 lines | 261 code | 0 blank | 0 comment | 0 complexity | 9f58d1b9390b6e218d4ce23127d6992c MD5 | raw file
  1c;6885;
  2window.CPLogDisable=false;
  3var _1="Cappuccino";
  4var _2=["fatal","error","warn","info","debug","trace"];
  5var _3=_2[0];
  6var _4={};
  7for(var i=0;i<_2.length;i++){
  8_4[_2[i]]=i;
  9}
 10var _6={};
 11var _7=function(_8,_9,_a){
 12var _b=new Date();
 13_9=(_9==null?"":" ["+_9+"]");
 14if(typeof sprintf=="function"){
 15return sprintf("%4d-%02d-%02d %02d:%02d:%02d.%03d %s%s: %s",_b.getFullYear(),_b.getMonth(),_b.getDate(),_b.getHours(),_b.getMinutes(),_b.getSeconds(),_b.getMilliseconds(),_a,_9,_8);
 16}else{
 17return _b+" "+_a+_9+": "+_8;
 18}
 19};
 20CPLogRegister=function(_c,_d){
 21CPLogRegisterRange(_c,_2[0],_d||_2[_2.length-1]);
 22};
 23CPLogRegisterRange=function(_e,_f,_10){
 24var min=_4[_f];
 25var max=_4[_10];
 26if(min!=undefined&&max!=undefined){
 27for(var i=0;i<=max;i++){
 28CPLogRegisterSingle(_e,_2[i]);
 29}
 30}
 31};
 32CPLogRegisterSingle=function(_14,_15){
 33if(_6[_15]==undefined){
 34_6[_15]=[_14];
 35}else{
 36_6[_15].push(_14);
 37}
 38};
 39_CPLogDispatch=function(_16,_17,_18){
 40if(_18==undefined){
 41_18=_1;
 42}
 43if(_17==undefined){
 44_17=_3;
 45}
 46var _19=(typeof _16[0]=="string"&&_16.length>1)?sprintf.apply(null,_16):String(_16[0]);
 47if(_6[_17]){
 48for(var i=0;i<_6[_17].length;i++){
 49_6[_17][i](_19,_17,_18);
 50}
 51}
 52};
 53CPLog=function(){
 54_CPLogDispatch(arguments);
 55};
 56for(var i=0;i<_2.length;i++){
 57CPLog[_2[i]]=(function(_1b){
 58return function(){
 59_CPLogDispatch(arguments,_1b);
 60};
 61})(_2[i]);
 62}
 63ANSI_ESC=String.fromCharCode(27);
 64ANSI_CSI=ANSI_ESC+"[";
 65ANSI_TEXT_PROP="m";
 66ANSI_RESET="0";
 67ANSI_BOLD="1";
 68ANSI_FAINT="2";
 69ANSI_NORMAL="22";
 70ANSI_ITALIC="3";
 71ANSI_UNDER="4";
 72ANSI_UNDER_DBL="21";
 73ANSI_UNDER_OFF="24";
 74ANSI_BLINK="5";
 75ANSI_BLINK_FAST="6";
 76ANSI_BLINK_OFF="25";
 77ANSI_REVERSE="7";
 78ANSI_POSITIVE="27";
 79ANSI_CONCEAL="8";
 80ANSI_REVEAL="28";
 81ANSI_FG="3";
 82ANSI_BG="4";
 83ANSI_FG_INTENSE="9";
 84ANSI_BG_INTENSE="10";
 85ANSI_BLACK="0";
 86ANSI_RED="1";
 87ANSI_GREEN="2";
 88ANSI_YELLOW="3";
 89ANSI_BLUE="4";
 90ANSI_MAGENTA="5";
 91ANSI_CYAN="6";
 92ANSI_WHITE="7";
 93var _1c={"black":ANSI_BLACK,"red":ANSI_RED,"green":ANSI_GREEN,"yellow":ANSI_YELLOW,"blue":ANSI_BLUE,"magenta":ANSI_MAGENTA,"cyan":ANSI_CYAN,"white":ANSI_WHITE};
 94ANSIControlCode=function(_1d,_1e){
 95if(_1e==undefined){
 96_1e="";
 97}else{
 98if(typeof (_1e)=="object"&&(_1e instanceof Array)){
 99_1e=_1e.join(";");
100}
101}
102return ANSI_CSI+String(_1e)+String(_1d);
103};
104ANSITextApplyProperties=function(_1f,_20){
105return ANSIControlCode(ANSI_TEXT_PROP,_20)+String(_1f)+ANSIControlCode(ANSI_TEXT_PROP);
106};
107ANSITextColorize=function(_21,_22){
108if(_1c[_22]==undefined){
109return _21;
110}
111return ANSITextApplyProperties(_21,ANSI_FG+_1c[_22]);
112};
113var _23={"fatal":"red","error":"red","warn":"yellow","info":"green","debug":"cyan","trace":"blue"};
114CPLogPrint=function(_24,_25,_26){
115if(typeof print!="undefined"){
116if(_25=="fatal"||_25=="error"||_25=="warn"){
117var _27=ANSITextColorize(_7(_24,_25,_26),_23[_25]);
118}else{
119var _27=_7(_24,ANSITextColorize(_25,_23[_25]),_26);
120}
121print(_27);
122}
123};
124CPLogAlert=function(_28,_29,_2a){
125if(typeof alert!="undefined"&&!window.CPLogDisable){
126var _2b=_7(_28,_29,_2a);
127window.CPLogDisable=!confirm(_2b+"\n\n(Click cancel to stop log alerts)");
128}
129};
130CPLogConsole=function(_2c,_2d,_2e){
131if(typeof console!="undefined"){
132var _2f=_7(_2c,_2d,_2e);
133var _30={"fatal":"error","error":"error","warn":"warn","info":"info","debug":"debug","trace":"debug"}[_2d];
134if(_30&&console[_30]){
135console[_30](_2f);
136}else{
137if(console.log){
138console.log(_2f);
139}
140}
141}
142};
143var _31=null;
144CPLogPopup=function(_32,_33,_34){
145try{
146if(window.CPLogDisable||window.open==undefined){
147return;
148}
149if(!_31||!_31.document){
150_31=window.open("","_blank","width=600,height=400,status=no,resizable=yes,scrollbars=yes");
151if(!_31){
152window.CPLogDisable=!confirm(_32+"\n\n(Disable pop-up blocking for CPLog window; Click cancel to stop log alerts)");
153return;
154}
155_35(_31);
156}
157var _36=_31.document.createElement("div");
158_36.setAttribute("class",_33||"fatal");
159var _37=_7(_32,null,_34);
160_36.appendChild(_31.document.createTextNode(_37));
161_31.log.appendChild(_36);
162if(_31.focusEnabled.checked){
163_31.focus();
164}
165if(_31.blockEnabled.checked){
166_31.blockEnabled.checked=_31.confirm(_37+"\nContinue blocking?");
167}
168if(_31.scrollEnabled.checked){
169_31.scrollToBottom();
170}
171}
172catch(e){
173}
174};
175var _35=function(_38){
176var doc=_38.document;
177doc.writeln("<html><head><title></title></head><body></body></html>");
178doc.title=_1+" Run Log";
179var _3a=doc.getElementsByTagName("head")[0];
180var _3b=doc.getElementsByTagName("body")[0];
181var _3c=window.location.protocol+"//"+window.location.host+window.location.pathname;
182_3c=_3c.substring(0,_3c.lastIndexOf("/")+1);
183var _3d=doc.createElement("link");
184_3d.setAttribute("type","text/css");
185_3d.setAttribute("rel","stylesheet");
186_3d.setAttribute("href",_3c+"Frameworks/Foundation/Resources/log.css");
187_3d.setAttribute("media","screen");
188_3a.appendChild(_3d);
189var div=doc.createElement("div");
190div.setAttribute("id","header");
191_3b.appendChild(div);
192var ul=doc.createElement("ul");
193ul.setAttribute("id","enablers");
194div.appendChild(ul);
195for(var i=0;i<_2.length;i++){
196var li=doc.createElement("li");
197li.setAttribute("id","en"+_2[i]);
198li.setAttribute("class",_2[i]);
199li.setAttribute("onclick","toggle(this);");
200li.setAttribute("enabled","yes");
201li.appendChild(doc.createTextNode(_2[i]));
202ul.appendChild(li);
203}
204var ul=doc.createElement("ul");
205ul.setAttribute("id","options");
206div.appendChild(ul);
207var _42={"focus":["Focus",false],"block":["Block",false],"wrap":["Wrap",false],"scroll":["Scroll",true],"close":["Close",true]};
208for(o in _42){
209var li=doc.createElement("li");
210ul.appendChild(li);
211_38[o+"Enabled"]=doc.createElement("input");
212_38[o+"Enabled"].setAttribute("id",o);
213_38[o+"Enabled"].setAttribute("type","checkbox");
214if(_42[o][1]){
215_38[o+"Enabled"].setAttribute("checked","checked");
216}
217li.appendChild(_38[o+"Enabled"]);
218var _43=doc.createElement("label");
219_43.setAttribute("for",o);
220_43.appendChild(doc.createTextNode(_42[o][0]));
221li.appendChild(_43);
222}
223_38.log=doc.createElement("div");
224_38.log.setAttribute("class","enerror endebug enwarn eninfo enfatal entrace");
225_3b.appendChild(_38.log);
226_38.toggle=function(_44){
227var _45=(_44.getAttribute("enabled")=="yes")?"no":"yes";
228_44.setAttribute("enabled",_45);
229if(_45=="yes"){
230_38.log.className+=" "+_44.id;
231}else{
232_38.log.className=_38.log.className.replace(new RegExp("[\\s]*"+_44.id,"g"),"");
233}
234};
235_38.scrollToBottom=function(){
236_38.scrollTo(0,_3b.offsetHeight);
237};
238_38.wrapEnabled.addEventListener("click",function(){
239_38.log.setAttribute("wrap",_38.wrapEnabled.checked?"yes":"no");
240},false);
241_38.addEventListener("keydown",function(e){
242var e=e||_38.event;
243if(e.keyCode==75&&(e.ctrlKey||e.metaKey)){
244while(_38.log.firstChild){
245_38.log.removeChild(_38.log.firstChild);
246}
247e.preventDefault();
248}
249},"false");
250window.addEventListener("unload",function(){
251if(_38&&_38.closeEnabled&&_38.closeEnabled.checked){
252window.CPLogDisable=true;
253_38.close();
254}
255},false);
256_38.addEventListener("unload",function(){
257if(!window.CPLogDisable){
258window.CPLogDisable=!confirm("Click cancel to stop logging");
259}
260},false);
261};