Ticket #6619: firebug_JS.patch

File firebug_JS.patch, 13.6 kB (added by guest, 9 months ago)

Firebug js file

  • firebug.js

     
    120120                        } 
    121121                }, 
    122122                 
    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, "&nbsp;&nbsp;&nbsp;&nbsp;"); 
     127                        logRow([str], "dir"); 
    153128                }, 
    154129                 
    155130                dirxml: function(node){ 
    156131                        // summary:  
    157132                        // 
    158133                        var html = []; 
    159                          
    160134                        appendNode(node, html); 
    161135                        logRow(html, "dirxml"); 
    162136                }, 
     
    237211                                toggleConsole(); 
    238212                        } 
    239213                }, 
    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(){ 
    241250                        // summary:  
    242251                        //              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"; 
    244254                        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                        } 
    246275                } 
    247276        }; 
    248   
     277         
    249278        // *************************************************************************** 
    250279         
    251280        // using global objects so they can be accessed 
     
    256285         
    257286        var consoleFrame = null; 
    258287        var consoleBody = null; 
     288        var consoleObjectInspector = null; 
     289        var fireBugTabs = null; 
    259290        var commandLine = null; 
    260291        var consoleToolbar = null; 
    261292         
     
    264295        var groupStack = []; 
    265296        var timeMap = {}; 
    266297         
    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; 
    268307 
    269308        // *************************************************************************** 
    270309 
     
    293332                var newDoc=win.document; 
    294333                //Safari needs an HTML height 
    295334                HTMLstring=     '<html style="height:100%;"><head><title>Firebug Lite</title></head>\n' + 
    296                                         '<body bgColor="#ccc" style="height:98%;" onresize="opener.onFirebugResize()">\n' + 
     335                                        '<body bgColor="#ccc" style="height:97%;" onresize="opener.onFirebugResize()">\n' + 
    297336                                        '<div id="fb"></div>' + 
    298337                                        '</body></html>'; 
    299338         
     
    403442                consoleFrame.style.height = containerHeight; 
    404443                consoleFrame.style.display = (frameVisible ? "block" : "none");    
    405444                 
    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                } 
    407448                consoleFrame.innerHTML =  
    408449                          '<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>' 
    413460                        + '</div>' 
    414461                        + '<input type="text" id="firebugCommandLine" />' 
    415462                        + '<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>'; 
    417465 
    418466 
    419467                consoleToolbar = _firebugDoc.getElementById("firebugToolbar"); 
    420                 consoleToolbar.onmousedown = onSplitterMouseDown; 
    421468 
    422469                commandLine = _firebugDoc.getElementById("firebugCommandLine"); 
    423470                addEvent(commandLine, "keydown", onCommandLineKeyDown); 
     
    426473                 
    427474                consoleBody = _firebugDoc.getElementById("firebugLog"); 
    428475                consoleObjectInspector = _firebugDoc.getElementById("objectLog"); 
    429  
     476                consoleDomInspector = _firebugDoc.getElementById("domInspect"); 
     477                fireBugTabs = _firebugDoc.getElementById("fireBugTabs"); 
    430478                layout(); 
    431479                flush(); 
    432480        } 
     
    443491                consoleFrame = null; 
    444492                consoleBody = null; 
    445493                consoleObjectInspector = null; 
     494                consoleDomInspector = null; 
    446495                commandLine = null; 
    447496                messageQueue = []; 
    448497                groupStack = []; 
     
    467516        } 
    468517         
    469518        function layout(h){ 
     519                var tHeight = 25; //consoleToolbar.offsetHeight; // tab style not ready on load - throws off layout 
    470520                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"; 
    473523                 
    474                 consoleBody.style.top = consoleToolbar.offsetHeight + "px"; 
     524                consoleBody.style.top = tHeight + "px"; 
    475525                consoleBody.style.height = height; 
    476526                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"; 
    478530                commandLine.style.bottom = 0; 
    479531        } 
    480532         
     
    572624 
    573625                        }else if(typeof(object) == "string"){ 
    574626                                appendText(object, html); 
    575                  
     627                         
     628                        }else if(object instanceof Date){ 
     629                                appendText(object.toString(), html); 
     630                                 
    576631                        }else if(object.nodeType == 9){ 
    577632                                appendText("[ XmlDoc ]", html); 
    578633 
    579                         }else if(object.nodeType == 1){ 
    580                                 // simple tracing of dom nodes 
    581                                 appendText("< "+object.tagName+" id=\""+ object.id+"\" />", html); 
    582                                  
    583634                        }else{ 
    584635                                // Create link for object inspector 
    585636                                // need to create an ID for this link, since it is currently text 
     
    605656                        btn.obj = obs[i]; 
    606657         
    607658                        _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();">&nbsp;<<&nbsp;Back</a>'; 
     659                                 
     660                                console.openObjectInspector(); 
     661                                 
    613662                                try{ 
    614663                                        printObject(this.obj); 
    615664                                }catch(e){ 
    616665                                        this.obj = e; 
    617666                                } 
    618                                 consoleObjectInspector.innerHTML = bkBtn + "<pre>" + printObject( this.obj ) + "</pre>"; 
     667                                consoleObjectInspector.innerHTML = "<pre>" + printObject( this.obj ) + "</pre>"; 
    619668                        })); 
    620669                } 
    621670        } 
     
    844893                } 
    845894        } 
    846895 
    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          
    889896        function onCommandLineKeyDown(event){ 
    890897                if(event.keyCode == 13 && commandLine.value){ 
    891898                        addToHistory(commandLine.value); 
     
    978985 
    979986        //*************************************************************************************************** 
    980987        // 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++    
    991992                } 
     993                return cnt; 
    992994        } 
    993  
     995         
    994996        function printObject(o, i, txt, used){ 
    995997                // 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"; 
    9991000                txt = txt || ""; 
    10001001                i = i || ind; 
    10011002                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                 
    10021016                looking: 
    10031017                for(var nm in o){ 
     1018                        cnt++; 
     1019                        if(cnt==length) br = "\n"; 
    10041020                        if(o[nm] === window || o[nm] === document){ 
    10051021                                continue; 
    10061022                        }else if(o[nm] && o[nm].nodeType){ 
    10071023                                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; 
    10091025                                }else if(o[nm].nodeType == 3){ 
    10101026                                        txt += i+nm + " : [ TextNode "+o[nm].data + " ]" + br; 
    10111027                                } 
     1028                         
    10121029                        }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                                 
    10141035                        }else if(typeof(o[nm]) == "object" && o[nm]){ 
    10151036                                for(var j = 0, seen; seen = used[j]; j++){ 
    10161037                                        if(o[nm] === seen){ 
     
    10191040                                        } 
    10201041                                } 
    10211042                                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) 
    10231046                                txt += printObject(o[nm], i+ind, "", used); 
     1047                                txt += i + opnCls[1] + br; 
     1048                         
    10241049                        }else if(typeof o[nm] == "undefined"){ 
    10251050                                txt += i+nm + " : undefined" + br; 
    10261051                        }else if(nm == "toString" && typeof o[nm] == "function"){ 
     
    10331058                                txt += i+nm +" : "+ escapeHTML(getObjectAbbr(o[nm])) + br; 
    10341059                        } 
    10351060                } 
    1036                 txt += br; // keeps data from running to the edge of page 
    10371061                return txt; 
    10381062        } 
    10391063 
     
    10431067                // X items in an array 
    10441068                // TODO: Firebug Sr. actually goes by char count 
    10451069                var isError = (obj instanceof Error); 
     1070                if(obj.nodeType == 1 || obj.nodeType == 3){ 
     1071                        return escapeHTML('< '+obj.tagName.toLowerCase()+' id=\"'+ obj.id+ '\" />'); 
     1072                } 
    10461073                var nm = (obj && (obj.id || obj.name || obj.ObjectID || obj.widgetId)); 
    10471074                if(!isError && nm){ return "{"+nm+"}";  } 
    10481075