console-debug.js revision 145fddab811fa63e280b6dd283c1ef7d8ad732f8
/**
* Console creates a visualization for Y.log statements. Log messages
* include a log level such as "info" or "warn" (also called the category), a
* source, and various timing info. Messages are rendered to the Console in
* asynchronous buffered batches so as to avoid interfering with the operation
* of your page.
*
* @class Console
* @extends Widget
*/
CONSOLE = 'console',
ENTRY = 'entry',
RESET = 'reset',
CHECKED = 'checked',
TITLE = 'title',
PAUSE = 'pause',
PAUSED = 'paused',
CLEAR = 'clear',
INFO = 'info',
WARN = 'warn',
ERROR = 'error',
INNER_HTML = 'innerHTML',
CLICK = 'click',
CONTENT_BOX = 'contentBox',
DISABLED = 'disabled',
START_TIME = 'startTime',
LAST_TIME = 'lastTime',
DOT = '.',
RE_INLINE_SOURCE = /^(\S+)\s/,
RE_AMP = /&/g,
RE_LT = /</g,
RE_GT = />/g,
ESC_AMP = '&',
ESC_LT = '<',
ESC_GT = '>',
L = Y.Lang,
substitute = Y.substitute,
// Here for defaulting in ATTRS.entryTemplate.value
'<pre class="{entry_class}">'+
'<div class="{entry_meta_class}">'+
'<p>'+
'<span class="{entry_cat_class}">'+
'{label}</span>'+
'<span class="{entry_time_class}">'+
' {totalTime}ms (+{elapsedTime}) {localTime}:'+
'</span>'+
'</p>'+
'<p class="{entry_src_class}">'+
'{sourceAndDetail}'+
'</p>'+
'</div>'+
'<p class="{entry_content_class}">{message}</p>'+
'</pre>';
function Console() {
}
/**
* The identity of the widget.
*
* @property Console.NAME
* @type String
* @static
*/
LOG_LEVEL_INFO : 3,
LOG_LEVEL_WARN : 2,
LOG_LEVEL_ERROR : 1,
ENTRY_CLASSES : {
},
CHROME_CLASSES : {
},
'<div class="{console_hd_class}">'+
'<h4 class="{console_title_class}">{str_title}</h4>'+
'</div>',
CONSOLE_TEMPLATE : '<div class="{console_bd_class}"></div>',
'<div class="{console_ft_class}">'+
'<div class="{console_controls_class}">'+
'<input type="checkbox" class="{console_checkbox_class} '+
'{console_pause_class}" value="1"> '+
'<label class="{console_pause_label_class}">'+
'{str_pause}</label>' +
'<input type="button" class="'+
'{console_button_class} {console_clear_class}" '+
'value="{str_clear}">'+
'</div>'+
'</div>',
ATTRS : {
/**
* Strings used in the Console UI. Default locale en-us.
*
* @attribute strings
* @type Object
*/
strings : {
value : {
title : "Log Console",
pause : "Pause",
clear : "Clear"
}
},
/**
* Boolean to pause the outputting of new messages to the console.
* When paused, messages will accumulate in the buffer.
*
* @attribute paused
* @type boolean
* @default false
*/
paused : {
value : false,
},
/**
* If a category is not specified in the Y.log(..) statement, this
* category will be used.
*
* @attribute defaultCategory
* @type String
* @default "info"
*/
defaultCategory : {
},
/**
* If a source is not specified in the Y.log(..) statement, this
* source will be used.
*
* @attribute defaultSource
* @type String
* @default "global"
*/
defaultSource : {
value : 'global',
},
/**
* The markup template to use to render log entries. Bracketed
* placeholders {likeThis} will be replaced with the appropriate data
* from the entry object.
*
* @attribute entryTemplate
* @type String
* @default (see Console.ENTRY_TEMPLATE)
*/
entryTemplate : {
},
logLevel : {
validator : function (v) {
return this._validateLogLevel(v);
},
set : function (v) {
return this._setLogLevel(v);
}
},
printTimeout : {
value : 100,
},
consoleLimit : {
value : 500,
},
newestOnTop : {
value : true
},
scrollIntoView : {
value : true
},
startTime : {
value : new Date()
},
lastTime : {
value : new Date(),
readOnly: true
}
}
});
_title : null,
_console : null,
_foot : null,
_timeout : null,
buffer : null,
// API methods
log : function () {
},
clearConsole : function () {
// TODO: clear event listeners from console contents
this._clearTimeout();
this.buffer = [];
return this;
},
reset : function () {
return this;
},
printBuffer: function () {
// Called from timeout, so calls to Y.log will not be caught by the
// recursion protection in event. Turn off logging while printing.
this._clearTimeout();
i,len;
this.buffer = [];
// TODO: use doc frag
this.printLogEntry(messages[i]);
}
this._trimOldEntries();
}
return this;
},
printLogEntry : function (m) {
m = merge(
this._htmlEscapeMessage(m),
{
});
this._addToConsole(n);
return this;
},
// Widget core methods
initializer : function (cfg) {
this.buffer = [];
},
renderUI : function () {
this._initHead();
this._initConsole();
this._initFoot();
},
syncUI : function () {
},
bindUI : function () {
// Attribute changes
},
// Support methods
// TODO: HTML_PARSER
_initHead : function () {
});
},
_initConsole : function () {
this._foot || null);
},
_initFoot : function () {
});
},
},
var m = {
time : new Date(),
source : null,
label : null,
localTime : null,
elapsedTime : null,
totalTime : null
};
// Extract m.source "Foo" from m.sourceAndDetail "Foo bar baz"
RegExp.$1 : m.sourceAndDetail;
return m;
},
_schedulePrint : function () {
this.get('printTimeout'),
this,this.printBuffer);
}
},
_addToConsole : function (node) {
if (this.get('scrollIntoView')) {
}
},
_htmlEscapeMessage : function (m) {
m = Y.clone(m);
return m;
},
_trimOldEntries : function () {
if (this._console) {
if (i > 0) {
if (this.get('newestOnTop')) {
}
} else {
for (;i>=0;--i) {
}
}
}
}
},
_encodeHTML : function (s) {
return isString(s) ?
s;
},
_clearTimeout : function () {
if (this._timeout) {
this._timeout = null;
}
},
// DOM event handlers
_onPauseClick : function (e) {
},
_onClearClick : function (e) {
this.clearConsole();
},
// Attribute setters and validators
_setLogLevel : function (v) {
if (isString(v)) {
v = v.toLowerCase();
v = v === ERROR ?
v === WARN ?
} else if (!isNumber(v)) {
v = Console.LOG_LEVEL_INFO;
}
return v;
},
_validateLogLevel : function (v) {
return v === Console.LOG_LEVEL_INFO ||
v === Console.LOG_LEVEL_WARN ||
v === Console.LOG_LEVEL_ERROR;
},
// Attribute event handlers
_afterStringsChange : function (e) {
el;
if (el) {
}
}
if (el) {
}
}
if (el) {
}
}
},
_afterPausedChange : function (e) {
if (node) {
}
}
if (!paused) {
this._schedulePrint();
} else if (this._timeout) {
clearTimeout(this._timeout);
this._timeout = null;
}
},
_afterConsoleLimitChange : function () {
this._trimOldEntries();
},
// Custom event listeners and default functions
// TODO: needed?
});
}
},
_defResetFn : function () {
this.clearConsole();
this.set(START_TIME,new Date());
},
_defEntryFn : function (e) {
if (e.message) {
this._schedulePrint();
}
}
});