2 Copyright (c) 2010, Yahoo! Inc. All rights reserved.
3 Code licensed under the BSD License:
4 http://developer.yahoo.com/yui/license.html
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)
28 var getCN = Y.ClassNameManager.getClassName,
32 COLLAPSED = 'collapsed',
34 CONTENT_BOX = 'contentBox',
35 DISABLED = 'disabled',
40 INNER_HTML = 'innerHTML',
41 LAST_TIME = 'lastTime',
45 START_TIME = 'startTime',
51 C_BUTTON = getCN(CONSOLE,'button'),
52 C_CHECKBOX = getCN(CONSOLE,'checkbox'),
53 C_CLEAR = getCN(CONSOLE,CLEAR),
54 C_COLLAPSE = getCN(CONSOLE,'collapse'),
55 C_COLLAPSED = getCN(CONSOLE,COLLAPSED),
56 C_CONSOLE_CONTROLS = getCN(CONSOLE,'controls'),
57 C_CONSOLE_HD = getCN(CONSOLE,'hd'),
58 C_CONSOLE_BD = getCN(CONSOLE,'bd'),
59 C_CONSOLE_FT = getCN(CONSOLE,'ft'),
60 C_CONSOLE_TITLE = getCN(CONSOLE,TITLE),
61 C_ENTRY = getCN(CONSOLE,ENTRY),
62 C_ENTRY_CAT = getCN(CONSOLE,ENTRY,'cat'),
63 C_ENTRY_CONTENT = getCN(CONSOLE,ENTRY,'content'),
64 C_ENTRY_META = getCN(CONSOLE,ENTRY,'meta'),
65 C_ENTRY_SRC = getCN(CONSOLE,ENTRY,'src'),
66 C_ENTRY_TIME = getCN(CONSOLE,ENTRY,'time'),
67 C_PAUSE = getCN(CONSOLE,PAUSE),
68 C_PAUSE_LABEL = getCN(CONSOLE,PAUSE,'label'),
70 RE_INLINE_SOURCE = /^(\S+)\s/,
71 RE_AMP = /&(?!#?[a-z0-9]+;)/g,
80 '<div class="{entry_class} {cat_class} {src_class}">'+
81 '<p class="{entry_meta_class}">'+
82 '<span class="{entry_src_class}">'+
85 '<span class="{entry_cat_class}">'+
87 '<span class="{entry_time_class}">'+
88 ' {totalTime}ms (+{elapsedTime}) {localTime}'+
91 '<pre class="{entry_content_class}">{message}</pre>'+
95 create = Y.Node.create,
96 isNumber = L.isNumber,
97 isString = L.isString,
99 substitute = Y.substitute;
103 Console.superclass.constructor.apply(this,arguments);
106 Y.Console = Y.extend(Console, Y.Widget,
108 // Y.Console prototype
111 * Category to prefix all event subscriptions to allow for ease of detach
121 * Reference to the Node instance containing the header contents.
131 * Reference to the Node instance that will house the console messages.
141 * Reference to the Node instance containing the footer contents.
151 * Holds the object API returned from <code>Y.later</code> for the print
154 * @property _printLoop
162 * Array of normalized message objects awaiting printing.
172 * Wrapper for <code>Y.log</code>.
175 * @param arg* {MIXED} (all arguments passed through to <code>Y.log</code>)
179 Y.log.apply(Y,arguments);
185 * Clear the console of messages and flush the buffer of pending messages.
187 * @method clearConsole
190 clearConsole : function () {
191 // TODO: clear event listeners from console contents
192 this._body.set(INNER_HTML,'');
194 this._cancelPrintLoop();
202 * Clears the console and resets internal timers.
207 reset : function () {
214 * Collapses the body and footer.
219 collapse : function () {
220 this.set(COLLAPSED, true);
226 * Expands the body and footer if collapsed.
231 expand : function () {
232 this.set(COLLAPSED, false);
238 * Outputs buffered messages to the console UI. This is typically called
239 * from a scheduled interval until the buffer is empty (referred to as the
240 * print loop). The number of buffered messages output to the Console is
241 * limited to the number provided as an argument. If no limit is passed,
242 * all buffered messages are rendered.
244 * @method printBuffer
245 * @param limit {Number} (optional) max number of buffered entries to write
248 printBuffer: function (limit) {
249 var messages = this.buffer,
250 debug = Y.config.debug,
252 consoleLimit= this.get('consoleLimit'),
253 newestOnTop = this.get('newestOnTop'),
254 anchor = newestOnTop ? this._body.get('firstChild') : null,
257 if (messages.length > consoleLimit) {
258 messages.splice(0, messages.length - consoleLimit);
261 limit = Math.min(messages.length, (limit || messages.length));
263 // turn off logging system
264 Y.config.debug = false;
266 if (!this.get(PAUSED) && this.get('rendered')) {
268 for (i = 0; i < limit && messages.length; ++i) {
269 entries[i] = this._createEntryHTML(messages.shift());
272 if (!messages.length) {
273 this._cancelPrintLoop();
276 if (entries.length) {
281 this._body.insertBefore(create(entries.join('')), anchor);
283 if (this.get('scrollIntoView')) {
284 this.scrollToLatest();
287 this._trimOldEntries();
291 // restore logging system
292 Y.config.debug = debug;
299 * Constructor code. Set up the buffer and entry template, publish
300 * internal events, and subscribe to the configured logEvent.
302 * @method initializer
305 initializer : function () {
306 this._evtCat = Y.stamp(this) + '|';
310 this.get('logSource').on(this._evtCat +
311 this.get('logEvent'),Y.bind("_onLogEvent",this));
314 * Transfers a received message to the print loop buffer. Default
315 * behavior defined in _defEntryFn.
318 * @param event {Event.Facade} An Event Facade object with the following attribute specific properties added:
321 * <dd>The message data normalized into an object literal (see _normalizeMessage)</dd>
323 * @preventable _defEntryFn
325 this.publish(ENTRY, { defaultFn: this._defEntryFn });
328 * Triggers the reset behavior via the default logic in _defResetFn.
331 * @param event {Event.Facade} Event Facade object
332 * @preventable _defResetFn
334 this.publish(RESET, { defaultFn: this._defResetFn });
336 this.after('rendered', this._schedulePrint);
340 * Tears down the instance, flushing event subscriptions and purging the UI.
345 destructor : function () {
346 var bb = this.get('boundingBox');
348 this._cancelPrintLoop();
350 this.get('logSource').detach(this._evtCat + '*');
352 Y.Event.purgeElement(bb, true);
354 bb.set('innerHTML','');
358 * Generate the Console UI.
363 renderUI : function () {
368 // Apply positioning to the bounding box if appropriate
369 var style = this.get('style');
370 if (style !== 'block') {
371 this.get('boundingBox').addClass('yui3-'+style+'-console');
376 * Sync the UI state to the current attribute state.
380 syncUI : function () {
381 this._uiUpdatePaused(this.get(PAUSED));
382 this._uiUpdateCollapsed(this.get(COLLAPSED));
383 this._uiSetHeight(this.get(HEIGHT));
387 * Set up event listeners to wire up the UI to the internal state.
392 bindUI : function () {
393 this.get(CONTENT_BOX).one('button.'+C_COLLAPSE).
394 on(CLICK,this._onCollapseClick,this);
396 this.get(CONTENT_BOX).one('input[type=checkbox].'+C_PAUSE).
397 on(CLICK,this._onPauseClick,this);
399 this.get(CONTENT_BOX).one('button.'+C_CLEAR).
400 on(CLICK,this._onClearClick,this);
403 this.after(this._evtCat + 'stringsChange',
404 this._afterStringsChange);
405 this.after(this._evtCat + 'pausedChange',
406 this._afterPausedChange);
407 this.after(this._evtCat + 'consoleLimitChange',
408 this._afterConsoleLimitChange);
409 this.after(this._evtCat + 'collapsedChange',
410 this._afterCollapsedChange);
415 * Create the DOM structure for the header elements.
420 _initHead : function () {
421 var cb = this.get(CONTENT_BOX),
422 info = merge(Console.CHROME_CLASSES, {
423 str_collapse : this.get('strings.collapse'),
424 str_title : this.get('strings.title')
427 this._head = create(substitute(Console.HEADER_TEMPLATE,info));
429 cb.insertBefore(this._head,cb.get('firstChild'));
433 * Create the DOM structure for the console body—where messages are
439 _initBody : function () {
440 this._body = create(substitute(
441 Console.BODY_TEMPLATE,
442 Console.CHROME_CLASSES));
444 this.get(CONTENT_BOX).appendChild(this._body);
448 * Create the DOM structure for the footer elements.
453 _initFoot : function () {
454 var info = merge(Console.CHROME_CLASSES, {
456 str_pause : this.get('strings.pause'),
457 str_clear : this.get('strings.clear')
460 this._foot = create(substitute(Console.FOOTER_TEMPLATE,info));
462 this.get(CONTENT_BOX).appendChild(this._foot);
466 * Determine if incoming log messages are within the configured logLevel
467 * to be buffered for printing.
469 * @method _isInLogLevel
472 _isInLogLevel : function (e) {
473 var cat = e.cat, lvl = this.get('logLevel');
479 cat = cat.toLowerCase();
482 if ((cat === WARN && lvl === ERROR) ||
483 (cat === INFO && lvl !== INFO)) {
492 * Create a log entry message from the inputs including the following keys:
494 * <li>time - this moment</li>
495 * <li>message - leg message</li>
496 * <li>category - logLevel or custom category for the message</li>
497 * <li>source - when provided, the widget or util calling Y.log</li>
498 * <li>sourceAndDetail - same as source but can include instance info</li>
499 * <li>localTime - readable version of time</li>
500 * <li>elapsedTime - ms since last entry</li>
501 * <li>totalTime - ms since Console was instantiated or reset</li>
504 * @method _normalizeMessage
505 * @param e {Event} custom event containing the log message
506 * @return Object the message object
509 _normalizeMessage : function (e) {
518 category : cat || this.get('defaultCategory'),
519 sourceAndDetail : src || this.get('defaultSource'),
526 // Extract m.source "Foo" from m.sourceAndDetail "Foo bar baz"
527 m.source = RE_INLINE_SOURCE.test(m.sourceAndDetail) ?
528 RegExp.$1 : m.sourceAndDetail;
529 m.localTime = m.time.toLocaleTimeString ?
530 m.time.toLocaleTimeString() : (m.time + '');
531 m.elapsedTime = m.time - this.get(LAST_TIME);
532 m.totalTime = m.time - this.get(START_TIME);
534 this._set(LAST_TIME,m.time);
540 * Sets an interval for buffered messages to be output to the console.
542 * @method _schedulePrint
545 _schedulePrint : function () {
546 if (!this._printLoop && !this.get(PAUSED) && this.get('rendered')) {
547 this._printLoop = Y.later(
548 this.get('printTimeout'),
549 this, this.printBuffer,
550 this.get('printLimit'), true);
555 * Translates message meta into the markup for a console entry.
557 * @method _createEntryHTML
558 * @param m {Object} object literal containing normalized message metadata
562 _createEntryHTML : function (m) {
564 this._htmlEscapeMessage(m),
565 Console.ENTRY_CLASSES,
567 cat_class : this.getClassName(ENTRY,m.category),
568 src_class : this.getClassName(ENTRY,m.source)
571 return this.get('entryTemplate').replace(/\{(\w+)\}/g,
573 return token in m ? m[token] : '';
578 * Scrolls to the most recent entry
580 * @method scrollToLatest
583 scrollToLatest : function () {
584 var scrollTop = this.get('newestOnTop') ?
586 this._body.get('scrollHeight');
588 this._body.set('scrollTop', scrollTop);
592 * Performs HTML escaping on strings in the message object.
594 * @method _htmlEscapeMessage
595 * @param m {Object} the normalized message object
596 * @return Object the message object with proper escapement
599 _htmlEscapeMessage : function (m) {
600 m.message = this._encodeHTML(m.message);
601 m.source = this._encodeHTML(m.source);
602 m.sourceAndDetail = this._encodeHTML(m.sourceAndDetail);
603 m.category = this._encodeHTML(m.category);
609 * Removes the oldest message entries from the UI to maintain the limit
610 * specified in the consoleLimit configuration.
612 * @method _trimOldEntries
615 _trimOldEntries : function () {
616 // Turn off the logging system for the duration of this operation
617 // to prevent an infinite loop
618 Y.config.debug = false;
621 limit = this.get('consoleLimit'),
622 debug = Y.config.debug,
626 entries = bd.all(DOT+C_ENTRY);
627 l = entries.size() - limit;
630 if (this.get('newestOnTop')) {
637 this._body.setStyle('display','none');
646 this._body.setStyle('display','');
651 Y.config.debug = debug;
655 * Returns the input string with ampersands (&), <, and > encoded
658 * @method _encodeHTML
659 * @param s {String} the raw string
660 * @return String the encoded string
663 _encodeHTML : function (s) {
665 s.replace(RE_AMP,ESC_AMP).
666 replace(RE_LT, ESC_LT).
667 replace(RE_GT, ESC_GT) :
672 * Clears the timeout for printing buffered messages.
674 * @method _cancelPrintLoop
677 _cancelPrintLoop : function () {
678 if (this._printLoop) {
679 this._printLoop.cancel();
680 this._printLoop = null;
685 * Validates input value for style attribute. Accepts only values 'inline',
686 * 'block', and 'separate'.
688 * @method _validateStyle
689 * @param style {String} the proposed value
690 * @return {Boolean} pass/fail
693 _validateStyle : function (style) {
694 return style === 'inline' || style === 'block' || style === 'separate';
698 * Event handler for clicking on the Pause checkbox to update the paused
701 * @method _onPauseClick
702 * @param e {Event} DOM event facade for the click event
705 _onPauseClick : function (e) {
706 this.set(PAUSED,e.target.get(CHECKED));
710 * Event handler for clicking on the Clear button. Pass-through to
711 * <code>this.clearConsole()</code>.
713 * @method _onClearClick
714 * @param e {Event} DOM event facade for the click event
717 _onClearClick : function (e) {
722 * Event handler for clicking on the Collapse/Expand button. Sets the
723 * "collapsed" attribute accordingly.
725 * @method _onCollapseClick
726 * @param e {Event} DOM event facade for the click event
729 _onCollapseClick : function (e) {
730 this.set(COLLAPSED, !this.get(COLLAPSED));
735 * Validator for logSource attribute.
737 * @method _validateLogSource
738 * @param v {Object} the desired logSource
739 * @return {Boolean} true if the input is an object with an <code>on</code>
743 _validateLogSource: function (v) {
744 return v && Y.Lang.isFunction(v.on);
748 * Setter method for logLevel attribute. Acceptable values are
749 * "error", "warn", and "info" (case
750 * insensitive). Other values are treated as "info".
752 * @method _setLogLevel
753 * @param v {String} the desired log level
754 * @return String One of Console.LOG_LEVEL_INFO, _WARN, or _ERROR
757 _setLogLevel : function (v) {
762 return (v === WARN || v === ERROR) ? v : INFO;
766 * Getter method for useBrowserConsole attribute. Just a pass through to
767 * the YUI instance configuration setting.
769 * @method _getUseBrowserConsole
770 * @return {Boolean} or null if logSource is not a YUI instance
773 _getUseBrowserConsole: function () {
774 var logSource = this.get('logSource');
775 return logSource instanceof YUI ?
776 logSource.config.useBrowserConsole : null;
780 * Setter method for useBrowserConsole attributes. Only functional if the
781 * logSource attribute points to a YUI instance. Passes the value down to
782 * the YUI instance. NOTE: multiple Console instances cannot maintain
783 * independent useBrowserConsole values, since it is just a pass through to
784 * the YUI instance configuration.
786 * @method _setUseBrowserConsole
787 * @param v {Boolean} false to disable browser console printing (default)
788 * @return {Boolean} true|false if logSource is a YUI instance
791 _setUseBrowserConsole: function (v) {
792 var logSource = this.get('logSource');
793 if (logSource instanceof YUI) {
795 logSource.config.useBrowserConsole = v;
798 return Y.Attribute.INVALID_VALUE;
803 * 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.
804 * Overrides Widget.prototype._uiSetHeight.
806 * @method _uiSetHeight
807 * @param v {String|Number} the new height
810 _uiSetHeight : function (v) {
811 Console.superclass._uiSetHeight.apply(this,arguments);
813 if (this._head && this._foot) {
814 var h = this.get('boundingBox').get('offsetHeight') -
815 this._head.get('offsetHeight') -
816 this._foot.get('offsetHeight');
818 this._body.setStyle(HEIGHT,h+'px');
823 * Over-ride default content box sizing to do nothing, since we're sizing
824 * the body section to fill out height ourselves.
829 _uiSizeCB : function() {
830 // Do Nothing. Ideally want to move to Widget-StdMod, which accounts for
835 * Updates the UI if changes are made to any of the strings in the strings
838 * @method _afterStringsChange
839 * @param e {Event} Custom event for the attribute change
842 _afterStringsChange : function (e) {
843 var prop = e.subAttrName ? e.subAttrName.split(DOT)[1] : null,
844 cb = this.get(CONTENT_BOX),
848 if ((!prop || prop === TITLE) && before.title !== after.title) {
849 cb.all(DOT+C_CONSOLE_TITLE).set(INNER_HTML, after.title);
852 if ((!prop || prop === PAUSE) && before.pause !== after.pause) {
853 cb.all(DOT+C_PAUSE_LABEL).set(INNER_HTML, after.pause);
856 if ((!prop || prop === CLEAR) && before.clear !== after.clear) {
857 cb.all(DOT+C_CLEAR).set('value',after.clear);
862 * Updates the UI and schedules or cancels the print loop.
864 * @method _afterPausedChange
865 * @param e {Event} Custom event for the attribute change
868 _afterPausedChange : function (e) {
869 var paused = e.newVal;
871 if (e.src !== Y.Widget.SRC_UI) {
872 this._uiUpdatePaused(paused);
876 this._schedulePrint();
877 } else if (this._printLoop) {
878 this._cancelPrintLoop();
883 * Checks or unchecks the paused checkbox
885 * @method _uiUpdatePaused
886 * @param on {Boolean} the new checked state
889 _uiUpdatePaused : function (on) {
890 var node = this._foot.all('input[type=checkbox].'+C_PAUSE);
893 node.set(CHECKED,on);
898 * Calls this._trimOldEntries() in response to changes in the configured
899 * consoleLimit attribute.
901 * @method _afterConsoleLimitChange
902 * @param e {Event} Custom event for the attribute change
905 _afterConsoleLimitChange : function () {
906 this._trimOldEntries();
911 * Updates the className of the contentBox, which should trigger CSS to
912 * hide or show the body and footer sections depending on the new value.
914 * @method _afterCollapsedChange
915 * @param e {Event} Custom event for the attribute change
918 _afterCollapsedChange : function (e) {
919 this._uiUpdateCollapsed(e.newVal);
923 * Updates the UI to reflect the new Collapsed state
925 * @method _uiUpdateCollapsed
926 * @param v {Boolean} true for collapsed, false for expanded
929 _uiUpdateCollapsed : function (v) {
930 var bb = this.get('boundingBox'),
931 button = bb.all('button.'+C_COLLAPSE),
932 method = v ? 'addClass' : 'removeClass',
933 str = this.get('strings.'+(v ? 'expand' : 'collapse'));
935 bb[method](C_COLLAPSED);
938 button.set('innerHTML',str);
941 this._uiSetHeight(v ? this._head.get('offsetHeight'): this.get(HEIGHT));
945 * Makes adjustments to the UI if needed when the Console is hidden or shown
947 * @method _afterVisibleChange
948 * @param e {Event} the visibleChange event
951 _afterVisibleChange : function (e) {
952 Console.superclass._afterVisibleChange.apply(this,arguments);
954 this._uiUpdateFromHideShow(e.newVal);
958 * Recalculates dimensions and updates appropriately when shown
960 * @method _uiUpdateFromHideShow
961 * @param v {Boolean} true for visible, false for hidden
964 _uiUpdateFromHideShow : function (v) {
966 this._uiSetHeight(this.get(HEIGHT));
971 * Responds to log events by normalizing qualifying messages and passing
972 * them along through the entry event for buffering etc.
974 * @method _onLogEvent
975 * @param msg {String} the log message
976 * @param cat {String} OPTIONAL the category or logLevel of the message
977 * @param src {String} OPTIONAL the source of the message (e.g. widget name)
980 _onLogEvent : function (e) {
982 if (!this.get(DISABLED) && this._isInLogLevel(e)) {
984 var debug = Y.config.debug;
987 Y.config.debug = false;
990 message : this._normalizeMessage(e)
993 Y.config.debug = debug;
998 * Clears the console, resets the startTime attribute, enables and
999 * unpauses the widget.
1001 * @method _defResetFn
1004 _defResetFn : function () {
1005 this.clearConsole();
1006 this.set(START_TIME,new Date());
1007 this.set(DISABLED,false);
1008 this.set(PAUSED,false);
1012 * Buffers incoming message objects and schedules the printing.
1014 * @method _defEntryFn
1015 * @param e {Event} The Custom event carrying the message in its payload
1018 _defEntryFn : function (e) {
1020 this.buffer.push(e.message);
1021 this._schedulePrint();
1027 // Y.Console static properties
1030 * The identity of the widget.
1032 * @property Console.NAME
1039 * Static identifier for logLevel configuration setting to allow all
1040 * incoming messages to generate Console entries.
1042 * @property Console.LOG_LEVEL_INFO
1046 LOG_LEVEL_INFO : INFO,
1049 * Static identifier for logLevel configuration setting to allow only
1050 * incoming messages of logLevel "warn" or "error"
1051 * to generate Console entries.
1053 * @property Console.LOG_LEVEL_WARN
1057 LOG_LEVEL_WARN : WARN,
1060 * Static identifier for logLevel configuration setting to allow only
1061 * incoming messages of logLevel "error" to generate
1064 * @property Console.LOG_LEVEL_ERROR
1068 LOG_LEVEL_ERROR : ERROR,
1071 * Map (object) of classNames used to populate the placeholders in the
1072 * Console.ENTRY_TEMPLATE markup when rendering a new Console entry.
1074 * <p>By default, the keys contained in the object are:</p>
1076 * <li>entry_class</li>
1077 * <li>entry_meta_class</li>
1078 * <li>entry_cat_class</li>
1079 * <li>entry_src_class</li>
1080 * <li>entry_time_class</li>
1081 * <li>entry_content_class</li>
1084 * @property Console.ENTRY_CLASSES
1089 entry_class : C_ENTRY,
1090 entry_meta_class : C_ENTRY_META,
1091 entry_cat_class : C_ENTRY_CAT,
1092 entry_src_class : C_ENTRY_SRC,
1093 entry_time_class : C_ENTRY_TIME,
1094 entry_content_class : C_ENTRY_CONTENT
1098 * Map (object) of classNames used to populate the placeholders in the
1099 * Console.HEADER_TEMPLATE, Console.BODY_TEMPLATE, and
1100 * Console.FOOTER_TEMPLATE markup when rendering the Console UI.
1102 * <p>By default, the keys contained in the object are:</p>
1104 * <li>console_hd_class</li>
1105 * <li>console_bd_class</li>
1106 * <li>console_ft_class</li>
1107 * <li>console_controls_class</li>
1108 * <li>console_checkbox_class</li>
1109 * <li>console_pause_class</li>
1110 * <li>console_pause_label_class</li>
1111 * <li>console_button_class</li>
1112 * <li>console_clear_class</li>
1113 * <li>console_collapse_class</li>
1114 * <li>console_title_class</li>
1117 * @property Console.CHROME_CLASSES
1122 console_hd_class : C_CONSOLE_HD,
1123 console_bd_class : C_CONSOLE_BD,
1124 console_ft_class : C_CONSOLE_FT,
1125 console_controls_class : C_CONSOLE_CONTROLS,
1126 console_checkbox_class : C_CHECKBOX,
1127 console_pause_class : C_PAUSE,
1128 console_pause_label_class : C_PAUSE_LABEL,
1129 console_button_class : C_BUTTON,
1130 console_clear_class : C_CLEAR,
1131 console_collapse_class : C_COLLAPSE,
1132 console_title_class : C_CONSOLE_TITLE
1136 * Markup template used to generate the DOM structure for the header
1137 * section of the Console when it is rendered. The template includes
1138 * these {placeholder}s:
1141 * <li>console_button_class - contributed by Console.CHROME_CLASSES</li>
1142 * <li>console_collapse_class - contributed by Console.CHROME_CLASSES</li>
1143 * <li>console_hd_class - contributed by Console.CHROME_CLASSES</li>
1144 * <li>console_title_class - contributed by Console.CHROME_CLASSES</li>
1145 * <li>str_collapse - pulled from attribute strings.collapse</li>
1146 * <li>str_title - pulled from attribute strings.title</li>
1149 * @property Console.HEADER_TEMPLATE
1154 '<div class="{console_hd_class}">'+
1155 '<h4 class="{console_title_class}">{str_title}</h4>'+
1156 '<button type="button" class="'+
1157 '{console_button_class} {console_collapse_class}">{str_collapse}'+
1162 * Markup template used to generate the DOM structure for the Console body
1163 * (where the messages are inserted) when it is rendered. The template
1164 * includes only the {placeholder} "console_bd_class", which is
1165 * constributed by Console.CHROME_CLASSES.
1167 * @property Console.BODY_TEMPLATE
1171 BODY_TEMPLATE : '<div class="{console_bd_class}"></div>',
1174 * Markup template used to generate the DOM structure for the footer
1175 * section of the Console when it is rendered. The template includes
1176 * many of the {placeholder}s from Console.CHROME_CLASSES as well as:
1179 * <li>id_guid - generated unique id, relates the label and checkbox</li>
1180 * <li>str_pause - pulled from attribute strings.pause</li>
1181 * <li>str_clear - pulled from attribute strings.clear</li>
1184 * @property Console.FOOTER_TEMPLATE
1189 '<div class="{console_ft_class}">'+
1190 '<div class="{console_controls_class}">'+
1191 '<label for="{id_guid}" class="{console_pause_label_class}">'+
1192 '<input type="checkbox" class="{console_checkbox_class} '+
1193 '{console_pause_class}" value="1" id="{id_guid}"> '+
1194 '{str_pause}</label>' +
1195 '<button type="button" class="'+
1196 '{console_button_class} {console_clear_class}">{str_clear}'+
1202 * Default markup template used to create the DOM structure for Console
1203 * entries. The markup contains {placeholder}s for content and classes
1204 * that are replaced via Y.substitute. The default template contains
1205 * the {placeholder}s identified in Console.ENTRY_CLASSES as well as the
1206 * following placeholders that will be populated by the log entry data:
1209 * <li>cat_class</li>
1210 * <li>src_class</li>
1211 * <li>totalTime</li>
1212 * <li>elapsedTime</li>
1213 * <li>localTime</li>
1214 * <li>sourceAndDetail</li>
1218 * @property Console.ENTRY_TEMPLATE
1222 ENTRY_TEMPLATE : ENTRY_TEMPLATE_STR,
1225 * Static property used to define the default attribute configuration of
1228 * @property Console.ATTRS
1235 * Name of the custom event that will communicate log messages.
1237 * @attribute logEvent
1239 * @default "yui:log"
1244 validator : isString
1248 * Object that will emit the log events. By default the YUI instance.
1249 * To have a single Console capture events from all YUI instances, set
1250 * this to the Y.Global object.
1252 * @attribute logSource
1259 validator : function (v) {
1260 return this._validateLogSource(v);
1265 * Collection of strings used to label elements in the Console UI.
1266 * Default collection contains the following name:value pairs:
1269 * <li>title : "Log Console"</li>
1270 * <li>pause : "Pause"</li>
1271 * <li>clear : "Clear"</li>
1272 * <li>collapse : "Collapse"</li>
1273 * <li>expand : "Expand"</li>
1276 * @attribute strings
1280 valueFn: function() { return Y.Intl.get("console"); }
1284 * Boolean to pause the outputting of new messages to the console.
1285 * When paused, messages will accumulate in the buffer.
1293 validator : L.isBoolean
1297 * If a category is not specified in the Y.log(..) statement, this
1298 * category will be used. Categories "info",
1299 * "warn", and "error" are also called log level.
1301 * @attribute defaultCategory
1307 validator : isString
1311 * If a source is not specified in the Y.log(..) statement, this
1312 * source will be used.
1314 * @attribute defaultSource
1320 validator : isString
1324 * Markup template used to create the DOM structure for Console entries.
1326 * @attribute entryTemplate
1328 * @default Console.ENTRY_TEMPLATE
1331 value : ENTRY_TEMPLATE_STR,
1332 validator : isString
1336 * Minimum entry log level to render into the Console. The initial
1337 * logLevel value for all Console instances defaults from the
1338 * Y.config.logLevel YUI configuration, or Console.LOG_LEVEL_INFO if
1339 * that configuration is not set.
1341 * Possible values are "info", "warn",
1342 * "error" (case insensitive), or their corresponding statics
1343 * Console.LOG_LEVEL_INFO and so on.
1345 * @attribute logLevel
1347 * @default Y.config.logLevel or Console.LOG_LEVEL_INFO
1350 value : Y.config.logLevel || INFO,
1351 setter : function (v) {
1352 return this._setLogLevel(v);
1357 * Millisecond timeout between iterations of the print loop, moving
1358 * entries from the buffer to the UI.
1360 * @attribute printTimeout
1366 validator : isNumber
1370 * Maximum number of entries printed in each iteration of the print
1371 * loop. This is used to prevent excessive logging locking the page UI.
1373 * @attribute printLimit
1379 validator : isNumber
1383 * Maximum number of Console entries allowed in the Console body at one
1384 * time. This is used to keep acquired messages from exploding the
1385 * DOM tree and impacting page performance.
1387 * @attribute consoleLimit
1393 validator : isNumber
1397 * New entries should display at the top of the Console or the bottom?
1399 * @attribute newestOnTop
1408 * When new entries are added to the Console UI, should they be
1409 * scrolled into view?
1411 * @attribute scrollIntoView
1420 * The baseline time for this Console instance, used to measure elapsed
1421 * time from the moment the console module is <code>use</code>d to the
1422 * moment each new entry is logged (not rendered).
1424 * This value is reset by the instance method myConsole.reset().
1426 * @attribute startTime
1428 * @default The moment the console module is <code>use</code>d
1435 * The precise time the last entry was logged. Used to measure elapsed
1436 * time between log messages.
1438 * @attribute lastTime
1440 * @default The moment the console module is <code>use</code>d
1448 * Controls the collapsed state of the Console
1450 * @attribute collapsed
1459 * String with units, or number, representing the height of the Console,
1460 * inclusive of header and footer. If a number is provided, the default
1461 * unit, defined by Widget's DEF_UNIT, property is used.
1465 * @type {String | Number}
1472 * String with units, or number, representing the width of the Console.
1473 * If a number is provided, the default unit, defined by Widget's
1474 * DEF_UNIT, property is used.
1478 * @type {String | Number}
1485 * Pass through to the YUI instance useBrowserConsole configuration.
1486 * By default this is set to false, which will disable logging to the
1487 * browser console when a Console instance is created. If the
1488 * logSource is not a YUI instance, this has no effect.
1490 * @attribute useBrowserConsole
1494 useBrowserConsole : {
1497 getter : function () {
1498 return this._getUseBrowserConsole();
1500 setter : function (v) {
1501 return this._setUseBrowserConsole(v);
1506 * Allows the Console to flow in the document. Available values are
1507 * 'inline', 'block', and 'separate' (the default).
1511 * @default 'separate'
1516 validator : function (v) {
1517 return this._validateStyle(v);
1525 }, '3.3.0' ,{requires:['substitute','widget'], lang:['en', 'es' ]});