Kwiki-JSLog
view release on metacpan or search on metacpan
lib/Kwiki/JSLog.pm view on Meta::CPAN
function $(o){return document.getElementById(o)};
/*------------------------------------------------------------------------------------
Public Methods
------------------------------------------------------------------------------------*/
function debug(msg) {
logMsg("DEBUG",msg);
}
function info(msg) {
logMsg("INFO",msg);
}
function warning(msg) {
logMsg("WARN",msg);
}
function error(msg) {
logMsg("ERROR",msg);
}
// This method toggles the on-screen display div on or off as needed
function toggleDisplay() {
var oBody = $(sDOMInstance+'_body');
if (oBody.style.display == 'none') {
oBody.style.display = 'block';
} else {
oBody.style.display = 'none';
}
if (bPersistState) {
EC.F.setCookie(sInstance+"_visibility",oBody.style.display);
}
}
// this function clears the on-screen display
function clearLog() {
$(sDOMInstance+'_logDisplay').innerHTML = '';
nNumMsgsLogged = 0;
$(sDOMInstance+'_handle').innerHTML=nNumMsgsLogged;
}
/*
Public method to programmatically enable jslog, even if it's turned off via the config.
Use this if you want jslog generally turned off, but turned on for one specific page.
If the logger is already enabled, does nothing.
*/
function enable() {
if (!bLoggerConfigured) {
initializeDisplay();
}
}
/*
Public method to set any amount of text into the text area
*/
function text(sText) {
$(sDOMInstance+"_textArea").value=sText;
}
/*
Public method to try to get the innerHTML of the element identified in the text input box, and place it into the clipboard
from view.
*/
function getHTML () {
var sIdToInspect = $(sDOMInstance+"_idToInspect").value;
if (sIdToInspect == "" ) {
warning("Provide a non-blank id");
} else {
try {
// get the element with the id entered, copy its outerHTML to a hidden text area, and then transfer it to the clipboard
var oTextArea = $(sDOMInstance+"_textArea").value = $(sIdToInspect).innerHTML;
info(sIdToInspect+" innerHTML is now in the text box below!");
} catch(e) {
error("Could not get innerHTML of id="+sIdToInspect+": "+e.message);
}
// finally, persist the id that was entered in a cookie
EC.F.setCookie(sInstance+"_idToInspect",sIdToInspect);
}
}
// Specify the methods that are to be public here. This is what exposes them publicly
this.debug=debug;
this.info=info;
this.warning=warning;
this.error=error;
this.toggleDisplay=toggleDisplay;
this.clearLog=clearLog;
this.text=text;
this.enable = enable;
this.getHTML = getHTML
/*------------------------------------------------------------------------------------
Private Methods
------------------------------------------------------------------------------------*/
//This function logs a message. All the level-specific methods (logger.debug, etc.) turn around and call this methods
function logMsg(level,msg) {
if (Config_Enabled) {
// increase the count in the handle
nNumMsgsLogged +=1;
$(sDOMInstance+'_handle').innerHTML=nNumMsgsLogged;
// Append the log to a display div so it can be seen right away
var oDisplay =$(sDOMInstance+'_logDisplay');
if (oDisplay.childNodes.length == 0 ) {
oDisplay.appendChild(createDisplayRow(level,msg));
} else {
oDisplay.insertBefore(createDisplayRow(level,msg),oDisplay.childNodes[0]);
}
} // end of is config enabled
}
// this private method creates the row to add the the display div. It generates what actually gets shown
// in the appropriate div each time there's a logged event
function createDisplayRow(sLevel, sMsg) {
if (document.all) { // very basic browser detection
var sFloat="styleFloat"; //ie
} else {
var sFloat="cssFloat"; //firefox
}
var oRes = document.createElement("div");
if (nNumMsgsLogged/2 == Math.floor(nNumMsgsLogged/2)) {
oRes.style.backgroundColor="#FFF";
} else {
oRes.style.backgroundColor="#F6F6F6";
}
oRes.style.borderBottom="1px solid #AAA";
oRes.style.verticalAlign="top";
var oSev=document.createElement("div");
oSev.style.width="40px";
( run in 2.141 seconds using v1.01-cache-2.11-cpan-84e82930d8c )