1 /* See license.txt for terms of usage */ 2 function _FirebugConsole() 3 { 4 this.log = function() { window._firebug.notifyFirebug(arguments, 'log', 'firebugAppendConsole'); } 5 this.debug = function() { window._firebug.notifyFirebug(arguments, 'debug', 'firebugAppendConsole'); } 6 this.info = function() { window._firebug.notifyFirebug(arguments, 'info', 'firebugAppendConsole'); } 7 this.warn = function() { window._firebug.notifyFirebug(arguments, 'warn', 'firebugAppendConsole'); } 8 this.error = function() { window._firebug.notifyFirebug(arguments, 'error', 'firebugAppendConsole'); } 9 this.exception = function() { window._firebug.notifyFirebug(arguments, 'exception', 'firebugAppendConsole'); } 10 this.assert = function() { window._firebug.notifyFirebug(arguments, 'assert', 'firebugAppendConsole'); } 11 this.dir = function() { window._firebug.notifyFirebug(arguments, 'dir', 'firebugAppendConsole'); } 12 this.dirxml = function() { window._firebug.notifyFirebug(arguments, 'dirxml', 'firebugAppendConsole'); } 13 this.trace = function firebugDebuggerTracer() { debugger; } 14 this.group = function() { window._firebug.notifyFirebug(arguments, 'group', 'firebugAppendConsole'); } 15 this.groupEnd = function() { window._firebug.notifyFirebug(arguments, 'groupEnd', 'firebugAppendConsole'); } 16 this.groupCollapsed = function() { window._firebug.notifyFirebug(arguments, 'groupCollapsed', 'firebugAppendConsole'); } 17 this.time = function() { window._firebug.notifyFirebug(arguments, 'time', 'firebugAppendConsole'); } 18 this.timeEnd = function() { window._firebug.notifyFirebug(arguments, 'timeEnd', 'firebugAppendConsole'); } 19 this.profile = function() { window._firebug.notifyFirebug(arguments, 'profile', 'firebugAppendConsole'); } 20 this.profileEnd = function() { window._firebug.notifyFirebug(arguments, 'profileEnd', 'firebugAppendConsole'); } 21 this.count = function() { window._firebug.notifyFirebug(arguments, 'count', 'firebugAppendConsole'); } 22 this.clear = function() { window._firebug.notifyFirebug(arguments, 'clear', 'firebugAppendConsole'); } 23 24 // DBG this.uid = Math.random(); 25 26 this.notifyFirebug = function(objs, methodName, eventID) 27 { 28 var element = this.getFirebugElement(); 29 30 var event = document.createEvent("Events"); 31 event.initEvent(eventID, true, false); 32 33 window._firebug.userObjects = []; 34 for (var i=0; i<objs.length; i++) 35 window._firebug.userObjects.push(objs[i]); 36 37 var length = window._firebug.userObjects.length; 38 element.setAttribute("methodName", methodName); 39 40 // DBG element.setAttribute("uid", this.uid); 41 42 // DBG if (length > 0) 43 // DBG element.setAttribute("checkUserObjects", this.userObjects[0].toString()); 44 // DBG else 45 // DBG element.setAttribute("checkUserObjects", "no userObjects"); 46 47 // DBG dump("FirebugConsole("+this.uid+") dispatching event "+methodName+" via "+eventID+" with "+length+ " user objects, [0]:"+this.userObjects[0]+"\n"); 48 //debugger; 49 50 element.dispatchEvent(event); 51 52 // DBG dump("FirebugConsole dispatched event "+methodName+" via "+eventID+" with "+length+ " user objects, [0]:"+this.userObjects[0]+"\n"); 53 54 var result; 55 if (element.getAttribute("retValueType") == "array") 56 result = []; 57 58 if (!result && this.userObjects.length == length+1) 59 return this.userObjects[length]; 60 61 for (var i=length; i<this.userObjects.length && result; i++) 62 result.push(this.userObjects[i]); 63 64 return result; 65 }; 66 67 this.getFirebugElement = function() 68 { 69 if (!this.element) 70 this.element = window._getFirebugConsoleElement(); 71 return this.element; 72 }, 73 74 // *********************************************************************** 75 // Console API 76 77 this.__defineGetter__("firebug", function(){ 78 return this.getFirebugElement().getAttribute("FirebugVersion"); 79 }); 80 } 81 82 window._getFirebugConsoleElement = function() // could this be done in extension code? but only after load.... 83 { 84 var element = document.getElementById("_firebugConsole"); 85 if (!element) 86 { 87 if (document.documentElement.nodeName == document.documentElement.nodeName.toUpperCase()) 88 element = document.createElement("div"); 89 else 90 element = document.createElementNS("http://www.w3.org/1999/xhtml","html:div"); // NS for XML/svg 91 92 element.setAttribute("id", "_firebugConsole"); 93 element.firebugIgnore = true; 94 element.setAttribute("style", "display:none"); 95 96 var body = document.body ? document.body : document.getElementsByTagName("body")[0]; 97 if (!body) 98 body = document.documentElement; // For non-HTML docs 99 100 body.appendChild(element); 101 } 102 return element; 103 }; 104