123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649 |
- // Licensed Materials - Property of IBM
- //
- // IBM Cognos Products: cpscrn
- //
- // (C) Copyright IBM Corp. 2005, 2011
- //
- // US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
- //
- //
- // Copyright (C) 2008 Cognos ULC, an IBM Company. All rights reserved.
- // Cognos (R) is a trademark of Cognos ULC, (formerly Cognos Incorporated).
- // _F_Debug object can
- // 1) output to a log
- // 2) display a fragment tree.
- // 3) dump an object's contents to a new html window - make sure popups are not blocked
- // For more details see:
- // Debugging Fragments section on http://sottcps4/wiki/index.php?title=Fragment_Implementation_Debugging
- /*
- ** general log object definition
- */
- function _FD_log(useFireBugLite)
- {
- this.useFireBugLite = useFireBugLite;
-
- // array of queued log entries
- this.entries = new Array();
- }
- _FD_log.prototype =
- {
- // add an entry to the log queue
- logEntry: function(obj, func, parms)
- {
- this.obj = obj; // "this" object for func
- this.func = func; // function to execute
- this.parms = parms; // array of arguments
- },
-
- // call this function to add new entries to the log queue
- // it is expected that the parameters to the func will be passed in the call to this function
- appendLogEntry: function(obj, func) // ...
- {
- var parms = Array.prototype.slice.call(arguments, 2);
- var entry = new this.logEntry(obj, func, parms);
- this.entries.push(entry);
- },
- // process the queue of log entries by calling the specified functions in each log entry
- processQueuedEntries: function()
- {
- var current = null;
- if (window.console !== undefined) {
- for (var i=0; i < this.entries.length; i++) {
- current = this.entries[i];
- if (typeof current.func == "string")
- {
- try
- {
- func = eval(current.func);
- }
- catch(e)
- {}
- }
- else
- {
- func = current.func;
- }
- if (typeof func == "function")
- {
- func.apply(current.obj, current.parms);
- }
- }
- }
- },
-
- // begin a new group
- group: function (text, addTimeStamp)
- {
- if (addTimeStamp) {
- var date = new Date();
- text += " : Time: " + date.toLocaleTimeString()
- }
- if (this.useFireBugLite) {
- if (_F_Config.browser == "unknown") {
- // firebug lite console has not finished loading
- // queue the log entry
- this.appendLogEntry(window, "console.group", text);
- return;
- }
- }
- if (window.console !== undefined) {
- console.group(text);
- }
- },
-
- // end group
- groupEnd: function ()
- {
- if (this.useFireBugLite) {
- if (_F_Config.browser == "unknown") {
- // firebug lite console has not finished loading
- // queue the log entry
- this.appendLogEntry(window, "console.groupEnd");
- return;
- }
- }
- if (window.console !== undefined) {
- console.groupEnd();
- }
- },
- // log text
- logText: function (text)
- {
- if (this.useFireBugLite) {
- if (_F_Config.browser == "unknown") {
- // firebug lite console has not finished loading
- // queue the log entry
- this.appendLogEntry(window, "console.log", text );
- return;
- }
- }
- if (window.console !== undefined) {
- console.log(text);
- }
- },
-
- // log with option to group and option to send multiple object arguments
- logDetails: function (groupText) // ...
- {
- if (_F_Debug.useFireBugLite) {
- if (_F_Config.browser == "unknown") {
- // firebug lite console has not finished loading
- // queue the log entry
- var newArgs = Array.prototype.slice.call(arguments, 0);
- newArgs.unshift(this.logDetails); // add "function to call" to front of arguments
- newArgs.unshift(this); // add "object instance to execute function in" to front of arguments
- this.appendLogEntry.apply(_F_Debug.log, newArgs);
- return;
- }
- }
- if (window.console !== undefined) {
- var objs = Array.prototype.slice.call(arguments, 1);
- if (groupText != null)
- {
- console.group(groupText);
- }
- var curObj = null;
- for ( i = 0 ; i < objs.length; i++)
- {
- curObj = objs[i];
- if (typeof curObj == "object")
- {
- if (curObj.debugInfo !== undefined) {
- curObj.debugInfo(curObj);
- }
- else
- {
- console.log(curObj);
- }
- }
- else
- {
- console.log(curObj);
- }
- }
-
- if (groupText != null)
- {
- console.groupEnd();
- }
- }
- }
- }
- /*
- ** fragTree object definition
- */
- function _FD_fragTree(useFireBugLite, IELiteLevel )
- {
- this.useFireBugLite = useFireBugLite;
- this.IELiteLevel = IELiteLevel;
- }
- _FD_fragTree.prototype =
- {
- // walk the fragment tree and process each node for display.
- display: function (nodeId, maxLevel)
- {
- var curLevel = 0;
- if (maxLevel == null) {
- maxLevel = 9999;
- }
- if (nodeId != null && nodeId != "root") {
- this.processFragment(fragments[nodeId], maxLevel, curLevel);
- }
- else {
- for (var id in fragments) {
- if (fragments[id].parent == null) {
- this.processFragment(fragments[id], maxLevel, curLevel);
- }
- }
- }
- },
-
- processFragment: function(frag, maxLevel, curLevel)
- {
- if (frag != null && window.console !== undefined) {
- console.group(frag.id + "\ttitle: " + _F_Strings.normalize(frag.title));
- this.outputFragmentNode(frag);
- this.processBranch(frag, maxLevel, curLevel);
- console.groupEnd();
- }
- },
- // recursive function to display the fragments in a tree branch
- processBranch: function(frag, maxLevel, curLevel)
- {
- curLevel++;
- if (frag != null && curLevel < maxLevel) {
- var children = frag.getChildren();
- var i, l = children.length;
- for (i = 0; i < l; i++) {
- this.processFragment(children[i], maxLevel, curLevel);
- }
- }
- },
-
- // output the fragment node to the console
- outputFragmentNode: function(frag)
- {
- if (window.console !== undefined) {
- if (this.useFireBugLite) {
- if (this.IELiteLevel & _F_Debug.OBJECT_LVL) {
- console.group("frag");
- console.dir(frag);
- console.groupEnd();
- }
- console.group("div");
- if (this.IELiteLevel & _F_Debug.DIV_LVL) {
- var divObj = $(frag.div);
- if (divObj !== null) {
- console.dirxml($(frag.div));
- }
- }
- else {
- console.log(frag.div);
- }
- console.groupEnd();
- }
- else { // Firebug on Firefox
- console.log(frag);
- console.log($(frag.div));
- }
- }
- }
- }
- /*
- ** Dump object definition
- */
- function _FD_Dump ()
- {
- _debug_all = [];
- }
- _FD_Dump.prototype =
- {
- DebugView: function(o)
- {
- this._debug_all = [];
- var w = window.open("about:blank");
- if ( w == null) {
- return ("Cannot open window!");
- }
- w.location.href = "about:blank";
- w.document.open();
- w.document.writeln("<HTML><HEAD>"+
- "<TITLE>Dump</TITLE>"+
- "<STYLE type=\"text/css\">"+
- "BODY{font-family:andale mono, courier; font-size: 8pt; -moz-user-select: none;}"+
- "DIV{display:inline}"+
- ".H{color:blue;text-decoration:underline;cursor:pointer}"+
- ".c{color:#006600}"+
- ".n{color:#FF6600}"+
- ".f{color:#000066;font-weight:bold}"+
- ".t{color:#3366CC}"+
- "</STYLE>"+
- "<SCRIPT type=\"text/javascript\">"+
- "var last=null;"+
- "var lastLeft=0;"+
- "var lastTop=0;"+
- "function _debug_hilite(id){"+
- "if(last!=null){"+
- "document.getElementById(last).style.backgroundColor=\"\";" +
- "window.scrollTo(lastLeft,lastTop);"+
- "}"+
- "if(id!=null){" +
- "lastLeft=document.body.scrollLeft;"+
- "lastTop=document.body.scrollTop;"+
- "document.getElementById(id).style.backgroundColor=\"#FFCC66\";" +
- "window.scrollTo(0,document.getElementById(id).offsetTop);"+
- "}" +
- "last=id;" +
- "return false;"+
- "}" +
- "window.onload = function() {"+
- "document.onselectstart = function() {return false;}"+
- "}"+
- "</SCRIPT>" +
- "</HEAD><BODY onmouseup=\"_debug_hilite(null)\">");
- w.document.writeln(this._debug_renderObject(o,1));
- w.document.writeln("</BODY></HTML>");
- w.document.close();
- return ("Done");
- },
- _debug_indent: function(l)
- {
- var ret = "";
- for (var i=0; i<l; i++) ret = ret + " ";
- return ret;
- },
- _debug_renderObject: function(o,l)
- {
- if (o==null) {
- return "<SPAN class=\"n\">null</SPAN>";
- } else if (typeof(o)=="string") {
- return "<SPAN class=\"t\">\"" + this._debugHtmlEncode(o) + "\"</SPAN>";
- } else if (typeof(o)=="boolean") {
- return "<SPAN class=\"n\">"+((o) ? "true" : "false")+"</SPAN>";
- } else if (typeof(o)=="number") {
- return "<SPAN class=\"n\">"+o+"</SPAN>";
- } else if (typeof(o)=="function") {
- return "<SPAN class=\"f\">function()</SPAN> { <SPAN class=\"c\">/* code omitted */</SPAN> }";
- } else if (typeof(o)=="object") {
- var ret = this._debug_filterObject(o);
- if (ret != null) {
- return ret;
- }
-
- var i = this._debug_wasDisplayed(o);
- if (i != -1) {
- return "{ <SPAN class=\"H\" onmousedown=\"_debug_hilite('I"+i+"')\">object</SPAN> }";
- }
-
- var ret;
- if (typeof(o.length)=="number" ) {
- ret = "<DIV id=\"I"+(this._debug_all.length-1)+"\">[ ";
- i = 0;
- if (o.length >= 0) {
- for (i=0; i<o.length;i++) {
- if (i>0) {
- ret += ",<BR>\n";
- }
- else {
- ret += "<BR>\n";
- }
- ret += this._debug_indent(l) + this._debug_renderObject(o[i],l+1);
- }
- }
- if (i > 0) {
- ret += "<BR>\n";
- }
- ret += this._debug_indent(l-1) + "]</DIV>";
- return ret;
- } else {
- ret = "<DIV id=\"I"+(this._debug_all.length-1)+"\">{ ";
- var count = 0;
- try {
- for (i in o) {
- if (count++>0) {
- ret += ",<BR>\n";
- }
- else {
- ret += "<BR>\n";
- }
- ret += this._debug_indent(l) + i + ": " + this._debug_renderObject(o[i],l+1);
- }
- } catch(e) {
-
- }
- if (count > 0) {
- ret += "<BR>\n";
- }
- ret += this._debug_indent(l-1) + "}</DIV>";
- return ret;
- }
- } else {
- return "!"+typeof(o);
- }
- },
- _debug_wasDisplayed: function(o) {
- var c=this._debug_all.length;
- for (var i=0; i<c; i++) {
- if (this._debug_all[i]===o) {
- return i;
- }
- }
- this._debug_all[c] = o;
- return -1;
- },
- _debug_filterObject: function (o) {
- if (o===document) {
- return "document";
- } else if (o===window) {
- return "window";
- } else if (o===document.body) {
- return "document.body";
- } else if (o===document.documentElement) {
- return "document.documentElement";
- } else if (o.constructor && o.constructor.toString().indexOf("[HTML") == 0) {
- return "HTMLDOM";
- }
- return null;
- },
- _debugHtmlEncode: function(text)
- {
- return text.replace(/</g, "<").replace(/>/g, ">");
- }
- }
- /**
- * Initial settings for _F_Debug come from pf.properties file
- * Main object for debug functionality
- */
- var _F_Debug =
- {
- enabled: false,
- useFireBugLite: (navigator.userAgent.indexOf("Firefox")== -1),
-
- // bit masks for IE logging level
- // developers can change this setting by calling setIELiteLevel
- NORMAL_LVL : 0x1, // 1 - minimal logging
- OBJECT_LVL : 0x2, // 2 - output object xml
- DIV_LVL : 0x4, // 4 - output div html
- // 15 - for all levels of IE Lite logging
- IELiteLevel: 1,
-
- // developers can change the global settings per object type directly on the firebug console cmd line.
- // _F_Debug.settings["fragment"]= 0; or 1 or 2 ( OFF, ON, DEPEND )
- // _F_Debug.settings["_F_Event"]= 2;
- SETTING_OFF: 0,
- SETTING_ON: 1,
- SETTING_DEPEND: 2, // example: if parent or source debug is on
- settings: new Object(),
- log: new _FD_log((navigator.userAgent.indexOf("Firefox")== -1)),
- fragTree: new _FD_fragTree((navigator.userAgent.indexOf("Firefox")== -1), 1),
- dump: new _FD_Dump(),
-
- initialize: function()
- {
- if(this.useFireBugLite) {
- if (window.console === undefined) {
- window.alert("FireBugLite is not installed");
- }
- else {
- _F_Debug.log.processQueuedEntries();
- }
- }
- else if (window.console === undefined) {
- window.alert("FireBug is not installed or it is disabled");
- }
- },
-
- /**
- * CONSOLE CMD: developer can change IE logging level from the firebug command line
- * see values above.
- **/
- setIELiteLevel: function (level)
- {
- _F_Debug.IELiteLevel = level;
- _F_Debug.fragTree.IELiteLevel = level;
- return ("Done");
- },
-
- /**
- * CONSOLE CMD: Used to set the debug override for fragment objects and possibly their children.
- *
- * Example to debug events that apply only to a particular fragment and the fragment's children:
- * _F_Debug.settings["fragment"] = 0; turn off global fragment debugging
- * _F_Debug.settings["_F_Event"]= 2; sets global event setting to DEPEND which will check the source fragment
- * setFragmentDebug(fragId, 1, true); turn on debugging for only certain fragments.
- */
- setFragmentSetting: function(objectId, setting, bChildren)
- {
- var frag = fragments[objectId];
- if (frag != null) {
- frag.debugOverride = setting;
- if (bChildren) {
- var children = frag.getChildren();
- var i, l = children.length;
- for (i = 0; i < l; i++) {
- children[i].debugOverride = setting;
- }
- }
- return "Done";
- }
- else
- {
- return "Fragment( " + objectId + ") was not found";
- }
- },
-
- /**
- * CONSOLE CMD: Used to display the fragments in a tree. Useful to get id to send to setFragmentSetting.
- * Examples:
- * showFragmentTree(); returns entire tree
- * showFragmentTree("root",4); returns the first 4 levels of the tree starting from the root
- * showFragmentTree("adminconsole_xmlbooklet"); returns the tree starting from the given fragment id.
- * showFragmentTree("adminconsole_xmlbooklet", 4); returns the first 4 levels starting from the given fragment id.
- **/
- showFragmentTree: function(nodeId, maxLevel)
- {
- if (_F_Debug.enabled) {
- _F_Debug.fragTree.display( nodeId, maxLevel);
- return("Done");
- }
- return ("Debug not enabled");
- },
-
- /**
- * CONSOLE CMD: Dumps the contents of an object to a new window
- */
- dumpObject: function(object)
- {
- return(_F_Debug.dump.DebugView(object));
- }
- }
- // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- // Extend the fragment object definition
- // set the debugOverride to override the global setting for this object
- fragment.prototype.debugOverride = -1; // 0 - off, 1 - on, 2 - depends
- fragment.prototype.debugEnabled = function()
- {
- if ( _F_Debug.enabled)
- {
- var debug = this.debugOverride != -1? this.debugOverride : _F_Debug.settings["fragment"];
- if ( debug == _F_Debug.SETTING_DEPEND)
- {
- var frag = this.parent;
- if (frag)
- {
- return frag.debugEnabled();
- }
- }
- return (debug == _F_Debug.SETTING_ON);
- }
- else
- {
- return false;
- }
- };
-
- // output the fragment information to the console
- fragment.prototype.debugInfo = function(frag)
- {
- if (window.console !== undefined) {
- if (_F_Debug.useFireBugLite) {
- if (_F_Debug.IELiteLevel & _F_Debug.OBJECT_LVL) {
- console.group("frag");
- console.dir(frag);
- console.groupEnd();
- }
- console.group("div");
- if (_F_Debug.IELiteLevel & _F_Debug.DIV_LVL) {
- var divObj = $(frag.div);
- if (divObj !== null) {
- console.dirxml($(frag.div));
- }
- }
- else {
- console.log(frag.div);
- }
- console.groupEnd();
- }
- else { // Firebug on Firefox
- console.log(frag);
- console.log($(frag.div));
- }
- }
- }
- // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- // Extend the _F_Event object definition
- // set the debugOverride to override the global setting for this object
- _F_Event.Event.prototype.debugOverride = -1; // 0 - off, 1 - on, 2 - depends
-
- _F_Event.Event.prototype.debugEnabled = function()
- {
- if ( _F_Debug.enabled)
- {
- var debug = this.debugOverride != -1? this.debugOverride : _F_Debug.settings["_F_Event"];
- if ( debug == _F_Debug.SETTING_DEPEND)
- {
- var frag = this.source;
- if (frag)
- {
- return frag.debugEnabled();
- }
- }
- return (debug == _F_Debug.SETTING_ON);
- }
- else
- {
- return false;
- }
- };
- //output event information to the console
- _F_Event.Event.prototype.debugInfo = function( evt)
- {
- if (window.console !== undefined) {
- if (this.useFireBugLite) {
- if (this.IELiteLevel & _F_Debug.OBJECT_LVL) {
- console.group("evt");
- console.dir(evt);
- console.groupEnd();
- }
- else {
- console.log(evt.name);
- }
- }
- else // Firebug on Firefox
- {
- console.log(evt);
- }
- }
- }
|