2 Copyright (c) 2009, Yahoo! Inc. All rights reserved.
3 Code licensed under the BSD License:
4 http://developer.yahoo.net/yui/license.txt
8 YUI.add('console', function(Y) {
11 * Console creates a visualization for messages logged through calls to a YUI
12 * instance's <code>Y.log( message, category, source )</code> method. The
13 * debug versions of YUI modules will include logging statements to offer some
14 * insight into the steps executed during that module's operation. Including
15 * log statements in your code will cause those messages to also appear in the
16 * Console. Use Console to aid in developing your page or application.
18 * Entry categories "info", "warn", and "error"
19 * are also referred to as the log level, and entries are filtered against the
20 * configured logLevel.
25 * @param conf {Object} Configuration object (see Configuration attributes)
29 Console.superclass.constructor.apply(this,arguments);
32 var getCN = Y.ClassNameManager.getClassName,
36 COLLAPSED = 'collapsed',
38 CONTENT_BOX = 'contentBox',
39 DISABLED = 'disabled',
44 INNER_HTML = 'innerHTML',
45 LAST_TIME = 'lastTime',
49 START_TIME = 'startTime',
55 C_BUTTON = getCN(CONSOLE,'button'),
56 C_CHECKBOX = getCN(CONSOLE,'checkbox'),
57 C_CLEAR = getCN(CONSOLE,CLEAR),
58 C_COLLAPSE = getCN(CONSOLE,'collapse'),
59 C_COLLAPSED = getCN(CONSOLE,COLLAPSED),
60 C_CONSOLE_CONTROLS = getCN(CONSOLE,'controls'),
61 C_CONSOLE_HD = getCN(CONSOLE,'hd'),
62 C_CONSOLE_BD = getCN(CONSOLE,'bd'),
63 C_CONSOLE_FT = getCN(CONSOLE,'ft'),
64 C_CONSOLE_TITLE = getCN(CONSOLE,TITLE),
65 C_ENTRY = getCN(CONSOLE,ENTRY),
66 C_ENTRY_CAT = getCN(CONSOLE,ENTRY,'cat'),
67 C_ENTRY_CONTENT = getCN(CONSOLE,ENTRY,'content'),
68 C_ENTRY_META = getCN(CONSOLE,ENTRY,'meta'),
69 C_ENTRY_SRC = getCN(CONSOLE,ENTRY,'src'),
70 C_ENTRY_TIME = getCN(CONSOLE,ENTRY,'time'),
71 C_PAUSE = getCN(CONSOLE,PAUSE),
72 C_PAUSE_LABEL = getCN(CONSOLE,PAUSE,'label'),
74 RE_INLINE_SOURCE = /^(\S+)\s/,
84 '<div class="{entry_class} {cat_class} {src_class}">'+
85 '<p class="{entry_meta_class}">'+
86 '<span class="{entry_src_class}">'+
89 '<span class="{entry_cat_class}">'+
91 '<span class="{entry_time_class}">'+
92 ' {totalTime}ms (+{elapsedTime}) {localTime}'+
95 '<pre class="{entry_content_class}">{message}</pre>'+
99 create = Y.Node.create,
100 isNumber = L.isNumber,
101 isString = L.isString,
103 substitute = Y.substitute;
109 * The identity of the widget.
111 * @property Console.NAME
118 * Static identifier for logLevel configuration setting to allow all
119 * incoming messages to generate Console entries.
121 * @property Console.LOG_LEVEL_INFO
125 LOG_LEVEL_INFO : INFO,
128 * Static identifier for logLevel configuration setting to allow only
129 * incoming messages of logLevel "warn" or "error"
130 * to generate Console entries.
132 * @property Console.LOG_LEVEL_WARN
136 LOG_LEVEL_WARN : WARN,
139 * Static identifier for logLevel configuration setting to allow only
140 * incoming messages of logLevel "error" to generate
143 * @property Console.LOG_LEVEL_ERROR
147 LOG_LEVEL_ERROR : ERROR,
150 * Map (object) of classNames used to populate the placeholders in the
151 * Console.ENTRY_TEMPLATE markup when rendering a new Console entry.
153 * <p>By default, the keys contained in the object are:</p>
155 * <li>entry_class</li>
156 * <li>entry_meta_class</li>
157 * <li>entry_cat_class</li>
158 * <li>entry_src_class</li>
159 * <li>entry_time_class</li>
160 * <li>entry_content_class</li>
163 * @property Console.ENTRY_CLASSES
168 entry_class : C_ENTRY,
169 entry_meta_class : C_ENTRY_META,
170 entry_cat_class : C_ENTRY_CAT,
171 entry_src_class : C_ENTRY_SRC,
172 entry_time_class : C_ENTRY_TIME,
173 entry_content_class : C_ENTRY_CONTENT
177 * Map (object) of classNames used to populate the placeholders in the
178 * Console.HEADER_TEMPLATE, Console.BODY_TEMPLATE, and
179 * Console.FOOTER_TEMPLATE markup when rendering the Console UI.
181 * <p>By default, the keys contained in the object are:</p>
183 * <li>console_hd_class</li>
184 * <li>console_bd_class</li>
185 * <li>console_ft_class</li>
186 * <li>console_controls_class</li>
187 * <li>console_checkbox_class</li>
188 * <li>console_pause_class</li>
189 * <li>console_pause_label_class</li>
190 * <li>console_button_class</li>
191 * <li>console_clear_class</li>
192 * <li>console_collapse_class</li>
193 * <li>console_title_class</li>
196 * @property Console.CHROME_CLASSES
201 console_hd_class : C_CONSOLE_HD,
202 console_bd_class : C_CONSOLE_BD,
203 console_ft_class : C_CONSOLE_FT,
204 console_controls_class : C_CONSOLE_CONTROLS,
205 console_checkbox_class : C_CHECKBOX,
206 console_pause_class : C_PAUSE,
207 console_pause_label_class : C_PAUSE_LABEL,
208 console_button_class : C_BUTTON,
209 console_clear_class : C_CLEAR,
210 console_collapse_class : C_COLLAPSE,
211 console_title_class : C_CONSOLE_TITLE
215 * Markup template used to generate the DOM structure for the header
216 * section of the Console when it is rendered. The template includes
217 * these {placeholder}s:
220 * <li>console_button_class - contributed by Console.CHROME_CLASSES</li>
221 * <li>console_collapse_class - contributed by Console.CHROME_CLASSES</li>
222 * <li>console_hd_class - contributed by Console.CHROME_CLASSES</li>
223 * <li>console_title_class - contributed by Console.CHROME_CLASSES</li>
224 * <li>str_collapse - pulled from attribute strings.collapse</li>
225 * <li>str_title - pulled from attribute strings.title</li>
228 * @property Console.HEADER_TEMPLATE
233 '<div class="{console_hd_class}">'+
234 '<h4 class="{console_title_class}">{str_title}</h4>'+
235 '<button type="button" class="'+
236 '{console_button_class} {console_collapse_class}">{str_collapse}'+
241 * Markup template used to generate the DOM structure for the Console body
242 * (where the messages are inserted) when it is rendered. The template
243 * includes only the {placeholder} "console_bd_class", which is
244 * constributed by Console.CHROME_CLASSES.
246 * @property Console.BODY_TEMPLATE
250 BODY_TEMPLATE : '<div class="{console_bd_class}"></div>',
253 * Markup template used to generate the DOM structure for the footer
254 * section of the Console when it is rendered. The template includes
255 * many of the {placeholder}s from Console.CHROME_CLASSES as well as:
258 * <li>id_guid - generated unique id, relates the label and checkbox</li>
259 * <li>str_pause - pulled from attribute strings.pause</li>
260 * <li>str_clear - pulled from attribute strings.clear</li>
263 * @property Console.FOOTER_TEMPLATE
268 '<div class="{console_ft_class}">'+
269 '<div class="{console_controls_class}">'+
270 '<label for="{id_guid}" class="{console_pause_label_class}">'+
271 '<input type="checkbox" class="{console_checkbox_class} '+
272 '{console_pause_class}" value="1" id="{id_guid}"> '+
273 '{str_pause}</label>' +
274 '<button type="button" class="'+
275 '{console_button_class} {console_clear_class}">{str_clear}'+
281 * Default markup template used to create the DOM structure for Console
282 * entries. The markup contains {placeholder}s for content and classes
283 * that are replaced via Y.substitute. The default template contains
284 * the {placeholder}s identified in Console.ENTRY_CLASSES as well as the
285 * following placeholders that will be populated by the log entry data:
291 * <li>elapsedTime</li>
293 * <li>sourceAndDetail</li>
297 * @property Console.ENTRY_TEMPLATE
301 ENTRY_TEMPLATE : ENTRY_TEMPLATE_STR,
304 * Static property used to define the default attribute configuration of
307 * @property Console.ATTRS
314 * Name of the custom event that will communicate log messages.
316 * @attribute logEvent
327 * Object that will emit the log events. By default the YUI instance.
328 * To have a single Console capture events from all YUI instances, set
329 * this to the Y.Global object.
331 * @attribute logSource
338 validator : function (v) {
339 return v && Y.Lang.isFunction(v.on);
344 * Collection of strings used to label elements in the Console UI.
345 * Default collection contains the following name:value pairs:
348 * <li>title : "Log Console"</li>
349 * <li>pause : "Pause"</li>
350 * <li>clear : "Clear"</li>
351 * <li>collapse : "Collapse"</li>
352 * <li>expand : "Expand"</li>
360 title : "Log Console",
363 collapse : "Collapse",
369 * Boolean to pause the outputting of new messages to the console.
370 * When paused, messages will accumulate in the buffer.
378 validator : L.isBoolean
382 * If a category is not specified in the Y.log(..) statement, this
383 * category will be used. Categories "info",
384 * "warn", and "error" are also called log level.
386 * @attribute defaultCategory
396 * If a source is not specified in the Y.log(..) statement, this
397 * source will be used.
399 * @attribute defaultSource
409 * Markup template used to create the DOM structure for Console entries.
411 * @attribute entryTemplate
413 * @default Console.ENTRY_TEMPLATE
416 value : ENTRY_TEMPLATE_STR,
421 * Minimum entry log level to render into the Console. The initial
422 * logLevel value for all Console instances defaults from the
423 * Y.config.logLevel YUI configuration, or Console.LOG_LEVEL_INFO if
424 * that configuration is not set.
426 * Possible values are "info", "warn",
427 * "error" (case insensitive), or their corresponding statics
428 * Console.LOG_LEVEL_INFO and so on.
430 * @attribute logLevel
432 * @default Y.config.logLevel or Console.LOG_LEVEL_INFO
435 value : Y.config.logLevel || INFO,
436 setter : function (v) {
437 return this._setLogLevel(v);
442 * Millisecond timeout between iterations of the print loop, moving
443 * entries from the buffer to the UI.
445 * @attribute printTimeout
455 * Maximum number of entries printed in each iteration of the print
456 * loop. This is used to prevent excessive logging locking the page UI.
458 * @attribute printLimit
468 * Maximum number of Console entries allowed in the Console body at one
469 * time. This is used to keep acquired messages from exploding the
470 * DOM tree and impacting page performance.
472 * @attribute consoleLimit
482 * New entries should display at the top of the Console or the bottom?
484 * @attribute newestOnTop
493 * When new entries are added to the Console UI, should they be
494 * scrolled into view?
496 * @attribute scrollIntoView
505 * The baseline time for this Console instance, used to measure elapsed
506 * time from the moment the console module is <code>use</code>d to the
507 * moment each new entry is logged (not rendered).
509 * This value is reset by the instance method myConsole.reset().
511 * @attribute startTime
513 * @default The moment the console module is <code>use</code>d
520 * The precise time the last entry was logged. Used to measure elapsed
521 * time between log messages.
523 * @attribute lastTime
525 * @default The moment the console module is <code>use</code>d
533 * Controls the collapsed state of the Console
535 * @attribute collapsed
544 * String with units, or number, representing the height of the Console,
545 * inclusive of header and footer. If a number is provided, the default
546 * unit, defined by Widget's DEF_UNIT, property is used.
550 * @type {String | Number}
557 * String with units, or number, representing the width of the Console.
558 * If a number is provided, the default unit, defined by Widget's
559 * DEF_UNIT, property is used.
563 * @type {String | Number}
570 * Pass through to the YUI instance useBrowserConsole configuration.
571 * By default this is set to false, which will disable logging to the
572 * browser console when a Console instance is created. If the
573 * logSource is not a YUI instance, this has no effect.
575 * @attribute useBrowserConsole
579 useBrowserConsole : {
582 getter : function () {
583 var logSource = this.get('logSource');
584 return logSource instanceof YUI ?
585 logSource.config.useBrowserConsole : null;
587 setter : function (v) {
588 var logSource = this.get('logSource');
589 if (logSource instanceof YUI) {
591 logSource.config.useBrowserConsole = !!v;
594 return Y.Attribute.INVALID_VALUE;
600 * Allows the Console to flow in the document. Available values are
601 * 'inline', 'block', and 'separate' (the default).
605 * @default 'separate'
610 validator : function (v) {
611 return this._validateStyle(v);
618 Y.extend(Console,Y.Widget,{
621 * Category to prefix all event subscriptions to allow for ease of detach
631 * Reference to the Node instance containing the header contents.
641 * Reference to the Node instance that will house the console messages.
651 * Reference to the Node instance containing the footer contents.
661 * Holds the object API returned from <code>Y.later</code> for the print
664 * @property _printLoop
672 * Array of normalized message objects awaiting printing.
682 * Wrapper for <code>Y.log</code>.
685 * @param arg* {MIXED} (all arguments passed through to <code>Y.log</code>)
689 Y.log.apply(Y,arguments);
695 * Clear the console of messages and flush the buffer of pending messages.
697 * @method clearConsole
700 clearConsole : function () {
701 // TODO: clear event listeners from console contents
702 this._body.set(INNER_HTML,'');
704 this._cancelPrintLoop();
712 * Clears the console and resets internal timers.
717 reset : function () {
724 * Collapses the body and footer.
729 collapse : function () {
730 this.set(COLLAPSED, true);
736 * Expands the body and footer if collapsed.
741 expand : function () {
742 this.set(COLLAPSED, false);
748 * Outputs buffered messages to the console UI. This is typically called
749 * from a scheduled interval until the buffer is empty (referred to as the
750 * print loop). The number of buffered messages output to the Console is
751 * limited to the number provided as an argument. If no limit is passed,
752 * all buffered messages are rendered.
754 * @method printBuffer
755 * @param limit {Number} (optional) max number of buffered entries to write
758 printBuffer: function (limit) {
759 var messages = this.buffer,
760 debug = Y.config.debug,
762 consoleLimit= this.get('consoleLimit'),
763 newestOnTop = this.get('newestOnTop'),
764 anchor = newestOnTop ? this._body.get('firstChild') : null,
767 if (messages.length > consoleLimit) {
768 messages.splice(0, messages.length - consoleLimit);
771 limit = Math.min(messages.length, (limit || messages.length));
773 // turn off logging system
774 Y.config.debug = false;
776 if (!this.get(PAUSED) && this.get('rendered')) {
778 for (i = 0; i < limit && messages.length; ++i) {
779 entries[i] = this._createEntryHTML(messages.shift());
782 if (!messages.length) {
783 this._cancelPrintLoop();
786 if (entries.length) {
791 this._body.insertBefore(create(entries.join('')), anchor);
793 if (this.get('scrollIntoView')) {
794 this.scrollToLatest();
797 this._trimOldEntries();
801 // restore logging system
802 Y.config.debug = debug;
809 * Constructor code. Set up the buffer and entry template, publish
810 * internal events, and subscribe to the configured logEvent.
812 * @method initializer
815 initializer : function () {
816 this._evtCat = Y.stamp(this) + '|';
820 this.get('logSource').on(this._evtCat +
821 this.get('logEvent'),Y.bind("_onLogEvent",this));
824 * Transfers a received message to the print loop buffer. Default
825 * behavior defined in _defEntryFn.
828 * @param event {Event.Facade} An Event Facade object with the following attribute specific properties added:
831 * <dd>The message data normalized into an object literal (see _normalizeMessage)</dd>
833 * @preventable _defEntryFn
835 this.publish(ENTRY, { defaultFn: this._defEntryFn });
838 * Triggers the reset behavior via the default logic in _defResetFn.
841 * @param event {Event.Facade} Event Facade object
842 * @preventable _defResetFn
844 this.publish(RESET, { defaultFn: this._defResetFn });
846 this.after('rendered', this._schedulePrint);
850 * Tears down the instance, flushing event subscriptions and purging the UI.
855 destructor : function () {
856 var bb = this.get('boundingBox');
858 this._cancelPrintLoop();
860 this.get('logSource').detach(this._evtCat + '*');
862 Y.Event.purgeElement(bb, true);
864 bb.set('innerHTML','');
868 * Generate the Console UI.
873 renderUI : function () {
878 // Apply positioning to the bounding box if appropriate
879 var style = this.get('style');
880 if (style !== 'block') {
881 this.get('boundingBox').addClass('yui-'+style+'-console');
886 * Sync the UI state to the current attribute state.
890 syncUI : function () {
891 this._uiUpdatePaused(this.get(PAUSED));
892 this._uiUpdateCollapsed(this.get(COLLAPSED));
893 this._uiSetHeight(this.get(HEIGHT));
897 * Set up event listeners to wire up the UI to the internal state.
902 bindUI : function () {
903 this.get(CONTENT_BOX).query('button.'+C_COLLAPSE).
904 on(CLICK,this._onCollapseClick,this);
906 this.get(CONTENT_BOX).query('input[type=checkbox].'+C_PAUSE).
907 on(CLICK,this._onPauseClick,this);
909 this.get(CONTENT_BOX).query('button.'+C_CLEAR).
910 on(CLICK,this._onClearClick,this);
913 this.after(this._evtCat + 'stringsChange',
914 this._afterStringsChange);
915 this.after(this._evtCat + 'pausedChange',
916 this._afterPausedChange);
917 this.after(this._evtCat + 'consoleLimitChange',
918 this._afterConsoleLimitChange);
919 this.after(this._evtCat + 'collapsedChange',
920 this._afterCollapsedChange);
925 * Create the DOM structure for the header elements.
930 _initHead : function () {
931 var cb = this.get(CONTENT_BOX),
932 info = merge(Console.CHROME_CLASSES, {
933 str_collapse : this.get('strings.collapse'),
934 str_title : this.get('strings.title')
937 this._head = create(substitute(Console.HEADER_TEMPLATE,info));
939 cb.insertBefore(this._head,cb.get('firstChild'));
943 * Create the DOM structure for the console body—where messages are
949 _initBody : function () {
950 this._body = create(substitute(
951 Console.BODY_TEMPLATE,
952 Console.CHROME_CLASSES));
954 this.get(CONTENT_BOX).appendChild(this._body);
958 * Create the DOM structure for the footer elements.
963 _initFoot : function () {
964 var info = merge(Console.CHROME_CLASSES, {
966 str_pause : this.get('strings.pause'),
967 str_clear : this.get('strings.clear')
970 this._foot = create(substitute(Console.FOOTER_TEMPLATE,info));
972 this.get(CONTENT_BOX).appendChild(this._foot);
976 * Determine if incoming log messages are within the configured logLevel
977 * to be buffered for printing.
979 * @method _isInLogLevel
982 _isInLogLevel : function (e) {
983 var cat = e.cat, lvl = this.get('logLevel');
989 cat = cat.toLowerCase();
992 if ((cat === WARN && lvl === ERROR) ||
993 (cat === INFO && lvl !== INFO)) {
1002 * Create a log entry message from the inputs including the following keys:
1004 * <li>time - this moment</li>
1005 * <li>message - leg message</li>
1006 * <li>category - logLevel or custom category for the message</li>
1007 * <li>source - when provided, the widget or util calling Y.log</li>
1008 * <li>sourceAndDetail - same as source but can include instance info</li>
1009 * <li>localTime - readable version of time</li>
1010 * <li>elapsedTime - ms since last entry</li>
1011 * <li>totalTime - ms since Console was instantiated or reset</li>
1014 * @method _normalizeMessage
1015 * @param e {Event} custom event containing the log message
1016 * @return Object the message object
1019 _normalizeMessage : function (e) {
1028 category : cat || this.get('defaultCategory'),
1029 sourceAndDetail : src || this.get('defaultSource'),
1036 // Extract m.source "Foo" from m.sourceAndDetail "Foo bar baz"
1037 m.source = RE_INLINE_SOURCE.test(m.sourceAndDetail) ?
1038 RegExp.$1 : m.sourceAndDetail;
1039 m.localTime = m.time.toLocaleTimeString ?
1040 m.time.toLocaleTimeString() : (m.time + '');
1041 m.elapsedTime = m.time - this.get(LAST_TIME);
1042 m.totalTime = m.time - this.get(START_TIME);
1044 this._set(LAST_TIME,m.time);
1050 * Sets an interval for buffered messages to be output to the console.
1052 * @method _schedulePrint
1055 _schedulePrint : function () {
1056 if (!this._printLoop && !this.get(PAUSED) && this.get('rendered')) {
1057 this._printLoop = Y.later(
1058 this.get('printTimeout'),
1059 this, this.printBuffer,
1060 this.get('printLimit'), true);
1065 * Translates message meta into the markup for a console entry.
1067 * @method _createEntryHTML
1068 * @param m {Object} object literal containing normalized message metadata
1072 _createEntryHTML : function (m) {
1074 this._htmlEscapeMessage(m),
1075 Console.ENTRY_CLASSES,
1077 cat_class : this.getClassName(ENTRY,m.category),
1078 src_class : this.getClassName(ENTRY,m.source)
1081 return this.get('entryTemplate').replace(/\{(\w+)\}/g,
1082 function (_,token) {
1083 return token in m ? m[token] : '';
1088 * Scrolls to the most recent entry
1090 * @method scrollToLatest
1093 scrollToLatest : function () {
1094 var scrollTop = this.get('newestOnTop') ?
1096 this._body.get('scrollHeight');
1098 this._body.set('scrollTop', scrollTop);
1102 * Performs HTML escaping on strings in the message object.
1104 * @method _htmlEscapeMessage
1105 * @param m {Object} the normalized message object
1106 * @return Object the message object with proper escapement
1109 _htmlEscapeMessage : function (m) {
1110 m.message = this._encodeHTML(m.message);
1111 m.source = this._encodeHTML(m.source);
1112 m.sourceAndDetail = this._encodeHTML(m.sourceAndDetail);
1113 m.category = this._encodeHTML(m.category);
1119 * Removes the oldest message entries from the UI to maintain the limit
1120 * specified in the consoleLimit configuration.
1122 * @method _trimOldEntries
1125 _trimOldEntries : function () {
1126 // Turn off the logging system for the duration of this operation
1127 // to prevent an infinite loop
1128 Y.config.debug = false;
1130 var bd = this._body,
1131 limit = this.get('consoleLimit'),
1132 debug = Y.config.debug,
1136 entries = bd.queryAll(DOT+C_ENTRY);
1137 l = entries.size() - limit;
1140 if (this.get('newestOnTop')) {
1147 this._body.setStyle('display','none');
1150 e = entries.item(i);
1156 this._body.setStyle('display','');
1161 Y.config.debug = debug;
1165 * Returns the input string with ampersands (&), <, and > encoded
1168 * @method _encodeHTML
1169 * @param s {String} the raw string
1170 * @return String the encoded string
1173 _encodeHTML : function (s) {
1174 return isString(s) ?
1175 s.replace(RE_AMP,ESC_AMP).
1176 replace(RE_LT, ESC_LT).
1177 replace(RE_GT, ESC_GT) :
1182 * Clears the timeout for printing buffered messages.
1184 * @method _cancelPrintLoop
1187 _cancelPrintLoop : function () {
1188 if (this._printLoop) {
1189 this._printLoop.cancel();
1190 this._printLoop = null;
1195 * Validates input value for style attribute. Accepts only values 'inline',
1196 * 'block', and 'separate'.
1198 * @method _validateStyle
1199 * @param style {String} the proposed value
1200 * @return {Boolean} pass/fail
1203 _validateStyle : function (style) {
1204 return style === 'inline' || style === 'block' || style === 'separate';
1208 * Event handler for clicking on the Pause checkbox to update the paused
1211 * @method _onPauseClick
1212 * @param e {Event} DOM event facade for the click event
1215 _onPauseClick : function (e) {
1216 this.set(PAUSED,e.target.get(CHECKED));
1220 * Event handler for clicking on the Clear button. Pass-through to
1221 * <code>this.clearConsole()</code>.
1223 * @method _onClearClick
1224 * @param e {Event} DOM event facade for the click event
1227 _onClearClick : function (e) {
1228 this.clearConsole();
1232 * Event handler for clicking on the Collapse/Expand button. Sets the
1233 * "collapsed" attribute accordingly.
1235 * @method _onCollapseClick
1236 * @param e {Event} DOM event facade for the click event
1239 _onCollapseClick : function (e) {
1240 this.set(COLLAPSED, !this.get(COLLAPSED));
1245 * Setter method for logLevel attribute. Acceptable values are
1246 * "error", "warn", and "info" (case
1247 * insensitive). Other values are treated as "info".
1249 * @method _setLogLevel
1250 * @param v {String} the desired log level
1251 * @return String One of Console.LOG_LEVEL_INFO, _WARN, or _ERROR
1254 _setLogLevel : function (v) {
1256 v = v.toLowerCase();
1259 return (v === WARN || v === ERROR) ? v : INFO;
1263 * Set the height of the Console container. Set the body height to the difference between the configured height and the calculated heights of the header and footer.
1264 * Overrides Widget.prototype._uiSetHeight.
1266 * @method _uiSetHeight
1267 * @param v {String|Number} the new height
1270 _uiSetHeight : function (v) {
1271 Console.superclass._uiSetHeight.apply(this,arguments);
1273 if (this._head && this._foot) {
1274 var h = this.get('boundingBox').get('offsetHeight') -
1275 this._head.get('offsetHeight') -
1276 this._foot.get('offsetHeight');
1278 this._body.setStyle(HEIGHT,h+'px');
1283 * Updates the UI if changes are made to any of the strings in the strings
1286 * @method _afterStringsChange
1287 * @param e {Event} Custom event for the attribute change
1290 _afterStringsChange : function (e) {
1291 var prop = e.subAttrName ? e.subAttrName.split(DOT)[1] : null,
1292 cb = this.get(CONTENT_BOX),
1296 if ((!prop || prop === TITLE) && before.title !== after.title) {
1297 cb.queryAll(DOT+C_CONSOLE_TITLE).set(INNER_HTML, after.title);
1300 if ((!prop || prop === PAUSE) && before.pause !== after.pause) {
1301 cb.queryAll(DOT+C_PAUSE_LABEL).set(INNER_HTML, after.pause);
1304 if ((!prop || prop === CLEAR) && before.clear !== after.clear) {
1305 cb.queryAll(DOT+C_CLEAR).set('value',after.clear);
1310 * Updates the UI and schedules or cancels the print loop.
1312 * @method _afterPausedChange
1313 * @param e {Event} Custom event for the attribute change
1316 _afterPausedChange : function (e) {
1317 var paused = e.newVal;
1319 if (e.src !== Y.Widget.SRC_UI) {
1320 this._uiUpdatePaused(paused);
1324 this._schedulePrint();
1325 } else if (this._printLoop) {
1326 this._cancelPrintLoop();
1331 * Checks or unchecks the paused checkbox
1333 * @method _uiUpdatePaused
1334 * @param on {Boolean} the new checked state
1337 _uiUpdatePaused : function (on) {
1338 var node = this._foot.queryAll('input[type=checkbox].'+C_PAUSE);
1341 node.set(CHECKED,on);
1346 * Calls this._trimOldEntries() in response to changes in the configured
1347 * consoleLimit attribute.
1349 * @method _afterConsoleLimitChange
1350 * @param e {Event} Custom event for the attribute change
1353 _afterConsoleLimitChange : function () {
1354 this._trimOldEntries();
1359 * Updates the className of the contentBox, which should trigger CSS to
1360 * hide or show the body and footer sections depending on the new value.
1362 * @method _afterCollapsedChange
1363 * @param e {Event} Custom event for the attribute change
1366 _afterCollapsedChange : function (e) {
1367 this._uiUpdateCollapsed(e.newVal);
1371 * Updates the UI to reflect the new Collapsed state
1373 * @method _uiUpdateCollapsed
1374 * @param v {Boolean} true for collapsed, false for expanded
1377 _uiUpdateCollapsed : function (v) {
1378 var bb = this.get('boundingBox'),
1379 button = bb.queryAll('button.'+C_COLLAPSE),
1380 method = v ? 'addClass' : 'removeClass',
1381 str = this.get('strings.'+(v ? 'expand' : 'collapse'));
1383 bb[method](C_COLLAPSED);
1386 button.set('innerHTML',str);
1389 this._uiSetHeight(v ? this._head.get('offsetHeight'): this.get(HEIGHT));
1393 * Makes adjustments to the UI if needed when the Console is hidden or shown
1395 * @method _afterVisibleChange
1396 * @param e {Event} the visibleChange event
1399 _afterVisibleChange : function (e) {
1400 Console.superclass._afterVisibleChange.apply(this,arguments);
1402 this._uiUpdateFromHideShow(e.newVal);
1406 * Recalculates dimensions and updates appropriately when shown
1408 * @method _uiUpdateFromHideShow
1409 * @param v {Boolean} true for visible, false for hidden
1412 _uiUpdateFromHideShow : function (v) {
1414 this._uiSetHeight(this.get(HEIGHT));
1419 * Responds to log events by normalizing qualifying messages and passing
1420 * them along through the entry event for buffering etc.
1422 * @method _onLogEvent
1423 * @param msg {String} the log message
1424 * @param cat {String} OPTIONAL the category or logLevel of the message
1425 * @param src {String} OPTIONAL the source of the message (e.g. widget name)
1428 _onLogEvent : function (e) {
1430 if (!this.get(DISABLED) && this._isInLogLevel(e)) {
1432 var debug = Y.config.debug;
1435 Y.config.debug = false;
1438 message : this._normalizeMessage(e)
1441 Y.config.debug = debug;
1446 * Clears the console, resets the startTime attribute, enables and
1447 * unpauses the widget.
1449 * @method _defResetFn
1452 _defResetFn : function () {
1453 this.clearConsole();
1454 this.set(START_TIME,new Date());
1455 this.set(DISABLED,false);
1456 this.set(PAUSED,false);
1460 * Buffers incoming message objects and schedules the printing.
1462 * @method _defEntryFn
1463 * @param e {Event} The Custom event carrying the message in its payload
1466 _defEntryFn : function (e) {
1468 this.buffer.push(e.message);
1469 this._schedulePrint();
1475 Y.Console = Console;
1478 }, '3.0.0' ,{requires:['substitute','widget']});