console.js revision 9327ef7ad1fee11b0e494b97cc07386565326c03
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich/**
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich * A user interface for viewing log messages.
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich *
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich * @module console
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich */
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich
7211944935145abdba8a3ea3b17621ec264d8e21Allen Rabinovichvar getCN = Y.ClassNameManager.getClassName,
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich CONSOLE = 'console',
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich ENTRY = 'entry',
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich RESET = 'reset',
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich CHECKED = 'checked',
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich TITLE = 'title',
6a0b5391dbcaace88784e407eb97b46fc8ffb619Allen Rabinovich PAUSE = 'pause',
6a0b5391dbcaace88784e407eb97b46fc8ffb619Allen Rabinovich PAUSED = 'paused',
6a0b5391dbcaace88784e407eb97b46fc8ffb619Allen Rabinovich CLEAR = 'clear',
6a0b5391dbcaace88784e407eb97b46fc8ffb619Allen Rabinovich INFO = 'info',
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich WARN = 'warn',
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich ERROR = 'error',
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich INNER_HTML = 'innerHTML',
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich CLICK = 'click',
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich CONTENT_BOX = 'contentBox',
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich DISABLED = 'disabled',
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich START_TIME = 'startTime',
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich LAST_TIME = 'lastTime',
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich ENTRY_TEMPLATE = 'entryTemplate',
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich RENDERED = 'rendered',
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich DOT = '.',
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich C_ENTRY = getCN(CONSOLE,ENTRY),
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich C_PAUSE = getCN(CONSOLE,PAUSE),
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich C_CHECKBOX = getCN(CONSOLE,'checkbox'),
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich C_BUTTON = getCN(CONSOLE,'button'),
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich C_CLEAR = getCN(CONSOLE,CLEAR),
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich C_PAUSE_LABEL = getCN(CONSOLE,PAUSE,'label'),
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich C_ENTRY_META = getCN(CONSOLE,ENTRY,'meta'),
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich C_ENTRY_CAT = getCN(CONSOLE,ENTRY,'cat'),
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich C_ENTRY_SRC = getCN(CONSOLE,ENTRY,'src'),
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich C_ENTRY_TIME = getCN(CONSOLE,ENTRY,'time'),
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich C_ENTRY_CONTENT = getCN(CONSOLE,ENTRY,'content'),
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich C_CONSOLE_HD = getCN(CONSOLE,'hd'),
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich C_CONSOLE_BD = getCN(CONSOLE,'bd'),
7211944935145abdba8a3ea3b17621ec264d8e21Allen Rabinovich C_CONSOLE_FT = getCN(CONSOLE,'ft'),
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich C_CONSOLE_CONTROLS = getCN(CONSOLE,'controls'),
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich C_CONSOLE_TITLE = getCN(CONSOLE,TITLE),
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich RE_INLINE_SOURCE = /^(\S+)\s/,
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich RE_AMP = /&/g,
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich RE_LT = /</g,
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich RE_GT = />/g,
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich ESC_AMP = '&#38;',
7211944935145abdba8a3ea3b17621ec264d8e21Allen Rabinovich ESC_LT = '&#60;',
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich ESC_GT = '&#62;',
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich L = Y.Lang,
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich isString = L.isString,
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich isNumber = L.isNumber,
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich merge = Y.merge,
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich substitute = Y.substitute,
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich create = Y.Node.create;
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich
7211944935145abdba8a3ea3b17621ec264d8e21Allen Rabinovich
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich/**
6a0b5391dbcaace88784e407eb97b46fc8ffb619Allen Rabinovich * Console creates a visualization for messages logged through calls to a YUI
6a0b5391dbcaace88784e407eb97b46fc8ffb619Allen Rabinovich * instance's <code>Y.log( message, category, source )</code> method. The
6a0b5391dbcaace88784e407eb97b46fc8ffb619Allen Rabinovich * debug versions of YUI modules will include logging statements to offer some
6a0b5391dbcaace88784e407eb97b46fc8ffb619Allen Rabinovich * insight into the steps executed during that module's operation. Including
6a0b5391dbcaace88784e407eb97b46fc8ffb619Allen Rabinovich * log statements in your code will cause those messages to also appear in the
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich * Console. Use Console to aid in developing your page or application.
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich *
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich * Entry categories are also referred to as the log level, and entries are
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich * filtered against the configured logLevel.
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich *
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich * @class Console
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich * @extends Widget
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich */
7211944935145abdba8a3ea3b17621ec264d8e21Allen Rabinovich
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovichfunction Console() {
7211944935145abdba8a3ea3b17621ec264d8e21Allen Rabinovich Console.superclass.constructor.apply(this,arguments);
7211944935145abdba8a3ea3b17621ec264d8e21Allen Rabinovich}
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich
9b1ad7c4722db362bee7d39c851c94ba95f118b8Allen RabinovichY.mix(Console, {
9b1ad7c4722db362bee7d39c851c94ba95f118b8Allen Rabinovich
9b1ad7c4722db362bee7d39c851c94ba95f118b8Allen Rabinovich /**
9b1ad7c4722db362bee7d39c851c94ba95f118b8Allen Rabinovich * The identity of the widget.
9b1ad7c4722db362bee7d39c851c94ba95f118b8Allen Rabinovich *
9b1ad7c4722db362bee7d39c851c94ba95f118b8Allen Rabinovich * @property Console.NAME
9b1ad7c4722db362bee7d39c851c94ba95f118b8Allen Rabinovich * @type String
9b1ad7c4722db362bee7d39c851c94ba95f118b8Allen Rabinovich * @static
9b1ad7c4722db362bee7d39c851c94ba95f118b8Allen Rabinovich */
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich NAME : CONSOLE,
7211944935145abdba8a3ea3b17621ec264d8e21Allen Rabinovich
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich /**
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich * Static identifier for logLevel configuration setting to allow all
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich * incoming messages to generate Console entries.
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich *
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich * @property Console.LOG_LEVEL_INFO
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich * @type Number
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich * @static
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich */
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich LOG_LEVEL_INFO : 30,
7211944935145abdba8a3ea3b17621ec264d8e21Allen Rabinovich
7211944935145abdba8a3ea3b17621ec264d8e21Allen Rabinovich /**
9b1ad7c4722db362bee7d39c851c94ba95f118b8Allen Rabinovich * Static identifier for logLevel configuration setting to allow only
9b1ad7c4722db362bee7d39c851c94ba95f118b8Allen Rabinovich * incoming messages of logLevel &quot;warn&quot; or &quot;error&quot;
9b1ad7c4722db362bee7d39c851c94ba95f118b8Allen Rabinovich * to generate Console entries.
9b1ad7c4722db362bee7d39c851c94ba95f118b8Allen Rabinovich *
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich * @property Console.LOG_LEVEL_WARN
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich * @type Number
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich * @static
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich */
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich LOG_LEVEL_WARN : 20,
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich /**
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich * Static identifier for logLevel configuration setting to allow only
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich * incoming messages of logLevel &quot;error&quot; to generate
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich * Console entries.
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich *
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich * @property Console.LOG_LEVEL_ERROR
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich * @type Number
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich * @static
9b1ad7c4722db362bee7d39c851c94ba95f118b8Allen Rabinovich */
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich LOG_LEVEL_ERROR : 10,
7211944935145abdba8a3ea3b17621ec264d8e21Allen Rabinovich
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich /**
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich * Map (object) of classNames used to populate the placeholders in the
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich * Console.ENTRY_TEMPLATE markup when rendering a new Console entry.
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich *
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich * <p>By default, the keys contained in the object are:</p>
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich * <ul>
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich * <li>entry_class</li>
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich * <li>entry_meta_class</li>
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich * <li>entry_cat_class</li>
7211944935145abdba8a3ea3b17621ec264d8e21Allen Rabinovich * <li>entry_src_class</li>
7211944935145abdba8a3ea3b17621ec264d8e21Allen Rabinovich * <li>entry_time_class</li>
7211944935145abdba8a3ea3b17621ec264d8e21Allen Rabinovich * <li>entry_content_class</li>
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich * </ul>
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich *
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich * @property Console.ENTRY_CLASSES
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich * @type Object
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich * @static
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich */
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich ENTRY_CLASSES : {
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich entry_class : C_ENTRY,
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich entry_meta_class : C_ENTRY_META,
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich entry_cat_class : C_ENTRY_CAT,
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich entry_src_class : C_ENTRY_SRC,
7211944935145abdba8a3ea3b17621ec264d8e21Allen Rabinovich entry_time_class : C_ENTRY_TIME,
7211944935145abdba8a3ea3b17621ec264d8e21Allen Rabinovich entry_content_class : C_ENTRY_CONTENT
7211944935145abdba8a3ea3b17621ec264d8e21Allen Rabinovich },
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich /**
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich * Map (object) of classNames used to populate the placeholders in the
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich * Console.HEADER_TEMPLATE, Console.BODY_TEMPLATE, and
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich * Console.FOOTER_TEMPLATE markup when rendering the Console UI.
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich *
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich * <p>By default, the keys contained in the object are:</p>
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich * <ul>
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich * <li>console_hd_class</li>
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich * <li>console_bd_class</li>
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich * <li>console_ft_class</li>
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich * <li>console_controls_class</li>
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich * <li>console_checkbox_class</li>
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich * <li>console_pause_class</li>
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich * <li>console_pause_label_class</li>
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich * <li>console_button_class</li>
a9a4fee30864f00049b02201b1af50ada7f769e3Allen Rabinovich * <li>console_clear_class</li>
a9a4fee30864f00049b02201b1af50ada7f769e3Allen Rabinovich * <li>console_title_class</li>
a9a4fee30864f00049b02201b1af50ada7f769e3Allen Rabinovich * </ul>
a9a4fee30864f00049b02201b1af50ada7f769e3Allen Rabinovich *
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich * @property Console.CHROME_CLASSES
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich * @type Object
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich * @static
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich */
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich CHROME_CLASSES : {
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich console_hd_class : C_CONSOLE_HD,
7211944935145abdba8a3ea3b17621ec264d8e21Allen Rabinovich console_bd_class : C_CONSOLE_BD,
7211944935145abdba8a3ea3b17621ec264d8e21Allen Rabinovich console_ft_class : C_CONSOLE_FT,
7211944935145abdba8a3ea3b17621ec264d8e21Allen Rabinovich console_controls_class : C_CONSOLE_CONTROLS,
7211944935145abdba8a3ea3b17621ec264d8e21Allen Rabinovich console_checkbox_class : C_CHECKBOX,
7211944935145abdba8a3ea3b17621ec264d8e21Allen Rabinovich console_pause_class : C_PAUSE,
7211944935145abdba8a3ea3b17621ec264d8e21Allen Rabinovich console_pause_label_class : C_PAUSE_LABEL,
7211944935145abdba8a3ea3b17621ec264d8e21Allen Rabinovich console_button_class : C_BUTTON,
7211944935145abdba8a3ea3b17621ec264d8e21Allen Rabinovich console_clear_class : C_CLEAR,
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich console_title_class : C_CONSOLE_TITLE
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich },
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich /**
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich * Markup template used to generate the DOM structure for the header
70837a7c5871ea73a84ab67d8c34fcd9d2daa31cAllen Rabinovich * section of the Console when it is rendered. The template includes
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich * these {placeholder}s:
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich *
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich * <ul>
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich * <li>console_hd_class - contributed by Console.CHROME_CLASSES</li>
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich * <li>console_title_class - contributed by Console.CHROME_CLASSES</li>
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich * <li>str_title - pulled from attribute strings.title</li>
7211944935145abdba8a3ea3b17621ec264d8e21Allen Rabinovich * </ul>
7211944935145abdba8a3ea3b17621ec264d8e21Allen Rabinovich *
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich * @property Console.HEADER_TEMPLATE
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich * @type String
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich * @static
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich */
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich HEADER_TEMPLATE :
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich '<div class="{console_hd_class}">'+
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich '<h4 class="{console_title_class}">{str_title}</h4>'+
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich '</div>',
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich /**
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich * Markup template used to generate the DOM structure for the Console body
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich * (where the messages are inserted) when it is rendered. The template
7211944935145abdba8a3ea3b17621ec264d8e21Allen Rabinovich * includes only the {placeholder} &quot;console_bd_class&quot;, which is
7211944935145abdba8a3ea3b17621ec264d8e21Allen Rabinovich * constributed by Console.CHROME_CLASSES.
7211944935145abdba8a3ea3b17621ec264d8e21Allen Rabinovich *
7211944935145abdba8a3ea3b17621ec264d8e21Allen Rabinovich * @property Console.BODY_TEMPLATE
7211944935145abdba8a3ea3b17621ec264d8e21Allen Rabinovich * @type String
7211944935145abdba8a3ea3b17621ec264d8e21Allen Rabinovich * @static
7211944935145abdba8a3ea3b17621ec264d8e21Allen Rabinovich */
7211944935145abdba8a3ea3b17621ec264d8e21Allen Rabinovich BODY_TEMPLATE : '<div class="{console_bd_class}"></div>',
7211944935145abdba8a3ea3b17621ec264d8e21Allen Rabinovich
7211944935145abdba8a3ea3b17621ec264d8e21Allen Rabinovich /**
7211944935145abdba8a3ea3b17621ec264d8e21Allen Rabinovich * Markup template used to generate the DOM structure for the footer
7211944935145abdba8a3ea3b17621ec264d8e21Allen Rabinovich * section of the Console when it is rendered. The template includes
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich * many of the {placeholder}s from Console.CHROME_CLASSES as well as:
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich *
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich * <ul>
a9a4fee30864f00049b02201b1af50ada7f769e3Allen Rabinovich * <li>id_guid - generated unique id, relates the label and checkbox</li>
7211944935145abdba8a3ea3b17621ec264d8e21Allen Rabinovich * <li>str_pause - pulled from attribute strings.pause</li>
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich * <li>str_clear - pulled from attribute strings.clear</li>
7211944935145abdba8a3ea3b17621ec264d8e21Allen Rabinovich * </ul>
7211944935145abdba8a3ea3b17621ec264d8e21Allen Rabinovich *
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich * @property Console.HEADER_TEMPLATE
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich * @type String
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich * @static
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich */
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich FOOTER_TEMPLATE :
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich '<div class="{console_ft_class}">'+
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich '<div class="{console_controls_class}">'+
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich '<input type="checkbox" class="{console_checkbox_class} '+
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich '{console_pause_class}" value="1" id="{id_guid}"> '+
7211944935145abdba8a3ea3b17621ec264d8e21Allen Rabinovich '<label for="{id_guid}" class="{console_pause_label_class}">'+
7211944935145abdba8a3ea3b17621ec264d8e21Allen Rabinovich '{str_pause}</label>' +
7211944935145abdba8a3ea3b17621ec264d8e21Allen Rabinovich '<input type="button" class="'+
7211944935145abdba8a3ea3b17621ec264d8e21Allen Rabinovich '{console_button_class} {console_clear_class}" '+
7211944935145abdba8a3ea3b17621ec264d8e21Allen Rabinovich 'value="{str_clear}">'+
7211944935145abdba8a3ea3b17621ec264d8e21Allen Rabinovich '</div>'+
7211944935145abdba8a3ea3b17621ec264d8e21Allen Rabinovich '</div>',
7211944935145abdba8a3ea3b17621ec264d8e21Allen Rabinovich
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich /**
7211944935145abdba8a3ea3b17621ec264d8e21Allen Rabinovich * Default markup template used to create the DOM structure for Console
6a0b5391dbcaace88784e407eb97b46fc8ffb619Allen Rabinovich * entries. The markup contains {placeholder}s for content and classes
6a0b5391dbcaace88784e407eb97b46fc8ffb619Allen Rabinovich * that are replaced via Y.substitute. The default template contains
6a0b5391dbcaace88784e407eb97b46fc8ffb619Allen Rabinovich * the {placeholder}s identified in Console.ENTRY_CLASSES as well as the
6a0b5391dbcaace88784e407eb97b46fc8ffb619Allen Rabinovich * following placeholders that will be populated by the log entry data:
70837a7c5871ea73a84ab67d8c34fcd9d2daa31cAllen Rabinovich *
a9a4fee30864f00049b02201b1af50ada7f769e3Allen Rabinovich * <ul>
6a0b5391dbcaace88784e407eb97b46fc8ffb619Allen Rabinovich * <li>cat_class</li>
6a0b5391dbcaace88784e407eb97b46fc8ffb619Allen Rabinovich * <li>src_class</li>
6a0b5391dbcaace88784e407eb97b46fc8ffb619Allen Rabinovich * <li>label</li>
6a0b5391dbcaace88784e407eb97b46fc8ffb619Allen Rabinovich * <li>totalTime</li>
6a0b5391dbcaace88784e407eb97b46fc8ffb619Allen Rabinovich * <li>elapsedTime</li>
6a0b5391dbcaace88784e407eb97b46fc8ffb619Allen Rabinovich * <li>localTime</li>
6a0b5391dbcaace88784e407eb97b46fc8ffb619Allen Rabinovich * <li>sourceAndDetail</li>
6a0b5391dbcaace88784e407eb97b46fc8ffb619Allen Rabinovich * <li>message</li>
6a0b5391dbcaace88784e407eb97b46fc8ffb619Allen Rabinovich * </ul>
6a0b5391dbcaace88784e407eb97b46fc8ffb619Allen Rabinovich *
6a0b5391dbcaace88784e407eb97b46fc8ffb619Allen Rabinovich * @property Console.ENTRY_TEMPLATE
6a0b5391dbcaace88784e407eb97b46fc8ffb619Allen Rabinovich * @type String
6a0b5391dbcaace88784e407eb97b46fc8ffb619Allen Rabinovich * @static
6a0b5391dbcaace88784e407eb97b46fc8ffb619Allen Rabinovich */
6a0b5391dbcaace88784e407eb97b46fc8ffb619Allen Rabinovich ENTRY_TEMPLATE :
6a0b5391dbcaace88784e407eb97b46fc8ffb619Allen Rabinovich '<pre class="{entry_class} {cat_class} {src_class}">'+
6a0b5391dbcaace88784e407eb97b46fc8ffb619Allen Rabinovich '<div class="{entry_meta_class}">'+
6a0b5391dbcaace88784e407eb97b46fc8ffb619Allen Rabinovich '<p>'+
6a0b5391dbcaace88784e407eb97b46fc8ffb619Allen Rabinovich '<span class="{entry_cat_class}">'+
6a0b5391dbcaace88784e407eb97b46fc8ffb619Allen Rabinovich '{label}</span>'+
6a0b5391dbcaace88784e407eb97b46fc8ffb619Allen Rabinovich '<span class="{entry_time_class}">'+
6a0b5391dbcaace88784e407eb97b46fc8ffb619Allen Rabinovich ' {totalTime}ms (+{elapsedTime}) {localTime}:'+
a9a4fee30864f00049b02201b1af50ada7f769e3Allen Rabinovich '</span>'+
a9a4fee30864f00049b02201b1af50ada7f769e3Allen Rabinovich '</p>'+
6a0b5391dbcaace88784e407eb97b46fc8ffb619Allen Rabinovich '<p class="{entry_src_class}">'+
7211944935145abdba8a3ea3b17621ec264d8e21Allen Rabinovich '{sourceAndDetail}'+
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich '</p>'+
6a0b5391dbcaace88784e407eb97b46fc8ffb619Allen Rabinovich '</div>'+
6a0b5391dbcaace88784e407eb97b46fc8ffb619Allen Rabinovich '<p class="{entry_content_class}">{message}</p>'+
6a0b5391dbcaace88784e407eb97b46fc8ffb619Allen Rabinovich '</pre>',
6a0b5391dbcaace88784e407eb97b46fc8ffb619Allen Rabinovich
6a0b5391dbcaace88784e407eb97b46fc8ffb619Allen Rabinovich /**
6a0b5391dbcaace88784e407eb97b46fc8ffb619Allen Rabinovich * Static property used to define the default attribute configuration of
6a0b5391dbcaace88784e407eb97b46fc8ffb619Allen Rabinovich * the Widget.
6a0b5391dbcaace88784e407eb97b46fc8ffb619Allen Rabinovich *
6a0b5391dbcaace88784e407eb97b46fc8ffb619Allen Rabinovich * @property Console.ATTRS
6a0b5391dbcaace88784e407eb97b46fc8ffb619Allen Rabinovich * @Type Object
7211944935145abdba8a3ea3b17621ec264d8e21Allen Rabinovich * @static
6a0b5391dbcaace88784e407eb97b46fc8ffb619Allen Rabinovich */
6a0b5391dbcaace88784e407eb97b46fc8ffb619Allen Rabinovich ATTRS : {
6a0b5391dbcaace88784e407eb97b46fc8ffb619Allen Rabinovich
6a0b5391dbcaace88784e407eb97b46fc8ffb619Allen Rabinovich /**
6a0b5391dbcaace88784e407eb97b46fc8ffb619Allen Rabinovich * Name of the custom event that will communicate log messages.
6a0b5391dbcaace88784e407eb97b46fc8ffb619Allen Rabinovich *
6a0b5391dbcaace88784e407eb97b46fc8ffb619Allen Rabinovich * @attribute logEvent
6a0b5391dbcaace88784e407eb97b46fc8ffb619Allen Rabinovich * @type String
6a0b5391dbcaace88784e407eb97b46fc8ffb619Allen Rabinovich * @default "yui:log"
6a0b5391dbcaace88784e407eb97b46fc8ffb619Allen Rabinovich */
6a0b5391dbcaace88784e407eb97b46fc8ffb619Allen Rabinovich logEvent : {
6a0b5391dbcaace88784e407eb97b46fc8ffb619Allen Rabinovich value : 'yui:log',
6a0b5391dbcaace88784e407eb97b46fc8ffb619Allen Rabinovich writeOnce : true,
6a0b5391dbcaace88784e407eb97b46fc8ffb619Allen Rabinovich validator : isString
6a0b5391dbcaace88784e407eb97b46fc8ffb619Allen Rabinovich },
6a0b5391dbcaace88784e407eb97b46fc8ffb619Allen Rabinovich
6a0b5391dbcaace88784e407eb97b46fc8ffb619Allen Rabinovich /**
6a0b5391dbcaace88784e407eb97b46fc8ffb619Allen Rabinovich * Collection of strings used to label elements in the Console UI.
6a0b5391dbcaace88784e407eb97b46fc8ffb619Allen Rabinovich * Default collection contains the following name:value pairs:
6a0b5391dbcaace88784e407eb97b46fc8ffb619Allen Rabinovich *
6a0b5391dbcaace88784e407eb97b46fc8ffb619Allen Rabinovich * <ul>
6a0b5391dbcaace88784e407eb97b46fc8ffb619Allen Rabinovich * <li>title : &quot;Log Console&quot;</li>
a9a4fee30864f00049b02201b1af50ada7f769e3Allen Rabinovich * <li>pause : &quot;Pause&quot;</li>
a9a4fee30864f00049b02201b1af50ada7f769e3Allen Rabinovich * <li>clear : &quot;Clear&quot;</li>
6a0b5391dbcaace88784e407eb97b46fc8ffb619Allen Rabinovich * </ul>
a9a4fee30864f00049b02201b1af50ada7f769e3Allen Rabinovich *
6a0b5391dbcaace88784e407eb97b46fc8ffb619Allen Rabinovich * @attribute strings
6a0b5391dbcaace88784e407eb97b46fc8ffb619Allen Rabinovich * @type Object
6a0b5391dbcaace88784e407eb97b46fc8ffb619Allen Rabinovich */
6a0b5391dbcaace88784e407eb97b46fc8ffb619Allen Rabinovich strings : {
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich value : {
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich title : "Log Console",
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich pause : "Pause",
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich clear : "Clear"
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich }
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich },
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich
7211944935145abdba8a3ea3b17621ec264d8e21Allen Rabinovich /**
7211944935145abdba8a3ea3b17621ec264d8e21Allen Rabinovich * Boolean to pause the outputting of new messages to the console.
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich * When paused, messages will accumulate in the buffer.
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich *
7211944935145abdba8a3ea3b17621ec264d8e21Allen Rabinovich * @attribute paused
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich * @type boolean
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich * @default false
9b1ad7c4722db362bee7d39c851c94ba95f118b8Allen Rabinovich */
9b1ad7c4722db362bee7d39c851c94ba95f118b8Allen Rabinovich paused : {
9b1ad7c4722db362bee7d39c851c94ba95f118b8Allen Rabinovich value : false,
9b1ad7c4722db362bee7d39c851c94ba95f118b8Allen Rabinovich validator : L.isBoolean
9b1ad7c4722db362bee7d39c851c94ba95f118b8Allen Rabinovich },
70837a7c5871ea73a84ab67d8c34fcd9d2daa31cAllen Rabinovich
9b1ad7c4722db362bee7d39c851c94ba95f118b8Allen Rabinovich /**
9b1ad7c4722db362bee7d39c851c94ba95f118b8Allen Rabinovich * If a category is not specified in the Y.log(..) statement, this
9b1ad7c4722db362bee7d39c851c94ba95f118b8Allen Rabinovich * category will be used. Category is also called &quot;log level&quot;.
9b1ad7c4722db362bee7d39c851c94ba95f118b8Allen Rabinovich *
9b1ad7c4722db362bee7d39c851c94ba95f118b8Allen Rabinovich * @attribute defaultCategory
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich * @type String
9b1ad7c4722db362bee7d39c851c94ba95f118b8Allen Rabinovich * @default "info"
9b1ad7c4722db362bee7d39c851c94ba95f118b8Allen Rabinovich */
7211944935145abdba8a3ea3b17621ec264d8e21Allen Rabinovich defaultCategory : {
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich value : INFO,
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich validator : isString
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich },
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich /**
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich * If a source is not specified in the Y.log(..) statement, this
7211944935145abdba8a3ea3b17621ec264d8e21Allen Rabinovich * source will be used.
7211944935145abdba8a3ea3b17621ec264d8e21Allen Rabinovich *
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich * @attribute defaultSource
7211944935145abdba8a3ea3b17621ec264d8e21Allen Rabinovich * @type String
9b1ad7c4722db362bee7d39c851c94ba95f118b8Allen Rabinovich * @default "global"
7211944935145abdba8a3ea3b17621ec264d8e21Allen Rabinovich */
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich defaultSource : {
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich value : 'global',
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich validator : isString
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich },
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich /**
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich * Markup template used to create the DOM structure for Console entries.
7211944935145abdba8a3ea3b17621ec264d8e21Allen Rabinovich *
7211944935145abdba8a3ea3b17621ec264d8e21Allen Rabinovich * @attribute entryTemplate
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich * @type String
7211944935145abdba8a3ea3b17621ec264d8e21Allen Rabinovich * @default (see Console.ENTRY_TEMPLATE)
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich */
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich entryTemplate : {
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich value : '',
9b1ad7c4722db362bee7d39c851c94ba95f118b8Allen Rabinovich validator : isString
9b1ad7c4722db362bee7d39c851c94ba95f118b8Allen Rabinovich },
9b1ad7c4722db362bee7d39c851c94ba95f118b8Allen Rabinovich
9b1ad7c4722db362bee7d39c851c94ba95f118b8Allen Rabinovich /**
9b1ad7c4722db362bee7d39c851c94ba95f118b8Allen Rabinovich * Minimum entry log level to render into the Console. The initial
9b1ad7c4722db362bee7d39c851c94ba95f118b8Allen Rabinovich * logLevel value for all Console instances defaults from the
9b1ad7c4722db362bee7d39c851c94ba95f118b8Allen Rabinovich * Y.config.logLevel YUI configuration, or Console.LOG_LEVEL_INFO if
9b1ad7c4722db362bee7d39c851c94ba95f118b8Allen Rabinovich * that configuration is not set.
9b1ad7c4722db362bee7d39c851c94ba95f118b8Allen Rabinovich *
9b1ad7c4722db362bee7d39c851c94ba95f118b8Allen Rabinovich * Possible values are &quot;info&quot;, &quot;warn&quot;,
9b1ad7c4722db362bee7d39c851c94ba95f118b8Allen Rabinovich * &quot;error&quot; (case insensitive), or the corresponding statics
9b1ad7c4722db362bee7d39c851c94ba95f118b8Allen Rabinovich * Console.LOG_LEVEL_INFO and so on.
9b1ad7c4722db362bee7d39c851c94ba95f118b8Allen Rabinovich *
9b1ad7c4722db362bee7d39c851c94ba95f118b8Allen Rabinovich * @attribute logLevel
9b1ad7c4722db362bee7d39c851c94ba95f118b8Allen Rabinovich * @type String|Number
7211944935145abdba8a3ea3b17621ec264d8e21Allen Rabinovich * @default Y.config.logLevel or Console.LOG_LEVEL_INFO
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich */
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich logLevel : {
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich value : Y.config.logLevel || 30,
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich validator : function (v) {
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich return this._validateNewLogLevel(v);
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich },
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich setter : function (v) {
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich return this._setLogLevel(v);
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich }
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich },
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich /**
7211944935145abdba8a3ea3b17621ec264d8e21Allen Rabinovich * Millisecond timeout to maintain before emptying buffer of Console
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich * entries to the UI.
a9a4fee30864f00049b02201b1af50ada7f769e3Allen Rabinovich *
6a0b5391dbcaace88784e407eb97b46fc8ffb619Allen Rabinovich * @attribute printTimeout
a9a4fee30864f00049b02201b1af50ada7f769e3Allen Rabinovich * @type Number
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich * @default 100
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich */
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich printTimeout : {
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich value : 100,
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich validator : isNumber
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich },
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich /**
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich * Maximum number of Console entries allowed in the Console body at one
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich * time. This is used to keep acquired messages from exploding the
7211944935145abdba8a3ea3b17621ec264d8e21Allen Rabinovich * DOM tree and impacting page performance.
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich *
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich * @attribute consoleLimit
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich * @type Number
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich * @default 500
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich */
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich consoleLimit : {
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich value : 500,
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich validator : isNumber
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich },
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich
7211944935145abdba8a3ea3b17621ec264d8e21Allen Rabinovich /**
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich * New entries should display at the top of the Console or the bottom?
6a0b5391dbcaace88784e407eb97b46fc8ffb619Allen Rabinovich *
6a0b5391dbcaace88784e407eb97b46fc8ffb619Allen Rabinovich * @attribute newestOnTop
6a0b5391dbcaace88784e407eb97b46fc8ffb619Allen Rabinovich * @type Boolean
6a0b5391dbcaace88784e407eb97b46fc8ffb619Allen Rabinovich * @default true
6a0b5391dbcaace88784e407eb97b46fc8ffb619Allen Rabinovich */
6a0b5391dbcaace88784e407eb97b46fc8ffb619Allen Rabinovich newestOnTop : {
6a0b5391dbcaace88784e407eb97b46fc8ffb619Allen Rabinovich value : true
6a0b5391dbcaace88784e407eb97b46fc8ffb619Allen Rabinovich },
6a0b5391dbcaace88784e407eb97b46fc8ffb619Allen Rabinovich
6a0b5391dbcaace88784e407eb97b46fc8ffb619Allen Rabinovich /**
6a0b5391dbcaace88784e407eb97b46fc8ffb619Allen Rabinovich * When new entries are added to the Console UI, should they be
6a0b5391dbcaace88784e407eb97b46fc8ffb619Allen Rabinovich * scrolled into view?
6a0b5391dbcaace88784e407eb97b46fc8ffb619Allen Rabinovich *
9b1ad7c4722db362bee7d39c851c94ba95f118b8Allen Rabinovich * @attribute scrollIntoView
9b1ad7c4722db362bee7d39c851c94ba95f118b8Allen Rabinovich * @type Boolean
9b1ad7c4722db362bee7d39c851c94ba95f118b8Allen Rabinovich * @default true
6a0b5391dbcaace88784e407eb97b46fc8ffb619Allen Rabinovich */
6a0b5391dbcaace88784e407eb97b46fc8ffb619Allen Rabinovich scrollIntoView : {
9b1ad7c4722db362bee7d39c851c94ba95f118b8Allen Rabinovich value : true
9b1ad7c4722db362bee7d39c851c94ba95f118b8Allen Rabinovich },
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich /**
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich * The baseline time for this Console instance, used to measure elapsed
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich * time from the moment the console module is <code>use</code>d to the
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich * moment each new entry is logged (not rendered).
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich *
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich * This value is reset by the instance method myConsole.reset().
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich *
7211944935145abdba8a3ea3b17621ec264d8e21Allen Rabinovich * @attribute startTime
7211944935145abdba8a3ea3b17621ec264d8e21Allen Rabinovich * @type Date
6a0b5391dbcaace88784e407eb97b46fc8ffb619Allen Rabinovich * @default The moment the console module is <code>use</code>d
6a0b5391dbcaace88784e407eb97b46fc8ffb619Allen Rabinovich */
7211944935145abdba8a3ea3b17621ec264d8e21Allen Rabinovich startTime : {
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich value : new Date()
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich },
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich /**
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich * The precise time the last entry was logged. Used to measure elapsed
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich * time between log messages.
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich *
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich * @attribute lastTime
7211944935145abdba8a3ea3b17621ec264d8e21Allen Rabinovich * @type Date
7211944935145abdba8a3ea3b17621ec264d8e21Allen Rabinovich * @default The moment the console module is <code>use</code>d
7211944935145abdba8a3ea3b17621ec264d8e21Allen Rabinovich */
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich lastTime : {
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich value : new Date(),
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich readOnly: true
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich }
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich },
7211944935145abdba8a3ea3b17621ec264d8e21Allen Rabinovich
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich /**
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich * Used to normalize input values for available logLevels.
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich *
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich * @property Console._logLevels
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich * @type Object
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich * @protected
7211944935145abdba8a3ea3b17621ec264d8e21Allen Rabinovich */
7211944935145abdba8a3ea3b17621ec264d8e21Allen Rabinovich _logLevels : {}
7211944935145abdba8a3ea3b17621ec264d8e21Allen Rabinovich
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich});
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen RabinovichConsole._logLevels[INFO] = Console.LOG_LEVEL_INFO;
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen RabinovichConsole._logLevels[WARN] = Console.LOG_LEVEL_WARN;
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen RabinovichConsole._logLevels[ERROR] = Console.LOG_LEVEL_ERROR;
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen RabinovichConsole._logLevels[Console.LOG_LEVEL_INFO] = Console.LOG_LEVEL_INFO;
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen RabinovichConsole._logLevels[Console.LOG_LEVEL_WARN] = Console.LOG_LEVEL_WARN;
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen RabinovichConsole._logLevels[Console.LOG_LEVEL_ERROR] = Console.LOG_LEVEL_ERROR;
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich
7211944935145abdba8a3ea3b17621ec264d8e21Allen RabinovichY.extend(Console,Y.Widget,{
7211944935145abdba8a3ea3b17621ec264d8e21Allen Rabinovich
7211944935145abdba8a3ea3b17621ec264d8e21Allen Rabinovich /**
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich * Reference to the Node instance containing the head contents.
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich *
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich * @property _head
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich * @type Node
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich * @default null
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich * @protected
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich */
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich _head : null,
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich
7211944935145abdba8a3ea3b17621ec264d8e21Allen Rabinovich /**
7211944935145abdba8a3ea3b17621ec264d8e21Allen Rabinovich * Reference to the Node instance that will house the console messages.
7211944935145abdba8a3ea3b17621ec264d8e21Allen Rabinovich *
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich * @property _body
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich * @type Node
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich * @default null
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich * @protected
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich */
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich _body : null,
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich /**
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich * Reference to the Node instance containing the footer contents.
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich *
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich * @property _head
7211944935145abdba8a3ea3b17621ec264d8e21Allen Rabinovich * @type Node
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich * @default null
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich * @protected
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich */
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich _foot : null,
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich /**
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich * Object API returned from <code>Y.later</code>. Holds the timer id
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich * returned by <code>setTimout</code> for scheduling of buffered messages.
7211944935145abdba8a3ea3b17621ec264d8e21Allen Rabinovich *
7211944935145abdba8a3ea3b17621ec264d8e21Allen Rabinovich * @property _timeout
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich * @type Object
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich * @default null
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich * @protected
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich */
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich _timeout : null,
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich
7211944935145abdba8a3ea3b17621ec264d8e21Allen Rabinovich /**
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich * Array of normalized message objects awaiting printing.
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich *
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich * @property buffer
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich * @type Array
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich * @default null
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich */
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich buffer : null,
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich /**
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich * Wrapper for <code>Y.log</code>.
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich *
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich * @method log
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich * @param {Any*} * (all arguments passed through to <code>Y.log</code>)
7211944935145abdba8a3ea3b17621ec264d8e21Allen Rabinovich */
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich log : function () {
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich return Y.log.apply(Y,arguments);
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich },
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich /**
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich * Clear the console of messages and flush the buffer of pending messages.
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich *
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich * @method clearConsole
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich * @chainable
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich */
7211944935145abdba8a3ea3b17621ec264d8e21Allen Rabinovich clearConsole : function () {
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich // TODO: clear event listeners from console contents
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich this._body.set(INNER_HTML,'');
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich this._clearTimeout();
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich this.buffer = [];
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich return this;
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich },
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich /**
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich * Clears the console and resets internal timers.
7211944935145abdba8a3ea3b17621ec264d8e21Allen Rabinovich *
6a0b5391dbcaace88784e407eb97b46fc8ffb619Allen Rabinovich * @method reset
6a0b5391dbcaace88784e407eb97b46fc8ffb619Allen Rabinovich * @chainable
6a0b5391dbcaace88784e407eb97b46fc8ffb619Allen Rabinovich */
6a0b5391dbcaace88784e407eb97b46fc8ffb619Allen Rabinovich reset : function () {
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich this.fire(RESET);
7211944935145abdba8a3ea3b17621ec264d8e21Allen Rabinovich
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich return this;
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich },
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich /**
66900b43227bf441b6a6b1084af2c96ce2c747c8Allen Rabinovich * Outputs all buffered messages to the console UI.
*
* @method printBuffer
* @chainable
*/
printBuffer: function () {
if (!this.get(PAUSED) && this.get('rendered')) {
this._clearTimeout();
var messages = this.buffer,
i,len;
this.buffer = [];
// TODO: use doc frag
for (i = 0, len = messages.length; i < len; ++i) {
this.printLogEntry(messages[i]);
}
this._trimOldEntries();
}
return this;
},
/**
* Prints the provided message to the console UI.
*
* @method printLogEntry
* @param m {Object} Normalized message object
* @chainable
*/
printLogEntry : function (m) {
m = merge(
this._htmlEscapeMessage(m),
Console.ENTRY_CLASSES,
{
cat_class : this.getClassName(ENTRY,m.category),
src_class : this.getClassName(ENTRY,m.source)
});
var n = create(substitute(this.get('entryTemplate'),m));
this._addToConsole(n);
return this;
},
/**
* Constructor code. Set up the buffer and entry template, publish
* internal events, and subscribe to the configured logEvent.
*
* @method initializer
* @protected
*/
initializer : function () {
this.buffer = [];
if (!this.get(ENTRY_TEMPLATE)) {
this.set(ENTRY_TEMPLATE,Console.ENTRY_TEMPLATE);
}
Y.on(this.get('logEvent'),Y.bind(this._onLogEvent,this));
/**
* Triggers the processing of an incoming message via the default logic
* in _defEntryFn.
*
* @event entry
* @param event {Event.Facade} An Event Facade object with the following attribute specific properties added:
* <dl>
* <dt>message</dt>
* <dd>The message data normalized into an object literal (see _normalizeMessage)</dd>
* </dl>
* @preventable _defEntryFn
*/
this.publish(ENTRY, { defaultFn: this._defEntryFn });
/**
* Triggers the reset behavior via the default logic in _defResetFn.
*
* @event reset
* @param event {Event.Facade} Event Facade object
* @preventable _defResetFn
*/
this.publish(RESET, { defaultFn: this._defResetFn });
},
/**
* Generate the Console UI.
*
* @method renderUI
* @protected
*/
renderUI : function () {
this._initHead();
this._initConsole();
this._initFoot();
},
/**
* Sync the UI state to the current attribute state.
*
* @method syncUI
*/
syncUI : function () {
this.set(PAUSED,this.get(PAUSED));
},
/**
* Set up event listeners to wire up the UI to the internal state.
*
* @method bindUI
* @protected
*/
bindUI : function () {
this.get(CONTENT_BOX).query('input[type=checkbox].'+C_PAUSE).
on(CLICK,this._onPauseClick,this);
this.get(CONTENT_BOX).query('input[type=button].'+C_CLEAR).
on(CLICK,this._onClearClick,this);
// Attribute changes
this.after('stringsChange', this._afterStringsChange);
this.after('pausedChange', this._afterPausedChange);
this.after('consoleLimitChange', this._afterConsoleLimitChange);
},
/**
* Create the DOM structure for the header elements.
*
* @method _initHead
* @protected
*/
_initHead : function () {
var cb = this.get(CONTENT_BOX),
info = merge(Console.CHROME_CLASSES, {
str_title : this.get('strings.title')
});
this._head = create(substitute(Console.HEADER_TEMPLATE,info));
cb.insertBefore(this._head,cb.get('firstChild'));
},
/**
* Create the DOM structure for the console body&#8212;where messages are
* rendered.
*
* @method _initConsole
* @protected
*/
_initConsole : function () {
this._body = create(substitute(
Console.BODY_TEMPLATE,
Console.CHROME_CLASSES));
this.get(CONTENT_BOX).appendChild(this._body);
},
/**
* Create the DOM structure for the footer elements.
*
* @method _initFoot
* @protected
*/
_initFoot : function () {
var info = merge(Console.CHROME_CLASSES, {
id_guid : Y.guid(),
str_pause : this.get('strings.pause'),
str_clear : this.get('strings.clear')
});
this._foot = create(substitute(Console.FOOTER_TEMPLATE,info));
this.get(CONTENT_BOX).appendChild(this._foot);
},
/**
* Determine if incoming log messages are within the configured logLevel
* to be buffered for printing.
*
* @method _isInLogLevel
* @protected
*/
_isInLogLevel : function (msg,cat) {
var lvl = this.get('logLevel'),
mlvl = cat === ERROR ? Console.LOG_LEVEL_ERROR :
cat === WARN ? Console.LOG_LEVEL_WARN :
Console.LOG_LEVEL_INFO;
return lvl >= mlvl;
},
/**
* Create a log entry message from the inputs including the following keys:
* <ul>
* <li>time - this moment</li>
* <li>message - leg message</li>
* <li>category - aka logLevel</li>
* <li>source - when provided, the widget or util calling Y.log</li>
* <li>sourceAndDetail - same as source but can include instance info</li>
* <li>label - logLevel/category label for the entry</li>
* <li>localTime - readable version of time</li>
* <li>elapsedTime - ms since last entry</li>
* <li>totalTime - ms since Console was instantiated or reset</li>
* </ul>
*
* @mehod _normalizeMessage
* @param msg {String} the log message
* @param cat {String} OPTIONAL the category or logLevel of the message
* @param src {String} OPTIONAL the source widget or util of the message
* @return Object the message object
* @protected
*/
_normalizeMessage : function (msg,cat,src) {
var m = {
time : new Date(),
message : msg,
category : cat || this.get('defaultCategory'),
sourceAndDetail : src || this.get('defaultSource'),
source : null,
label : null,
localTime : null,
elapsedTime : null,
totalTime : null
};
// Extract m.source "Foo" from m.sourceAndDetail "Foo bar baz"
m.source = RE_INLINE_SOURCE.test(m.sourceAndDetail) ?
RegExp.$1 : m.sourceAndDetail;
m.label = m.category;
m.localTime = m.time.toLocaleTimeString ?
m.time.toLocaleTimeString() : (m.time + '');
m.elapsedTime = m.time - this.get(LAST_TIME);
m.totalTime = m.time - this.get(START_TIME);
this._set(LAST_TIME,m.time);
return m;
},
/**
* Sets a timeout for buffered messages to be output to the console.
*
* @method _schedulePrint
* @protected
*/
_schedulePrint : function () {
if (!this.get(PAUSED) && !this._timeout) {
this._timeout = Y.later(
this.get('printTimeout'),
this,this.printBuffer);
}
},
/**
* Inserts a Node into the console body at the top or bottom depending on
* the configuration value of newestOnTop.
*
* @method _addToConsole
* @param node {Node} the node to insert into the console body
* @protected
*/
_addToConsole : function (node) {
var toTop = this.get('newestOnTop'),
bd = this._body,
scrollTop;
bd.insertBefore(node,toTop ? bd.get('firstChild') : null);
if (this.get('scrollIntoView')) {
scrollTop = toTop ? 0 : bd.get('scrollHeight');
bd.set('scrollTop', scrollTop);
}
},
/**
* Performs HTML escaping on strings in the message object.
*
* @method _htmlEscapeMessage
* @param m {Object} the normalized message object
* @return Object a clone of the message object with proper escapement
* @protected
*/
_htmlEscapeMessage : function (m) {
m = Y.clone(m);
m.message = this._encodeHTML(m.message);
m.label = this._encodeHTML(m.label);
m.source = this._encodeHTML(m.source);
m.sourceAndDetail = this._encodeHTML(m.sourceAndDetail);
m.category = this._encodeHTML(m.category);
return m;
},
/**
* Removes the oldest message entries from the UI to maintain the limit
* specified in the consoleLimit configuration.
*
* @method _trimOldEntries
* @protected
*/
_trimOldEntries : function () {
var bd = this._body;
if (bd) {
var entries = bd.queryAll(DOT+C_ENTRY),
i = entries ? entries.size() - this.get('consoleLimit') : 0;
if (i > 0) {
if (this.get('newestOnTop')) {
for (var l = entries.size(); i<l; i++) {
bd.removeChild(entries.item(i));
}
} else {
for (;i>=0;--i) {
bd.removeChild(entries.item(i));
}
}
}
}
},
/**
* Returns the input string with ampersands (&amp;), &lt, and &gt; encoded
* as HTML entities.
*
* @method _encodeHTML
* @param s {String} the raw string
* @return String the encoded string
* @protected
*/
_encodeHTML : function (s) {
return isString(s) ?
s.replace(RE_AMP,ESC_AMP).
replace(RE_LT, ESC_LT).
replace(RE_GT, ESC_GT) :
s;
},
/**
* Clears the timeout for printing buffered messages.
*
* @method _clearTimeout
* @protected
*/
_clearTimeout : function () {
if (this._timeout) {
this._timeout.cancel();
this._timeout = null;
}
},
/**
* Event handler for clicking on the Pause checkbox to update the paused
* attribute.
*
* @method _onPauseClick
* @param e {Event} DOM event facade for the click event
* @protected
*/
_onPauseClick : function (e) {
var paused = e.target.get(CHECKED);
this.set(PAUSED,paused,{ src: Y.Widget.UI_SRC });
},
/**
* Event handler for clicking on the Clear button. Pass-through to
* <code>this.clearConsole()</code>.
*
* @method _onClearClick
* @param e {Event} DOM event facade for the click event
* @protected
*/
_onClearClick : function (e) {
this.clearConsole();
},
/**
* Setter method for logLevel attribute. Acceptable values are
* &quot;error&quot, &quot;warn&quot, &quot;info&quot, and
* Y.Console.LOG_LEVEL_ERROR, Y.Console.LOG_LEVEL_WARN,
* Y.Console.LOG_LEVEL_INFO. Any other value becomes
* Y.Console.LOG_LEVEL_INFO.
*
* @method _setLogLevel
* @param v {String|Number} String or numeric alias for the desired logLevel
* @return Number LOG_LEVEL_ERROR, _WARN, or _INFO
* @protected
*/
_setLogLevel : function (v) {
return Console._logLevels[(v+'').toLowerCase()];
},
/**
* Verifies input logLevel is one of Y.Console.LOG_LEVEL_ERROR,
* Y.Console.LOG_LEVEL_WARN, or Y.Console.LOG_LEVEL_INFO.
*
* @method _validateNewLogLevel
* @param v {Number} requested logLevel
* @return Boolean
* @protected
*/
_validateNewLogLevel : function (v) {
return (v+'').toLowerCase() in Console._logLevels;
},
/**
* Updates the UI if changes are made to any of the strings in the strings
* attribute.
*
* @method _afterStringsChange
* @param e {Event} Custom event for the attribute change
* @protected
*/
_afterStringsChange : function (e) {
var prop = e.subAttrName ? e.subAttrName.split(DOT)[1] : null,
cb = this.get(CONTENT_BOX),
before = e.prevVal,
after = e.newVal,
el;
if ((!prop || prop === TITLE) && before.title !== after.title) {
el = cb.query(DOT+C_CONSOLE_TITLE);
if (el) {
el.set(INNER_HTML,after.title);
}
}
if ((!prop || prop === PAUSE) && before.pause !== after.pause) {
el = cb.query(DOT+C_PAUSE_LABEL);
if (el) {
el.set(INNER_HTML,after.pause);
}
}
if ((!prop || prop === CLEAR) && before.clear !== after.clear) {
el = cb.query(DOT+C_CLEAR);
if (el) {
el.set('value',after.clear);
}
}
},
/**
* Updates the UI and schedules or cancels the scheduled buffer printing
* operation.
*
* @method _afterPausedChange
* @param e {Event} Custom event for the attribute change
* @protected
*/
_afterPausedChange : function (e) {
var paused = e.newVal;
if (e.src !== Y.Widget.SRC_UI) {
var node = this._foot.queryAll('input[type=checkbox].'+C_PAUSE);
if (node) {
node.set(CHECKED,paused);
}
}
if (!paused) {
this._schedulePrint();
} else if (this._timeout) {
clearTimeout(this._timeout);
this._timeout = null;
}
},
/**
* Calls this._trimOldEntries() in response to changes in the configured
* consoleLimit attribute.
*
* @method _afterConsoleLimitChange
* @param e {Event} Custom event for the attribute change
* @protected
*/
_afterConsoleLimitChange : function () {
this._trimOldEntries();
},
/**
* Responds to log events by normalizing qualifying messages and passing
* them along through the entry event for buffering etc.
*
* @method _onLogEvent
* @param msg {String} the log message
* @param cat {String} OPTIONAL the category or logLevel of the message
* @param src {String} OPTIONAL the source of the message (e.g. widget name)
* @protected
*/
_onLogEvent : function (msg,cat,src) {
if (!this.get(DISABLED) && this._isInLogLevel(msg,cat,src)) {
/* TODO: needed? */
var debug = Y.config.debug;
Y.config.debug = false;
this.fire(ENTRY, {
message : this._normalizeMessage.apply(this,arguments)
});
Y.config.debug = debug;
}
},
/**
* Clears the console, resets the startTime attribute, enables and
* unpauses the widget.
*
* @method _defResetFn
* @protected
*/
_defResetFn : function () {
this.clearConsole();
this.set(START_TIME,new Date());
this.set(DISABLED,false);
this.set(PAUSED,false);
},
/**
* Buffers incoming message objects and schedules the printing.
*
* @method _defEntryFn
* @param e {Event} The Custom event carrying the message in its payload
* @protected
*/
_defEntryFn : function (e) {
if (e.message) {
this.buffer.push(e.message);
this._schedulePrint();
}
}
});
Y.Console = Console;