window.Babu = { };
Babu.Debugging = {};
Babu.Debugging.writeLine = function(format, arg1, arg2) {
var console = Babu.Debugging._getConsole(); .get_visible( )) {
var msg = format;
if (typeof msg !== "未定義" && msg !== null) {
var インデックス;
if (typeof msg == = "string ") {
var array = format.match(/{(d )}/g);
if (array) {
for (var i = 0; i index = array[i];
index = parseInt(index.substr(1,index.length - 2)) 1;
msg = msg.replace(array[i],引数[インデックス]);
}
}
}
}
var span = document.createElement("SPAN");
span.appendChild(document.createTextNode(msg) );
console._output.appendChild(document.createElement("BR"));
span.scrollIntoView(); >}
}
Babu.Debugging._getConsole = function() {
var console = Babu.Debugging._console;
if (!console) {
var div = document.createElement( "DIV" );
div.style.right = "3px";
div.style.bottom = "3px"; .width = "350px";
div.style.height = "180px";
div.style.color = "黒"; .style.border = "solid 2px #afafaf";
div.style.fontSize = "12px";
Babu.Debugging._console = div;
div = document.createElement("DIV");
div.style.backgroundColor = "#e0e0e0";
div.style.position = "absolute"; "0px" ;
div.style.right = "0px";
div.style.height = "16px";パディング = " 2px 2px";
console.appendChild(div);
console._toolbar = div = document.createElement(" ");
div.style.overflow = "auto";
div.style.whiteSpace = "nowrap";
div.style.position = "absolute";
div.style.left = "0px";
div.style.top = "20px"; .height = "auto";
console._output = div;
btn = document.createElement("SPAN"); .innerHTML = "縮小";
btn.style.margin = "0px 3px";
console._toolbar.appendChild(btn); .onclick = function() { if (console.get_collapsed()) console.expand(); else console.collapse(); }
btn = document.createElement("SPAN"); "クリア" ;
btn.style.margin = "0px 3px";
console._toolbar.appendChild(btn); Babu.Debugging .clearConsole;
btn = document.createElement("SPAN");
btn.style.cursor = "pointer"; .margin = "0px 3px";
console._toolbar.appendChild(btn);
btn.onclick = function() { Babu.Debugging.hideConsole() }
console.get_visible = function(); { return this .style.display !== "none" };
console.get_collapsed = function() { return !(!this._collapseState) };
console.collapse = function() {
if (! this.get_collapsed()) {
this._output.style.display = "none";
this._toolbar.childNodes[1].style.display = "none"; _toolbar.childNodes [2].style.display = "none";
this._toolbar.childNodes[0].innerHTML = "expand";
this._collapseState = { width: this.style.width, height : this.style.height }
this.style.width = "30px";
}
}
console.expand = function( ) {
if (this.get_collapsed()) {
this._output.style.display = "";
this._toolbar.childNodes[1].style.display = ""; this._toolbar .childNodes[2].style.display = "";
this._toolbar.childNodes[0].innerHTML = "折りたたむ";
this.style.width = this._collapseState.width; 🎜>this .style.height = this._collapseState.height;
this._collapseState = null;
}
}
コンソールに戻ります。 Debugging.showConsole = function() {
Babu.Debugging._getConsole().style.display = "";
}
Babu.Debugging.hideConsole = function() {
var console = Babu .Debugging._console;
if (コンソール) {
console.style.display = "none";
Babu.Debugging.clearConsole = function() {
var console = Babu.Debugging._console;
if (console) console._output.innerHTML = "";
}
呼び出しメソッドは非常に簡単です:
コードをコピー
コードは次のとおりです:
Babu.Debugging.writeLine("デバッグ情報");
Babu.Debugging.writeLine("パラメータ付きのデバッグ情報: パラメータ 1={0}、パラメータ 2={1}"、arg1 、 arg2);
呼び出し後、固定位置のウィンドウがウィンドウの右下隅に自動的に表示され、対応するコンテンツが表示されます。以下のレンダリングをご覧ください: