/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

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