if (!("console" in window) || !("firebug" in console)) { (function() { window.console = { firebug: "ibug0.1", log: function() { logFormatted(arguments, ""); }, debug: function() { logFormatted(arguments, "debug"); }, info: function() { logFormatted(arguments, "info"); }, warn: function() { logFormatted(arguments, "warning"); }, error: function() { logFormatted(arguments, "error"); }, assert: function(truth, message) { if (!truth) { var args = []; for (var i = 1; i < arguments.length; ++i) args.push(arguments[i]); logFormatted(args.length ? args : ["Assertion Failure"], "error"); throw message ? message : "Assertion Failure"; } }, dir: function(object) { var html = []; var pairs = []; for (var name in object) { try { pairs.push([name, object[name]]); } catch (exc) { } } pairs.sort(function(a, b) { return a[0] < b[0] ? -1 : 1; }); html.push(''); for (var i = 0; i < pairs.length; ++i) { var name = pairs[i][0], value = pairs[i][1]; html.push('', '', ''); } html.push('
', escapeHTML(name), ''); appendObject(value, html); html.push('
'); logRow(html, "dir"); }, dirxml: function(node) { var html = []; appendNode(node, html); logRow(html, "dirxml"); }, group: function() { logRow(arguments, "group", pushGroup); }, groupEnd: function() { logRow(arguments, "", popGroup); }, time: function(name) { timeMap[name] = (new Date()).getTime(); }, timeEnd: function(name) { if (name in timeMap) { var delta = (new Date()).getTime() - timeMap[name]; logFormatted([name+ ":", delta+"ms"]); delete timeMap[name]; } }, count: function() { this.warn(["count() not supported."]); }, trace: function() { this.warn(["trace() not supported."]); }, profile: function() { this.warn(["profile() not supported."]); }, profileEnd: function() { }, // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * $: function(id) { return document.getElementById(id); }, $$: function(selector) { // XXXjoe Make this into getElementsBySelector return document.getElementsByTagName(selector); }, // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * onError: function(msg, href, lineNo) { var html = []; var lastSlash = href.lastIndexOf("/"); var fileName = lastSlash == -1 ? href : href.substr(lastSlash+1); html.push( '', msg, '', '' ); logRow(html, "error"); }, command: function(text) { with (console) { try { var result = eval(text); if (result !== undefined) console.log(result); } catch (exc) { console.onError(exc.message, exc.sourceId+"", exc.line); } } } }; // ******************************************************************************************** var timeMap = {}; // ******************************************************************************************** function appendText(object, html) { html.push(escapeHTML(objectToString(object))); } function appendNull(object, html) { html.push('', escapeHTML(objectToString(object)), ''); } function appendString(object, html) { html.push('"', escapeHTML(objectToString(object)), '"'); } function appendInteger(object, html) { html.push('', escapeHTML(objectToString(object)), ''); } function appendFloat(object, html) { html.push('', escapeHTML(objectToString(object)), ''); } function appendFunction(object, html) { var reName = /function ?(.*?)\(/; var m = reName.exec(objectToString(object)); var name = m ? m[1] : "function"; html.push('', escapeHTML(name), '()'); } function appendArray(object, html) { html.push('['); for (var i = 0; i < object.length; ++i) { if (i > 0) html.push(','); appendObject(object[i], html); } html.push(']'); } function appendObject(object, html) { try { if (object == undefined) appendNull("undefined", html); else if (object == null) appendNull("null", html); else if (typeof object == "string") appendString(object, html); else if (typeof object == "number") appendInteger(object, html); else if (object.nodeType == 1) appendSelector(object, html); else if (typeof(object.length) == "number") appendArray(object, html); else if (typeof object == "object") appendObjectFormatted(object, html); else if (typeof object == "function") appendFunction(object, html); else appendText(object, html); } catch (exc) { } } function appendObjectFormatted(object, html) { var text = objectToString(object); var reObject = /\[object (.*?)\]/; var m = reObject.exec(text); html.push('', m ? m[1] : text, '') } function appendSelector(object, html) { html.push(''); html.push('', escapeHTML(object.nodeName.toLowerCase()), ''); if (object.id) html.push('#', escapeHTML(object.id), ''); if (object.className) html.push('.', escapeHTML(object.className), ''); html.push(''); } function appendNode(node, html) { if (node.nodeType == 1) { html.push( '
', '<', node.nodeName.toLowerCase(), ''); for (var i = 0; i < node.attributes.length; ++i) { var attr = node.attributes[i]; if (!attr.specified) continue; html.push(' ', attr.nodeName.toLowerCase(), '="', escapeHTML(attr.nodeValue), '"') } if (node.firstChild) { html.push('>
'); for (var child = node.firstChild; child; child = child.nextSibling) appendNode(child, html); html.push('
</', node.nodeName.toLowerCase(), '>
'); } else html.push('/>'); } else if (node.nodeType == 3) { html.push('
', escapeHTML(node.nodeValue), '
'); } } // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * function logRow(message, className, handler) { console.respond(className + "\0" + message.join("")); } function logFormatted(objects, className) { var html = []; var format = objects[0]; var objIndex = 0; if (typeof(format) != "string") { format = ""; objIndex = -1; } var parts = parseFormat(format); for (var i = 0; i < parts.length; ++i) { var part = parts[i]; if (part && typeof(part) == "object") { var object = objects[++objIndex]; part.appender(object, html); } else appendText(part, html); } for (var i = objIndex+1; i < objects.length; ++i) { appendText(" ", html); var object = objects[i]; if (typeof(object) == "string") appendText(object, html); else appendObject(object, html); } if (!className && html.length == 1 && typeof(objects[0]) == "string") className = "text"; logRow(html, className); } function parseFormat(format) { var parts = []; var reg = /((^%|[^\\]%)(\d+)?(\.)([a-zA-Z]))|((^%|[^\\]%)([a-zA-Z]))/; var appenderMap = {s: appendText, d: appendInteger, i: appendInteger, f: appendFloat}; for (var m = reg.exec(format); m; m = reg.exec(format)) { var type = m[8] ? m[8] : m[5]; var appender = type in appenderMap ? appenderMap[type] : appendObject; var precision = m[3] ? parseInt(m[3]) : (m[4] == "." ? -1 : 0); parts.push(format.substr(0, m[0][0] == "%" ? m.index : m.index+1)); parts.push({appender: appender, precision: precision}); format = format.substr(m.index+m[0].length); } parts.push(format); return parts; } function escapeHTML(value) { function replaceChars(ch) { switch (ch) { case "<": return "<"; case ">": return ">"; case "&": return "&"; case "'": return "'"; case '"': return """; } return "?"; }; return String(value).replace(/[<>&"']/g, replaceChars); } function objectToString(object) { try { return object+""; } catch (exc) { return null; } } function init() { var iframe = document.createElement("iframe"); document.body.appendChild(iframe); iframe.src = "http://" + ibugHost + "/phone"; } setTimeout(init, 0); })(); }