Ticket #6619: firebug_JS.patch
| File firebug_JS.patch, 13.6 kB (added by guest, 9 months ago) |
|---|
-
firebug.js
120 120 } 121 121 }, 122 122 123 dir: function(object){ 124 // summary: 125 // Traces object. Only partially implemented. 126 127 var pairs = []; 128 for(var prop in object){ 129 try{ 130 pairs.push([prop, object[prop]]); 131 }catch(e){ 132 /* squelch */ 133 } 134 } 135 136 pairs.sort(function(a, b){ 137 return a[0] < b[0] ? -1 : 1; 138 }); 139 140 var html = ['<table>']; 141 for(var i = 0; i < pairs.length; ++i){ 142 var name = pairs[i][0], value = pairs[i][1]; 143 144 html.push('<tr>', 145 '<td class="propertyNameCell"><span class="propertyName">', 146 escapeHTML(name), '</span></td>', '<td><span class="propertyValue">'); 147 appendObject(value, html); 148 html.push('</span></td></tr>'); 149 } 150 html.push('</table>'); 151 152 logRow(html, "dir"); 123 dir: function(obj){ 124 var str = printObject( obj ); 125 str = str.replace(/\n/g, "<br />"); 126 str = str.replace(/\t/g, " "); 127 logRow([str], "dir"); 153 128 }, 154 129 155 130 dirxml: function(node){ 156 131 // summary: 157 132 // 158 133 var html = []; 159 160 134 appendNode(node, html); 161 135 logRow(html, "dirxml"); 162 136 }, … … 237 211 toggleConsole(); 238 212 } 239 213 }, 240 closeObjectInspector:function(){ 214 openDomInspector: function(){ 215 consoleBody.style.display = "none"; 216 consoleDomInspector.style.display = "block"; 217 consoleObjectInspector.style.display = "none"; 218 document.body.style.cursor = "pointer"; 219 _inspectionMoveConnection = dojo.connect(document, "mousemove", function(evt){ 220 var node = evt.target; 221 if(_inspectionEnabled && node){ 222 var parent = true; 223 224 if(_inspectCurrentNode){ 225 _inspectCurrentNode.style.border = _restoreBorderStyle; 226 } 227 var html = []; 228 appendNode(node, html); 229 consoleDomInspector.innerHTML = html.join(""); 230 231 _inspectCurrentNode = node; 232 _restoreBorderStyle = _inspectCurrentNode.style.border; 233 _inspectCurrentNode.style.border = "#0000FF 1px solid"; 234 } 235 }); 236 _inspectionClickConnection = dojo.connect(document, "click", function(evt){ 237 _inspectionEnabled = !_inspectionEnabled; 238 }); 239 }, 240 _closeDomInspector: function(){ 241 document.body.style.cursor = "default"; 242 dojo.disconnect(_inspectionMoveConnection); 243 dojo.disconnect(_inspectionClickConnection); 244 _inspectionEnabled = true; 245 if(_inspectCurrentNode){ 246 _inspectCurrentNode.style.border = _restoreBorderStyle; 247 } 248 }, 249 openConsole:function(){ 241 250 // summary: 242 251 // Closes object inspector and opens message console. Do not call this directly 243 consoleObjectInspector.innerHTML = ""; 252 consoleBody.style.display = "block"; 253 consoleDomInspector.style.display = "none"; 244 254 consoleObjectInspector.style.display = "none"; 245 consoleBody.style.display = "block"; 255 console._closeDomInspector(); 256 }, 257 openObjectInspector:function(){ 258 consoleBody.style.display = "none"; 259 consoleDomInspector.style.display = "none"; 260 consoleObjectInspector.style.display = "block"; 261 console._closeDomInspector(); 262 }, 263 recss: function(){ 264 // http://turtle.dojotoolkit.org/~david/recss.html 265 // this is placed in dojo since the console is most likely 266 // in another window and dojo is easilly accessible 267 var i,a,s;a=document.getElementsByTagName('link'); 268 for(i=0;i<a.length;i++){ 269 s=a[i]; 270 if(s.rel.toLowerCase().indexOf('stylesheet')>=0&&s.href) { 271 var h=s.href.replace(/(&|%5C?)forceReload=\d+/,''); 272 s.href=h+(h.indexOf('?')>=0?'&':'?')+'forceReload='+(new Date().valueOf()) 273 } 274 } 246 275 } 247 276 }; 248 277 249 278 // *************************************************************************** 250 279 251 280 // using global objects so they can be accessed … … 256 285 257 286 var consoleFrame = null; 258 287 var consoleBody = null; 288 var consoleObjectInspector = null; 289 var fireBugTabs = null; 259 290 var commandLine = null; 260 291 var consoleToolbar = null; 261 292 … … 264 295 var groupStack = []; 265 296 var timeMap = {}; 266 297 267 var clPrefix = ">>> "; 298 var consoleDomInspector = null; 299 var _inspectionMoveConnection; 300 var _inspectionClickConnection; 301 var _inspectionEnabled = true; 302 var _inspectTempNode = document.createElement("div"); 303 304 305 var _inspectCurrentNode; 306 var _restoreBorderStyle; 268 307 269 308 // *************************************************************************** 270 309 … … 293 332 var newDoc=win.document; 294 333 //Safari needs an HTML height 295 334 HTMLstring= '<html style="height:100%;"><head><title>Firebug Lite</title></head>\n' + 296 '<body bgColor="#ccc" style="height:9 8%;" onresize="opener.onFirebugResize()">\n' +335 '<body bgColor="#ccc" style="height:97%;" onresize="opener.onFirebugResize()">\n' + 297 336 '<div id="fb"></div>' + 298 337 '</body></html>'; 299 338 … … 403 442 consoleFrame.style.height = containerHeight; 404 443 consoleFrame.style.display = (frameVisible ? "block" : "none"); 405 444 406 var closeStr = dojo.config.popup ? "" : ' <a href="#" onclick="console.close(); return false;">Close</a>'; 445 var buildLink = function(label, title, method, _class){ 446 return '<li class="'+_class+'"><a href="javascript:void(0);" onclick="console.'+ method +'(); return false;" title="'+title+'">'+label+'</a></li>' 447 } 407 448 consoleFrame.innerHTML = 408 449 '<div id="firebugToolbar">' 409 + ' <a href="#" onclick="console.clear(); return false;">Clear</a>' 410 + ' <span class="firebugToolbarRight">' 411 + closeStr 412 + ' </span>' 450 + ' <ul id="fireBugTabs" class="tabs">' 451 452 + buildLink("Clear", "Remove All Console Logs", "clear", "") 453 + buildLink("ReCSS", "Refresh CSS without reloading page", "recss", "") 454 455 + buildLink("Console", "Show Console Logs", "openConsole", "right") 456 + buildLink("Object", "Show Object Inspector", "openObjectInspector", "right") 457 + buildLink("DOM", "Show DOM Inspector", "openDomInspector", "right") 458 459 + ' </ul>' 413 460 + '</div>' 414 461 + '<input type="text" id="firebugCommandLine" />' 415 462 + '<div id="firebugLog"></div>' 416 + '<div id="objectLog" style="display:none;"></div>'; 463 + '<div id="objectLog" style="display:none;">Click on an object in the Log display</div>' 464 + '<div id="domInspect" style="display:none;">Hover over HTML elements in the main page. Click to hold selection.</div>'; 417 465 418 466 419 467 consoleToolbar = _firebugDoc.getElementById("firebugToolbar"); 420 consoleToolbar.onmousedown = onSplitterMouseDown;421 468 422 469 commandLine = _firebugDoc.getElementById("firebugCommandLine"); 423 470 addEvent(commandLine, "keydown", onCommandLineKeyDown); … … 426 473 427 474 consoleBody = _firebugDoc.getElementById("firebugLog"); 428 475 consoleObjectInspector = _firebugDoc.getElementById("objectLog"); 429 476 consoleDomInspector = _firebugDoc.getElementById("domInspect"); 477 fireBugTabs = _firebugDoc.getElementById("fireBugTabs"); 430 478 layout(); 431 479 flush(); 432 480 } … … 443 491 consoleFrame = null; 444 492 consoleBody = null; 445 493 consoleObjectInspector = null; 494 consoleDomInspector = null; 446 495 commandLine = null; 447 496 messageQueue = []; 448 497 groupStack = []; … … 467 516 } 468 517 469 518 function layout(h){ 519 var tHeight = 25; //consoleToolbar.offsetHeight; // tab style not ready on load - throws off layout 470 520 var height = h ? 471 h - ( consoleToolbar.offsetHeight + commandLine.offsetHeight +25 + (h*.01)) + "px" :472 consoleFrame.offsetHeight - (consoleToolbar.offsetHeight +commandLine.offsetHeight) + "px";521 h - (tHeight + commandLine.offsetHeight +25 + (h*.01)) + "px" : 522 (consoleFrame.offsetHeight - tHeight - commandLine.offsetHeight) + "px"; 473 523 474 consoleBody.style.top = consoleToolbar.offsetHeight + "px";524 consoleBody.style.top = tHeight + "px"; 475 525 consoleBody.style.height = height; 476 526 consoleObjectInspector.style.height = height; 477 consoleObjectInspector.style.top = consoleToolbar.offsetHeight + "px"; 527 consoleObjectInspector.style.top = tHeight + "px"; 528 consoleDomInspector.style.height = height; 529 consoleDomInspector.style.top = tHeight + "px"; 478 530 commandLine.style.bottom = 0; 479 531 } 480 532 … … 572 624 573 625 }else if(typeof(object) == "string"){ 574 626 appendText(object, html); 575 627 628 }else if(object instanceof Date){ 629 appendText(object.toString(), html); 630 576 631 }else if(object.nodeType == 9){ 577 632 appendText("[ XmlDoc ]", html); 578 633 579 }else if(object.nodeType == 1){580 // simple tracing of dom nodes581 appendText("< "+object.tagName+" id=\""+ object.id+"\" />", html);582 583 634 }else{ 584 635 // Create link for object inspector 585 636 // need to create an ID for this link, since it is currently text … … 605 656 btn.obj = obs[i]; 606 657 607 658 _firebugWin.console._connects.push(dojo.connect(btn, "onclick", function(){ 608 // hide rows 609 consoleBody.style.display = "none"; 610 consoleObjectInspector.style.display = "block"; 611 // create a back button 612 var bkBtn = '<a href="javascript:console.closeObjectInspector();"> << Back</a>'; 659 660 console.openObjectInspector(); 661 613 662 try{ 614 663 printObject(this.obj); 615 664 }catch(e){ 616 665 this.obj = e; 617 666 } 618 consoleObjectInspector.innerHTML = bkBtn +"<pre>" + printObject( this.obj ) + "</pre>";667 consoleObjectInspector.innerHTML = "<pre>" + printObject( this.obj ) + "</pre>"; 619 668 })); 620 669 } 621 670 } … … 844 893 } 845 894 } 846 895 847 848 function onSplitterMouseDown(event){849 if(dojo.isSafari || dojo.isOpera){850 return;851 }852 853 addEvent(document, "mousemove", onSplitterMouseMove);854 addEvent(document, "mouseup", onSplitterMouseUp);855 856 for(var i = 0; i < frames.length; ++i){857 addEvent(frames[i].document, "mousemove", onSplitterMouseMove);858 addEvent(frames[i].document, "mouseup", onSplitterMouseUp);859 }860 }861 862 function onSplitterMouseMove(event){863 var win = document.all ?864 event.srcElement.ownerDocument.parentWindow :865 event.target.ownerDocument.defaultView;866 867 var clientY = event.clientY;868 if(win != win.parent){869 clientY += win.frameElement ? win.frameElement.offsetTop : 0;870 }871 872 var height = consoleFrame.offsetTop + consoleFrame.clientHeight;873 var y = height - clientY;874 875 consoleFrame.style.height = y + "px";876 layout();877 }878 879 function onSplitterMouseUp(event){880 removeEvent(document, "mousemove", onSplitterMouseMove);881 removeEvent(document, "mouseup", onSplitterMouseUp);882 883 for(var i = 0; i < frames.length; ++i){884 removeEvent(frames[i].document, "mousemove", onSplitterMouseMove);885 removeEvent(frames[i].document, "mouseup", onSplitterMouseUp);886 }887 }888 889 896 function onCommandLineKeyDown(event){ 890 897 if(event.keyCode == 13 && commandLine.value){ 891 898 addToHistory(commandLine.value); … … 978 985 979 986 //*************************************************************************************************** 980 987 // Print Object Helpers 981 function getAtts(o){ 982 //Get amount of items in an object 983 if(isArray(o)){ 984 return "[array with " + o.length + " slots]"; 985 }else{ 986 var i = 0; 987 for(var nm in o){ 988 i++; 989 } 990 return "{object with " + i + " items}"; 988 function objectLength(o){ 989 var cnt = 0; 990 for(var nm in o){ 991 cnt++ 991 992 } 993 return cnt; 992 994 } 993 995 994 996 function printObject(o, i, txt, used){ 995 997 // Recursively trace object, indenting to represent depth for display in object inspector 996 // TODO: counter to prevent overly complex or looped objects (will probably help with dom nodes) 997 var br = "\n"; // using a <pre>... otherwise we'd need a <br /> 998 var ind = " "; 998 var br = "\n"; 999 var ind = " \t"; 999 1000 txt = txt || ""; 1000 1001 i = i || ind; 1001 1002 used = used || []; 1003 var opnCls; 1004 1005 if(o && o.nodeType == 1){ 1006 var html = []; 1007 appendNode(o, html); 1008 return html.join(""); 1009 } 1010 if(o instanceof Date){ 1011 return i + o.toString() + br; 1012 } 1013 1014 var br=",\n", cnt = 0, length = objectLength(o) 1015 1002 1016 looking: 1003 1017 for(var nm in o){ 1018 cnt++; 1019 if(cnt==length) br = "\n"; 1004 1020 if(o[nm] === window || o[nm] === document){ 1005 1021 continue; 1006 1022 }else if(o[nm] && o[nm].nodeType){ 1007 1023 if(o[nm].nodeType == 1){ 1008 txt += i+nm + " : < "+o[nm].tagName+" id=\""+ o[nm].id+"\" />" + br;1024 //txt += i+nm + " : < "+o[nm].tagName+" id=\""+ o[nm].id+"\" />" + br; 1009 1025 }else if(o[nm].nodeType == 3){ 1010 1026 txt += i+nm + " : [ TextNode "+o[nm].data + " ]" + br; 1011 1027 } 1028 1012 1029 }else if(typeof o[nm] == "object" && (o[nm] instanceof String || o[nm] instanceof Number || o[nm] instanceof Boolean)){ 1013 txt += i+nm + " : " + o[nm] + br; 1030 txt += i+nm + " : " + o[nm] + "," + br; 1031 1032 }else if(o[nm] instanceof Date){ 1033 txt += i+nm + " : " + o[nm].toString() + br; 1034 1014 1035 }else if(typeof(o[nm]) == "object" && o[nm]){ 1015 1036 for(var j = 0, seen; seen = used[j]; j++){ 1016 1037 if(o[nm] === seen){ … … 1019 1040 } 1020 1041 } 1021 1042 used.push(o[nm]); 1022 txt += i+nm +" -> " + getAtts(o[nm]) + br; 1043 1044 opnCls = (isArray(o))?["[","]"]:["{","}"] 1045 txt += i+nm +" : " + opnCls[0] + "\n";//non-standard break, (no comma) 1023 1046 txt += printObject(o[nm], i+ind, "", used); 1047 txt += i + opnCls[1] + br; 1048 1024 1049 }else if(typeof o[nm] == "undefined"){ 1025 1050 txt += i+nm + " : undefined" + br; 1026 1051 }else if(nm == "toString" && typeof o[nm] == "function"){ … … 1033 1058 txt += i+nm +" : "+ escapeHTML(getObjectAbbr(o[nm])) + br; 1034 1059 } 1035 1060 } 1036 txt += br; // keeps data from running to the edge of page1037 1061 return txt; 1038 1062 } 1039 1063 … … 1043 1067 // X items in an array 1044 1068 // TODO: Firebug Sr. actually goes by char count 1045 1069 var isError = (obj instanceof Error); 1070 if(obj.nodeType == 1 || obj.nodeType == 3){ 1071 return escapeHTML('< '+obj.tagName.toLowerCase()+' id=\"'+ obj.id+ '\" />'); 1072 } 1046 1073 var nm = (obj && (obj.id || obj.name || obj.ObjectID || obj.widgetId)); 1047 1074 if(!isError && nm){ return "{"+nm+"}"; } 1048 1075