console-min.js revision 8951c05b281fd712464388c237e1f0be6b6487a7
YUI.add("console",function(D){function W(){W.superclass.constructor.apply(this,arguments);}var G=D.ClassNameManager.getClassName,B="checked",t="clear",s="click",U="collapsed",AF="console",e="contentBox",i="disabled",p="entry",H="entryTemplate",m="error",k="height",Q="info",z="innerHTML",N="lastTime",F="pause",g="paused",y="reset",w="startTime",q="title",j="warn",a=".",Z=G(AF,"button"),c=G(AF,"checkbox"),AE=G(AF,t),x=G(AF,"collapse"),T=G(AF,U),E=G(AF,"controls"),f=G(AF,"hd"),d=G(AF,"bd"),C=G(AF,"ft"),l=G(AF,q),AA=G(AF,p),u=G(AF,p,"cat"),b=G(AF,p,"content"),V=G(AF,p,"meta"),h=G(AF,p,"src"),A=G(AF,p,"time"),R=G(AF,F),X=G(AF,F,"label"),o=/^(\S+)\s/,AB=/&/g,v=/>/g,K=/</g,I="&#38;",S="&#62;",n="&#60;",P='<div class="{entry_class} {cat_class} {src_class}">'+'<p class="{entry_meta_class}">'+'<span class="{entry_src_class}">'+"{sourceAndDetail}"+"</span>"+'<span class="{entry_cat_class}">'+"{label}</span>"+'<span class="{entry_time_class}">'+" {totalTime}ms (+{elapsedTime}) {localTime}"+"</span>"+"</p>"+'<pre class="{entry_content_class}">{message}</pre>'+"</div>",J=D.Lang,M=D.Node.create,AD=J.isNumber,O=J.isString,r=D.merge,AC=D.substitute;D.mix(W,{NAME:AF,LOG_LEVEL_INFO:Q,LOG_LEVEL_WARN:j,LOG_LEVEL_ERROR:m,ENTRY_CLASSES:{entry_class:AA,entry_meta_class:V,entry_cat_class:u,entry_src_class:h,entry_time_class:A,entry_content_class:b},CHROME_CLASSES:{console_hd_class:f,console_bd_class:d,console_ft_class:C,console_controls_class:E,console_checkbox_class:c,console_pause_class:R,console_pause_label_class:X,console_button_class:Z,console_clear_class:AE,console_collapse_class:x,console_title_class:l},HEADER_TEMPLATE:'<div class="{console_hd_class}">'+'<h4 class="{console_title_class}">{str_title}</h4>'+'<button type="button" class="'+'{console_button_class} {console_collapse_class}">{str_collapse}'+"</button>"+"</div>",BODY_TEMPLATE:'<div class="{console_bd_class}"></div>',FOOTER_TEMPLATE:'<div class="{console_ft_class}">'+'<div class="{console_controls_class}">'+'<label for="{id_guid}" class="{console_pause_label_class}">'+'<input type="checkbox" class="{console_checkbox_class} '+'{console_pause_class}" value="1" id="{id_guid}"> '+"{str_pause}</label>"+'<button type="button" class="'+'{console_button_class} {console_clear_class}">{str_clear}'+"</button>"+"</div>"+"</div>",ENTRY_TEMPLATE:P,ATTRS:{logEvent:{value:"yui:log",writeOnce:true,validator:O},logSource:{value:D,writeOnce:true,validator:function(L){return L&&D.Lang.isFunction(L.on);}},strings:{value:{title:"Log Console",pause:"Pause",clear:"Clear",collapse:"Collapse",expand:"Expand"}},paused:{value:false,validator:J.isBoolean},defaultCategory:{value:Q,validator:O},defaultSource:{value:"global",validator:O},entryTemplate:{value:P,validator:O},logLevel:{value:D.config.logLevel||Q,setter:function(L){return this._setLogLevel(L);}},printTimeout:{value:100,validator:AD},printLimit:{value:50,validator:AD},consoleLimit:{value:300,validator:AD},newestOnTop:{value:true},scrollIntoView:{value:true},startTime:{value:new Date()},lastTime:{value:new Date(),readOnly:true},collapsed:{value:false},height:{value:"300px"},width:{value:"300px"}}});D.extend(W,D.Widget,{_evtCat:null,_head:null,_body:null,_foot:null,_printLoop:null,buffer:null,log:function(){D.log.apply(D,arguments);return this;},clearConsole:function(){this._body.set(z,"");this._cancelPrintLoop();this.buffer=[];return this;},reset:function(){this.fire(y);return this;},collapse:function(){this.set(U,true);return this;},expand:function(){this.set(U,false);return this;},printBuffer:function(Y){var AL=this.buffer,AG=D.config.debug,L=[],AI=this.get("consoleLimit"),AK=this.get("newestOnTop"),AH=AK?this._body.get("firstChild"):null,AJ;if(AL.length>AI){AL.splice(0,AL.length-AI);}Y=Math.min(AL.length,(Y||AL.length));D.config.debug=false;if(!this.get(g)&&this.get("rendered")){for(AJ=0;AJ<Y&&AL.length;++AJ){L[AJ]=this._createEntryHTML(AL.shift());}if(!AL.length){this._cancelPrintLoop();}if(AK){L.reverse();}this._body.insertBefore(M(L.join("")),AH);if(this.get("scrollIntoView")){this.scrollToLatest();}this._trimOldEntries();}D.config.debug=AG;return this;},initializer:function(){this._evtCat=D.stamp(this)+"|";this.buffer=[];this.get("logSource").on(this._evtCat+this.get("logEvent"),D.bind("_onLogEvent",this));this.publish(p,{defaultFn:this._defEntryFn});this.publish(y,{defaultFn:this._defResetFn});this.after("rendered",this._schedulePrint);},destructor:function(){var L=this.get("boundingBox");this._cancelPrintLoop();this.get("logSource").detach(this._evtCat+"*");D.Event.purgeElement(L,true);L.set("innerHTML","");},renderUI:function(){this._initHead();this._initBody();this._initFoot();},syncUI:function(){this._uiUpdatePaused(this.get(g));this._uiUpdateCollapsed(this.get(U));this._uiSetHeight(this.get(k));},bindUI:function(){this.get(e).query("button."+x).on(s,this._onCollapseClick,this);this.get(e).query("input[type=checkbox]."+R).on(s,this._onPauseClick,this);this.get(e).query("button."+AE).on(s,this._onClearClick,this);this.after(this._evtCat+"stringsChange",this._afterStringsChange);this.after(this._evtCat+"pausedChange",this._afterPausedChange);this.after(this._evtCat+"consoleLimitChange",this._afterConsoleLimitChange);this.after(this._evtCat+"collapsedChange",this._afterCollapsedChange);},_initHead:function(){var L=this.get(e),Y=r(W.CHROME_CLASSES,{str_collapse:this.get("strings.collapse"),str_title:this.get("strings.title")});this._head=M(AC(W.HEADER_TEMPLATE,Y));L.insertBefore(this._head,L.get("firstChild"));},_initBody:function(){this._body=M(AC(W.BODY_TEMPLATE,W.CHROME_CLASSES));this.get(e).appendChild(this._body);},_initFoot:function(){var L=r(W.CHROME_CLASSES,{id_guid:D.guid(),str_pause:this.get("strings.pause"),str_clear:this.get("strings.clear")});this._foot=M(AC(W.FOOTER_TEMPLATE,L));this.get(e).appendChild(this._foot);},_isInLogLevel:function(AG){var L=AG.cat,Y=this.get("logLevel");if(Y!==Q){L=L||Q;if(O(L)){L=L.toLowerCase();}if((L===j&&Y===m)||(L===Q&&Y!==Q)){return false;}}return true;},_normalizeMessage:function(AG){var AI=AG.msg,Y=AG.cat,AH=AG.src,L={time:new Date(),message:AI,category:Y||this.get("defaultCategory"),sourceAndDetail:AH||this.get("defaultSource"),source:null,label:null,localTime:null,elapsedTime:null,totalTime:null};
L.source=o.test(L.sourceAndDetail)?RegExp.$1:L.sourceAndDetail;L.label=L.category;L.localTime=L.time.toLocaleTimeString?L.time.toLocaleTimeString():(L.time+"");L.elapsedTime=L.time-this.get(N);L.totalTime=L.time-this.get(w);this._set(N,L.time);return L;},_schedulePrint:function(){if(!this._printLoop&&!this.get(g)&&this.get("rendered")){this._printLoop=D.later(this.get("printTimeout"),this,this.printBuffer,this.get("printLimit"),true);}},_createEntryHTML:function(L){L=r(this._htmlEscapeMessage(L),W.ENTRY_CLASSES,{cat_class:this.getClassName(p,L.category),src_class:this.getClassName(p,L.source)});return this.get("entryTemplate").replace(/\{(\w+)\}/g,function(Y,AG){return AG in L?L[AG]:"";});},scrollToLatest:function(){var L=this.get("newestOnTop")?0:this._body.get("scrollHeight");this._body.set("scrollTop",L);},_htmlEscapeMessage:function(L){L=D.clone(L);L.message=this._encodeHTML(L.message);L.label=this._encodeHTML(L.label);L.source=this._encodeHTML(L.source);L.sourceAndDetail=this._encodeHTML(L.sourceAndDetail);L.category=this._encodeHTML(L.category);return L;},_trimOldEntries:function(){D.config.debug=false;var AJ=this._body,AG=this.get("consoleLimit"),AH=D.config.debug,L,AK,AI,Y;if(AJ){L=AJ.queryAll(a+AA);Y=L.size()-AG;if(Y>0){if(this.get("newestOnTop")){AI=AG;Y=L.size();}else{AI=0;}this._body.setStyle("display","none");for(;AI<Y;++AI){AK=L.item(AI);if(AK){AK.remove();}}this._body.setStyle("display","");}}D.config.debug=AH;},_encodeHTML:function(L){return O(L)?L.replace(AB,I).replace(K,n).replace(v,S):L;},_cancelPrintLoop:function(){if(this._printLoop){this._printLoop.cancel();this._printLoop=null;}},_onPauseClick:function(L){this.set(g,L.target.get(B));},_onClearClick:function(L){this.clearConsole();},_onCollapseClick:function(L){this.set(U,!this.get(U));},_setLogLevel:function(L){if(O(L)){L=L.toLowerCase();}return(L===j||L===m)?L:Q;},_uiSetHeight:function(L){W.superclass._uiSetHeight.apply(this,arguments);if(this._head&&this._foot){var Y=this.get("boundingBox").get("offsetHeight")-this._head.get("offsetHeight")-this._foot.get("offsetHeight");this._body.setStyle(k,Y+"px");}},_afterStringsChange:function(AH){var AJ=AH.subAttrName?AH.subAttrName.split(a)[1]:null,L=this.get(e),AG=AH.prevVal,AI=AH.newVal,Y;if((!AJ||AJ===q)&&AG.title!==AI.title){Y=L.query(a+l);if(Y){Y.set(z,AI.title);}}if((!AJ||AJ===F)&&AG.pause!==AI.pause){Y=L.query(a+X);if(Y){Y.set(z,AI.pause);}}if((!AJ||AJ===t)&&AG.clear!==AI.clear){Y=L.query(a+AE);if(Y){Y.set("value",AI.clear);}}},_afterPausedChange:function(Y){var L=Y.newVal;if(Y.src!==D.Widget.SRC_UI){this._uiUpdatePaused(L);}if(!L){this._schedulePrint();}else{if(this._printLoop){this._cancelPrintLoop();}}},_uiUpdatePaused:function(L){var Y=this._foot.queryAll("input[type=checkbox]."+R);if(Y){Y.set(B,L);}},_afterConsoleLimitChange:function(){this._trimOldEntries();},_afterCollapsedChange:function(L){this._uiUpdateCollapsed(L.newVal);},_uiUpdateCollapsed:function(Y){var L=this.get(e),AG=L.queryAll("button."+x),AI=Y?"addClass":"removeClass",AH=this.get("strings."+(Y?"expand":"collapse"));L[AI](T);if(AG){AG.set("innerHTML",AH);}if(!Y){this._uiSetHeight(this.get(k));}},_afterVisibleChange:function(L){W.superclass._afterVisibleChange.apply(this,arguments);this._uiUpdateFromHideShow(L.newVal);},_uiUpdateFromHideShow:function(L){if(L){this._uiSetHeight(this.get(k));}},_onLogEvent:function(Y){if(!this.get(i)&&this._isInLogLevel(Y)){var L=D.config.debug;D.config.debug=false;this.fire(p,{message:this._normalizeMessage(Y)});D.config.debug=L;}},_defResetFn:function(){this.clearConsole();this.set(w,new Date());this.set(i,false);this.set(g,false);},_defEntryFn:function(L){if(L.message){this.buffer.push(L.message);this._schedulePrint();}}});D.Console=W;},"@VERSION@",{requires:["substitute","widget"]});