3 Copyright 2012 Yahoo! Inc. All rights reserved.
4 Licensed under the BSD License.
5 http://yuilibrary.com/license/
7 YUI.add('console', function(Y) {
10 * Console creates a visualization for messages logged through calls to a YUI
11 * instance's <code>Y.log( message, category, source )</code> method. The
12 * debug versions of YUI modules will include logging statements to offer some
13 * insight into the steps executed during that module's operation. Including
14 * log statements in your code will cause those messages to also appear in the
15 * Console. Use Console to aid in developing your page or application.
17 * Entry categories "info", "warn", and "error"
18 * are also referred to as the log level, and entries are filtered against the
19 * configured logLevel.
24 * @param conf {Object} Configuration object (see Configuration attributes)
27 var getCN = Y.ClassNameManager.getClassName,
31 COLLAPSED = 'collapsed',
33 CONTENT_BOX = 'contentBox',
34 DISABLED = 'disabled',
39 LAST_TIME = 'lastTime',
43 START_TIME = 'startTime',
49 C_BUTTON = getCN(CONSOLE,'button'),
50 C_CHECKBOX = getCN(CONSOLE,'checkbox'),
51 C_CLEAR = getCN(CONSOLE,CLEAR),
52 C_COLLAPSE = getCN(CONSOLE,'collapse'),
53 C_COLLAPSED = getCN(CONSOLE,COLLAPSED),
54 C_CONSOLE_CONTROLS = getCN(CONSOLE,'controls'),
55 C_CONSOLE_HD = getCN(CONSOLE,'hd'),
56 C_CONSOLE_BD = getCN(CONSOLE,'bd'),
57 C_CONSOLE_FT = getCN(CONSOLE,'ft'),
58 C_CONSOLE_TITLE = getCN(CONSOLE,TITLE),
59 C_ENTRY = getCN(CONSOLE,ENTRY),
60 C_ENTRY_CAT = getCN(CONSOLE,ENTRY,'cat'),
61 C_ENTRY_CONTENT = getCN(CONSOLE,ENTRY,'content'),
62 C_ENTRY_META = getCN(CONSOLE,ENTRY,'meta'),
63 C_ENTRY_SRC = getCN(CONSOLE,ENTRY,'src'),
64 C_ENTRY_TIME = getCN(CONSOLE,ENTRY,'time'),
65 C_PAUSE = getCN(CONSOLE,PAUSE),
66 C_PAUSE_LABEL = getCN(CONSOLE,PAUSE,'label'),
68 RE_INLINE_SOURCE = /^(\S+)\s/,
69 RE_AMP = /&(?!#?[a-z0-9]+;)/g,
78 '<div class="{entry_class} {cat_class} {src_class}">'+
79 '<p class="{entry_meta_class}">'+
80 '<span class="{entry_src_class}">'+
83 '<span class="{entry_cat_class}">'+
85 '<span class="{entry_time_class}">'+
86 ' {totalTime}ms (+{elapsedTime}) {localTime}'+
89 '<pre class="{entry_content_class}">{message}</pre>'+
93 create = Y.Node.create,
94 isNumber = L.isNumber,
95 isString = L.isString,
97 substitute = Y.substitute;
101 Console.superclass.constructor.apply(this,arguments);
104 Y.Console = Y.extend(Console, Y.Widget,
106 // Y.Console prototype
109 * Category to prefix all event subscriptions to allow for ease of detach
119 * Reference to the Node instance containing the header contents.
129 * Reference to the Node instance that will house the console messages.
139 * Reference to the Node instance containing the footer contents.
149 * Holds the object API returned from <code>Y.later</code> for the print
152 * @property _printLoop
160 * Array of normalized message objects awaiting printing.
170 * Wrapper for <code>Y.log</code>.
173 * @param arg* {MIXED} (all arguments passed through to <code>Y.log</code>)
177 Y.log.apply(Y,arguments);
183 * Clear the console of messages and flush the buffer of pending messages.
185 * @method clearConsole
188 clearConsole : function () {
189 // TODO: clear event listeners from console contents
192 this._cancelPrintLoop();
200 * Clears the console and resets internal timers.
205 reset : function () {
212 * Collapses the body and footer.
217 collapse : function () {
218 this.set(COLLAPSED, true);
224 * Expands the body and footer if collapsed.
229 expand : function () {
230 this.set(COLLAPSED, false);
236 * Outputs buffered messages to the console UI. This is typically called
237 * from a scheduled interval until the buffer is empty (referred to as the
238 * print loop). The number of buffered messages output to the Console is
239 * limited to the number provided as an argument. If no limit is passed,
240 * all buffered messages are rendered.
242 * @method printBuffer
243 * @param limit {Number} (optional) max number of buffered entries to write
246 printBuffer: function (limit) {
247 var messages = this.buffer,
248 debug = Y.config.debug,
250 consoleLimit= this.get('consoleLimit'),
251 newestOnTop = this.get('newestOnTop'),
252 anchor = newestOnTop ? this._body.get('firstChild') : null,
255 if (messages.length > consoleLimit) {
256 messages.splice(0, messages.length - consoleLimit);
259 limit = Math.min(messages.length, (limit || messages.length));
261 // turn off logging system
262 Y.config.debug = false;
264 if (!this.get(PAUSED) && this.get('rendered')) {
266 for (i = 0; i < limit && messages.length; ++i) {
267 entries[i] = this._createEntryHTML(messages.shift());
270 if (!messages.length) {
271 this._cancelPrintLoop();
274 if (entries.length) {
279 this._body.insertBefore(create(entries.join('')), anchor);
281 if (this.get('scrollIntoView')) {
282 this.scrollToLatest();
285 this._trimOldEntries();
289 // restore logging system
290 Y.config.debug = debug;
297 * Constructor code. Set up the buffer and entry template, publish
298 * internal events, and subscribe to the configured logEvent.
300 * @method initializer
303 initializer : function () {
304 this._evtCat = Y.stamp(this) + '|';
308 this.get('logSource').on(this._evtCat +
309 this.get('logEvent'),Y.bind("_onLogEvent",this));
312 * Transfers a received message to the print loop buffer. Default
313 * behavior defined in _defEntryFn.
316 * @param event {Event.Facade} An Event Facade object with the following attribute specific properties added:
319 * <dd>The message data normalized into an object literal (see _normalizeMessage)</dd>
321 * @preventable _defEntryFn
323 this.publish(ENTRY, { defaultFn: this._defEntryFn });
326 * Triggers the reset behavior via the default logic in _defResetFn.
329 * @param event {Event.Facade} Event Facade object
330 * @preventable _defResetFn
332 this.publish(RESET, { defaultFn: this._defResetFn });
334 this.after('rendered', this._schedulePrint);
338 * Tears down the instance, flushing event subscriptions and purging the UI.
343 destructor : function () {
344 var bb = this.get('boundingBox');
346 this._cancelPrintLoop();
348 this.get('logSource').detach(this._evtCat + '*');
354 * Generate the Console UI.
359 renderUI : function () {
364 // Apply positioning to the bounding box if appropriate
365 var style = this.get('style');
366 if (style !== 'block') {
367 this.get('boundingBox').addClass(this.getClassName(style));
372 * Sync the UI state to the current attribute state.
376 syncUI : function () {
377 this._uiUpdatePaused(this.get(PAUSED));
378 this._uiUpdateCollapsed(this.get(COLLAPSED));
379 this._uiSetHeight(this.get(HEIGHT));
383 * Set up event listeners to wire up the UI to the internal state.
388 bindUI : function () {
389 this.get(CONTENT_BOX).one('button.'+C_COLLAPSE).
390 on(CLICK,this._onCollapseClick,this);
392 this.get(CONTENT_BOX).one('input[type=checkbox].'+C_PAUSE).
393 on(CLICK,this._onPauseClick,this);
395 this.get(CONTENT_BOX).one('button.'+C_CLEAR).
396 on(CLICK,this._onClearClick,this);
399 this.after(this._evtCat + 'stringsChange',
400 this._afterStringsChange);
401 this.after(this._evtCat + 'pausedChange',
402 this._afterPausedChange);
403 this.after(this._evtCat + 'consoleLimitChange',
404 this._afterConsoleLimitChange);
405 this.after(this._evtCat + 'collapsedChange',
406 this._afterCollapsedChange);
411 * Create the DOM structure for the header elements.
416 _initHead : function () {
417 var cb = this.get(CONTENT_BOX),
418 info = merge(Console.CHROME_CLASSES, {
419 str_collapse : this.get('strings.collapse'),
420 str_title : this.get('strings.title')
423 this._head = create(substitute(Console.HEADER_TEMPLATE,info));
425 cb.insertBefore(this._head,cb.get('firstChild'));
429 * Create the DOM structure for the console body—where messages are
435 _initBody : function () {
436 this._body = create(substitute(
437 Console.BODY_TEMPLATE,
438 Console.CHROME_CLASSES));
440 this.get(CONTENT_BOX).appendChild(this._body);
444 * Create the DOM structure for the footer elements.
449 _initFoot : function () {
450 var info = merge(Console.CHROME_CLASSES, {
452 str_pause : this.get('strings.pause'),
453 str_clear : this.get('strings.clear')
456 this._foot = create(substitute(Console.FOOTER_TEMPLATE,info));
458 this.get(CONTENT_BOX).appendChild(this._foot);
462 * Determine if incoming log messages are within the configured logLevel
463 * to be buffered for printing.
465 * @method _isInLogLevel
468 _isInLogLevel : function (e) {
469 var cat = e.cat, lvl = this.get('logLevel');
475 cat = cat.toLowerCase();
478 if ((cat === WARN && lvl === ERROR) ||
479 (cat === INFO && lvl !== INFO)) {
488 * Create a log entry message from the inputs including the following keys:
490 * <li>time - this moment</li>
491 * <li>message - leg message</li>
492 * <li>category - logLevel or custom category for the message</li>
493 * <li>source - when provided, the widget or util calling Y.log</li>
494 * <li>sourceAndDetail - same as source but can include instance info</li>
495 * <li>localTime - readable version of time</li>
496 * <li>elapsedTime - ms since last entry</li>
497 * <li>totalTime - ms since Console was instantiated or reset</li>
500 * @method _normalizeMessage
501 * @param e {Event} custom event containing the log message
502 * @return Object the message object
505 _normalizeMessage : function (e) {
514 category : cat || this.get('defaultCategory'),
515 sourceAndDetail : src || this.get('defaultSource'),
522 // Extract m.source "Foo" from m.sourceAndDetail "Foo bar baz"
523 m.source = RE_INLINE_SOURCE.test(m.sourceAndDetail) ?
524 RegExp.$1 : m.sourceAndDetail;
525 m.localTime = m.time.toLocaleTimeString ?
526 m.time.toLocaleTimeString() : (m.time + '');
527 m.elapsedTime = m.time - this.get(LAST_TIME);
528 m.totalTime = m.time - this.get(START_TIME);
530 this._set(LAST_TIME,m.time);
536 * Sets an interval for buffered messages to be output to the console.
538 * @method _schedulePrint
541 _schedulePrint : function () {
542 if (!this._printLoop && !this.get(PAUSED) && this.get('rendered')) {
543 this._printLoop = Y.later(
544 this.get('printTimeout'),
545 this, this.printBuffer,
546 this.get('printLimit'), true);
551 * Translates message meta into the markup for a console entry.
553 * @method _createEntryHTML
554 * @param m {Object} object literal containing normalized message metadata
558 _createEntryHTML : function (m) {
560 this._htmlEscapeMessage(m),
561 Console.ENTRY_CLASSES,
563 cat_class : this.getClassName(ENTRY,m.category),
564 src_class : this.getClassName(ENTRY,m.source)
567 return this.get('entryTemplate').replace(/\{(\w+)\}/g,
569 return token in m ? m[token] : '';
574 * Scrolls to the most recent entry
576 * @method scrollToLatest
579 scrollToLatest : function () {
580 var scrollTop = this.get('newestOnTop') ?
582 this._body.get('scrollHeight');
584 this._body.set('scrollTop', scrollTop);
588 * Performs HTML escaping on strings in the message object.
590 * @method _htmlEscapeMessage
591 * @param m {Object} the normalized message object
592 * @return Object the message object with proper escapement
595 _htmlEscapeMessage : function (m) {
596 m.message = this._encodeHTML(m.message);
597 m.source = this._encodeHTML(m.source);
598 m.sourceAndDetail = this._encodeHTML(m.sourceAndDetail);
599 m.category = this._encodeHTML(m.category);
605 * Removes the oldest message entries from the UI to maintain the limit
606 * specified in the consoleLimit configuration.
608 * @method _trimOldEntries
611 _trimOldEntries : function () {
612 // Turn off the logging system for the duration of this operation
613 // to prevent an infinite loop
614 Y.config.debug = false;
617 limit = this.get('consoleLimit'),
618 debug = Y.config.debug,
622 entries = bd.all(DOT+C_ENTRY);
623 l = entries.size() - limit;
626 if (this.get('newestOnTop')) {
633 this._body.setStyle('display','none');
642 this._body.setStyle('display','');
647 Y.config.debug = debug;
651 * Returns the input string with ampersands (&), <, and > encoded
654 * @method _encodeHTML
655 * @param s {String} the raw string
656 * @return String the encoded string
659 _encodeHTML : function (s) {
661 s.replace(RE_AMP,ESC_AMP).
662 replace(RE_LT, ESC_LT).
663 replace(RE_GT, ESC_GT) :
668 * Clears the timeout for printing buffered messages.
670 * @method _cancelPrintLoop
673 _cancelPrintLoop : function () {
674 if (this._printLoop) {
675 this._printLoop.cancel();
676 this._printLoop = null;
681 * Validates input value for style attribute. Accepts only values 'inline',
682 * 'block', and 'separate'.
684 * @method _validateStyle
685 * @param style {String} the proposed value
686 * @return {Boolean} pass/fail
689 _validateStyle : function (style) {
690 return style === 'inline' || style === 'block' || style === 'separate';
694 * Event handler for clicking on the Pause checkbox to update the paused
697 * @method _onPauseClick
698 * @param e {Event} DOM event facade for the click event
701 _onPauseClick : function (e) {
702 this.set(PAUSED,e.target.get(CHECKED));
706 * Event handler for clicking on the Clear button. Pass-through to
707 * <code>this.clearConsole()</code>.
709 * @method _onClearClick
710 * @param e {Event} DOM event facade for the click event
713 _onClearClick : function (e) {
718 * Event handler for clicking on the Collapse/Expand button. Sets the
719 * "collapsed" attribute accordingly.
721 * @method _onCollapseClick
722 * @param e {Event} DOM event facade for the click event
725 _onCollapseClick : function (e) {
726 this.set(COLLAPSED, !this.get(COLLAPSED));
731 * Validator for logSource attribute.
733 * @method _validateLogSource
734 * @param v {Object} the desired logSource
735 * @return {Boolean} true if the input is an object with an <code>on</code>
739 _validateLogSource: function (v) {
740 return v && Y.Lang.isFunction(v.on);
744 * Setter method for logLevel attribute. Acceptable values are
745 * "error", "warn", and "info" (case
746 * insensitive). Other values are treated as "info".
748 * @method _setLogLevel
749 * @param v {String} the desired log level
750 * @return String One of Console.LOG_LEVEL_INFO, _WARN, or _ERROR
753 _setLogLevel : function (v) {
758 return (v === WARN || v === ERROR) ? v : INFO;
762 * Getter method for useBrowserConsole attribute. Just a pass through to
763 * the YUI instance configuration setting.
765 * @method _getUseBrowserConsole
766 * @return {Boolean} or null if logSource is not a YUI instance
769 _getUseBrowserConsole: function () {
770 var logSource = this.get('logSource');
771 return logSource instanceof YUI ?
772 logSource.config.useBrowserConsole : null;
776 * Setter method for useBrowserConsole attributes. Only functional if the
777 * logSource attribute points to a YUI instance. Passes the value down to
778 * the YUI instance. NOTE: multiple Console instances cannot maintain
779 * independent useBrowserConsole values, since it is just a pass through to
780 * the YUI instance configuration.
782 * @method _setUseBrowserConsole
783 * @param v {Boolean} false to disable browser console printing (default)
784 * @return {Boolean} true|false if logSource is a YUI instance
787 _setUseBrowserConsole: function (v) {
788 var logSource = this.get('logSource');
789 if (logSource instanceof YUI) {
791 logSource.config.useBrowserConsole = v;
794 return Y.Attribute.INVALID_VALUE;
799 * Set the height of the Console container. Set the body height to the
800 * difference between the configured height and the calculated heights of
801 * the header and footer.
802 * Overrides Widget.prototype._uiSetHeight.
804 * @method _uiSetHeight
805 * @param v {String|Number} the new height
808 _uiSetHeight : function (v) {
809 Console.superclass._uiSetHeight.apply(this,arguments);
811 if (this._head && this._foot) {
812 var h = this.get('boundingBox').get('offsetHeight') -
813 this._head.get('offsetHeight') -
814 this._foot.get('offsetHeight');
816 this._body.setStyle(HEIGHT,h+'px');
821 * Over-ride default content box sizing to do nothing, since we're sizing
822 * the body section to fill out height ourselves.
827 _uiSizeCB : function() {
828 // Do Nothing. Ideally want to move to Widget-StdMod, which accounts for
833 * Updates the UI if changes are made to any of the strings in the strings
836 * @method _afterStringsChange
837 * @param e {Event} Custom event for the attribute change
840 _afterStringsChange : function (e) {
841 var prop = e.subAttrName ? e.subAttrName.split(DOT)[1] : null,
842 cb = this.get(CONTENT_BOX),
846 if ((!prop || prop === TITLE) && before.title !== after.title) {
847 cb.all(DOT+C_CONSOLE_TITLE).setContent(after.title);
850 if ((!prop || prop === PAUSE) && before.pause !== after.pause) {
851 cb.all(DOT+C_PAUSE_LABEL).setContent(after.pause);
854 if ((!prop || prop === CLEAR) && before.clear !== after.clear) {
855 cb.all(DOT+C_CLEAR).set('value',after.clear);
860 * Updates the UI and schedules or cancels the print loop.
862 * @method _afterPausedChange
863 * @param e {Event} Custom event for the attribute change
866 _afterPausedChange : function (e) {
867 var paused = e.newVal;
869 if (e.src !== Y.Widget.SRC_UI) {
870 this._uiUpdatePaused(paused);
874 this._schedulePrint();
875 } else if (this._printLoop) {
876 this._cancelPrintLoop();
881 * Checks or unchecks the paused checkbox
883 * @method _uiUpdatePaused
884 * @param on {Boolean} the new checked state
887 _uiUpdatePaused : function (on) {
888 var node = this._foot.all('input[type=checkbox].'+C_PAUSE);
891 node.set(CHECKED,on);
896 * Calls this._trimOldEntries() in response to changes in the configured
897 * consoleLimit attribute.
899 * @method _afterConsoleLimitChange
900 * @param e {Event} Custom event for the attribute change
903 _afterConsoleLimitChange : function () {
904 this._trimOldEntries();
909 * Updates the className of the contentBox, which should trigger CSS to
910 * hide or show the body and footer sections depending on the new value.
912 * @method _afterCollapsedChange
913 * @param e {Event} Custom event for the attribute change
916 _afterCollapsedChange : function (e) {
917 this._uiUpdateCollapsed(e.newVal);
921 * Updates the UI to reflect the new Collapsed state
923 * @method _uiUpdateCollapsed
924 * @param v {Boolean} true for collapsed, false for expanded
927 _uiUpdateCollapsed : function (v) {
928 var bb = this.get('boundingBox'),
929 button = bb.all('button.'+C_COLLAPSE),
930 method = v ? 'addClass' : 'removeClass',
931 str = this.get('strings.'+(v ? 'expand' : 'collapse'));
933 bb[method](C_COLLAPSED);
936 button.setContent(str);
939 this._uiSetHeight(v ? this._head.get('offsetHeight'): this.get(HEIGHT));
943 * Makes adjustments to the UI if needed when the Console is hidden or shown
945 * @method _afterVisibleChange
946 * @param e {Event} the visibleChange event
949 _afterVisibleChange : function (e) {
950 Console.superclass._afterVisibleChange.apply(this,arguments);
952 this._uiUpdateFromHideShow(e.newVal);
956 * Recalculates dimensions and updates appropriately when shown
958 * @method _uiUpdateFromHideShow
959 * @param v {Boolean} true for visible, false for hidden
962 _uiUpdateFromHideShow : function (v) {
964 this._uiSetHeight(this.get(HEIGHT));
969 * Responds to log events by normalizing qualifying messages and passing
970 * them along through the entry event for buffering etc.
972 * @method _onLogEvent
973 * @param msg {String} the log message
974 * @param cat {String} OPTIONAL the category or logLevel of the message
975 * @param src {String} OPTIONAL the source of the message (e.g. widget name)
978 _onLogEvent : function (e) {
980 if (!this.get(DISABLED) && this._isInLogLevel(e)) {
982 var debug = Y.config.debug;
985 Y.config.debug = false;
988 message : this._normalizeMessage(e)
991 Y.config.debug = debug;
996 * Clears the console, resets the startTime attribute, enables and
997 * unpauses the widget.
999 * @method _defResetFn
1002 _defResetFn : function () {
1003 this.clearConsole();
1004 this.set(START_TIME,new Date());
1005 this.set(DISABLED,false);
1006 this.set(PAUSED,false);
1010 * Buffers incoming message objects and schedules the printing.
1012 * @method _defEntryFn
1013 * @param e {Event} The Custom event carrying the message in its payload
1016 _defEntryFn : function (e) {
1018 this.buffer.push(e.message);
1019 this._schedulePrint();
1025 // Y.Console static properties
1028 * The identity of the widget.
1037 * Static identifier for logLevel configuration setting to allow all
1038 * incoming messages to generate Console entries.
1040 * @property LOG_LEVEL_INFO
1044 LOG_LEVEL_INFO : INFO,
1047 * Static identifier for logLevel configuration setting to allow only
1048 * incoming messages of logLevel "warn" or "error"
1049 * to generate Console entries.
1051 * @property LOG_LEVEL_WARN
1055 LOG_LEVEL_WARN : WARN,
1058 * Static identifier for logLevel configuration setting to allow only
1059 * incoming messages of logLevel "error" to generate
1062 * @property LOG_LEVEL_ERROR
1066 LOG_LEVEL_ERROR : ERROR,
1069 * Map (object) of classNames used to populate the placeholders in the
1070 * Console.ENTRY_TEMPLATE markup when rendering a new Console entry.
1072 * <p>By default, the keys contained in the object are:</p>
1074 * <li>entry_class</li>
1075 * <li>entry_meta_class</li>
1076 * <li>entry_cat_class</li>
1077 * <li>entry_src_class</li>
1078 * <li>entry_time_class</li>
1079 * <li>entry_content_class</li>
1082 * @property ENTRY_CLASSES
1087 entry_class : C_ENTRY,
1088 entry_meta_class : C_ENTRY_META,
1089 entry_cat_class : C_ENTRY_CAT,
1090 entry_src_class : C_ENTRY_SRC,
1091 entry_time_class : C_ENTRY_TIME,
1092 entry_content_class : C_ENTRY_CONTENT
1096 * Map (object) of classNames used to populate the placeholders in the
1097 * Console.HEADER_TEMPLATE, Console.BODY_TEMPLATE, and
1098 * Console.FOOTER_TEMPLATE markup when rendering the Console UI.
1100 * <p>By default, the keys contained in the object are:</p>
1102 * <li>console_hd_class</li>
1103 * <li>console_bd_class</li>
1104 * <li>console_ft_class</li>
1105 * <li>console_controls_class</li>
1106 * <li>console_checkbox_class</li>
1107 * <li>console_pause_class</li>
1108 * <li>console_pause_label_class</li>
1109 * <li>console_button_class</li>
1110 * <li>console_clear_class</li>
1111 * <li>console_collapse_class</li>
1112 * <li>console_title_class</li>
1115 * @property CHROME_CLASSES
1120 console_hd_class : C_CONSOLE_HD,
1121 console_bd_class : C_CONSOLE_BD,
1122 console_ft_class : C_CONSOLE_FT,
1123 console_controls_class : C_CONSOLE_CONTROLS,
1124 console_checkbox_class : C_CHECKBOX,
1125 console_pause_class : C_PAUSE,
1126 console_pause_label_class : C_PAUSE_LABEL,
1127 console_button_class : C_BUTTON,
1128 console_clear_class : C_CLEAR,
1129 console_collapse_class : C_COLLAPSE,
1130 console_title_class : C_CONSOLE_TITLE
1134 * Markup template used to generate the DOM structure for the header
1135 * section of the Console when it is rendered. The template includes
1136 * these {placeholder}s:
1139 * <li>console_button_class - contributed by Console.CHROME_CLASSES</li>
1140 * <li>console_collapse_class - contributed by Console.CHROME_CLASSES</li>
1141 * <li>console_hd_class - contributed by Console.CHROME_CLASSES</li>
1142 * <li>console_title_class - contributed by Console.CHROME_CLASSES</li>
1143 * <li>str_collapse - pulled from attribute strings.collapse</li>
1144 * <li>str_title - pulled from attribute strings.title</li>
1147 * @property HEADER_TEMPLATE
1152 '<div class="{console_hd_class}">'+
1153 '<h4 class="{console_title_class}">{str_title}</h4>'+
1154 '<button type="button" class="'+
1155 '{console_button_class} {console_collapse_class}">{str_collapse}'+
1160 * Markup template used to generate the DOM structure for the Console body
1161 * (where the messages are inserted) when it is rendered. The template
1162 * includes only the {placeholder} "console_bd_class", which is
1163 * constributed by Console.CHROME_CLASSES.
1165 * @property BODY_TEMPLATE
1169 BODY_TEMPLATE : '<div class="{console_bd_class}"></div>',
1172 * Markup template used to generate the DOM structure for the footer
1173 * section of the Console when it is rendered. The template includes
1174 * many of the {placeholder}s from Console.CHROME_CLASSES as well as:
1177 * <li>id_guid - generated unique id, relates the label and checkbox</li>
1178 * <li>str_pause - pulled from attribute strings.pause</li>
1179 * <li>str_clear - pulled from attribute strings.clear</li>
1182 * @property FOOTER_TEMPLATE
1187 '<div class="{console_ft_class}">'+
1188 '<div class="{console_controls_class}">'+
1189 '<label for="{id_guid}" class="{console_pause_label_class}">'+
1190 '<input type="checkbox" class="{console_checkbox_class} '+
1191 '{console_pause_class}" value="1" id="{id_guid}"> '+
1192 '{str_pause}</label>' +
1193 '<button type="button" class="'+
1194 '{console_button_class} {console_clear_class}">{str_clear}'+
1200 * Default markup template used to create the DOM structure for Console
1201 * entries. The markup contains {placeholder}s for content and classes
1202 * that are replaced via Y.substitute. The default template contains
1203 * the {placeholder}s identified in Console.ENTRY_CLASSES as well as the
1204 * following placeholders that will be populated by the log entry data:
1207 * <li>cat_class</li>
1208 * <li>src_class</li>
1209 * <li>totalTime</li>
1210 * <li>elapsedTime</li>
1211 * <li>localTime</li>
1212 * <li>sourceAndDetail</li>
1216 * @property ENTRY_TEMPLATE
1220 ENTRY_TEMPLATE : ENTRY_TEMPLATE_STR,
1223 * Static property used to define the default attribute configuration of
1233 * Name of the custom event that will communicate log messages.
1235 * @attribute logEvent
1237 * @default "yui:log"
1242 validator : isString
1246 * Object that will emit the log events. By default the YUI instance.
1247 * To have a single Console capture events from all YUI instances, set
1248 * this to the Y.Global object.
1250 * @attribute logSource
1257 validator : function (v) {
1258 return this._validateLogSource(v);
1263 * Collection of strings used to label elements in the Console UI.
1264 * Default collection contains the following name:value pairs:
1267 * <li>title : "Log Console"</li>
1268 * <li>pause : "Pause"</li>
1269 * <li>clear : "Clear"</li>
1270 * <li>collapse : "Collapse"</li>
1271 * <li>expand : "Expand"</li>
1274 * @attribute strings
1278 valueFn: function() { return Y.Intl.get("console"); }
1282 * Boolean to pause the outputting of new messages to the console.
1283 * When paused, messages will accumulate in the buffer.
1291 validator : L.isBoolean
1295 * If a category is not specified in the Y.log(..) statement, this
1296 * category will be used. Categories "info",
1297 * "warn", and "error" are also called log level.
1299 * @attribute defaultCategory
1305 validator : isString
1309 * If a source is not specified in the Y.log(..) statement, this
1310 * source will be used.
1312 * @attribute defaultSource
1318 validator : isString
1322 * Markup template used to create the DOM structure for Console entries.
1324 * @attribute entryTemplate
1326 * @default Console.ENTRY_TEMPLATE
1329 value : ENTRY_TEMPLATE_STR,
1330 validator : isString
1334 * Minimum entry log level to render into the Console. The initial
1335 * logLevel value for all Console instances defaults from the
1336 * Y.config.logLevel YUI configuration, or Console.LOG_LEVEL_INFO if
1337 * that configuration is not set.
1339 * Possible values are "info", "warn",
1340 * "error" (case insensitive), or their corresponding statics
1341 * Console.LOG_LEVEL_INFO and so on.
1343 * @attribute logLevel
1345 * @default Y.config.logLevel or Console.LOG_LEVEL_INFO
1348 value : Y.config.logLevel || INFO,
1349 setter : function (v) {
1350 return this._setLogLevel(v);
1355 * Millisecond timeout between iterations of the print loop, moving
1356 * entries from the buffer to the UI.
1358 * @attribute printTimeout
1364 validator : isNumber
1368 * Maximum number of entries printed in each iteration of the print
1369 * loop. This is used to prevent excessive logging locking the page UI.
1371 * @attribute printLimit
1377 validator : isNumber
1381 * Maximum number of Console entries allowed in the Console body at one
1382 * time. This is used to keep acquired messages from exploding the
1383 * DOM tree and impacting page performance.
1385 * @attribute consoleLimit
1391 validator : isNumber
1395 * New entries should display at the top of the Console or the bottom?
1397 * @attribute newestOnTop
1406 * When new entries are added to the Console UI, should they be
1407 * scrolled into view?
1409 * @attribute scrollIntoView
1418 * The baseline time for this Console instance, used to measure elapsed
1419 * time from the moment the console module is <code>use</code>d to the
1420 * moment each new entry is logged (not rendered).
1422 * This value is reset by the instance method myConsole.reset().
1424 * @attribute startTime
1426 * @default The moment the console module is <code>use</code>d
1433 * The precise time the last entry was logged. Used to measure elapsed
1434 * time between log messages.
1436 * @attribute lastTime
1438 * @default The moment the console module is <code>use</code>d
1446 * Controls the collapsed state of the Console
1448 * @attribute collapsed
1457 * String with units, or number, representing the height of the Console,
1458 * inclusive of header and footer. If a number is provided, the default
1459 * unit, defined by Widget's DEF_UNIT, property is used.
1463 * @type {String | Number}
1470 * String with units, or number, representing the width of the Console.
1471 * If a number is provided, the default unit, defined by Widget's
1472 * DEF_UNIT, property is used.
1476 * @type {String | Number}
1483 * Pass through to the YUI instance useBrowserConsole configuration.
1484 * By default this is set to false, which will disable logging to the
1485 * browser console when a Console instance is created. If the
1486 * logSource is not a YUI instance, this has no effect.
1488 * @attribute useBrowserConsole
1492 useBrowserConsole : {
1495 getter : function () {
1496 return this._getUseBrowserConsole();
1498 setter : function (v) {
1499 return this._setUseBrowserConsole(v);
1504 * Allows the Console to flow in the document. Available values are
1505 * 'inline', 'block', and 'separate' (the default).
1509 * @default 'separate'
1514 validator : function (v) {
1515 return this._validateStyle(v);
1523 }, '3.5.1' ,{lang:['en', 'es', 'ja'], requires:['substitute','widget','yui-log']});