webgui/www/extras/yui/docs/logger/overview-summary-LogReader.js.html
JT Smith 4f68a0933c added YUI and YUI-ext
fixed the resizable text area with IE problem
fixed the ad space with IE problem
merged the 7.2.0 and 7.1.4 change logs
2006-11-07 23:15:57 +00:00

1037 lines
42 KiB
HTML

<html>
<head>
<title>JavaScript Documentation - LogReader.js</title>
<link href="stylesheet.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="header">
<h1>JavaScript Documentation</h1>
<h3><a href="./index.html">Logger</a></h3>
<div class="breadcrumbs">
<a href="./index.html">Logger</a>
&gt;
<strong>LogReader.js</strong>
</div>
</div>
<div id="body">
<div class="nav">
<div class="module resources">
<ul class="content">
<li><a href="overview-tree.html">Tree View</a></li>
<li><a href="index-all.html">Element Index</a></li>
</ul>
</div>
<div class="module">
<h4><a href="./allclasses-noframe.html">Classes</a></h4>
<ul class="content">
<li>
<a href="YAHOO.widget.html">
YAHOO.widget</a>
</li>
<li>
<a href="YAHOO.widget.LogReader.html">
YAHOO.widget.LogReader</a>
</li>
<li>
<a href="YAHOO.widget.LogWriter.html">
YAHOO.widget.LogWriter</a>
</li>
</ul>
</div>
<div class="module">
<h4><a href="./overview-summary.html">Files</a></h4>
<ul class="content">
<li>
<a href="overview-summary-Logger.js.html">
Logger.js</a>
</li>
<li>
<a href="overview-summary-LogReader.js.html">
LogReader.js</a>
</li>
<li>
<a href="overview-summary-LogWriter.js.html">
LogWriter.js</a>
</li>
</ul>
</div>
</div>
<div class="main">
<h2>LogReader.js</h2>
<div class="meta">
</div>
<div class="quick-links">
<strong>Quick Links:</strong>&nbsp;
<a href="#classSummary">Class Summary</a> |
<a href="#source">Source Code</a>
</div>
<div class="section class summaries">
<h3><a name="classSummary">Class Summary</a> <span class="top">[<a href="#top">top</a>]</span></h3>
<div class="content">
<table border="1" cellpadding="3" cellspacing="0">
<tr>
<td class="name">
<a href="YAHOO.widget.LogReader.html">YAHOO.widget.LogReader</a>
</td>
<td class="overview">&nbsp;</td>
</tr>
</table>
</div>
</div>
<div class="section source">
<h3><a name="source">Souce Code</a> <span class="top">[<a href="#top">top</a>]</span></h3>
<pre class="sourceview"><span class="comment">/****************************************************************************/</span>
<span class="comment">/****************************************************************************/</span>
<span class="comment">/****************************************************************************/</span>
<span class="comment">/**
* Class providing UI to read messages logged to YAHOO.widget.Logger.
*
* requires YAHOO.util.Dom DOM utility
* requires YAHOO.util.Event Event utility
* optional YAHOO.util.DragDrop Drag and drop utility
*
* <span class="attrib">@constructor</span>
* <span class="attrib">@param</span> {el or ID} containerEl DOM element object or ID of container to wrap reader UI
* <span class="attrib">@param</span> {object} oConfig Optional object literal of configuration params
*/</span>
YAHOO.widget.LogReader = <span class="reserved">function</span>(containerEl, oConfig) {
var oSelf = <span class="reserved">this</span>;
<span class="comment">
// Parse config vars here</span>
<span class="reserved">if</span> (typeof oConfig == <span class="literal">"object"</span>) {
<span class="reserved">for</span>(var param in oConfig) {
<span class="reserved">this</span>[param] = oConfig[param];
}
}
<span class="comment">
// Attach container...</span>
<span class="reserved">if</span>(containerEl) {
<span class="reserved">if</span>(typeof containerEl == <span class="literal">"string"</span>) {
<span class="reserved">this</span>._containerEl = document.getElementById(containerEl);
}
<span class="reserved">else</span> <span class="reserved">if</span>(containerEl.tagName) {
<span class="reserved">this</span>._containerEl = containerEl;
}
<span class="reserved">this</span>._containerEl.className = <span class="literal">"yui-log"</span>;
}
<span class="comment"> // ...or create container from scratch</span>
<span class="reserved">if</span>(!<span class="reserved">this</span>._containerEl) {
<span class="reserved">if</span>(YAHOO.widget.LogReader._defaultContainerEl) {
<span class="reserved">this</span>._containerEl = YAHOO.widget.LogReader._defaultContainerEl;
}
<span class="reserved">else</span> {
<span class="reserved">this</span>._containerEl = document.body.appendChild(document.createElement(<span class="literal">"div"</span>));
<span class="reserved">this</span>._containerEl.id = <span class="literal">"yui-log"</span>;
<span class="reserved">this</span>._containerEl.className = <span class="literal">"yui-log"</span>;
YAHOO.widget.LogReader._defaultContainerEl = <span class="reserved">this</span>._containerEl;
}
<span class="comment">
// If implementer has provided container values, trust and set those</span>
var containerStyle = <span class="reserved">this</span>._containerEl.style;
<span class="reserved">if</span>(<span class="reserved">this</span>.width) {
containerStyle.width = <span class="reserved">this</span>.width;
}
<span class="reserved">if</span>(<span class="reserved">this</span>.left) {
containerStyle.left = <span class="reserved">this</span>.left;
}
<span class="reserved">if</span>(<span class="reserved">this</span>.right) {
containerStyle.right = <span class="reserved">this</span>.right;
}
<span class="reserved">if</span>(<span class="reserved">this</span>.bottom) {
containerStyle.bottom = <span class="reserved">this</span>.bottom;
}
<span class="reserved">if</span>(<span class="reserved">this</span>.top) {
containerStyle.top = <span class="reserved">this</span>.top;
}
<span class="reserved">if</span>(<span class="reserved">this</span>.fontSize) {
containerStyle.fontSize = <span class="reserved">this</span>.fontSize;
}
}
<span class="reserved">if</span>(<span class="reserved">this</span>._containerEl) {
<span class="comment"> // Create header</span>
if(!this._hdEl) {
this._hdEl = this._containerEl.appendChild(document.createElement("div"));
this._hdEl.id = "yui-log-hd" + YAHOO.widget.LogReader._index;
this._hdEl.className = "yui-log-hd";
this._collapseEl = this._hdEl.appendChild(document.createElement("div"));
this._collapseEl.className = "yui-log-btns";
this._collapseBtn = document.createElement("input");
this._collapseBtn.type = "button";
this._collapseBtn.style.fontSize = YAHOO.util.Dom.getStyle(this._containerEl,"fontSize");
this._collapseBtn.className = "yui-log-button";
this._collapseBtn.value = "Collapse";
this._collapseBtn = this._collapseEl.appendChild(this._collapseBtn);
YAHOO.util.Event.addListener(oSelf._collapseBtn,'click',oSelf._onClickCollapseBtn,oSelf);
this._title = this._hdEl.appendChild(document.createElement("h4"));
this._title.innerHTML = "Logger Console";
// If Drag and Drop utility is available...
// ...and this container was created from scratch...
// ...then make the header draggable
if(YAHOO.util.DD &amp;&amp;
(YAHOO.widget.LogReader._defaultContainerEl == this._containerEl)) {
var ylog_dd = new YAHOO.util.DD(this._containerEl.id);
ylog_dd.setHandleElId(this._hdEl.id);
this._hdEl.style.cursor = "move";
}
}
// Ceate console
if(!this._consoleEl) {
this._consoleEl = this._containerEl.appendChild(document.createElement("div"));
this._consoleEl.className = "yui-log-bd";
// If implementer has provided console, trust and set those
if(this.height) {
this._consoleEl.style.height = this.height;
}
}
// Don't create footer if disabled
if(!this._ftEl &amp;&amp; this.footerEnabled) {
this._ftEl = this._containerEl.appendChild(document.createElement("div"));
this._ftEl.className = "yui-log-ft";
this._btnsEl = this._ftEl.appendChild(document.createElement("div"));
this._btnsEl.className = "yui-log-btns";
this._pauseBtn = document.createElement("input");
this._pauseBtn.type = "button";
this._pauseBtn.style.fontSize = YAHOO.util.Dom.getStyle(this._containerEl,"fontSize");
this._pauseBtn.className = "yui-log-button";
this._pauseBtn.value = "Pause";
this._pauseBtn = this._btnsEl.appendChild(this._pauseBtn);
YAHOO.util.Event.addListener(oSelf._pauseBtn,'click',oSelf._onClickPauseBtn,oSelf);
this._clearBtn = document.createElement("input");
this._clearBtn.type = "button";
this._clearBtn.style.fontSize = YAHOO.util.Dom.getStyle(this._containerEl,"fontSize");
this._clearBtn.className = "yui-log-button";
this._clearBtn.value = "Clear";
this._clearBtn = this._btnsEl.appendChild(this._clearBtn);
YAHOO.util.Event.addListener(oSelf._clearBtn,'click',oSelf._onClickClearBtn,oSelf);
this._categoryFiltersEl = this._ftEl.appendChild(document.createElement("div"));
this._categoryFiltersEl.className = "yui-log-categoryfilters";
this._sourceFiltersEl = this._ftEl.appendChild(document.createElement("div"));
this._sourceFiltersEl.className = "yui-log-sourcefilters";
}
}
<span class="comment">
// Initialize buffer</span>
<span class="reserved">if</span>(!<span class="reserved">this</span>._buffer) {
<span class="reserved">this</span>._buffer = []; // output buffer
}
YAHOO.widget.Logger.newLogEvent.subscribe(<span class="reserved">this</span>._onNewLog, <span class="reserved">this</span>);
<span class="reserved">this</span>._lastTime = YAHOO.widget.Logger.getStartTime(); // timestamp of last log message to console
<span class="comment">
// Initialize category filters</span>
<span class="reserved">this</span>._categoryFilters = [];
var catsLen = YAHOO.widget.Logger.categories.length;
<span class="reserved">if</span>(<span class="reserved">this</span>._categoryFiltersEl) {
<span class="reserved">for</span>(var i=0; i &lt; catsLen; i++) {
<span class="reserved">this</span>._createCategoryCheckbox(YAHOO.widget.Logger.categories[i]);
}
}
<span class="comment"> // Initialize source filters</span>
<span class="reserved">this</span>._sourceFilters = [];
var sourcesLen = YAHOO.widget.Logger.sources.length;
<span class="reserved">if</span>(<span class="reserved">this</span>._sourceFiltersEl) {
<span class="reserved">for</span>(var j=0; j &lt; sourcesLen; j++) {
<span class="reserved">this</span>._createSourceCheckbox(YAHOO.widget.Logger.sources[j]);
}
}
YAHOO.widget.Logger.categoryCreateEvent.subscribe(<span class="reserved">this</span>._onCategoryCreate, <span class="reserved">this</span>);
YAHOO.widget.Logger.sourceCreateEvent.subscribe(<span class="reserved">this</span>._onSourceCreate, <span class="reserved">this</span>);
YAHOO.widget.LogReader._index++;
<span class="reserved">this</span>._filterLogs();
};
<span class="comment">/***************************************************************************
* Public members
***************************************************************************/</span>
<span class="comment">/**
* Whether or not the log reader is enabled to output log messages. Default:
* true.
*
* <span class="attrib">@type</span> boolean
*/</span>
YAHOO.widget.LogReader.<span class="reserved">prototype</span>.logReaderEnabled = true;
<span class="comment">/**
* Public member to access CSS width of the log reader container.
*
* <span class="attrib">@type</span> string
*/</span>
YAHOO.widget.LogReader.<span class="reserved">prototype</span>.width = null;
<span class="comment">/**
* Public member to access CSS height of the log reader container.
*
* <span class="attrib">@type</span> string
*/</span>
YAHOO.widget.LogReader.<span class="reserved">prototype</span>.height = null;
<span class="comment">/**
* Public member to access CSS top position of the log reader container.
*
* <span class="attrib">@type</span> string
*/</span>
YAHOO.widget.LogReader.<span class="reserved">prototype</span>.top = null;
<span class="comment">/**
* Public member to access CSS left position of the log reader container.
*
* <span class="attrib">@type</span> string
*/</span>
YAHOO.widget.LogReader.<span class="reserved">prototype</span>.left = null;
<span class="comment">/**
* Public member to access CSS right position of the log reader container.
*
* <span class="attrib">@type</span> string
*/</span>
YAHOO.widget.LogReader.<span class="reserved">prototype</span>.right = null;
<span class="comment">/**
* Public member to access CSS bottom position of the log reader container.
*
* <span class="attrib">@type</span> string
*/</span>
YAHOO.widget.LogReader.<span class="reserved">prototype</span>.bottom = null;
<span class="comment">/**
* Public member to access CSS font size of the log reader container.
*
* <span class="attrib">@type</span> string
*/</span>
YAHOO.widget.LogReader.<span class="reserved">prototype</span>.fontSize = null;
<span class="comment">/**
* Whether or not the footer UI is enabled for the log reader. Default: true.
*
* <span class="attrib">@type</span> boolean
*/</span>
YAHOO.widget.LogReader.<span class="reserved">prototype</span>.footerEnabled = true;
<span class="comment">/**
* Whether or not output is verbose (more readable). Setting to true will make
* output more compact (less readable). Default: true.
*
* <span class="attrib">@type</span> boolean
*/</span>
YAHOO.widget.LogReader.<span class="reserved">prototype</span>.verboseOutput = true;
<span class="comment">/**
* Whether or not newest message is printed on top. Default: true.
*
* <span class="attrib">@type</span> boolean
*/</span>
YAHOO.widget.LogReader.<span class="reserved">prototype</span>.newestOnTop = true;
<span class="comment">/**
* Maximum number of messages a LogReader console will display. Default: 500;
*
* <span class="attrib">@type</span> number
*/</span>
YAHOO.widget.LogReader.<span class="reserved">prototype</span>.thresholdMax = 500;
<span class="comment">/**
* When a LogReader console reaches its thresholdMax, it will clear out messages
* and print out the latest thresholdMin number of messages. Default: 100;
*
* <span class="attrib">@type</span> number
*/</span>
YAHOO.widget.LogReader.<span class="reserved">prototype</span>.thresholdMin = 100;
<span class="comment">/***************************************************************************
* Public methods
***************************************************************************/</span>
<span class="comment">/**
* Pauses output of log messages. While paused, log messages are not lost, but
* get saved to a buffer and then output upon resume of log reader.
*/</span>
YAHOO.widget.LogReader.<span class="reserved">prototype</span>.pause = <span class="reserved">function</span>() {
<span class="reserved">this</span>._timeout = null;
<span class="reserved">this</span>.logReaderEnabled = false;
};
<span class="comment">/**
* Resumes output of log messages, including outputting any log messages that
* have been saved to buffer while paused.
*/</span>
YAHOO.widget.LogReader.<span class="reserved">prototype</span>.resume = <span class="reserved">function</span>() {
<span class="reserved">this</span>.logReaderEnabled = true;
<span class="reserved">this</span>._printBuffer();
};
<span class="comment">/**
* Hides UI of log reader. Logging functionality is not disrupted.
*/</span>
YAHOO.widget.LogReader.<span class="reserved">prototype</span>.hide = <span class="reserved">function</span>() {
<span class="reserved">this</span>._containerEl.style.display = <span class="literal">"none"</span>;
};
<span class="comment">/**
* Shows UI of log reader. Logging functionality is not disrupted.
*/</span>
YAHOO.widget.LogReader.<span class="reserved">prototype</span>.show = <span class="reserved">function</span>() {
<span class="reserved">this</span>._containerEl.style.display = <span class="literal">"block"</span>;
};
<span class="comment">/**
* Updates title to given string.
*
* <span class="attrib">@param</span> {string} sTitle String to display in log reader's title bar.
*/</span>
YAHOO.widget.LogReader.<span class="reserved">prototype</span>.setTitle = <span class="reserved">function</span>(sTitle) {
var regEx = /&gt;/g;
sTitle = sTitle.replace(regEx,<span class="literal">"&amp;gt;"</span>);
regEx = /&lt;/g;
sTitle = sTitle.replace(regEx,<span class="literal">"&amp;lt;"</span>);
<span class="reserved">this</span>._title.innerHTML = (sTitle);
};
<span class="comment">/***************************************************************************
* Private members
***************************************************************************/</span>
<span class="comment">/**
* Internal class member to index multiple log reader instances.
*
* <span class="attrib">@type</span> number
* <span class="attrib">@private</span>
*/</span>
YAHOO.widget.LogReader._index = 0;
<span class="comment">/**
* A class member shared by all log readers if a container needs to be
* created during instantiation. Will be null if a container element never needs to
* be created on the fly, such as when the implementer passes in their own element.
*
* <span class="attrib">@type</span> HTMLElement
* <span class="attrib">@private</span>
*/</span>
YAHOO.widget.LogReader._defaultContainerEl = null;
<span class="comment">/**
* Buffer of log messages for batch output.
*
* <span class="attrib">@type</span> array
* <span class="attrib">@private</span>
*/</span>
YAHOO.widget.LogReader.<span class="reserved">prototype</span>._buffer = null;
<span class="comment">/**
* Date of last output log message.
*
* <span class="attrib">@type</span> date
* <span class="attrib">@private</span>
*/</span>
YAHOO.widget.LogReader.<span class="reserved">prototype</span>._lastTime = null;
<span class="comment">/**
* Batched output timeout ID.
*
* <span class="attrib">@type</span> number
* <span class="attrib">@private</span>
*/</span>
YAHOO.widget.LogReader.<span class="reserved">prototype</span>._timeout = null;
<span class="comment">/**
* Array of filters for log message categories.
*
* <span class="attrib">@type</span> array
* <span class="attrib">@private</span>
*/</span>
YAHOO.widget.LogReader.<span class="reserved">prototype</span>._categoryFilters = null;
<span class="comment">/**
* Array of filters for log message sources.
*
* <span class="attrib">@type</span> array
* <span class="attrib">@private</span>
*/</span>
YAHOO.widget.LogReader.<span class="reserved">prototype</span>._sourceFilters = null;
<span class="comment">/**
* Log reader container element.
*
* <span class="attrib">@type</span> HTMLElement
* <span class="attrib">@private</span>
*/</span>
YAHOO.widget.LogReader.<span class="reserved">prototype</span>._containerEl = null;
<span class="comment">/**
* Log reader header element.
*
* <span class="attrib">@type</span> HTMLElement
* <span class="attrib">@private</span>
*/</span>
YAHOO.widget.LogReader.<span class="reserved">prototype</span>._hdEl = null;
<span class="comment">/**
* Log reader collapse element.
*
* <span class="attrib">@type</span> HTMLElement
* <span class="attrib">@private</span>
*/</span>
YAHOO.widget.LogReader.<span class="reserved">prototype</span>._collapseEl = null;
<span class="comment">/**
* Log reader collapse button element.
*
* <span class="attrib">@type</span> HTMLElement
* <span class="attrib">@private</span>
*/</span>
YAHOO.widget.LogReader.<span class="reserved">prototype</span>._collapseBtn = null;
<span class="comment">/**
* Log reader title header element.
*
* <span class="attrib">@type</span> HTMLElement
* <span class="attrib">@private</span>
*/</span>
YAHOO.widget.LogReader.<span class="reserved">prototype</span>._title = null;
<span class="comment">/**
* Log reader console element.
*
* <span class="attrib">@type</span> HTMLElement
* <span class="attrib">@private</span>
*/</span>
YAHOO.widget.LogReader.<span class="reserved">prototype</span>._consoleEl = null;
<span class="comment">/**
* Log reader footer element.
*
* <span class="attrib">@type</span> HTMLElement
* <span class="attrib">@private</span>
*/</span>
YAHOO.widget.LogReader.<span class="reserved">prototype</span>._ftEl = null;
<span class="comment">/**
* Log reader buttons container element.
*
* <span class="attrib">@type</span> HTMLElement
* <span class="attrib">@private</span>
*/</span>
YAHOO.widget.LogReader.<span class="reserved">prototype</span>._btnsEl = null;
<span class="comment">/**
* Container element for log reader category filter checkboxes.
*
* <span class="attrib">@type</span> HTMLElement
* <span class="attrib">@private</span>
*/</span>
YAHOO.widget.LogReader.<span class="reserved">prototype</span>._categoryFiltersEl = null;
<span class="comment">/**
* Container element for log reader source filter checkboxes.
*
* <span class="attrib">@type</span> HTMLElement
* <span class="attrib">@private</span>
*/</span>
YAHOO.widget.LogReader.<span class="reserved">prototype</span>._sourceFiltersEl = null;
<span class="comment">/**
* Log reader pause button element.
*
* <span class="attrib">@type</span> HTMLElement
* <span class="attrib">@private</span>
*/</span>
YAHOO.widget.LogReader.<span class="reserved">prototype</span>._pauseBtn = null;
<span class="comment">/**
* lear button element.
*
* <span class="attrib">@type</span> HTMLElement
* <span class="attrib">@private</span>
*/</span>
YAHOO.widget.LogReader.<span class="reserved">prototype</span>._clearBtn = null;
<span class="comment">/***************************************************************************
* Private methods
***************************************************************************/</span>
<span class="comment">/**
* Creates the UI for a category filter in the log reader footer element.
*
* <span class="attrib">@param</span> {string} category Category name
* <span class="attrib">@private</span>
*/</span>
YAHOO.widget.LogReader.<span class="reserved">prototype</span>._createCategoryCheckbox = <span class="reserved">function</span>(category) {
var oSelf = <span class="reserved">this</span>;
<span class="reserved">if</span>(<span class="reserved">this</span>._ftEl) {
var parentEl = <span class="reserved">this</span>._categoryFiltersEl;
var filters = <span class="reserved">this</span>._categoryFilters;
var filterEl = parentEl.appendChild(document.createElement(<span class="literal">"span"</span>));
filterEl.className = <span class="literal">"yui-log-filtergrp"</span>;
<span class="comment"> // Append el at the end so IE 5.5 can set "type" attribute</span>
<span class="comment"> // and THEN set checked property</span>
var categoryChk = document.createElement(<span class="literal">"input"</span>);
categoryChk.id = <span class="literal">"yui-log-filter-"</span> + category + YAHOO.widget.LogReader._index;
categoryChk.className = <span class="literal">"yui-log-filter-"</span> + category;
categoryChk.type = <span class="literal">"checkbox"</span>;
categoryChk.category = category;
categoryChk = filterEl.appendChild(categoryChk);
categoryChk.checked = true;
<span class="comment">
// Add this checked filter to the internal array of filters</span>
filters.push(category);
<span class="comment"> // Subscribe to the click event</span>
YAHOO.util.Event.addListener(categoryChk,<span class="literal">'click'</span>,oSelf._onCheckCategory,oSelf);
<span class="comment">
// Create and class the text label</span>
var categoryChkLbl = filterEl.appendChild(document.createElement(<span class="literal">"label"</span>));
categoryChkLbl.htmlFor = categoryChk.id;
categoryChkLbl.className = category;
categoryChkLbl.innerHTML = category;
}
};
YAHOO.widget.LogReader.<span class="reserved">prototype</span>._createSourceCheckbox = <span class="reserved">function</span>(source) {
var oSelf = <span class="reserved">this</span>;
<span class="reserved">if</span>(<span class="reserved">this</span>._ftEl) {
var parentEl = <span class="reserved">this</span>._sourceFiltersEl;
var filters = <span class="reserved">this</span>._sourceFilters;
var filterEl = parentEl.appendChild(document.createElement(<span class="literal">"span"</span>));
filterEl.className = <span class="literal">"yui-log-filtergrp"</span>;
<span class="comment">
// Append el at the end so IE 5.5 can set "type" attribute</span>
<span class="comment"> // and THEN set checked property</span>
var sourceChk = document.createElement(<span class="literal">"input"</span>);
sourceChk.id = <span class="literal">"yui-log-filter"</span> + source + YAHOO.widget.LogReader._index;
sourceChk.className = <span class="literal">"yui-log-filter"</span> + source;
sourceChk.type = <span class="literal">"checkbox"</span>;
sourceChk.source = source;
sourceChk = filterEl.appendChild(sourceChk);
sourceChk.checked = true;
<span class="comment">
// Add this checked filter to the internal array of filters</span>
filters.push(source);
<span class="comment"> // Subscribe to the click event</span>
YAHOO.util.Event.addListener(sourceChk,<span class="literal">'click'</span>,oSelf._onCheckSource,oSelf);
<span class="comment">
// Create and class the text label</span>
var sourceChkLbl = filterEl.appendChild(document.createElement(<span class="literal">"label"</span>));
sourceChkLbl.htmlFor = sourceChk.id;
sourceChkLbl.className = source;
sourceChkLbl.innerHTML = source;
}
};
<span class="comment">/**
* Reprints all log messages in the stack through filters.
*
* <span class="attrib">@private</span>
*/</span>
YAHOO.widget.LogReader.<span class="reserved">prototype</span>._filterLogs = <span class="reserved">function</span>() {
<span class="comment"> // Reprint stack with new filters</span>
<span class="reserved">if</span> (<span class="reserved">this</span>._consoleEl !== null) {
<span class="reserved">this</span>._clearConsole();
<span class="reserved">this</span>._printToConsole(YAHOO.widget.Logger.getStack());
}
};
<span class="comment">/**
* Clears all outputted log messages from the console and resets the time of the
* last output log message.
*
* <span class="attrib">@private</span>
*/</span>
YAHOO.widget.LogReader.<span class="reserved">prototype</span>._clearConsole = <span class="reserved">function</span>() {
<span class="comment"> // Clear the buffer of any pending messages</span>
<span class="reserved">this</span>._timeout = null;
<span class="reserved">this</span>._buffer = [];
<span class="comment">
// Reset the rolling timer</span>
<span class="reserved">this</span>._lastTime = YAHOO.widget.Logger.getStartTime();
var consoleEl = <span class="reserved">this</span>._consoleEl;
<span class="reserved">while</span>(consoleEl.hasChildNodes()) {
consoleEl.removeChild(consoleEl.firstChild);
}
};
<span class="comment">/**
* Sends buffer of log messages to output and clears buffer.
*
* <span class="attrib">@private</span>
*/</span>
YAHOO.widget.LogReader.<span class="reserved">prototype</span>._printBuffer = <span class="reserved">function</span>() {
<span class="reserved">this</span>._timeout = null;
<span class="reserved">if</span>(<span class="reserved">this</span>._consoleEl !== null) {
var thresholdMax = <span class="reserved">this</span>.thresholdMax;
thresholdMax = (thresholdMax && !isNaN(thresholdMax)) ? thresholdMax : 500;
<span class="reserved">if</span>(<span class="reserved">this</span>._consoleMsgCount &lt; thresholdMax) {
var entries = [];
<span class="reserved">for</span> (var i=0; i&lt;<span class="reserved">this</span>._buffer.length; i++) {
entries[i] = <span class="reserved">this</span>._buffer[i];
}
<span class="reserved">this</span>._buffer = [];
<span class="reserved">this</span>._printToConsole(entries);
}
<span class="reserved">else</span> {
<span class="reserved">this</span>._filterLogs();
}
<span class="reserved">if</span>(!<span class="reserved">this</span>.newestOnTop) {
<span class="reserved">this</span>._consoleEl.scrollTop = <span class="reserved">this</span>._consoleEl.scrollHeight;
}
}
};
<span class="comment">/**
* Cycles through an array of log messages, and outputs each one to the console
* if its category has not been filtered out.
*
* <span class="attrib">@param</span> {array} aEntries
* <span class="attrib">@private</span>
*/</span>
YAHOO.widget.LogReader.<span class="reserved">prototype</span>._printToConsole = <span class="reserved">function</span>(aEntries) {
<span class="comment"> // Manage the number of messages displayed in the console</span>
var entriesLen = aEntries.length;
var thresholdMin = <span class="reserved">this</span>.thresholdMin;
<span class="reserved">if</span>(isNaN(thresholdMin) || (thresholdMin > <span class="reserved">this</span>.thresholdMax)) {
thresholdMin = 0;
}
var entriesStartIndex = (entriesLen &gt; thresholdMin) ? (entriesLen - thresholdMin) : 0;
<span class="comment"> // Iterate through all log entries to print the ones that filter through</span>
var sourceFiltersLen = <span class="reserved">this</span>._sourceFilters.length;
var categoryFiltersLen = <span class="reserved">this</span>._categoryFilters.length;
<span class="reserved">for</span>(var i=entriesStartIndex; i&lt;entriesLen; i++) {
var entry = aEntries[i];
var category = entry.category;
var source = entry.source;
var sourceDetail = entry.sourceDetail;
var okToPrint = false;
var okToFilterCats = false;
<span class="reserved">for</span>(var j=0; j&lt;sourceFiltersLen; j++) {
<span class="reserved">if</span>(source == <span class="reserved">this</span>._sourceFilters[j]) {
okToFilterCats = true;
break;
}
}
<span class="reserved">if</span>(okToFilterCats) {
<span class="reserved">for</span>(var k=0; k&lt;categoryFiltersLen; k++) {
<span class="reserved">if</span>(category == <span class="reserved">this</span>._categoryFilters[k]) {
okToPrint = true;
break;
}
}
}
<span class="reserved">if</span>(okToPrint) {
<span class="comment"> // To format for console, calculate the elapsed time</span>
<span class="comment"> // to be from the last item that passed through the filter,</span>
<span class="comment"> // not the absolute previous item in the stack</span>
var label = entry.category.substring(0,4).toUpperCase();
var time = entry.time;
<span class="reserved">if</span> (time.toLocaleTimeString) {
var localTime = time.toLocaleTimeString();
}
<span class="reserved">else</span> {
localTime = time.toString();
}
var msecs = time.getTime();
var startTime = YAHOO.widget.Logger.getStartTime();
var totalTime = msecs - startTime;
var elapsedTime = msecs - <span class="reserved">this</span>._lastTime;
<span class="reserved">this</span>._lastTime = msecs;
var verboseOutput = (<span class="reserved">this</span>.verboseOutput) ? <span class="literal">"&lt;br&gt;"</span> : <span class="literal">""</span>;
var sourceAndDetail = (sourceDetail) ?
source + <span class="literal">" "</span> + sourceDetail : source;
var output = <span class="literal">"&lt;span class='"</span>+category+<span class="literal">"'&gt;"</span>+label+<span class="literal">"&lt;/span&gt; "</span> +
totalTime + <span class="literal">"ms (+"</span> +
elapsedTime + <span class="literal">") "</span> + localTime + <span class="literal">": "</span> +
sourceAndDetail + <span class="literal">": "</span> +
verboseOutput +
entry.msg;
var oNewElement = (<span class="reserved">this</span>.newestOnTop) ?
<span class="reserved">this</span>._consoleEl.insertBefore(document.createElement(<span class="literal">"p"</span>),<span class="reserved">this</span>._consoleEl.firstChild):
<span class="reserved">this</span>._consoleEl.appendChild(document.createElement(<span class="literal">"p"</span>));
oNewElement.innerHTML = output;
}
}
};
<span class="comment">/***************************************************************************
* Private event handlers
***************************************************************************/</span>
<span class="comment">/**
* Handles Logger's categoryCreateEvent.
*
* <span class="attrib">@param</span> {string} type The event
* <span class="attrib">@param</span> {array} args Data passed from event firer
* <span class="attrib">@param</span> {object} oSelf The log reader instance
* <span class="attrib">@private</span>
*/</span>
YAHOO.widget.LogReader.<span class="reserved">prototype</span>._onCategoryCreate = <span class="reserved">function</span>(type, args, oSelf) {
var category = args[0];
<span class="reserved">if</span>(oSelf._ftEl) {
oSelf._createCategoryCheckbox(category);
}
};
<span class="comment">/**
* Handles Logger's sourceCreateEvent.
*
* <span class="attrib">@param</span> {string} type The event
* <span class="attrib">@param</span> {array} args Data passed from event firer
* <span class="attrib">@param</span> {object} oSelf The log reader instance
* <span class="attrib">@private</span>
*/</span>
YAHOO.widget.LogReader.<span class="reserved">prototype</span>._onSourceCreate = <span class="reserved">function</span>(type, args, oSelf) {
var source = args[0];
<span class="reserved">if</span>(oSelf._ftEl) {
oSelf._createSourceCheckbox(source);
}
};
<span class="comment">/**
* Handles check events on the category filter checkboxes.
*
* <span class="attrib">@param</span> {event} v The click event
* <span class="attrib">@param</span> {object} oSelf The log reader instance
* <span class="attrib">@private</span>
*/</span>
YAHOO.widget.LogReader.<span class="reserved">prototype</span>._onCheckCategory = <span class="reserved">function</span>(v, oSelf) {
var newFilter = <span class="reserved">this</span>.category;
var filtersArray = oSelf._categoryFilters;
<span class="reserved">if</span>(!<span class="reserved">this</span>.checked) { // Remove category from filters
<span class="reserved">for</span>(var i=0; i&lt;filtersArray.length; i++) {
<span class="reserved">if</span>(newFilter == filtersArray[i]) {
filtersArray.splice(i, 1);
break;
}
}
}
<span class="reserved">else</span> { // Add category to filters
filtersArray.push(newFilter);
}
oSelf._filterLogs();
};
<span class="comment">/**
* Handles check events on the category filter checkboxes.
*
* <span class="attrib">@param</span> {event} v The click event
* <span class="attrib">@param</span> {object} oSelf The log reader instance
* <span class="attrib">@private</span>
*/</span>
YAHOO.widget.LogReader.<span class="reserved">prototype</span>._onCheckSource = <span class="reserved">function</span>(v, oSelf) {
var newFilter = <span class="reserved">this</span>.source;
var filtersArray = oSelf._sourceFilters;
<span class="reserved">if</span>(!<span class="reserved">this</span>.checked) { // Remove category from filters
<span class="reserved">for</span>(var i=0; i&lt;filtersArray.length; i++) {
<span class="reserved">if</span>(newFilter == filtersArray[i]) {
filtersArray.splice(i, 1);
break;
}
}
}
<span class="reserved">else</span> { // Add category to filters
filtersArray.push(newFilter);
}
oSelf._filterLogs();
};
<span class="comment">/**
* Handles click events on the collapse button.
*
* <span class="attrib">@param</span> {event} v The click event
* <span class="attrib">@param</span> {object} oSelf The log reader instance
* <span class="attrib">@private</span>
*/</span>
YAHOO.widget.LogReader.<span class="reserved">prototype</span>._onClickCollapseBtn = <span class="reserved">function</span>(v, oSelf) {
var btn = oSelf._collapseBtn;
<span class="reserved">if</span>(btn.value == <span class="literal">"Expand"</span>) {
oSelf._consoleEl.style.display = <span class="literal">"block"</span>;
<span class="reserved">if</span>(oSelf._ftEl) {
oSelf._ftEl.style.display = <span class="literal">"block"</span>;
}
btn.value = <span class="literal">"Collapse"</span>;
}
<span class="reserved">else</span> {
oSelf._consoleEl.style.display = <span class="literal">"none"</span>;
<span class="reserved">if</span>(oSelf._ftEl) {
oSelf._ftEl.style.display = <span class="literal">"none"</span>;
}
btn.value = <span class="literal">"Expand"</span>;
}
};
<span class="comment">/**
* Handles click events on the pause button.
*
* <span class="attrib">@param</span> {event} v The click event
* <span class="attrib">@param</span> {object} oSelf The log reader instance
* <span class="attrib">@private</span>
*/</span>
YAHOO.widget.LogReader.<span class="reserved">prototype</span>._onClickPauseBtn = <span class="reserved">function</span>(v, oSelf) {
var btn = oSelf._pauseBtn;
<span class="reserved">if</span>(btn.value == <span class="literal">"Resume"</span>) {
oSelf.resume();
btn.value = <span class="literal">"Pause"</span>;
}
<span class="reserved">else</span> {
oSelf.pause();
btn.value = <span class="literal">"Resume"</span>;
}
};
<span class="comment">/**
* Handles click events on the clear button.
*
* <span class="attrib">@param</span> {event} v The click event
* <span class="attrib">@param</span> {object} oSelf The log reader instance
* <span class="attrib">@private</span>
*/</span>
YAHOO.widget.LogReader.<span class="reserved">prototype</span>._onClickClearBtn = <span class="reserved">function</span>(v, oSelf) {
oSelf._clearConsole();
};
<span class="comment">/**
* Handles Logger's onNewEvent.
*
* <span class="attrib">@param</span> {string} type The click event
* <span class="attrib">@param</span> {array} args Data passed from event firer
* <span class="attrib">@param</span> {object} oSelf The log reader instance
* <span class="attrib">@private</span>
*/</span>
YAHOO.widget.LogReader.<span class="reserved">prototype</span>._onNewLog = <span class="reserved">function</span>(type, args, oSelf) {
var logEntry = args[0];
oSelf._buffer.push(logEntry);
<span class="reserved">if</span> (oSelf.logReaderEnabled === true &amp;&amp; oSelf._timeout === null) {
oSelf._timeout = setTimeout(<span class="reserved">function</span>(){oSelf._printBuffer();}, 100);
}
};
</pre>
</div>
</div>
</div>
<div id="footer">
<hr />
Copyright &copy; 2006 Yahoo! Inc. All rights reserved.
<br />
Documentation generated by <a href="http://jsdoc.sourceforge.net/">JSDoc</a>
</div>
</body>
</html>