src/cm/media/js/lib/yui/yui_3.10.3/build/console/console-debug.js
changeset 525 89ef5ed3c48b
equal deleted inserted replaced
524:322d0feea350 525:89ef5ed3c48b
       
     1 /*
       
     2 YUI 3.10.3 (build 2fb5187)
       
     3 Copyright 2013 Yahoo! Inc. All rights reserved.
       
     4 Licensed under the BSD License.
       
     5 http://yuilibrary.com/license/
       
     6 */
       
     7 
       
     8 YUI.add('console', function (Y, NAME) {
       
     9 
       
    10 /**
       
    11  * Console creates a visualization for messages logged through calls to a YUI
       
    12  * instance's <code>Y.log( message, category, source )</code> method.  The
       
    13  * debug versions of YUI modules will include logging statements to offer some
       
    14  * insight into the steps executed during that module's operation.  Including
       
    15  * log statements in your code will cause those messages to also appear in the
       
    16  * Console.  Use Console to aid in developing your page or application.
       
    17  *
       
    18  * Entry categories &quot;info&quot;, &quot;warn&quot;, and &quot;error&quot;
       
    19  * are also referred to as the log level, and entries are filtered against the
       
    20  * configured logLevel.
       
    21  *
       
    22  * @module console
       
    23  * @class Console
       
    24  * @extends Widget
       
    25  * @param conf {Object} Configuration object (see Configuration attributes)
       
    26  * @constructor
       
    27  */
       
    28 var getCN = Y.ClassNameManager.getClassName,
       
    29     CHECKED        = 'checked',
       
    30     CLEAR          = 'clear',
       
    31     CLICK          = 'click',
       
    32     COLLAPSED      = 'collapsed',
       
    33     CONSOLE        = 'console',
       
    34     CONTENT_BOX    = 'contentBox',
       
    35     DISABLED       = 'disabled',
       
    36     ENTRY          = 'entry',
       
    37     ERROR          = 'error',
       
    38     HEIGHT         = 'height',
       
    39     INFO           = 'info',
       
    40     LAST_TIME      = 'lastTime',
       
    41     PAUSE          = 'pause',
       
    42     PAUSED         = 'paused',
       
    43     RESET          = 'reset',
       
    44     START_TIME     = 'startTime',
       
    45     TITLE          = 'title',
       
    46     WARN           = 'warn',
       
    47 
       
    48     DOT = '.',
       
    49 
       
    50     C_BUTTON           = getCN(CONSOLE,'button'),
       
    51     C_CHECKBOX         = getCN(CONSOLE,'checkbox'),
       
    52     C_CLEAR            = getCN(CONSOLE,CLEAR),
       
    53     C_COLLAPSE         = getCN(CONSOLE,'collapse'),
       
    54     C_COLLAPSED        = getCN(CONSOLE,COLLAPSED),
       
    55     C_CONSOLE_CONTROLS = getCN(CONSOLE,'controls'),
       
    56     C_CONSOLE_HD       = getCN(CONSOLE,'hd'),
       
    57     C_CONSOLE_BD       = getCN(CONSOLE,'bd'),
       
    58     C_CONSOLE_FT       = getCN(CONSOLE,'ft'),
       
    59     C_CONSOLE_TITLE    = getCN(CONSOLE,TITLE),
       
    60     C_ENTRY            = getCN(CONSOLE,ENTRY),
       
    61     C_ENTRY_CAT        = getCN(CONSOLE,ENTRY,'cat'),
       
    62     C_ENTRY_CONTENT    = getCN(CONSOLE,ENTRY,'content'),
       
    63     C_ENTRY_META       = getCN(CONSOLE,ENTRY,'meta'),
       
    64     C_ENTRY_SRC        = getCN(CONSOLE,ENTRY,'src'),
       
    65     C_ENTRY_TIME       = getCN(CONSOLE,ENTRY,'time'),
       
    66     C_PAUSE            = getCN(CONSOLE,PAUSE),
       
    67     C_PAUSE_LABEL      = getCN(CONSOLE,PAUSE,'label'),
       
    68 
       
    69     RE_INLINE_SOURCE = /^(\S+)\s/,
       
    70     RE_AMP = /&(?!#?[a-z0-9]+;)/g,
       
    71     RE_GT  = />/g,
       
    72     RE_LT  = /</g,
       
    73 
       
    74     ESC_AMP = '&#38;',
       
    75     ESC_GT  = '&#62;',
       
    76     ESC_LT  = '&#60;',
       
    77     
       
    78     ENTRY_TEMPLATE_STR =
       
    79         '<div class="{entry_class} {cat_class} {src_class}">'+
       
    80             '<p class="{entry_meta_class}">'+
       
    81                 '<span class="{entry_src_class}">'+
       
    82                     '{sourceAndDetail}'+
       
    83                 '</span>'+
       
    84                 '<span class="{entry_cat_class}">'+
       
    85                     '{category}</span>'+
       
    86                 '<span class="{entry_time_class}">'+
       
    87                     ' {totalTime}ms (+{elapsedTime}) {localTime}'+
       
    88                 '</span>'+
       
    89             '</p>'+
       
    90             '<pre class="{entry_content_class}">{message}</pre>'+
       
    91         '</div>',
       
    92 
       
    93     L = Y.Lang,
       
    94     create     = Y.Node.create,
       
    95     isNumber   = L.isNumber,
       
    96     isString   = L.isString,
       
    97     merge      = Y.merge,
       
    98     substitute = Y.Lang.sub;
       
    99     
       
   100 
       
   101 function Console() {
       
   102     Console.superclass.constructor.apply(this,arguments);
       
   103 }
       
   104 
       
   105 Y.Console = Y.extend(Console, Y.Widget,
       
   106 
       
   107 // Y.Console prototype
       
   108 {
       
   109     /**
       
   110      * Category to prefix all event subscriptions to allow for ease of detach
       
   111      * during destroy.
       
   112      *
       
   113      * @property _evtCat
       
   114      * @type string
       
   115      * @protected
       
   116      */
       
   117     _evtCat : null,
       
   118 
       
   119     /**
       
   120      * Reference to the Node instance containing the header contents.
       
   121      *
       
   122      * @property _head
       
   123      * @type Node
       
   124      * @default null
       
   125      * @protected
       
   126      */
       
   127     _head    : null,
       
   128 
       
   129     /**
       
   130      * Reference to the Node instance that will house the console messages.
       
   131      *
       
   132      * @property _body
       
   133      * @type Node
       
   134      * @default null
       
   135      * @protected
       
   136      */
       
   137     _body    : null,
       
   138 
       
   139     /**
       
   140      * Reference to the Node instance containing the footer contents.
       
   141      *
       
   142      * @property _foot
       
   143      * @type Node
       
   144      * @default null
       
   145      * @protected
       
   146      */
       
   147     _foot    : null,
       
   148 
       
   149     /**
       
   150      * Holds the object API returned from <code>Y.later</code> for the print
       
   151      * loop interval.
       
   152      *
       
   153      * @property _printLoop
       
   154      * @type Object
       
   155      * @default null
       
   156      * @protected
       
   157      */
       
   158     _printLoop : null,
       
   159 
       
   160     /**
       
   161      * Array of normalized message objects awaiting printing.
       
   162      *
       
   163      * @property buffer
       
   164      * @type Array
       
   165      * @default null
       
   166      * @protected
       
   167      */
       
   168     buffer   : null,
       
   169 
       
   170     /**
       
   171      * Wrapper for <code>Y.log</code>.
       
   172      *
       
   173      * @method log
       
   174      * @param arg* {MIXED} (all arguments passed through to <code>Y.log</code>)
       
   175      * @chainable
       
   176      */
       
   177     log : function () {
       
   178         Y.log.apply(Y,arguments);
       
   179 
       
   180         return this;
       
   181     },
       
   182 
       
   183     /**
       
   184      * Clear the console of messages and flush the buffer of pending messages.
       
   185      *
       
   186      * @method clearConsole
       
   187      * @chainable
       
   188      */
       
   189     clearConsole : function () {
       
   190         // TODO: clear event listeners from console contents
       
   191         this._body.empty();
       
   192 
       
   193         this._cancelPrintLoop();
       
   194 
       
   195         this.buffer = [];
       
   196 
       
   197         return this;
       
   198     },
       
   199 
       
   200     /**
       
   201      * Clears the console and resets internal timers.
       
   202      *
       
   203      * @method reset
       
   204      * @chainable
       
   205      */
       
   206     reset : function () {
       
   207         this.fire(RESET);
       
   208         
       
   209         return this;
       
   210     },
       
   211 
       
   212     /**
       
   213      * Collapses the body and footer.
       
   214      *
       
   215      * @method collapse
       
   216      * @chainable
       
   217      */
       
   218     collapse : function () {
       
   219         this.set(COLLAPSED, true);
       
   220 
       
   221         return this;
       
   222     },
       
   223 
       
   224     /**
       
   225      * Expands the body and footer if collapsed.
       
   226      *
       
   227      * @method expand
       
   228      * @chainable
       
   229      */
       
   230     expand : function () {
       
   231         this.set(COLLAPSED, false);
       
   232 
       
   233         return this;
       
   234     },
       
   235 
       
   236     /**
       
   237      * Outputs buffered messages to the console UI.  This is typically called
       
   238      * from a scheduled interval until the buffer is empty (referred to as the
       
   239      * print loop).  The number of buffered messages output to the Console is
       
   240      * limited to the number provided as an argument.  If no limit is passed,
       
   241      * all buffered messages are rendered.
       
   242      * 
       
   243      * @method printBuffer
       
   244      * @param limit {Number} (optional) max number of buffered entries to write
       
   245      * @chainable
       
   246      */
       
   247     printBuffer: function (limit) {
       
   248         var messages    = this.buffer,
       
   249             debug       = Y.config.debug,
       
   250             entries     = [],
       
   251             consoleLimit= this.get('consoleLimit'),
       
   252             newestOnTop = this.get('newestOnTop'),
       
   253             anchor      = newestOnTop ? this._body.get('firstChild') : null,
       
   254             i;
       
   255 
       
   256         if (messages.length > consoleLimit) {
       
   257             messages.splice(0, messages.length - consoleLimit);
       
   258         }
       
   259 
       
   260         limit = Math.min(messages.length, (limit || messages.length));
       
   261         
       
   262         // turn off logging system
       
   263         Y.config.debug = false;
       
   264 
       
   265         if (!this.get(PAUSED) && this.get('rendered')) {
       
   266 
       
   267             for (i = 0; i < limit && messages.length; ++i) {
       
   268                 entries[i] = this._createEntryHTML(messages.shift());
       
   269             }
       
   270 
       
   271             if (!messages.length) {
       
   272                 this._cancelPrintLoop();
       
   273             }
       
   274 
       
   275             if (entries.length) {
       
   276                 if (newestOnTop) {
       
   277                     entries.reverse();
       
   278                 }
       
   279 
       
   280                 this._body.insertBefore(create(entries.join('')), anchor);
       
   281 
       
   282                 if (this.get('scrollIntoView')) {
       
   283                     this.scrollToLatest();
       
   284                 }
       
   285 
       
   286                 this._trimOldEntries();
       
   287             }
       
   288         }
       
   289 
       
   290         // restore logging system
       
   291         Y.config.debug = debug;
       
   292 
       
   293         return this;
       
   294     },
       
   295 
       
   296     
       
   297     /**
       
   298      * Constructor code.  Set up the buffer and entry template, publish
       
   299      * internal events, and subscribe to the configured logEvent.
       
   300      * 
       
   301      * @method initializer
       
   302      * @protected
       
   303      */
       
   304     initializer : function () {
       
   305         this._evtCat = Y.stamp(this) + '|';
       
   306 
       
   307         this.buffer = [];
       
   308 
       
   309         this.get('logSource').on(this._evtCat +
       
   310             this.get('logEvent'),Y.bind("_onLogEvent",this));
       
   311 
       
   312         /**
       
   313          * Transfers a received message to the print loop buffer.  Default
       
   314          * behavior defined in _defEntryFn.
       
   315          *
       
   316          * @event entry
       
   317          * @param event {Event.Facade} An Event Facade object with the following attribute specific properties added:
       
   318          *  <dl>
       
   319          *      <dt>message</dt>
       
   320          *          <dd>The message data normalized into an object literal (see _normalizeMessage)</dd>
       
   321          *  </dl>
       
   322          * @preventable _defEntryFn
       
   323          */
       
   324         this.publish(ENTRY, { defaultFn: this._defEntryFn });
       
   325 
       
   326         /**
       
   327          * Triggers the reset behavior via the default logic in _defResetFn.
       
   328          *
       
   329          * @event reset
       
   330          * @param event {Event.Facade} Event Facade object
       
   331          * @preventable _defResetFn
       
   332          */
       
   333         this.publish(RESET, { defaultFn: this._defResetFn });
       
   334 
       
   335         this.after('rendered', this._schedulePrint);
       
   336     },
       
   337 
       
   338     /**
       
   339      * Tears down the instance, flushing event subscriptions and purging the UI.
       
   340      *
       
   341      * @method destructor
       
   342      * @protected
       
   343      */
       
   344     destructor : function () {
       
   345         var bb = this.get('boundingBox');
       
   346 
       
   347         this._cancelPrintLoop();
       
   348 
       
   349         this.get('logSource').detach(this._evtCat + '*');
       
   350         
       
   351         bb.purge(true);
       
   352     },
       
   353 
       
   354     /**
       
   355      * Generate the Console UI.
       
   356      *
       
   357      * @method renderUI
       
   358      * @protected
       
   359      */
       
   360     renderUI : function () {
       
   361         this._initHead();
       
   362         this._initBody();
       
   363         this._initFoot();
       
   364 
       
   365         // Apply positioning to the bounding box if appropriate
       
   366         var style = this.get('style');
       
   367         if (style !== 'block') {
       
   368             this.get('boundingBox').addClass(this.getClassName(style));
       
   369         }
       
   370     },
       
   371 
       
   372     /**
       
   373      * Sync the UI state to the current attribute state.
       
   374      *
       
   375      * @method syncUI
       
   376      */
       
   377     syncUI : function () {
       
   378         this._uiUpdatePaused(this.get(PAUSED));
       
   379         this._uiUpdateCollapsed(this.get(COLLAPSED));
       
   380         this._uiSetHeight(this.get(HEIGHT));
       
   381     },
       
   382 
       
   383     /**
       
   384      * Set up event listeners to wire up the UI to the internal state.
       
   385      *
       
   386      * @method bindUI
       
   387      * @protected
       
   388      */
       
   389     bindUI : function () {
       
   390         this.get(CONTENT_BOX).one('button.'+C_COLLAPSE).
       
   391             on(CLICK,this._onCollapseClick,this);
       
   392 
       
   393         this.get(CONTENT_BOX).one('input[type=checkbox].'+C_PAUSE).
       
   394             on(CLICK,this._onPauseClick,this);
       
   395 
       
   396         this.get(CONTENT_BOX).one('button.'+C_CLEAR).
       
   397             on(CLICK,this._onClearClick,this);
       
   398 
       
   399         // Attribute changes
       
   400         this.after(this._evtCat + 'stringsChange',
       
   401             this._afterStringsChange);
       
   402         this.after(this._evtCat + 'pausedChange',
       
   403             this._afterPausedChange);
       
   404         this.after(this._evtCat + 'consoleLimitChange',
       
   405             this._afterConsoleLimitChange);
       
   406         this.after(this._evtCat + 'collapsedChange',
       
   407             this._afterCollapsedChange);
       
   408     },
       
   409 
       
   410     
       
   411     /**
       
   412      * Create the DOM structure for the header elements.
       
   413      *
       
   414      * @method _initHead
       
   415      * @protected
       
   416      */
       
   417     _initHead : function () {
       
   418         var cb   = this.get(CONTENT_BOX),
       
   419             info = merge(Console.CHROME_CLASSES, {
       
   420                         str_collapse : this.get('strings.collapse'),
       
   421                         str_title : this.get('strings.title')
       
   422                     });
       
   423 
       
   424         this._head = create(substitute(Console.HEADER_TEMPLATE,info));
       
   425 
       
   426         cb.insertBefore(this._head,cb.get('firstChild'));
       
   427     },
       
   428 
       
   429     /**
       
   430      * Create the DOM structure for the console body&#8212;where messages are
       
   431      * rendered.
       
   432      *
       
   433      * @method _initBody
       
   434      * @protected
       
   435      */
       
   436     _initBody : function () {
       
   437         this._body = create(substitute(
       
   438                             Console.BODY_TEMPLATE,
       
   439                             Console.CHROME_CLASSES));
       
   440 
       
   441         this.get(CONTENT_BOX).appendChild(this._body);
       
   442     },
       
   443 
       
   444     /**
       
   445      * Create the DOM structure for the footer elements.
       
   446      *
       
   447      * @method _initFoot
       
   448      * @protected
       
   449      */
       
   450     _initFoot : function () {
       
   451         var info = merge(Console.CHROME_CLASSES, {
       
   452                 id_guid   : Y.guid(),
       
   453                 str_pause : this.get('strings.pause'),
       
   454                 str_clear : this.get('strings.clear')
       
   455             });
       
   456 
       
   457         this._foot = create(substitute(Console.FOOTER_TEMPLATE,info));
       
   458 
       
   459         this.get(CONTENT_BOX).appendChild(this._foot);
       
   460     },
       
   461 
       
   462     /**
       
   463      * Determine if incoming log messages are within the configured logLevel
       
   464      * to be buffered for printing.
       
   465      *
       
   466      * @method _isInLogLevel
       
   467      * @protected
       
   468      */
       
   469     _isInLogLevel : function (e) {
       
   470         var cat = e.cat, lvl = this.get('logLevel');
       
   471 
       
   472         if (lvl !== INFO) {
       
   473             cat = cat || INFO;
       
   474 
       
   475             if (isString(cat)) {
       
   476                 cat = cat.toLowerCase();
       
   477             }
       
   478 
       
   479             if ((cat === WARN && lvl === ERROR) ||
       
   480                 (cat === INFO && lvl !== INFO)) {
       
   481                 return false;
       
   482             }
       
   483         }
       
   484 
       
   485         return true;
       
   486     },
       
   487 
       
   488     /**
       
   489      * Create a log entry message from the inputs including the following keys:
       
   490      * <ul>
       
   491      *     <li>time - this moment</li>
       
   492      *     <li>message - leg message</li>
       
   493      *     <li>category - logLevel or custom category for the message</li>
       
   494      *     <li>source - when provided, the widget or util calling Y.log</li>
       
   495      *     <li>sourceAndDetail - same as source but can include instance info</li>
       
   496      *     <li>localTime - readable version of time</li>
       
   497      *     <li>elapsedTime - ms since last entry</li>
       
   498      *     <li>totalTime - ms since Console was instantiated or reset</li>
       
   499      * </ul>
       
   500      *
       
   501      * @method _normalizeMessage
       
   502      * @param e {Event} custom event containing the log message
       
   503      * @return Object the message object
       
   504      * @protected
       
   505      */
       
   506     _normalizeMessage : function (e) {
       
   507 
       
   508         var msg = e.msg,
       
   509             cat = e.cat,
       
   510             src = e.src,
       
   511 
       
   512             m = {
       
   513                 time            : new Date(),
       
   514                 message         : msg,
       
   515                 category        : cat || this.get('defaultCategory'),
       
   516                 sourceAndDetail : src || this.get('defaultSource'),
       
   517                 source          : null,
       
   518                 localTime       : null,
       
   519                 elapsedTime     : null,
       
   520                 totalTime       : null
       
   521             };
       
   522 
       
   523         // Extract m.source "Foo" from m.sourceAndDetail "Foo bar baz"
       
   524         m.source          = RE_INLINE_SOURCE.test(m.sourceAndDetail) ?
       
   525                                 RegExp.$1 : m.sourceAndDetail;
       
   526         m.localTime       = m.time.toLocaleTimeString ? 
       
   527                             m.time.toLocaleTimeString() : (m.time + '');
       
   528         m.elapsedTime     = m.time - this.get(LAST_TIME);
       
   529         m.totalTime       = m.time - this.get(START_TIME);
       
   530 
       
   531         this._set(LAST_TIME,m.time);
       
   532 
       
   533         return m;
       
   534     },
       
   535 
       
   536     /**
       
   537      * Sets an interval for buffered messages to be output to the console.
       
   538      *
       
   539      * @method _schedulePrint
       
   540      * @protected
       
   541      */
       
   542     _schedulePrint : function () {
       
   543         if (!this._printLoop && !this.get(PAUSED) && this.get('rendered')) {
       
   544             this._printLoop = Y.later(
       
   545                                 this.get('printTimeout'),
       
   546                                 this, this.printBuffer,
       
   547                                 this.get('printLimit'), true);
       
   548         }
       
   549     },
       
   550 
       
   551     /**
       
   552      * Translates message meta into the markup for a console entry.
       
   553      *
       
   554      * @method _createEntryHTML
       
   555      * @param m {Object} object literal containing normalized message metadata
       
   556      * @return String
       
   557      * @protected
       
   558      */
       
   559     _createEntryHTML : function (m) {
       
   560         m = merge(
       
   561                 this._htmlEscapeMessage(m),
       
   562                 Console.ENTRY_CLASSES,
       
   563                 {
       
   564                     cat_class : this.getClassName(ENTRY,m.category),
       
   565                     src_class : this.getClassName(ENTRY,m.source)
       
   566                 });
       
   567 
       
   568         return this.get('entryTemplate').replace(/\{(\w+)\}/g,
       
   569             function (_,token) {
       
   570                 return token in m ? m[token] : '';
       
   571             });
       
   572     },
       
   573 
       
   574     /**
       
   575      * Scrolls to the most recent entry
       
   576      *
       
   577      * @method scrollToLatest
       
   578      * @chainable
       
   579      */
       
   580     scrollToLatest : function () {
       
   581         var scrollTop = this.get('newestOnTop') ?
       
   582                             0 :
       
   583                             this._body.get('scrollHeight');
       
   584 
       
   585         this._body.set('scrollTop', scrollTop);
       
   586     },
       
   587 
       
   588     /**
       
   589      * Performs HTML escaping on strings in the message object.
       
   590      *
       
   591      * @method _htmlEscapeMessage
       
   592      * @param m {Object} the normalized message object
       
   593      * @return Object the message object with proper escapement
       
   594      * @protected
       
   595      */
       
   596     _htmlEscapeMessage : function (m) {
       
   597         m.message         = this._encodeHTML(m.message);
       
   598         m.source          = this._encodeHTML(m.source);
       
   599         m.sourceAndDetail = this._encodeHTML(m.sourceAndDetail);
       
   600         m.category        = this._encodeHTML(m.category);
       
   601 
       
   602         return m;
       
   603     },
       
   604 
       
   605     /**
       
   606      * Removes the oldest message entries from the UI to maintain the limit
       
   607      * specified in the consoleLimit configuration.
       
   608      *
       
   609      * @method _trimOldEntries
       
   610      * @protected
       
   611      */
       
   612     _trimOldEntries : function () {
       
   613         // Turn off the logging system for the duration of this operation
       
   614         // to prevent an infinite loop
       
   615         Y.config.debug = false;
       
   616 
       
   617         var bd = this._body,
       
   618             limit = this.get('consoleLimit'),
       
   619             debug = Y.config.debug,
       
   620             entries,e,i,l;
       
   621 
       
   622         if (bd) {
       
   623             entries = bd.all(DOT+C_ENTRY);
       
   624             l = entries.size() - limit;
       
   625 
       
   626             if (l > 0) {
       
   627                 if (this.get('newestOnTop')) {
       
   628                     i = limit;
       
   629                     l = entries.size();
       
   630                 } else {
       
   631                     i = 0;
       
   632                 }
       
   633 
       
   634                 this._body.setStyle('display','none');
       
   635 
       
   636                 for (;i < l; ++i) {
       
   637                     e = entries.item(i);
       
   638                     if (e) {
       
   639                         e.remove();
       
   640                     }
       
   641                 }
       
   642 
       
   643                 this._body.setStyle('display','');
       
   644             }
       
   645 
       
   646         }
       
   647 
       
   648         Y.config.debug = debug;
       
   649     },
       
   650 
       
   651     /**
       
   652      * Returns the input string with ampersands (&amp;), &lt, and &gt; encoded
       
   653      * as HTML entities.
       
   654      *
       
   655      * @method _encodeHTML
       
   656      * @param s {String} the raw string
       
   657      * @return String the encoded string
       
   658      * @protected
       
   659      */
       
   660     _encodeHTML : function (s) {
       
   661         return isString(s) ?
       
   662             s.replace(RE_AMP,ESC_AMP).
       
   663               replace(RE_LT, ESC_LT).
       
   664               replace(RE_GT, ESC_GT) :
       
   665             s;
       
   666     },
       
   667 
       
   668     /**
       
   669      * Clears the timeout for printing buffered messages.
       
   670      *
       
   671      * @method _cancelPrintLoop
       
   672      * @protected
       
   673      */
       
   674     _cancelPrintLoop : function () {
       
   675         if (this._printLoop) {
       
   676             this._printLoop.cancel();
       
   677             this._printLoop = null;
       
   678         }
       
   679     },
       
   680 
       
   681     /**
       
   682      * Validates input value for style attribute.  Accepts only values 'inline',
       
   683      * 'block', and 'separate'.
       
   684      *
       
   685      * @method _validateStyle
       
   686      * @param style {String} the proposed value
       
   687      * @return {Boolean} pass/fail
       
   688      * @protected
       
   689      */
       
   690     _validateStyle : function (style) {
       
   691         return style === 'inline' || style === 'block' || style === 'separate';
       
   692     },
       
   693 
       
   694     /**
       
   695      * Event handler for clicking on the Pause checkbox to update the paused
       
   696      * attribute.
       
   697      *
       
   698      * @method _onPauseClick
       
   699      * @param e {Event} DOM event facade for the click event
       
   700      * @protected
       
   701      */
       
   702     _onPauseClick : function (e) {
       
   703         this.set(PAUSED,e.target.get(CHECKED));
       
   704     },
       
   705 
       
   706     /**
       
   707      * Event handler for clicking on the Clear button.  Pass-through to
       
   708      * <code>this.clearConsole()</code>.
       
   709      *
       
   710      * @method _onClearClick
       
   711      * @param e {Event} DOM event facade for the click event
       
   712      * @protected
       
   713      */
       
   714     _onClearClick : function (e) {
       
   715         this.clearConsole();
       
   716     },
       
   717 
       
   718     /**
       
   719      * Event handler for clicking on the Collapse/Expand button. Sets the
       
   720      * &quot;collapsed&quot; attribute accordingly.
       
   721      *
       
   722      * @method _onCollapseClick
       
   723      * @param e {Event} DOM event facade for the click event
       
   724      * @protected
       
   725      */
       
   726     _onCollapseClick : function (e) {
       
   727         this.set(COLLAPSED, !this.get(COLLAPSED));
       
   728     },
       
   729 
       
   730 
       
   731     /**
       
   732      * Validator for logSource attribute.
       
   733      *
       
   734      * @method _validateLogSource
       
   735      * @param v {Object} the desired logSource
       
   736      * @return {Boolean} true if the input is an object with an <code>on</code>
       
   737      *                   method
       
   738      * @protected
       
   739      */
       
   740     _validateLogSource: function (v) {
       
   741         return v && Y.Lang.isFunction(v.on);
       
   742     },
       
   743 
       
   744     /**
       
   745      * Setter method for logLevel attribute.  Acceptable values are
       
   746      * &quot;error&quot, &quot;warn&quot, and &quot;info&quot (case
       
   747      * insensitive).  Other values are treated as &quot;info&quot;.
       
   748      *
       
   749      * @method _setLogLevel
       
   750      * @param v {String} the desired log level
       
   751      * @return String One of Console.LOG_LEVEL_INFO, _WARN, or _ERROR
       
   752      * @protected
       
   753      */
       
   754     _setLogLevel : function (v) {
       
   755         if (isString(v)) {
       
   756             v = v.toLowerCase();
       
   757         }
       
   758         
       
   759         return (v === WARN || v === ERROR) ? v : INFO;
       
   760     },
       
   761 
       
   762     /**
       
   763      * Getter method for useBrowserConsole attribute.  Just a pass through to
       
   764      * the YUI instance configuration setting.
       
   765      *
       
   766      * @method _getUseBrowserConsole
       
   767      * @return {Boolean} or null if logSource is not a YUI instance
       
   768      * @protected
       
   769      */
       
   770     _getUseBrowserConsole: function () {
       
   771         var logSource = this.get('logSource');
       
   772         return logSource instanceof YUI ?
       
   773             logSource.config.useBrowserConsole : null;
       
   774     },
       
   775 
       
   776     /**
       
   777      * Setter method for useBrowserConsole attributes.  Only functional if the
       
   778      * logSource attribute points to a YUI instance.  Passes the value down to
       
   779      * the YUI instance.  NOTE: multiple Console instances cannot maintain
       
   780      * independent useBrowserConsole values, since it is just a pass through to
       
   781      * the YUI instance configuration.
       
   782      *
       
   783      * @method _setUseBrowserConsole
       
   784      * @param v {Boolean} false to disable browser console printing (default)
       
   785      * @return {Boolean} true|false if logSource is a YUI instance
       
   786      * @protected
       
   787      */
       
   788     _setUseBrowserConsole: function (v) {
       
   789         var logSource = this.get('logSource');
       
   790         if (logSource instanceof YUI) {
       
   791             v = !!v;
       
   792             logSource.config.useBrowserConsole = v;
       
   793             return v;
       
   794         } else {
       
   795             return Y.Attribute.INVALID_VALUE;
       
   796         }
       
   797     },
       
   798 
       
   799     /**
       
   800      * Set the height of the Console container.  Set the body height to the
       
   801      * difference between the configured height and the calculated heights of
       
   802      * the header and footer.
       
   803      * Overrides Widget.prototype._uiSetHeight.
       
   804      *
       
   805      * @method _uiSetHeight
       
   806      * @param v {String|Number} the new height
       
   807      * @protected
       
   808      */
       
   809     _uiSetHeight : function (v) {
       
   810         Console.superclass._uiSetHeight.apply(this,arguments);
       
   811 
       
   812         if (this._head && this._foot) {
       
   813             var h = this.get('boundingBox').get('offsetHeight') -
       
   814                     this._head.get('offsetHeight') -
       
   815                     this._foot.get('offsetHeight');
       
   816 
       
   817             this._body.setStyle(HEIGHT,h+'px');
       
   818         }
       
   819     },
       
   820 
       
   821     /**
       
   822      * Over-ride default content box sizing to do nothing, since we're sizing
       
   823      * the body section to fill out height ourselves.
       
   824      * 
       
   825      * @method _uiSizeCB
       
   826      * @protected
       
   827      */
       
   828     _uiSizeCB : function() {
       
   829         // Do Nothing. Ideally want to move to Widget-StdMod, which accounts for
       
   830         // _uiSizeCB        
       
   831     },
       
   832 
       
   833     /**
       
   834      * Updates the UI if changes are made to any of the strings in the strings
       
   835      * attribute.
       
   836      *
       
   837      * @method _afterStringsChange
       
   838      * @param e {Event} Custom event for the attribute change
       
   839      * @protected
       
   840      */
       
   841     _afterStringsChange : function (e) {
       
   842         var prop   = e.subAttrName ? e.subAttrName.split(DOT)[1] : null,
       
   843             cb     = this.get(CONTENT_BOX),
       
   844             before = e.prevVal,
       
   845             after  = e.newVal;
       
   846 
       
   847         if ((!prop || prop === TITLE) && before.title !== after.title) {
       
   848             cb.all(DOT+C_CONSOLE_TITLE).setHTML(after.title);
       
   849         }
       
   850 
       
   851         if ((!prop || prop === PAUSE) && before.pause !== after.pause) {
       
   852             cb.all(DOT+C_PAUSE_LABEL).setHTML(after.pause);
       
   853         }
       
   854 
       
   855         if ((!prop || prop === CLEAR) && before.clear !== after.clear) {
       
   856             cb.all(DOT+C_CLEAR).set('value',after.clear);
       
   857         }
       
   858     },
       
   859 
       
   860     /**
       
   861      * Updates the UI and schedules or cancels the print loop.
       
   862      *
       
   863      * @method _afterPausedChange
       
   864      * @param e {Event} Custom event for the attribute change
       
   865      * @protected
       
   866      */
       
   867     _afterPausedChange : function (e) {
       
   868         var paused = e.newVal;
       
   869 
       
   870         if (e.src !== Y.Widget.SRC_UI) {
       
   871             this._uiUpdatePaused(paused);
       
   872         }
       
   873 
       
   874         if (!paused) {
       
   875             this._schedulePrint();
       
   876         } else if (this._printLoop) {
       
   877             this._cancelPrintLoop();
       
   878         }
       
   879     },
       
   880 
       
   881     /**
       
   882      * Checks or unchecks the paused checkbox
       
   883      *
       
   884      * @method _uiUpdatePaused
       
   885      * @param on {Boolean} the new checked state
       
   886      * @protected
       
   887      */
       
   888     _uiUpdatePaused : function (on) {
       
   889         var node = this._foot.all('input[type=checkbox].'+C_PAUSE);
       
   890 
       
   891         if (node) {
       
   892             node.set(CHECKED,on);
       
   893         }
       
   894     },
       
   895 
       
   896     /**
       
   897      * Calls this._trimOldEntries() in response to changes in the configured
       
   898      * consoleLimit attribute.
       
   899      * 
       
   900      * @method _afterConsoleLimitChange
       
   901      * @param e {Event} Custom event for the attribute change
       
   902      * @protected
       
   903      */
       
   904     _afterConsoleLimitChange : function () {
       
   905         this._trimOldEntries();
       
   906     },
       
   907 
       
   908 
       
   909     /**
       
   910      * Updates the className of the contentBox, which should trigger CSS to
       
   911      * hide or show the body and footer sections depending on the new value.
       
   912      *
       
   913      * @method _afterCollapsedChange
       
   914      * @param e {Event} Custom event for the attribute change
       
   915      * @protected
       
   916      */
       
   917     _afterCollapsedChange : function (e) {
       
   918         this._uiUpdateCollapsed(e.newVal);
       
   919     },
       
   920 
       
   921     /**
       
   922      * Updates the UI to reflect the new Collapsed state
       
   923      *
       
   924      * @method _uiUpdateCollapsed
       
   925      * @param v {Boolean} true for collapsed, false for expanded
       
   926      * @protected
       
   927      */
       
   928     _uiUpdateCollapsed : function (v) {
       
   929         var bb     = this.get('boundingBox'),
       
   930             button = bb.all('button.'+C_COLLAPSE),
       
   931             method = v ? 'addClass' : 'removeClass',
       
   932             str    = this.get('strings.'+(v ? 'expand' : 'collapse'));
       
   933 
       
   934         bb[method](C_COLLAPSED);
       
   935 
       
   936         if (button) {
       
   937             button.setHTML(str);
       
   938         }
       
   939 
       
   940         this._uiSetHeight(v ? this._head.get('offsetHeight'): this.get(HEIGHT));
       
   941     },
       
   942 
       
   943     /**
       
   944      * Makes adjustments to the UI if needed when the Console is hidden or shown
       
   945      *
       
   946      * @method _afterVisibleChange
       
   947      * @param e {Event} the visibleChange event
       
   948      * @protected
       
   949      */
       
   950     _afterVisibleChange : function (e) {
       
   951         Console.superclass._afterVisibleChange.apply(this,arguments);
       
   952 
       
   953         this._uiUpdateFromHideShow(e.newVal);
       
   954     },
       
   955 
       
   956     /**
       
   957      * Recalculates dimensions and updates appropriately when shown
       
   958      *
       
   959      * @method _uiUpdateFromHideShow
       
   960      * @param v {Boolean} true for visible, false for hidden
       
   961      * @protected
       
   962      */
       
   963     _uiUpdateFromHideShow : function (v) {
       
   964         if (v) {
       
   965             this._uiSetHeight(this.get(HEIGHT));
       
   966         }
       
   967     },
       
   968 
       
   969     /**
       
   970      * Responds to log events by normalizing qualifying messages and passing
       
   971      * them along through the entry event for buffering etc.
       
   972      * 
       
   973      * @method _onLogEvent
       
   974      * @param msg {String} the log message
       
   975      * @param cat {String} OPTIONAL the category or logLevel of the message
       
   976      * @param src {String} OPTIONAL the source of the message (e.g. widget name)
       
   977      * @protected
       
   978      */
       
   979     _onLogEvent : function (e) {
       
   980 
       
   981         if (!this.get(DISABLED) && this._isInLogLevel(e)) {
       
   982 
       
   983             var debug = Y.config.debug;
       
   984 
       
   985             /* TODO: needed? */
       
   986             Y.config.debug = false;
       
   987 
       
   988             this.fire(ENTRY, {
       
   989                 message : this._normalizeMessage(e)
       
   990             });
       
   991 
       
   992             Y.config.debug = debug;
       
   993         }
       
   994     },
       
   995 
       
   996     /**
       
   997      * Clears the console, resets the startTime attribute, enables and
       
   998      * unpauses the widget.
       
   999      *
       
  1000      * @method _defResetFn
       
  1001      * @protected
       
  1002      */
       
  1003     _defResetFn : function () {
       
  1004         this.clearConsole();
       
  1005         this.set(START_TIME,new Date());
       
  1006         this.set(DISABLED,false);
       
  1007         this.set(PAUSED,false);
       
  1008     },
       
  1009 
       
  1010     /**
       
  1011      * Buffers incoming message objects and schedules the printing.
       
  1012      *
       
  1013      * @method _defEntryFn
       
  1014      * @param e {Event} The Custom event carrying the message in its payload
       
  1015      * @protected
       
  1016      */
       
  1017     _defEntryFn : function (e) {
       
  1018         if (e.message) {
       
  1019             this.buffer.push(e.message);
       
  1020             this._schedulePrint();
       
  1021         }
       
  1022     }
       
  1023 
       
  1024 },
       
  1025 
       
  1026 // Y.Console static properties
       
  1027 {
       
  1028     /**
       
  1029      * The identity of the widget.
       
  1030      *
       
  1031      * @property NAME
       
  1032      * @type String
       
  1033      * @static
       
  1034      */
       
  1035     NAME : CONSOLE,
       
  1036 
       
  1037     /**
       
  1038      * Static identifier for logLevel configuration setting to allow all
       
  1039      * incoming messages to generate Console entries.
       
  1040      *
       
  1041      * @property LOG_LEVEL_INFO
       
  1042      * @type String
       
  1043      * @static
       
  1044      */
       
  1045     LOG_LEVEL_INFO  : INFO,
       
  1046 
       
  1047     /**
       
  1048      * Static identifier for logLevel configuration setting to allow only
       
  1049      * incoming messages of logLevel &quot;warn&quot; or &quot;error&quot;
       
  1050      * to generate Console entries.
       
  1051      *
       
  1052      * @property LOG_LEVEL_WARN
       
  1053      * @type String
       
  1054      * @static
       
  1055      */
       
  1056     LOG_LEVEL_WARN  : WARN,
       
  1057 
       
  1058     /**
       
  1059      * Static identifier for logLevel configuration setting to allow only
       
  1060      * incoming messages of logLevel &quot;error&quot; to generate
       
  1061      * Console entries.
       
  1062      *
       
  1063      * @property LOG_LEVEL_ERROR
       
  1064      * @type String
       
  1065      * @static
       
  1066      */
       
  1067     LOG_LEVEL_ERROR : ERROR,
       
  1068 
       
  1069     /**
       
  1070      * Map (object) of classNames used to populate the placeholders in the
       
  1071      * Console.ENTRY_TEMPLATE markup when rendering a new Console entry.
       
  1072      *
       
  1073      * <p>By default, the keys contained in the object are:</p>
       
  1074      * <ul>
       
  1075      *    <li>entry_class</li>
       
  1076      *    <li>entry_meta_class</li>
       
  1077      *    <li>entry_cat_class</li>
       
  1078      *    <li>entry_src_class</li>
       
  1079      *    <li>entry_time_class</li>
       
  1080      *    <li>entry_content_class</li>
       
  1081      * </ul>
       
  1082      *
       
  1083      * @property ENTRY_CLASSES
       
  1084      * @type Object
       
  1085      * @static
       
  1086      */
       
  1087     ENTRY_CLASSES   : {
       
  1088         entry_class         : C_ENTRY,
       
  1089         entry_meta_class    : C_ENTRY_META,
       
  1090         entry_cat_class     : C_ENTRY_CAT,
       
  1091         entry_src_class     : C_ENTRY_SRC,
       
  1092         entry_time_class    : C_ENTRY_TIME,
       
  1093         entry_content_class : C_ENTRY_CONTENT
       
  1094     },
       
  1095 
       
  1096     /**
       
  1097      * Map (object) of classNames used to populate the placeholders in the
       
  1098      * Console.HEADER_TEMPLATE, Console.BODY_TEMPLATE, and
       
  1099      * Console.FOOTER_TEMPLATE markup when rendering the Console UI.
       
  1100      *
       
  1101      * <p>By default, the keys contained in the object are:</p>
       
  1102      * <ul>
       
  1103      *   <li>console_hd_class</li>
       
  1104      *   <li>console_bd_class</li>
       
  1105      *   <li>console_ft_class</li>
       
  1106      *   <li>console_controls_class</li>
       
  1107      *   <li>console_checkbox_class</li>
       
  1108      *   <li>console_pause_class</li>
       
  1109      *   <li>console_pause_label_class</li>
       
  1110      *   <li>console_button_class</li>
       
  1111      *   <li>console_clear_class</li>
       
  1112      *   <li>console_collapse_class</li>
       
  1113      *   <li>console_title_class</li>
       
  1114      * </ul>
       
  1115      *
       
  1116      * @property CHROME_CLASSES
       
  1117      * @type Object
       
  1118      * @static
       
  1119      */
       
  1120     CHROME_CLASSES  : {
       
  1121         console_hd_class       : C_CONSOLE_HD,
       
  1122         console_bd_class       : C_CONSOLE_BD,
       
  1123         console_ft_class       : C_CONSOLE_FT,
       
  1124         console_controls_class : C_CONSOLE_CONTROLS,
       
  1125         console_checkbox_class : C_CHECKBOX,
       
  1126         console_pause_class    : C_PAUSE,
       
  1127         console_pause_label_class : C_PAUSE_LABEL,
       
  1128         console_button_class   : C_BUTTON,
       
  1129         console_clear_class    : C_CLEAR,
       
  1130         console_collapse_class : C_COLLAPSE,
       
  1131         console_title_class    : C_CONSOLE_TITLE
       
  1132     },
       
  1133 
       
  1134     /**
       
  1135      * Markup template used to generate the DOM structure for the header
       
  1136      * section of the Console when it is rendered.  The template includes
       
  1137      * these {placeholder}s:
       
  1138      *
       
  1139      * <ul>
       
  1140      *   <li>console_button_class - contributed by Console.CHROME_CLASSES</li>
       
  1141      *   <li>console_collapse_class - contributed by Console.CHROME_CLASSES</li>
       
  1142      *   <li>console_hd_class - contributed by Console.CHROME_CLASSES</li>
       
  1143      *   <li>console_title_class - contributed by Console.CHROME_CLASSES</li>
       
  1144      *   <li>str_collapse - pulled from attribute strings.collapse</li>
       
  1145      *   <li>str_title - pulled from attribute strings.title</li>
       
  1146      * </ul>
       
  1147      *
       
  1148      * @property HEADER_TEMPLATE
       
  1149      * @type String
       
  1150      * @static
       
  1151      */
       
  1152     HEADER_TEMPLATE :
       
  1153         '<div class="{console_hd_class}">'+
       
  1154             '<h4 class="{console_title_class}">{str_title}</h4>'+
       
  1155             '<button type="button" class="'+
       
  1156                 '{console_button_class} {console_collapse_class}">{str_collapse}'+
       
  1157             '</button>'+
       
  1158         '</div>',
       
  1159 
       
  1160     /**
       
  1161      * Markup template used to generate the DOM structure for the Console body
       
  1162      * (where the messages are inserted) when it is rendered.  The template
       
  1163      * includes only the {placeholder} &quot;console_bd_class&quot;, which is
       
  1164      * constributed by Console.CHROME_CLASSES.
       
  1165      *
       
  1166      * @property BODY_TEMPLATE
       
  1167      * @type String
       
  1168      * @static
       
  1169      */
       
  1170     BODY_TEMPLATE : '<div class="{console_bd_class}"></div>',
       
  1171 
       
  1172     /**
       
  1173      * Markup template used to generate the DOM structure for the footer
       
  1174      * section of the Console when it is rendered.  The template includes
       
  1175      * many of the {placeholder}s from Console.CHROME_CLASSES as well as:
       
  1176      *
       
  1177      * <ul>
       
  1178      *   <li>id_guid - generated unique id, relates the label and checkbox</li>
       
  1179      *   <li>str_pause - pulled from attribute strings.pause</li>
       
  1180      *   <li>str_clear - pulled from attribute strings.clear</li>
       
  1181      * </ul>
       
  1182      *
       
  1183      * @property FOOTER_TEMPLATE
       
  1184      * @type String
       
  1185      * @static
       
  1186      */
       
  1187     FOOTER_TEMPLATE :
       
  1188         '<div class="{console_ft_class}">'+
       
  1189             '<div class="{console_controls_class}">'+
       
  1190                 '<label class="{console_pause_label_class}"><input type="checkbox" class="{console_checkbox_class} {console_pause_class}" value="1" id="{id_guid}"> {str_pause}</label>' +
       
  1191                 '<button type="button" class="'+
       
  1192                     '{console_button_class} {console_clear_class}">{str_clear}'+
       
  1193                 '</button>'+
       
  1194             '</div>'+
       
  1195         '</div>',
       
  1196 
       
  1197     /**
       
  1198      * Default markup template used to create the DOM structure for Console
       
  1199      * entries. The markup contains {placeholder}s for content and classes
       
  1200      * that are replaced via Y.Lang.sub.  The default template contains
       
  1201      * the {placeholder}s identified in Console.ENTRY_CLASSES as well as the
       
  1202      * following placeholders that will be populated by the log entry data:
       
  1203      *
       
  1204      * <ul>
       
  1205      *   <li>cat_class</li>
       
  1206      *   <li>src_class</li>
       
  1207      *   <li>totalTime</li>
       
  1208      *   <li>elapsedTime</li>
       
  1209      *   <li>localTime</li>
       
  1210      *   <li>sourceAndDetail</li>
       
  1211      *   <li>message</li>
       
  1212      * </ul>
       
  1213      *
       
  1214      * @property ENTRY_TEMPLATE
       
  1215      * @type String
       
  1216      * @static
       
  1217      */
       
  1218     ENTRY_TEMPLATE : ENTRY_TEMPLATE_STR,
       
  1219 
       
  1220     /**
       
  1221      * Static property used to define the default attribute configuration of
       
  1222      * the Widget.
       
  1223      *
       
  1224      * @property ATTRS
       
  1225      * @Type Object
       
  1226      * @static
       
  1227      */
       
  1228     ATTRS : {
       
  1229 
       
  1230         /**
       
  1231          * Name of the custom event that will communicate log messages.
       
  1232          *
       
  1233          * @attribute logEvent
       
  1234          * @type String
       
  1235          * @default "yui:log"
       
  1236          */
       
  1237         logEvent : {
       
  1238             value : 'yui:log',
       
  1239             writeOnce : true,
       
  1240             validator : isString
       
  1241         },
       
  1242 
       
  1243         /**
       
  1244          * Object that will emit the log events.  By default the YUI instance.
       
  1245          * To have a single Console capture events from all YUI instances, set
       
  1246          * this to the Y.Global object.
       
  1247          *
       
  1248          * @attribute logSource
       
  1249          * @type EventTarget
       
  1250          * @default Y
       
  1251          */
       
  1252         logSource : {
       
  1253             value : Y,
       
  1254             writeOnce : true,
       
  1255             validator : function (v) {
       
  1256                 return this._validateLogSource(v);
       
  1257             }
       
  1258         },
       
  1259 
       
  1260         /**
       
  1261          * Collection of strings used to label elements in the Console UI.
       
  1262          * Default collection contains the following name:value pairs:
       
  1263          *
       
  1264          * <ul>
       
  1265          *   <li>title : &quot;Log Console&quot;</li>
       
  1266          *   <li>pause : &quot;Pause&quot;</li>
       
  1267          *   <li>clear : &quot;Clear&quot;</li>
       
  1268          *   <li>collapse : &quot;Collapse&quot;</li>
       
  1269          *   <li>expand : &quot;Expand&quot;</li>
       
  1270          * </ul>
       
  1271          *
       
  1272          * @attribute strings
       
  1273          * @type Object
       
  1274          */
       
  1275         strings : {
       
  1276             valueFn: function() { return Y.Intl.get("console"); }
       
  1277         },
       
  1278 
       
  1279         /**
       
  1280          * Boolean to pause the outputting of new messages to the console.
       
  1281          * When paused, messages will accumulate in the buffer.
       
  1282          *
       
  1283          * @attribute paused
       
  1284          * @type boolean
       
  1285          * @default false
       
  1286          */
       
  1287         paused : {
       
  1288             value : false,
       
  1289             validator : L.isBoolean
       
  1290         },
       
  1291 
       
  1292         /**
       
  1293          * If a category is not specified in the Y.log(..) statement, this
       
  1294          * category will be used. Categories &quot;info&quot;,
       
  1295          * &quot;warn&quot;, and &quot;error&quot; are also called log level.
       
  1296          *
       
  1297          * @attribute defaultCategory
       
  1298          * @type String
       
  1299          * @default "info"
       
  1300          */
       
  1301         defaultCategory : {
       
  1302             value : INFO,
       
  1303             validator : isString
       
  1304         },
       
  1305 
       
  1306         /**
       
  1307          * If a source is not specified in the Y.log(..) statement, this
       
  1308          * source will be used.
       
  1309          *
       
  1310          * @attribute defaultSource
       
  1311          * @type String
       
  1312          * @default "global"
       
  1313          */
       
  1314         defaultSource   : {
       
  1315             value : 'global',
       
  1316             validator : isString
       
  1317         },
       
  1318 
       
  1319         /**
       
  1320          * Markup template used to create the DOM structure for Console entries.
       
  1321          *
       
  1322          * @attribute entryTemplate
       
  1323          * @type String
       
  1324          * @default Console.ENTRY_TEMPLATE
       
  1325          */
       
  1326         entryTemplate : {
       
  1327             value : ENTRY_TEMPLATE_STR,
       
  1328             validator : isString
       
  1329         },
       
  1330 
       
  1331         /**
       
  1332          * Minimum entry log level to render into the Console.  The initial
       
  1333          * logLevel value for all Console instances defaults from the
       
  1334          * Y.config.logLevel YUI configuration, or Console.LOG_LEVEL_INFO if
       
  1335          * that configuration is not set.
       
  1336          *
       
  1337          * Possible values are &quot;info&quot;, &quot;warn&quot;,
       
  1338          * &quot;error&quot; (case insensitive), or their corresponding statics
       
  1339          * Console.LOG_LEVEL_INFO and so on.
       
  1340          *
       
  1341          * @attribute logLevel
       
  1342          * @type String
       
  1343          * @default Y.config.logLevel or Console.LOG_LEVEL_INFO
       
  1344          */
       
  1345         logLevel : {
       
  1346             value : Y.config.logLevel || INFO,
       
  1347             setter : function (v) {
       
  1348                 return this._setLogLevel(v);
       
  1349             }
       
  1350         },
       
  1351 
       
  1352         /**
       
  1353          * Millisecond timeout between iterations of the print loop, moving
       
  1354          * entries from the buffer to the UI.
       
  1355          *
       
  1356          * @attribute printTimeout
       
  1357          * @type Number
       
  1358          * @default 100
       
  1359          */
       
  1360         printTimeout : {
       
  1361             value : 100,
       
  1362             validator : isNumber
       
  1363         },
       
  1364 
       
  1365         /**
       
  1366          * Maximum number of entries printed in each iteration of the print
       
  1367          * loop. This is used to prevent excessive logging locking the page UI.
       
  1368          *
       
  1369          * @attribute printLimit
       
  1370          * @type Number
       
  1371          * @default 50
       
  1372          */
       
  1373         printLimit : {
       
  1374             value : 50,
       
  1375             validator : isNumber
       
  1376         },
       
  1377 
       
  1378         /**
       
  1379          * Maximum number of Console entries allowed in the Console body at one
       
  1380          * time.  This is used to keep acquired messages from exploding the
       
  1381          * DOM tree and impacting page performance.
       
  1382          *
       
  1383          * @attribute consoleLimit
       
  1384          * @type Number
       
  1385          * @default 300
       
  1386          */
       
  1387         consoleLimit : {
       
  1388             value : 300,
       
  1389             validator : isNumber
       
  1390         },
       
  1391 
       
  1392         /**
       
  1393          * New entries should display at the top of the Console or the bottom?
       
  1394          *
       
  1395          * @attribute newestOnTop
       
  1396          * @type Boolean
       
  1397          * @default true
       
  1398          */
       
  1399         newestOnTop : {
       
  1400             value : true
       
  1401         },
       
  1402 
       
  1403         /**
       
  1404          * When new entries are added to the Console UI, should they be
       
  1405          * scrolled into view?
       
  1406          *
       
  1407          * @attribute scrollIntoView
       
  1408          * @type Boolean
       
  1409          * @default true
       
  1410          */
       
  1411         scrollIntoView : {
       
  1412             value : true
       
  1413         },
       
  1414 
       
  1415         /**
       
  1416          * The baseline time for this Console instance, used to measure elapsed
       
  1417          * time from the moment the console module is <code>use</code>d to the
       
  1418          * moment each new entry is logged (not rendered).
       
  1419          *
       
  1420          * This value is reset by the instance method myConsole.reset().
       
  1421          *
       
  1422          * @attribute startTime
       
  1423          * @type Date
       
  1424          * @default The moment the console module is <code>use</code>d
       
  1425          */
       
  1426         startTime : {
       
  1427             value : new Date()
       
  1428         },
       
  1429 
       
  1430         /**
       
  1431          * The precise time the last entry was logged.  Used to measure elapsed
       
  1432          * time between log messages.
       
  1433          *
       
  1434          * @attribute lastTime
       
  1435          * @type Date
       
  1436          * @default The moment the console module is <code>use</code>d
       
  1437          */
       
  1438         lastTime : {
       
  1439             value : new Date(),
       
  1440             readOnly: true
       
  1441         },
       
  1442 
       
  1443         /**
       
  1444          * Controls the collapsed state of the Console
       
  1445          *
       
  1446          * @attribute collapsed
       
  1447          * @type Boolean
       
  1448          * @default false
       
  1449          */
       
  1450         collapsed : {
       
  1451             value : false
       
  1452         },
       
  1453 
       
  1454         /**
       
  1455         * String with units, or number, representing the height of the Console,
       
  1456         * inclusive of header and footer. If a number is provided, the default
       
  1457         * unit, defined by Widget's DEF_UNIT, property is used.
       
  1458         *
       
  1459         * @attribute height
       
  1460         * @default "300px"
       
  1461         * @type {String | Number}
       
  1462         */
       
  1463         height: {
       
  1464             value: "300px"
       
  1465         },
       
  1466 
       
  1467         /**
       
  1468         * String with units, or number, representing the width of the Console.
       
  1469         * If a number is provided, the default unit, defined by Widget's
       
  1470         * DEF_UNIT, property is used.
       
  1471         *
       
  1472         * @attribute width
       
  1473         * @default "300px"
       
  1474         * @type {String | Number}
       
  1475         */
       
  1476         width: {
       
  1477             value: "300px"
       
  1478         },
       
  1479 
       
  1480         /**
       
  1481          * Pass through to the YUI instance useBrowserConsole configuration.
       
  1482          * By default this is set to false, which will disable logging to the
       
  1483          * browser console when a Console instance is created.  If the
       
  1484          * logSource is not a YUI instance, this has no effect.
       
  1485          * 
       
  1486          * @attribute useBrowserConsole
       
  1487          * @type {Boolean}
       
  1488          * @default false
       
  1489          */
       
  1490          useBrowserConsole : {
       
  1491             lazyAdd: false,
       
  1492             value: false,
       
  1493             getter : function () {
       
  1494                 return this._getUseBrowserConsole();
       
  1495             },
       
  1496             setter : function (v) {
       
  1497                 return this._setUseBrowserConsole(v);
       
  1498             }
       
  1499          },
       
  1500 
       
  1501          /**
       
  1502           * Allows the Console to flow in the document.  Available values are
       
  1503           * 'inline', 'block', and 'separate' (the default).  
       
  1504           *
       
  1505           * @attribute style
       
  1506           * @type {String}
       
  1507           * @default 'separate'
       
  1508           */
       
  1509          style : {
       
  1510             value : 'separate',
       
  1511             writeOnce : true,
       
  1512             validator : function (v) {
       
  1513                 return this._validateStyle(v);
       
  1514             }
       
  1515          }
       
  1516     }
       
  1517 
       
  1518 });
       
  1519 
       
  1520 
       
  1521 }, '3.10.3', {"requires": ["yui-log", "widget"], "skinnable": true, "lang": ["en", "es", "it", "ja"]});