2012-06-25 16:11:16 -07:00
|
|
|
// -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-07-24 07:56:51 -07:00
|
|
|
var gConsole, gConsoleBundle, gTextBoxEval, gEvaluator, gCodeToEvaluate;
|
2012-06-10 16:44:50 -07:00
|
|
|
var gFilter;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/* :::::::: Console Initialization ::::::::::::::: */
|
|
|
|
|
|
|
|
window.onload = function()
|
|
|
|
{
|
|
|
|
gConsole = document.getElementById("ConsoleBox");
|
|
|
|
gConsoleBundle = document.getElementById("ConsoleBundle");
|
|
|
|
gTextBoxEval = document.getElementById("TextboxEval")
|
2007-07-24 07:56:51 -07:00
|
|
|
gEvaluator = document.getElementById("Evaluator");
|
2012-06-10 16:44:50 -07:00
|
|
|
gFilter = document.getElementById("Filter");
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
updateSortCommand(gConsole.sortOrder);
|
|
|
|
updateModeCommand(gConsole.mode);
|
|
|
|
|
2007-07-24 07:56:51 -07:00
|
|
|
gEvaluator.addEventListener("load", loadOrDisplayResult, true);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* :::::::: Console UI Functions ::::::::::::::: */
|
|
|
|
|
2012-06-10 16:44:50 -07:00
|
|
|
function changeFilter()
|
|
|
|
{
|
|
|
|
gConsole.filter = gFilter.value;
|
|
|
|
|
|
|
|
document.persist("ConsoleBox", "filter")
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
function changeMode(aMode)
|
|
|
|
{
|
|
|
|
switch (aMode) {
|
|
|
|
case "Errors":
|
|
|
|
case "Warnings":
|
|
|
|
case "Messages":
|
|
|
|
gConsole.mode = aMode;
|
|
|
|
break;
|
|
|
|
case "All":
|
|
|
|
gConsole.mode = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
document.persist("ConsoleBox", "mode");
|
|
|
|
}
|
|
|
|
|
|
|
|
function clearConsole()
|
|
|
|
{
|
|
|
|
gConsole.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
function changeSortOrder(aOrder)
|
|
|
|
{
|
|
|
|
updateSortCommand(gConsole.sortOrder = aOrder);
|
|
|
|
}
|
|
|
|
|
|
|
|
function updateSortCommand(aOrder)
|
|
|
|
{
|
|
|
|
var orderString = aOrder == 'reverse' ? "Descend" : "Ascend";
|
|
|
|
var bc = document.getElementById("Console:sort"+orderString);
|
|
|
|
bc.setAttribute("checked", true);
|
|
|
|
|
|
|
|
orderString = aOrder == 'reverse' ? "Ascend" : "Descend";
|
|
|
|
bc = document.getElementById("Console:sort"+orderString);
|
|
|
|
bc.setAttribute("checked", false);
|
|
|
|
}
|
|
|
|
|
|
|
|
function updateModeCommand(aMode)
|
|
|
|
{
|
2009-06-14 01:32:45 -07:00
|
|
|
/* aMode can end up invalid if it set by an extension that replaces */
|
|
|
|
/* mode and then it is uninstalled or disabled */
|
|
|
|
var bc = document.getElementById("Console:mode" + aMode) ||
|
|
|
|
document.getElementById("Console:modeAll");
|
2007-03-22 10:30:00 -07:00
|
|
|
bc.setAttribute("checked", true);
|
|
|
|
}
|
|
|
|
|
|
|
|
function onEvalKeyPress(aEvent)
|
|
|
|
{
|
|
|
|
if (aEvent.keyCode == 13)
|
|
|
|
evaluateTypein();
|
|
|
|
}
|
|
|
|
|
|
|
|
function evaluateTypein()
|
|
|
|
{
|
2007-07-24 07:56:51 -07:00
|
|
|
gCodeToEvaluate = gTextBoxEval.value;
|
|
|
|
// reset the iframe first; the code will be evaluated in loadOrDisplayResult
|
|
|
|
// below, once about:blank has completed loading (see bug 385092)
|
|
|
|
gEvaluator.contentWindow.location = "about:blank";
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2007-07-24 07:56:51 -07:00
|
|
|
function loadOrDisplayResult()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2007-07-24 07:56:51 -07:00
|
|
|
if (gCodeToEvaluate) {
|
|
|
|
gEvaluator.contentWindow.location = "javascript: " +
|
|
|
|
gCodeToEvaluate.replace(/%/g, "%25");
|
|
|
|
gCodeToEvaluate = "";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var resultRange = gEvaluator.contentDocument.createRange();
|
|
|
|
resultRange.selectNode(gEvaluator.contentDocument.documentElement);
|
2007-03-22 10:30:00 -07:00
|
|
|
var result = resultRange.toString();
|
|
|
|
if (result)
|
|
|
|
gConsole.mCService.logStringMessage(result);
|
|
|
|
// or could use appendMessage which doesn't persist
|
|
|
|
}
|
|
|
|
|
|
|
|
// XXX DEBUG
|
|
|
|
function debug(aText)
|
|
|
|
{
|
|
|
|
var csClass = Components.classes['@mozilla.org/consoleservice;1'];
|
|
|
|
var cs = csClass.getService(Components.interfaces.nsIConsoleService);
|
|
|
|
cs.logStringMessage(aText);
|
|
|
|
}
|