fside
07-30-2008, 06:30 PM
It seemed a bit of a trivial routine to put here. People can use development tools in Firefox, for example. And probably many already have something like this, anyway. But you never know.
Sometimes you can't use "alert" for debugging. It throws things off, particularly with all the timed callbacks people use today for FX. So, instead, you take your variable states and put them in a div, instead. Simple.
So, to do that, you put the style in your main style sheet. You put the function code in your main js file. And to use it, just call the function - bug(var1, var2 . . . ); - anywhere in your code. If the variables don't matter, just use - bug('here'); - or something just to show exection is reaching that point. The last/most recent bug values will be at the top of the list in the div. It 'pushes' previous results down each time.
var C = {
container: "mainContainer",
debug: "debugger"
}
function bug(){
cd = $(C.debug);
if (cd){
cd.innerHTML = "<br>" +cd.innerHTML;
cd.style.display = "block";
for (var i=arguments.length-1; i >-1; i-=1){ cd.innerHTML = [i>0 ? ", " : "", arguments[i]].join("") +cd.innerHTML; }
}
}
D.newEl(C.debug, C.container, "div", "onclick='this.innerHTML=\"\"'");
D.newEl is whatever you use to add new elements to the DOM. I use the function shown in the Add/Hide thread posted right here in this forum. And "mainContainer" would be a div just inside the BODY tags.
#debugger {
display: none;
position: absolute;
text-align: left;
bottom: 0px;
right: 0px;
width: 600px;
height: 300px;
border: 4px solid #000;
background: #fff;
overflow: auto;
z-index: 1000;
}
Sometimes you can't use "alert" for debugging. It throws things off, particularly with all the timed callbacks people use today for FX. So, instead, you take your variable states and put them in a div, instead. Simple.
So, to do that, you put the style in your main style sheet. You put the function code in your main js file. And to use it, just call the function - bug(var1, var2 . . . ); - anywhere in your code. If the variables don't matter, just use - bug('here'); - or something just to show exection is reaching that point. The last/most recent bug values will be at the top of the list in the div. It 'pushes' previous results down each time.
var C = {
container: "mainContainer",
debug: "debugger"
}
function bug(){
cd = $(C.debug);
if (cd){
cd.innerHTML = "<br>" +cd.innerHTML;
cd.style.display = "block";
for (var i=arguments.length-1; i >-1; i-=1){ cd.innerHTML = [i>0 ? ", " : "", arguments[i]].join("") +cd.innerHTML; }
}
}
D.newEl(C.debug, C.container, "div", "onclick='this.innerHTML=\"\"'");
D.newEl is whatever you use to add new elements to the DOM. I use the function shown in the Add/Hide thread posted right here in this forum. And "mainContainer" would be a div just inside the BODY tags.
#debugger {
display: none;
position: absolute;
text-align: left;
bottom: 0px;
right: 0px;
width: 600px;
height: 300px;
border: 4px solid #000;
background: #fff;
overflow: auto;
z-index: 1000;
}