MochiKit has a ton of great features. A feature I've found helpful when
working with my TG app is the interactive interpreter as demonstrated
on the MochiKit site:
http://www.mochikit.com/examples/interpreter/index.html

I decided to integrate this into my application as a debugging tool,
but didn't want it to pop up on each page, so here's what I came up
with:

You should already have this line in the header:
<script type="text/javascript" src="tg_js/MochiKit.js"></script>

Download the MochiKit distribution (http://mochikit.com/download.html)
and put it somewhere accessible (like the static folder of your
project), then put the following code in your header as well
(substituting your path to the MochiKit distro as appropriate):
---------------------------------------------
<link href="[PATH TO MOCHIKIT]/examples/interpreter/interpreter.css"
rel="stylesheet" type="text/css" />
<script type="text/javascript" src="[PATH TO
MOCHIKIT]/examples/interpreter/interpreter.js"></script>
<script type="text/javascript">
function debug() {
    if (!debug.box) {
        debug.box = document.createElement("div");
        debug.box.setAttribute("style",
                               "background-color: white; " +
                               "border: solid black 3px; " +
                               "padding: 10px;");
        document.body.appendChild(debug.box);
    }

    // Start Mochikit interpreter
    if (!(typeof(interpreterManager) == "undefined")) {
            debugString = '<h5>Interactive Javascript
Interpreter/Debugger</h5><form id="interpreter_form"><div
id="interpreter_area"><div id="interpreter_output"></div></div><input
id="interpreter_text" name="input_text" type="text" class="textbox"
size="100" /></form>';
            debug.box.innerHTML = debugString;
            interpreterManager.initialize();
    } else {
            debugString = '<h5>MochiKit Interactive
Interpreter/Debugger Not Found</h5>';
            debug.box.innerHTML = debugString;
    }
}
</script>
---------------------------------------------

The code shouldn't intrude in your normal day-to-day development/usage
of the application; however, when you need to peek under the hood and
check out or experiment with the JavaScript on any given page, you just
type "javascript:window.debug()" in your browser's address bar (or
create a bookmarklet for it), and up pops the interpreter at the bottom
of your page.

Reply via email to