console.js revision d7a66fe2de41baa56b41e8b7b254d1f6a50a5135
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith/**
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * A user interface for viewing log messages.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith *
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @module console
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith */
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smithvar getCN = Y.ClassNameManager.getClassName,
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith CHECKED = 'checked',
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith CLEAR = 'clear',
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith CLICK = 'click',
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith COLLAPSED = 'collapsed',
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith CONSOLE = 'console',
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith CONTENT_BOX = 'contentBox',
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith DISABLED = 'disabled',
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith ENTRY = 'entry',
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith ENTRY_TEMPLATE = 'entryTemplate',
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith ERROR = 'error',
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith HEIGHT = 'height',
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith INFO = 'info',
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith INNER_HTML = 'innerHTML',
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith LAST_TIME = 'lastTime',
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith PAUSE = 'pause',
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith PAUSED = 'paused',
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith RESET = 'reset',
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith START_TIME = 'startTime',
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith TITLE = 'title',
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith WARN = 'warn',
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith DOT = '.',
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith C_BUTTON = getCN(CONSOLE,'button'),
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith C_CHECKBOX = getCN(CONSOLE,'checkbox'),
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith C_CLEAR = getCN(CONSOLE,CLEAR),
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith C_COLLAPSE = getCN(CONSOLE,'collapse'),
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith C_COLLAPSED = getCN(CONSOLE,COLLAPSED),
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith C_CONSOLE_CONTROLS = getCN(CONSOLE,'controls'),
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith C_CONSOLE_HD = getCN(CONSOLE,'hd'),
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith C_CONSOLE_BD = getCN(CONSOLE,'bd'),
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith C_CONSOLE_FT = getCN(CONSOLE,'ft'),
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith C_CONSOLE_TITLE = getCN(CONSOLE,TITLE),
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith C_ENTRY = getCN(CONSOLE,ENTRY),
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith C_ENTRY_CAT = getCN(CONSOLE,ENTRY,'cat'),
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith C_ENTRY_CONTENT = getCN(CONSOLE,ENTRY,'content'),
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith C_ENTRY_META = getCN(CONSOLE,ENTRY,'meta'),
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith C_ENTRY_SRC = getCN(CONSOLE,ENTRY,'src'),
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith C_ENTRY_TIME = getCN(CONSOLE,ENTRY,'time'),
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith C_PAUSE = getCN(CONSOLE,PAUSE),
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith C_PAUSE_LABEL = getCN(CONSOLE,PAUSE,'label'),
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith RE_INLINE_SOURCE = /^(\S+)\s/,
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith RE_AMP = /&/g,
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith RE_GT = />/g,
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith RE_LT = /</g,
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith ESC_AMP = '&#38;',
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith ESC_GT = '&#62;',
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith ESC_LT = '&#60;',
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith L = Y.Lang,
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith create = Y.Node.create,
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith isNumber = L.isNumber,
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith isString = L.isString,
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith merge = Y.merge,
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith substitute = Y.substitute;
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith
9327ef7ad1fee11b0e494b97cc07386565326c03Luke Smith
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith/**
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Console creates a visualization for messages logged through calls to a YUI
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * instance's <code>Y.log( message, category, source )</code> method. The
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * debug versions of YUI modules will include logging statements to offer some
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * insight into the steps executed during that module's operation. Including
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * log statements in your code will cause those messages to also appear in the
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Console. Use Console to aid in developing your page or application.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith *
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Entry categories are also referred to as the log level, and entries are
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * filtered against the configured logLevel.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith *
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @class Console
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @extends Widget
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith */
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smithfunction Console() {
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith Console.superclass.constructor.apply(this,arguments);
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith}
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith
b32d148b0052e1f874e9bc9803bef729bf859d97Luke SmithY.mix(Console, {
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith /**
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * The identity of the widget.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith *
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @property Console.NAME
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @type String
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @static
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith */
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith NAME : CONSOLE,
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith /**
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Static identifier for logLevel configuration setting to allow all
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * incoming messages to generate Console entries.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith *
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @property Console.LOG_LEVEL_INFO
8652e2d20f8ea9c9bfe21217ba427cf0d85ada9aLuke Smith * @type String
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @static
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith */
8652e2d20f8ea9c9bfe21217ba427cf0d85ada9aLuke Smith LOG_LEVEL_INFO : INFO,
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith /**
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Static identifier for logLevel configuration setting to allow only
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * incoming messages of logLevel &quot;warn&quot; or &quot;error&quot;
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * to generate Console entries.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith *
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @property Console.LOG_LEVEL_WARN
8652e2d20f8ea9c9bfe21217ba427cf0d85ada9aLuke Smith * @type String
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @static
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith */
8652e2d20f8ea9c9bfe21217ba427cf0d85ada9aLuke Smith LOG_LEVEL_WARN : WARN,
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith /**
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Static identifier for logLevel configuration setting to allow only
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * incoming messages of logLevel &quot;error&quot; to generate
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Console entries.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith *
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @property Console.LOG_LEVEL_ERROR
8652e2d20f8ea9c9bfe21217ba427cf0d85ada9aLuke Smith * @type String
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @static
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith */
8652e2d20f8ea9c9bfe21217ba427cf0d85ada9aLuke Smith LOG_LEVEL_ERROR : ERROR,
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith /**
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Map (object) of classNames used to populate the placeholders in the
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Console.ENTRY_TEMPLATE markup when rendering a new Console entry.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith *
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * <p>By default, the keys contained in the object are:</p>
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * <ul>
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * <li>entry_class</li>
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * <li>entry_meta_class</li>
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * <li>entry_cat_class</li>
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * <li>entry_src_class</li>
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * <li>entry_time_class</li>
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * <li>entry_content_class</li>
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * </ul>
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith *
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @property Console.ENTRY_CLASSES
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @type Object
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @static
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith */
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith ENTRY_CLASSES : {
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith entry_class : C_ENTRY,
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith entry_meta_class : C_ENTRY_META,
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith entry_cat_class : C_ENTRY_CAT,
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith entry_src_class : C_ENTRY_SRC,
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith entry_time_class : C_ENTRY_TIME,
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith entry_content_class : C_ENTRY_CONTENT
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith },
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith /**
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Map (object) of classNames used to populate the placeholders in the
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Console.HEADER_TEMPLATE, Console.BODY_TEMPLATE, and
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Console.FOOTER_TEMPLATE markup when rendering the Console UI.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith *
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * <p>By default, the keys contained in the object are:</p>
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * <ul>
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * <li>console_hd_class</li>
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * <li>console_bd_class</li>
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * <li>console_ft_class</li>
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * <li>console_controls_class</li>
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * <li>console_checkbox_class</li>
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * <li>console_pause_class</li>
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * <li>console_pause_label_class</li>
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * <li>console_button_class</li>
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * <li>console_clear_class</li>
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith * <li>console_collapse_class</li>
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * <li>console_title_class</li>
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * </ul>
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith *
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @property Console.CHROME_CLASSES
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @type Object
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @static
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith */
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith CHROME_CLASSES : {
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith console_hd_class : C_CONSOLE_HD,
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith console_bd_class : C_CONSOLE_BD,
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith console_ft_class : C_CONSOLE_FT,
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith console_controls_class : C_CONSOLE_CONTROLS,
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith console_checkbox_class : C_CHECKBOX,
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith console_pause_class : C_PAUSE,
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith console_pause_label_class : C_PAUSE_LABEL,
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith console_button_class : C_BUTTON,
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith console_clear_class : C_CLEAR,
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith console_collapse_class : C_COLLAPSE,
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith console_title_class : C_CONSOLE_TITLE
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith },
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith /**
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Markup template used to generate the DOM structure for the header
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * section of the Console when it is rendered. The template includes
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * these {placeholder}s:
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith *
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * <ul>
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * <li>console_hd_class - contributed by Console.CHROME_CLASSES</li>
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * <li>console_title_class - contributed by Console.CHROME_CLASSES</li>
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * <li>str_title - pulled from attribute strings.title</li>
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith * <li>str_collapse - pulled from attribute strings.collapse</li>
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * </ul>
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith *
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @property Console.HEADER_TEMPLATE
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @type String
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @static
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith */
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith HEADER_TEMPLATE :
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith '<div class="{console_hd_class}">'+
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith '<h4 class="{console_title_class}">{str_title}</h4>'+
d7a66fe2de41baa56b41e8b7b254d1f6a50a5135Luke Smith '<button type="button" class="'+
d7a66fe2de41baa56b41e8b7b254d1f6a50a5135Luke Smith '{console_button_class} {console_collapse_class}">{str_collapse}'+
d7a66fe2de41baa56b41e8b7b254d1f6a50a5135Luke Smith '</button>'+
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith '</div>',
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith /**
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Markup template used to generate the DOM structure for the Console body
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * (where the messages are inserted) when it is rendered. The template
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * includes only the {placeholder} &quot;console_bd_class&quot;, which is
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * constributed by Console.CHROME_CLASSES.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith *
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @property Console.BODY_TEMPLATE
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @type String
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @static
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith */
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith BODY_TEMPLATE : '<div class="{console_bd_class}"></div>',
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith /**
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Markup template used to generate the DOM structure for the footer
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * section of the Console when it is rendered. The template includes
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * many of the {placeholder}s from Console.CHROME_CLASSES as well as:
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith *
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * <ul>
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * <li>id_guid - generated unique id, relates the label and checkbox</li>
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * <li>str_pause - pulled from attribute strings.pause</li>
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * <li>str_clear - pulled from attribute strings.clear</li>
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * </ul>
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith *
0cd29719d36de1f7e3d0043f5d6fafb990a7b9e0Luke Smith * @property Console.FOOTER_TEMPLATE
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @type String
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @static
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith */
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith FOOTER_TEMPLATE :
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith '<div class="{console_ft_class}">'+
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith '<div class="{console_controls_class}">'+
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith '<label for="{id_guid}" class="{console_pause_label_class}">'+
d7a66fe2de41baa56b41e8b7b254d1f6a50a5135Luke Smith '<input type="checkbox" class="{console_checkbox_class} '+
d7a66fe2de41baa56b41e8b7b254d1f6a50a5135Luke Smith '{console_pause_class}" value="1" id="{id_guid}"> '+
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith '{str_pause}</label>' +
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith '<button type="button" class="'+
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith '{console_button_class} {console_clear_class}">{str_clear}'+
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith '</button>'+
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith '</div>'+
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith '</div>',
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith /**
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Default markup template used to create the DOM structure for Console
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * entries. The markup contains {placeholder}s for content and classes
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * that are replaced via Y.substitute. The default template contains
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * the {placeholder}s identified in Console.ENTRY_CLASSES as well as the
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * following placeholders that will be populated by the log entry data:
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith *
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * <ul>
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * <li>cat_class</li>
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * <li>src_class</li>
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * <li>label</li>
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * <li>totalTime</li>
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * <li>elapsedTime</li>
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * <li>localTime</li>
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * <li>sourceAndDetail</li>
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * <li>message</li>
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * </ul>
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith *
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @property Console.ENTRY_TEMPLATE
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @type String
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @static
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith */
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith ENTRY_TEMPLATE :
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith '<pre class="{entry_class} {cat_class} {src_class}">'+
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith '<div class="{entry_meta_class}">'+
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith '<p>'+
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith '<span class="{entry_cat_class}">'+
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith '{label}</span>'+
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith '<span class="{entry_time_class}">'+
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith ' {totalTime}ms (+{elapsedTime}) {localTime}:'+
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith '</span>'+
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith '</p>'+
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith '<p class="{entry_src_class}">'+
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith '{sourceAndDetail}'+
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith '</p>'+
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith '</div>'+
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith '<p class="{entry_content_class}">{message}</p>'+
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith '</pre>',
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith /**
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Static property used to define the default attribute configuration of
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * the Widget.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith *
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @property Console.ATTRS
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @Type Object
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @static
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith */
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith ATTRS : {
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith /**
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Name of the custom event that will communicate log messages.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith *
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @attribute logEvent
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @type String
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @default "yui:log"
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith */
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith logEvent : {
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith value : 'yui:log',
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith writeOnce : true,
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith validator : isString
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith },
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith
16479f9c396537f36d0d9c5633b24df618eee1e6Luke Smith /**
16479f9c396537f36d0d9c5633b24df618eee1e6Luke Smith * Object that will emit the log events. By default the YUI instance.
16479f9c396537f36d0d9c5633b24df618eee1e6Luke Smith * To have a single Console capture events from all YUI instances, set
16479f9c396537f36d0d9c5633b24df618eee1e6Luke Smith * this to the Y.Global object.
16479f9c396537f36d0d9c5633b24df618eee1e6Luke Smith *
16479f9c396537f36d0d9c5633b24df618eee1e6Luke Smith * @attribute logSource
16479f9c396537f36d0d9c5633b24df618eee1e6Luke Smith * @type EventTarget
16479f9c396537f36d0d9c5633b24df618eee1e6Luke Smith * @default Y
16479f9c396537f36d0d9c5633b24df618eee1e6Luke Smith */
16479f9c396537f36d0d9c5633b24df618eee1e6Luke Smith logSource : {
16479f9c396537f36d0d9c5633b24df618eee1e6Luke Smith value : Y,
16479f9c396537f36d0d9c5633b24df618eee1e6Luke Smith writeOnce : true,
16479f9c396537f36d0d9c5633b24df618eee1e6Luke Smith validator : function (v) {
16479f9c396537f36d0d9c5633b24df618eee1e6Luke Smith return v && Y.Lang.isFunction(v.on);
16479f9c396537f36d0d9c5633b24df618eee1e6Luke Smith }
16479f9c396537f36d0d9c5633b24df618eee1e6Luke Smith },
16479f9c396537f36d0d9c5633b24df618eee1e6Luke Smith
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith /**
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Collection of strings used to label elements in the Console UI.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Default collection contains the following name:value pairs:
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith *
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * <ul>
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * <li>title : &quot;Log Console&quot;</li>
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * <li>pause : &quot;Pause&quot;</li>
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * <li>clear : &quot;Clear&quot;</li>
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith * <li>collapse : &quot;Collapse&quot;</li>
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith * <li>expand : &quot;Expand&quot;</li>
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * </ul>
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith *
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @attribute strings
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @type Object
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith */
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith strings : {
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith value : {
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith title : "Log Console",
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith pause : "Pause",
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith clear : "Clear",
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith collapse : "Collapse",
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith expand : "Expand"
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith }
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith },
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith /**
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Boolean to pause the outputting of new messages to the console.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * When paused, messages will accumulate in the buffer.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith *
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @attribute paused
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @type boolean
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @default false
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith */
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith paused : {
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith value : false,
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith validator : L.isBoolean
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith },
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith /**
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * If a category is not specified in the Y.log(..) statement, this
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * category will be used. Category is also called &quot;log level&quot;.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith *
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @attribute defaultCategory
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @type String
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @default "info"
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith */
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith defaultCategory : {
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith value : INFO,
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith validator : isString
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith },
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith /**
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * If a source is not specified in the Y.log(..) statement, this
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * source will be used.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith *
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @attribute defaultSource
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @type String
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @default "global"
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith */
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith defaultSource : {
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith value : 'global',
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith validator : isString
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith },
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith /**
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Markup template used to create the DOM structure for Console entries.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith *
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @attribute entryTemplate
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @type String
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @default (see Console.ENTRY_TEMPLATE)
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith */
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith entryTemplate : {
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith value : '',
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith validator : isString
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith },
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith /**
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Minimum entry log level to render into the Console. The initial
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * logLevel value for all Console instances defaults from the
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Y.config.logLevel YUI configuration, or Console.LOG_LEVEL_INFO if
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * that configuration is not set.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith *
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Possible values are &quot;info&quot;, &quot;warn&quot;,
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * &quot;error&quot; (case insensitive), or the corresponding statics
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Console.LOG_LEVEL_INFO and so on.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith *
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @attribute logLevel
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @type String|Number
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @default Y.config.logLevel or Console.LOG_LEVEL_INFO
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith */
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith logLevel : {
8652e2d20f8ea9c9bfe21217ba427cf0d85ada9aLuke Smith value : Y.config.logLevel || INFO,
9327ef7ad1fee11b0e494b97cc07386565326c03Luke Smith setter : function (v) {
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith return this._setLogLevel(v);
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith }
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith },
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith /**
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Millisecond timeout to maintain before emptying buffer of Console
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * entries to the UI.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith *
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @attribute printTimeout
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @type Number
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @default 100
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith */
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith printTimeout : {
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith value : 100,
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith validator : isNumber
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith },
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith
c31ae0e3c3d2726907b1876b5fe81cfd94527d5dLuke Smith /**
c31ae0e3c3d2726907b1876b5fe81cfd94527d5dLuke Smith * Maximum number of entries printed in each printBuffer iteration.
c31ae0e3c3d2726907b1876b5fe81cfd94527d5dLuke Smith * This is used to prevent excessive logging bogging down runtime
c31ae0e3c3d2726907b1876b5fe81cfd94527d5dLuke Smith * performance.
c31ae0e3c3d2726907b1876b5fe81cfd94527d5dLuke Smith *
c31ae0e3c3d2726907b1876b5fe81cfd94527d5dLuke Smith * @attribute printLimit
c31ae0e3c3d2726907b1876b5fe81cfd94527d5dLuke Smith * @type Number
c31ae0e3c3d2726907b1876b5fe81cfd94527d5dLuke Smith * @default 00
c31ae0e3c3d2726907b1876b5fe81cfd94527d5dLuke Smith */
c31ae0e3c3d2726907b1876b5fe81cfd94527d5dLuke Smith printLimit : {
c31ae0e3c3d2726907b1876b5fe81cfd94527d5dLuke Smith value : 50,
c31ae0e3c3d2726907b1876b5fe81cfd94527d5dLuke Smith validator : isNumber
c31ae0e3c3d2726907b1876b5fe81cfd94527d5dLuke Smith },
c31ae0e3c3d2726907b1876b5fe81cfd94527d5dLuke Smith
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith /**
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Maximum number of Console entries allowed in the Console body at one
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * time. This is used to keep acquired messages from exploding the
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * DOM tree and impacting page performance.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith *
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @attribute consoleLimit
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @type Number
c31ae0e3c3d2726907b1876b5fe81cfd94527d5dLuke Smith * @default 300
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith */
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith consoleLimit : {
c31ae0e3c3d2726907b1876b5fe81cfd94527d5dLuke Smith value : 300,
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith validator : isNumber
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith },
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith /**
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * New entries should display at the top of the Console or the bottom?
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith *
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @attribute newestOnTop
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @type Boolean
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @default true
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith */
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith newestOnTop : {
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith value : true
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith },
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith /**
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * When new entries are added to the Console UI, should they be
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * scrolled into view?
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith *
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @attribute scrollIntoView
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @type Boolean
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @default true
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith */
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith scrollIntoView : {
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith value : true
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith },
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith /**
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * The baseline time for this Console instance, used to measure elapsed
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * time from the moment the console module is <code>use</code>d to the
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * moment each new entry is logged (not rendered).
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith *
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * This value is reset by the instance method myConsole.reset().
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith *
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @attribute startTime
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @type Date
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @default The moment the console module is <code>use</code>d
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith */
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith startTime : {
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith value : new Date()
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith },
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith /**
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * The precise time the last entry was logged. Used to measure elapsed
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * time between log messages.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith *
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @attribute lastTime
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @type Date
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @default The moment the console module is <code>use</code>d
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith */
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith lastTime : {
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith value : new Date(),
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith readOnly: true
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith },
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith /**
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith * Controls the collapsed state of the Console
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith *
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith * @attribute collapsed
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith * @type Boolean
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith * @default false
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith */
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith collapsed : {
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith value : false
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith },
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith /**
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith * String with units, or number, representing the height of the Console,
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith * inclusive of header and footer. If a number is provided, the default
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith * unit, defined by the Widgets DEF_UNIT, property is used.
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith *
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith * @attribute height
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith * @default "300px"
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith * @type {String | Number}
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith */
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith height: {
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith value: "300px"
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith },
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith /**
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith * String with units, or number, representing the width of the Console.
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith * If a number is provided, the default unit, defined by the Widgets
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith * DEF_UNIT, property is used.
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith *
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith * @attribute width
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith * @default "300px"
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith * @type {String | Number}
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith */
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith width: {
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith value: "300px"
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith }
8652e2d20f8ea9c9bfe21217ba427cf0d85ada9aLuke Smith }
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith});
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith
b32d148b0052e1f874e9bc9803bef729bf859d97Luke SmithY.extend(Console,Y.Widget,{
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith
16479f9c396537f36d0d9c5633b24df618eee1e6Luke Smith /**
16479f9c396537f36d0d9c5633b24df618eee1e6Luke Smith * Category to prefix all event subscriptions to allow for ease of detach
16479f9c396537f36d0d9c5633b24df618eee1e6Luke Smith * during destroy.
16479f9c396537f36d0d9c5633b24df618eee1e6Luke Smith *
16479f9c396537f36d0d9c5633b24df618eee1e6Luke Smith * @property _evtCat
16479f9c396537f36d0d9c5633b24df618eee1e6Luke Smith * @type string
16479f9c396537f36d0d9c5633b24df618eee1e6Luke Smith * @protected
16479f9c396537f36d0d9c5633b24df618eee1e6Luke Smith */
16479f9c396537f36d0d9c5633b24df618eee1e6Luke Smith _evtCat : null,
16479f9c396537f36d0d9c5633b24df618eee1e6Luke Smith
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith /**
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Reference to the Node instance containing the head contents.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith *
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @property _head
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @type Node
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @default null
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @protected
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith */
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith _head : null,
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith /**
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Reference to the Node instance that will house the console messages.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith *
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @property _body
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @type Node
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @default null
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @protected
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith */
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith _body : null,
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith /**
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Reference to the Node instance containing the footer contents.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith *
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @property _head
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @type Node
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @default null
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @protected
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith */
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith _foot : null,
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith /**
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Object API returned from <code>Y.later</code>. Holds the timer id
35eeab4975a1c9e62cf466455a59e80ba5e00fb0Luke Smith * returned by <code>setInterval</code> for scheduling of buffered messages.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith *
35eeab4975a1c9e62cf466455a59e80ba5e00fb0Luke Smith * @property _printLoop
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @type Object
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @default null
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @protected
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith */
35eeab4975a1c9e62cf466455a59e80ba5e00fb0Luke Smith _printLoop : null,
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith /**
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Array of normalized message objects awaiting printing.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith *
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @property buffer
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @type Array
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @default null
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith */
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith buffer : null,
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith /**
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Wrapper for <code>Y.log</code>.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith *
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @method log
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @param {Any*} * (all arguments passed through to <code>Y.log</code>)
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith */
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith log : function () {
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith return Y.log.apply(Y,arguments);
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith },
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith /**
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Clear the console of messages and flush the buffer of pending messages.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith *
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @method clearConsole
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @chainable
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith */
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith clearConsole : function () {
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith // TODO: clear event listeners from console contents
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith this._body.set(INNER_HTML,'');
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith
35eeab4975a1c9e62cf466455a59e80ba5e00fb0Luke Smith this._cancelPrintLoop();
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith this.buffer = [];
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith return this;
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith },
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith /**
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Clears the console and resets internal timers.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith *
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @method reset
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @chainable
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith */
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith reset : function () {
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith this.fire(RESET);
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith return this;
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith },
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith /**
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith * Collapses the UI.
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith *
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith * @method collapse
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith * @chainable
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith */
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith collapse : function () {
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith this.set(COLLAPSED, true);
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith },
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith /**
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith * Expands the UI if collapsed.
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith *
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith * @method collapse
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith * @chainable
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith */
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith expand : function () {
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith this.set(COLLAPSED, false);
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith },
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith /**
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Outputs all buffered messages to the console UI.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith *
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @method printBuffer
c31ae0e3c3d2726907b1876b5fe81cfd94527d5dLuke Smith * @param limit {Number} (optional) max number of buffered entries to write
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @chainable
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith */
c31ae0e3c3d2726907b1876b5fe81cfd94527d5dLuke Smith printBuffer: function (limit) {
12193f069c735c9fa68aa22d6b4a8ff1fc5b83f1Luke Smith var messages = this.buffer,
12193f069c735c9fa68aa22d6b4a8ff1fc5b83f1Luke Smith debug = Y.config.debug,
12193f069c735c9fa68aa22d6b4a8ff1fc5b83f1Luke Smith entries = [],
d7a66fe2de41baa56b41e8b7b254d1f6a50a5135Luke Smith consoleLimit= this.get('consoleLimit'),
12193f069c735c9fa68aa22d6b4a8ff1fc5b83f1Luke Smith newestOnTop = this.get('newestOnTop'),
12193f069c735c9fa68aa22d6b4a8ff1fc5b83f1Luke Smith anchor = newestOnTop ? this._body.get('firstChild') : null,
c31ae0e3c3d2726907b1876b5fe81cfd94527d5dLuke Smith i;
c31ae0e3c3d2726907b1876b5fe81cfd94527d5dLuke Smith
d7a66fe2de41baa56b41e8b7b254d1f6a50a5135Luke Smith if (messages.length > consoleLimit) {
d7a66fe2de41baa56b41e8b7b254d1f6a50a5135Luke Smith messages.splice(0, messages.length - consoleLimit);
d7a66fe2de41baa56b41e8b7b254d1f6a50a5135Luke Smith }
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith
d7a66fe2de41baa56b41e8b7b254d1f6a50a5135Luke Smith limit = Math.min(messages.length, (limit || messages.length));
d7a66fe2de41baa56b41e8b7b254d1f6a50a5135Luke Smith
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith // turn off logging system
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith Y.config.debug = false;
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith if (!this.get(PAUSED) && this.get('rendered')) {
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith
c31ae0e3c3d2726907b1876b5fe81cfd94527d5dLuke Smith for (i = 0; i < limit && messages.length; ++i) {
12193f069c735c9fa68aa22d6b4a8ff1fc5b83f1Luke Smith entries[i] = this._createEntryHTML(messages.shift());
c31ae0e3c3d2726907b1876b5fe81cfd94527d5dLuke Smith }
c31ae0e3c3d2726907b1876b5fe81cfd94527d5dLuke Smith
c31ae0e3c3d2726907b1876b5fe81cfd94527d5dLuke Smith if (!messages.length) {
35eeab4975a1c9e62cf466455a59e80ba5e00fb0Luke Smith this._cancelPrintLoop();
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith }
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith
d7a66fe2de41baa56b41e8b7b254d1f6a50a5135Luke Smith //if (newestOnTop) {
d7a66fe2de41baa56b41e8b7b254d1f6a50a5135Luke Smith if (!newestOnTop) { // workaround for bug 2527946
12193f069c735c9fa68aa22d6b4a8ff1fc5b83f1Luke Smith entries.reverse();
12193f069c735c9fa68aa22d6b4a8ff1fc5b83f1Luke Smith }
12193f069c735c9fa68aa22d6b4a8ff1fc5b83f1Luke Smith
12193f069c735c9fa68aa22d6b4a8ff1fc5b83f1Luke Smith this._body.insertBefore(create(entries.join('')), anchor);
12193f069c735c9fa68aa22d6b4a8ff1fc5b83f1Luke Smith
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith if (this.get('scrollIntoView')) {
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith this.scrollToLatest();
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith }
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith this._trimOldEntries();
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith }
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith // restore logging system
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith Y.config.debug = debug;
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith return this;
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith },
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith /**
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Constructor code. Set up the buffer and entry template, publish
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * internal events, and subscribe to the configured logEvent.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith *
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @method initializer
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @protected
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith */
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith initializer : function () {
16479f9c396537f36d0d9c5633b24df618eee1e6Luke Smith this._evtCat = Y.stamp(this) + '|';
16479f9c396537f36d0d9c5633b24df618eee1e6Luke Smith
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith this.buffer = [];
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith if (!this.get(ENTRY_TEMPLATE)) {
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith this.set(ENTRY_TEMPLATE,Console.ENTRY_TEMPLATE);
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith }
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith
16479f9c396537f36d0d9c5633b24df618eee1e6Luke Smith this.get('logSource').on(this._evtCat +
35eeab4975a1c9e62cf466455a59e80ba5e00fb0Luke Smith this.get('logEvent'),Y.bind("_onLogEvent",this));
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith /**
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Triggers the processing of an incoming message via the default logic
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * in _defEntryFn.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith *
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @event entry
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @param event {Event.Facade} An Event Facade object with the following attribute specific properties added:
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * <dl>
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * <dt>message</dt>
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * <dd>The message data normalized into an object literal (see _normalizeMessage)</dd>
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * </dl>
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @preventable _defEntryFn
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith */
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith this.publish(ENTRY, { defaultFn: this._defEntryFn });
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith /**
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Triggers the reset behavior via the default logic in _defResetFn.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith *
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @event reset
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @param event {Event.Facade} Event Facade object
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @preventable _defResetFn
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith */
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith this.publish(RESET, { defaultFn: this._defResetFn });
35eeab4975a1c9e62cf466455a59e80ba5e00fb0Luke Smith
35eeab4975a1c9e62cf466455a59e80ba5e00fb0Luke Smith this.after('rendered', this._schedulePrint);
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith },
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith
16479f9c396537f36d0d9c5633b24df618eee1e6Luke Smith destructor : function () {
16479f9c396537f36d0d9c5633b24df618eee1e6Luke Smith var bb = this.get('boundingBox');
16479f9c396537f36d0d9c5633b24df618eee1e6Luke Smith
35eeab4975a1c9e62cf466455a59e80ba5e00fb0Luke Smith this._cancelPrintLoop();
35eeab4975a1c9e62cf466455a59e80ba5e00fb0Luke Smith
16479f9c396537f36d0d9c5633b24df618eee1e6Luke Smith this.get('logSource').detach(this._evtCat + '*');
16479f9c396537f36d0d9c5633b24df618eee1e6Luke Smith
16479f9c396537f36d0d9c5633b24df618eee1e6Luke Smith Y.Event.purgeElement(bb, true);
16479f9c396537f36d0d9c5633b24df618eee1e6Luke Smith
16479f9c396537f36d0d9c5633b24df618eee1e6Luke Smith bb.set('innerHTML','');
16479f9c396537f36d0d9c5633b24df618eee1e6Luke Smith },
16479f9c396537f36d0d9c5633b24df618eee1e6Luke Smith
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith /**
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Generate the Console UI.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith *
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @method renderUI
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @protected
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith */
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith renderUI : function () {
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith this._initHead();
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith this._initBody();
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith this._initFoot();
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith },
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith /**
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Sync the UI state to the current attribute state.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith *
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @method syncUI
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith */
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith syncUI : function () {
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith this._uiUpdatePaused(this.get(PAUSED));
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith this._uiUpdateCollapsed(this.get(COLLAPSED));
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith this._uiSetHeight(this.get(HEIGHT));
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith },
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith /**
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Set up event listeners to wire up the UI to the internal state.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith *
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @method bindUI
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @protected
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith */
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith bindUI : function () {
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith this.get(CONTENT_BOX).query('button.'+C_COLLAPSE).
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith on(CLICK,this._onCollapseClick,this);
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith this.get(CONTENT_BOX).query('input[type=checkbox].'+C_PAUSE).
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith on(CLICK,this._onPauseClick,this);
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith this.get(CONTENT_BOX).query('button.'+C_CLEAR).
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith on(CLICK,this._onClearClick,this);
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith // Attribute changes
16479f9c396537f36d0d9c5633b24df618eee1e6Luke Smith this.after(this._evtCat + 'stringsChange',
16479f9c396537f36d0d9c5633b24df618eee1e6Luke Smith this._afterStringsChange);
16479f9c396537f36d0d9c5633b24df618eee1e6Luke Smith this.after(this._evtCat + 'pausedChange',
16479f9c396537f36d0d9c5633b24df618eee1e6Luke Smith this._afterPausedChange);
16479f9c396537f36d0d9c5633b24df618eee1e6Luke Smith this.after(this._evtCat + 'consoleLimitChange',
16479f9c396537f36d0d9c5633b24df618eee1e6Luke Smith this._afterConsoleLimitChange);
16479f9c396537f36d0d9c5633b24df618eee1e6Luke Smith this.after(this._evtCat + 'collapsedChange',
16479f9c396537f36d0d9c5633b24df618eee1e6Luke Smith this._afterCollapsedChange);
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith },
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith /**
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Create the DOM structure for the header elements.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith *
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @method _initHead
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @protected
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith */
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith _initHead : function () {
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith var cb = this.get(CONTENT_BOX),
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith info = merge(Console.CHROME_CLASSES, {
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith str_collapse : this.get('strings.collapse'),
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith str_title : this.get('strings.title')
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith });
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith this._head = create(substitute(Console.HEADER_TEMPLATE,info));
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith cb.insertBefore(this._head,cb.get('firstChild'));
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith },
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith /**
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Create the DOM structure for the console body&#8212;where messages are
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * rendered.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith *
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith * @method _initBody
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @protected
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith */
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith _initBody : function () {
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith this._body = create(substitute(
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith Console.BODY_TEMPLATE,
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith Console.CHROME_CLASSES));
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith this.get(CONTENT_BOX).appendChild(this._body);
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith },
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith /**
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Create the DOM structure for the footer elements.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith *
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @method _initFoot
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @protected
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith */
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith _initFoot : function () {
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith var info = merge(Console.CHROME_CLASSES, {
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith id_guid : Y.guid(),
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith str_pause : this.get('strings.pause'),
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith str_clear : this.get('strings.clear')
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith });
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith this._foot = create(substitute(Console.FOOTER_TEMPLATE,info));
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith this.get(CONTENT_BOX).appendChild(this._foot);
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith },
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith /**
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Determine if incoming log messages are within the configured logLevel
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * to be buffered for printing.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith *
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @method _isInLogLevel
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @protected
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith */
abdfe7cf11d34f89f17b26e4779bf6079d22a910Adam Moore _isInLogLevel : function (e) {
abdfe7cf11d34f89f17b26e4779bf6079d22a910Adam Moore var cat = e.cat, lvl = this.get('logLevel');
8652e2d20f8ea9c9bfe21217ba427cf0d85ada9aLuke Smith
8652e2d20f8ea9c9bfe21217ba427cf0d85ada9aLuke Smith if (lvl !== INFO) {
8652e2d20f8ea9c9bfe21217ba427cf0d85ada9aLuke Smith cat = cat || INFO;
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith
8652e2d20f8ea9c9bfe21217ba427cf0d85ada9aLuke Smith if (isString(cat)) {
8652e2d20f8ea9c9bfe21217ba427cf0d85ada9aLuke Smith cat = cat.toLowerCase();
8652e2d20f8ea9c9bfe21217ba427cf0d85ada9aLuke Smith }
8652e2d20f8ea9c9bfe21217ba427cf0d85ada9aLuke Smith
8652e2d20f8ea9c9bfe21217ba427cf0d85ada9aLuke Smith if ((cat === WARN && lvl === ERROR) ||
8652e2d20f8ea9c9bfe21217ba427cf0d85ada9aLuke Smith (cat === INFO && lvl !== INFO)) {
8652e2d20f8ea9c9bfe21217ba427cf0d85ada9aLuke Smith return false;
8652e2d20f8ea9c9bfe21217ba427cf0d85ada9aLuke Smith }
8652e2d20f8ea9c9bfe21217ba427cf0d85ada9aLuke Smith }
8652e2d20f8ea9c9bfe21217ba427cf0d85ada9aLuke Smith
8652e2d20f8ea9c9bfe21217ba427cf0d85ada9aLuke Smith return true;
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith },
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith /**
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Create a log entry message from the inputs including the following keys:
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * <ul>
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * <li>time - this moment</li>
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * <li>message - leg message</li>
8652e2d20f8ea9c9bfe21217ba427cf0d85ada9aLuke Smith * <li>category - logLevel or custom category for the message</li>
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * <li>source - when provided, the widget or util calling Y.log</li>
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * <li>sourceAndDetail - same as source but can include instance info</li>
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * <li>label - logLevel/category label for the entry</li>
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * <li>localTime - readable version of time</li>
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * <li>elapsedTime - ms since last entry</li>
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * <li>totalTime - ms since Console was instantiated or reset</li>
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * </ul>
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith *
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @mehod _normalizeMessage
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @param msg {String} the log message
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @param cat {String} OPTIONAL the category or logLevel of the message
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @param src {String} OPTIONAL the source widget or util of the message
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @return Object the message object
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @protected
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith */
abdfe7cf11d34f89f17b26e4779bf6079d22a910Adam Moore _normalizeMessage : function (e) {
abdfe7cf11d34f89f17b26e4779bf6079d22a910Adam Moore
abdfe7cf11d34f89f17b26e4779bf6079d22a910Adam Moore var msg = e.msg, cat = e.cat, src = e.src,
abdfe7cf11d34f89f17b26e4779bf6079d22a910Adam Moore
abdfe7cf11d34f89f17b26e4779bf6079d22a910Adam Moore m = {
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith time : new Date(),
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith message : msg,
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith category : cat || this.get('defaultCategory'),
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith sourceAndDetail : src || this.get('defaultSource'),
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith source : null,
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith label : null,
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith localTime : null,
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith elapsedTime : null,
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith totalTime : null
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith };
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith // Extract m.source "Foo" from m.sourceAndDetail "Foo bar baz"
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith m.source = RE_INLINE_SOURCE.test(m.sourceAndDetail) ?
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith RegExp.$1 : m.sourceAndDetail;
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith m.label = m.category;
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith m.localTime = m.time.toLocaleTimeString ?
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith m.time.toLocaleTimeString() : (m.time + '');
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith m.elapsedTime = m.time - this.get(LAST_TIME);
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith m.totalTime = m.time - this.get(START_TIME);
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith this._set(LAST_TIME,m.time);
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith return m;
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith },
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith /**
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Sets a timeout for buffered messages to be output to the console.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith *
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @method _schedulePrint
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @protected
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith */
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith _schedulePrint : function () {
d7a66fe2de41baa56b41e8b7b254d1f6a50a5135Luke Smith if (!this._printLoop && !this.get(PAUSED) && this.get('rendered')) {
35eeab4975a1c9e62cf466455a59e80ba5e00fb0Luke Smith this._printLoop = Y.later(
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith this.get('printTimeout'),
c31ae0e3c3d2726907b1876b5fe81cfd94527d5dLuke Smith this, this.printBuffer,
c31ae0e3c3d2726907b1876b5fe81cfd94527d5dLuke Smith this.get('printLimit'), true);
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith }
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith },
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith /**
12193f069c735c9fa68aa22d6b4a8ff1fc5b83f1Luke Smith * Translates message meta into the markup for a console entry
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith *
12193f069c735c9fa68aa22d6b4a8ff1fc5b83f1Luke Smith * @method _createEntryHTML
35eeab4975a1c9e62cf466455a59e80ba5e00fb0Luke Smith * @param m {Object} object literal containing normalized message metadata
12193f069c735c9fa68aa22d6b4a8ff1fc5b83f1Luke Smith * @return String
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @protected
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith */
12193f069c735c9fa68aa22d6b4a8ff1fc5b83f1Luke Smith _createEntryHTML : function (m) {
35eeab4975a1c9e62cf466455a59e80ba5e00fb0Luke Smith m = merge(
35eeab4975a1c9e62cf466455a59e80ba5e00fb0Luke Smith this._htmlEscapeMessage(m),
35eeab4975a1c9e62cf466455a59e80ba5e00fb0Luke Smith Console.ENTRY_CLASSES,
35eeab4975a1c9e62cf466455a59e80ba5e00fb0Luke Smith {
35eeab4975a1c9e62cf466455a59e80ba5e00fb0Luke Smith cat_class : this.getClassName(ENTRY,m.category),
35eeab4975a1c9e62cf466455a59e80ba5e00fb0Luke Smith src_class : this.getClassName(ENTRY,m.source)
35eeab4975a1c9e62cf466455a59e80ba5e00fb0Luke Smith });
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith
12193f069c735c9fa68aa22d6b4a8ff1fc5b83f1Luke Smith return this.get('entryTemplate').replace(/\{(\w+)\}/g,
12193f069c735c9fa68aa22d6b4a8ff1fc5b83f1Luke Smith function (_,token) {
12193f069c735c9fa68aa22d6b4a8ff1fc5b83f1Luke Smith return token in m ? m[token] : '';
12193f069c735c9fa68aa22d6b4a8ff1fc5b83f1Luke Smith });
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith },
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith /**
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith * Scrolls to the most recent entry
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith *
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith * @method scrollToLatest
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith * @chainable
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith */
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith scrollToLatest : function () {
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith var scrollTop = this.get('newestOnTop') ?
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith 0 :
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith this._body.get('scrollHeight');
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith this._body.set('scrollTop', scrollTop);
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith },
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith /**
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Performs HTML escaping on strings in the message object.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith *
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @method _htmlEscapeMessage
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @param m {Object} the normalized message object
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @return Object a clone of the message object with proper escapement
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @protected
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith */
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith _htmlEscapeMessage : function (m) {
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith m = Y.clone(m);
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith m.message = this._encodeHTML(m.message);
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith m.label = this._encodeHTML(m.label);
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith m.source = this._encodeHTML(m.source);
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith m.sourceAndDetail = this._encodeHTML(m.sourceAndDetail);
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith m.category = this._encodeHTML(m.category);
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith return m;
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith },
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith /**
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Removes the oldest message entries from the UI to maintain the limit
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * specified in the consoleLimit configuration.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith *
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @method _trimOldEntries
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @protected
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith */
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith _trimOldEntries : function () {
35eeab4975a1c9e62cf466455a59e80ba5e00fb0Luke Smith // Turn off the logging system for the duration of this operation
35eeab4975a1c9e62cf466455a59e80ba5e00fb0Luke Smith // to prevent an infinite loop
35eeab4975a1c9e62cf466455a59e80ba5e00fb0Luke Smith Y.config.debug = false;
35eeab4975a1c9e62cf466455a59e80ba5e00fb0Luke Smith
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith var bd = this._body,
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith limit = this.get('consoleLimit'),
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith debug = Y.config.debug,
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith entries,e,i,l;
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith if (bd) {
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith entries = bd.queryAll(DOT+C_ENTRY);
35eeab4975a1c9e62cf466455a59e80ba5e00fb0Luke Smith l = entries.size() - limit;
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith
35eeab4975a1c9e62cf466455a59e80ba5e00fb0Luke Smith if (l > 0) {
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith if (this.get('newestOnTop')) {
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith i = limit;
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith l = entries.size();
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith } else {
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith i = 0;
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith }
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith
c31ae0e3c3d2726907b1876b5fe81cfd94527d5dLuke Smith this._body.setStyle('display','none');
c31ae0e3c3d2726907b1876b5fe81cfd94527d5dLuke Smith
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith for (;i < l; ++i) {
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith e = entries.item(i);
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith if (e) {
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith e.get('parentNode').removeChild(e);
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith }
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith }
c31ae0e3c3d2726907b1876b5fe81cfd94527d5dLuke Smith
c31ae0e3c3d2726907b1876b5fe81cfd94527d5dLuke Smith this._body.setStyle('display','');
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith }
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith }
35eeab4975a1c9e62cf466455a59e80ba5e00fb0Luke Smith
35eeab4975a1c9e62cf466455a59e80ba5e00fb0Luke Smith Y.config.debug = debug;
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith },
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith /**
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Returns the input string with ampersands (&amp;), &lt, and &gt; encoded
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * as HTML entities.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith *
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @method _encodeHTML
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @param s {String} the raw string
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @return String the encoded string
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @protected
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith */
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith _encodeHTML : function (s) {
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith return isString(s) ?
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith s.replace(RE_AMP,ESC_AMP).
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith replace(RE_LT, ESC_LT).
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith replace(RE_GT, ESC_GT) :
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith s;
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith },
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith /**
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Clears the timeout for printing buffered messages.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith *
35eeab4975a1c9e62cf466455a59e80ba5e00fb0Luke Smith * @method _cancelPrintLoop
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @protected
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith */
35eeab4975a1c9e62cf466455a59e80ba5e00fb0Luke Smith _cancelPrintLoop : function () {
35eeab4975a1c9e62cf466455a59e80ba5e00fb0Luke Smith if (this._printLoop) {
35eeab4975a1c9e62cf466455a59e80ba5e00fb0Luke Smith this._printLoop.cancel();
35eeab4975a1c9e62cf466455a59e80ba5e00fb0Luke Smith this._printLoop = null;
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith }
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith },
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith /**
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Event handler for clicking on the Pause checkbox to update the paused
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * attribute.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith *
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @method _onPauseClick
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @param e {Event} DOM event facade for the click event
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @protected
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith */
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith _onPauseClick : function (e) {
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith this.set(PAUSED,e.target.get(CHECKED));
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith },
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith /**
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Event handler for clicking on the Clear button. Pass-through to
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * <code>this.clearConsole()</code>.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith *
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @method _onClearClick
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @param e {Event} DOM event facade for the click event
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @protected
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith */
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith _onClearClick : function (e) {
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith this.clearConsole();
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith },
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith /**
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith * Event handler for clicking on the Collapse/Expand button. Sets the
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith * &quot;collapsed&quot; attribute accordingly
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith *
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith * @method _onClearClick
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith * @param e {Event} DOM event facade for the click event
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith * @protected
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith */
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith _onCollapseClick : function (e) {
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith this.set(COLLAPSED, !this.get(COLLAPSED));
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith },
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith /**
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Setter method for logLevel attribute. Acceptable values are
8652e2d20f8ea9c9bfe21217ba427cf0d85ada9aLuke Smith * &quot;error&quot, &quot;warn&quot, &quot;info&quot (case insensitive),
8652e2d20f8ea9c9bfe21217ba427cf0d85ada9aLuke Smith * and Y.Console.LOG_LEVEL_ERROR, Y.Console.LOG_LEVEL_WARN,
8652e2d20f8ea9c9bfe21217ba427cf0d85ada9aLuke Smith * Y.Console.LOG_LEVEL_INFO. Any other value is treated as
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Y.Console.LOG_LEVEL_INFO.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith *
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @method _setLogLevel
8652e2d20f8ea9c9bfe21217ba427cf0d85ada9aLuke Smith * @param v {String} the desired log level
8652e2d20f8ea9c9bfe21217ba427cf0d85ada9aLuke Smith * @return String One of Console.LOG_LEVEL_INFO, _WARN, or _ERROR
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @protected
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith */
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith _setLogLevel : function (v) {
8652e2d20f8ea9c9bfe21217ba427cf0d85ada9aLuke Smith if (isString(v)) {
8652e2d20f8ea9c9bfe21217ba427cf0d85ada9aLuke Smith v = v.toLowerCase();
8652e2d20f8ea9c9bfe21217ba427cf0d85ada9aLuke Smith }
8652e2d20f8ea9c9bfe21217ba427cf0d85ada9aLuke Smith
8652e2d20f8ea9c9bfe21217ba427cf0d85ada9aLuke Smith return (v === WARN || v === ERROR) ? v : INFO;
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith },
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith /**
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith * 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.
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith * Overrides Widget.prototype._uiSetHeight.
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith *
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith * @method _uiSetHeight
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith * @param v {String|Number} the new height
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith * @protected
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith */
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith _uiSetHeight : function (v) {
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith Console.superclass._uiSetHeight.apply(this,arguments);
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith if (this._head && this._foot) {
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith var h = this.get('boundingBox').get('offsetHeight') -
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith this._head.get('offsetHeight') -
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith this._foot.get('offsetHeight');
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith this._body.setStyle(HEIGHT,h+'px');
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith }
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith },
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith /**
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Updates the UI if changes are made to any of the strings in the strings
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * attribute.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith *
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @method _afterStringsChange
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @param e {Event} Custom event for the attribute change
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @protected
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith */
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith _afterStringsChange : function (e) {
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith var prop = e.subAttrName ? e.subAttrName.split(DOT)[1] : null,
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith cb = this.get(CONTENT_BOX),
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith before = e.prevVal,
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith after = e.newVal,
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith el;
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith if ((!prop || prop === TITLE) && before.title !== after.title) {
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith el = cb.query(DOT+C_CONSOLE_TITLE);
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith if (el) {
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith el.set(INNER_HTML,after.title);
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith }
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith }
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith if ((!prop || prop === PAUSE) && before.pause !== after.pause) {
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith el = cb.query(DOT+C_PAUSE_LABEL);
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith if (el) {
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith el.set(INNER_HTML,after.pause);
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith }
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith }
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith if ((!prop || prop === CLEAR) && before.clear !== after.clear) {
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith el = cb.query(DOT+C_CLEAR);
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith if (el) {
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith el.set('value',after.clear);
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith }
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith }
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith },
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith /**
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Updates the UI and schedules or cancels the scheduled buffer printing
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * operation.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith *
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @method _afterPausedChange
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @param e {Event} Custom event for the attribute change
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @protected
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith */
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith _afterPausedChange : function (e) {
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith var paused = e.newVal;
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith if (e.src !== Y.Widget.SRC_UI) {
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith this._uiUpdatePaused(paused);
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith }
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith if (!paused) {
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith this._schedulePrint();
35eeab4975a1c9e62cf466455a59e80ba5e00fb0Luke Smith } else if (this._printLoop) {
35eeab4975a1c9e62cf466455a59e80ba5e00fb0Luke Smith this._cancelPrintLoop();
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith }
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith },
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith /**
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith * Checks or unchecks the paused checkbox
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith *
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith * @method _uiUpdatePaused
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith * @param on {Boolean} the new checked state
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith * @protected
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith */
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith _uiUpdatePaused : function (on) {
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith var node = this._foot.queryAll('input[type=checkbox].'+C_PAUSE);
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith if (node) {
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith node.set(CHECKED,on);
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith }
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith },
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith /**
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Calls this._trimOldEntries() in response to changes in the configured
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * consoleLimit attribute.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith *
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @method _afterConsoleLimitChange
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @param e {Event} Custom event for the attribute change
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @protected
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith */
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith _afterConsoleLimitChange : function () {
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith this._trimOldEntries();
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith },
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith /**
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith * Updates the className of the contentBox, which should trigger CSS to
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith * hide or show the body and footer sections depending on the new value.
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith *
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith * @method _afterCollapsedChange
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith * @param e {Event} Custom event for the attribute change
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith * @protected
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith */
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith _afterCollapsedChange : function (e) {
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith this._uiUpdateCollapsed(e.newVal);
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith },
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith /**
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith * Updates the UI to reflect the new Collapsed state
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith *
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith * @method _uiUpdateCollapsed
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith * @param v {Boolean} true for collapsed, false for expanded
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith * @protected
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith */
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith _uiUpdateCollapsed : function (v) {
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith var cb = this.get(CONTENT_BOX),
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith button = cb.queryAll('button.'+C_COLLAPSE),
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith method = v ? 'addClass' : 'removeClass',
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith str = this.get('strings.'+(v ? 'expand' : 'collapse'));
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith cb[method](C_COLLAPSED);
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith if (button) {
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith button.set('innerHTML',str);
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith }
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith if (!v) {
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith this._uiSetHeight(this.get(HEIGHT));
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith }
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith },
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith /**
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith * Makes adjustments to the UI if needed when the Console is hidden or shown
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith *
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith * @method _afterVisibleChange
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith * @param e {Event} the visibleChange event
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith * @protected
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith */
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith _afterVisibleChange : function (e) {
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith Console.superclass._afterVisibleChange.apply(this,arguments);
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith this._uiUpdateFromHideShow(e.newVal);
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith },
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith /**
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith * Recalculates dimensions and updates appropriately when shown
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith *
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith * @method _uiUpdateFromHideShow
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith * @param v {Boolean} true for visible, false for hidden
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith * @protected
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith */
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith _uiUpdateFromHideShow : function (v) {
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith if (v) {
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith this._uiSetHeight(this.get(HEIGHT));
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith }
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith },
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith /**
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Responds to log events by normalizing qualifying messages and passing
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * them along through the entry event for buffering etc.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith *
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @method _onLogEvent
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @param msg {String} the log message
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @param cat {String} OPTIONAL the category or logLevel of the message
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @param src {String} OPTIONAL the source of the message (e.g. widget name)
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @protected
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith */
abdfe7cf11d34f89f17b26e4779bf6079d22a910Adam Moore _onLogEvent : function (e) {
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith
abdfe7cf11d34f89f17b26e4779bf6079d22a910Adam Moore if (!this.get(DISABLED) && this._isInLogLevel(e)) {
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith var debug = Y.config.debug;
abdfe7cf11d34f89f17b26e4779bf6079d22a910Adam Moore
abdfe7cf11d34f89f17b26e4779bf6079d22a910Adam Moore /* TODO: needed? */
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith Y.config.debug = false;
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith this.fire(ENTRY, {
abdfe7cf11d34f89f17b26e4779bf6079d22a910Adam Moore message : this._normalizeMessage.call(this, e)
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith });
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith Y.config.debug = debug;
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith }
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith },
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith /**
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Clears the console, resets the startTime attribute, enables and
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * unpauses the widget.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith *
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @method _defResetFn
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @protected
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith */
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith _defResetFn : function () {
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith this.clearConsole();
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith this.set(START_TIME,new Date());
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith this.set(DISABLED,false);
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith this.set(PAUSED,false);
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith },
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith /**
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Buffers incoming message objects and schedules the printing.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith *
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @method _defEntryFn
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @param e {Event} The Custom event carrying the message in its payload
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @protected
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith */
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith _defEntryFn : function (e) {
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith if (e.message) {
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith this.buffer.push(e.message);
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith this._schedulePrint();
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith }
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith }
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith});
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith
b32d148b0052e1f874e9bc9803bef729bf859d97Luke SmithY.Console = Console;