~azzar1/unity/add-show-desktop-key

« back to all changes in this revision

Viewing changes to www/media/console/console.js

  • Committer: mattgiuca
  • Date: 2008-01-30 22:43:35 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:339
console:
    Bugfix - error trying to "maximize" the window in the full console app.
    Minimize and maximize functions check that the mode is window pane.

    Added support for the Tab key on the console. Now inserts spaces
    (can be changed to '\t' through a constant at the top), and doesn't move
    focus away from the input box.

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
var server_port;
27
27
var server_magic;
28
28
 
 
29
/* Begin religious debate (tabs vs spaces) here: */
 
30
/* (This string will be inserted in the console when the user presses the Tab
 
31
 * key) */
 
32
TAB_STRING = "    ";
 
33
 
29
34
/* Console DOM objects */
30
35
console_body = null;
31
36
console_filler = null;
32
37
 
 
38
windowpane_mode = false;
 
39
 
33
40
/* Starts the console server.
34
41
 * Returns an object with fields "host", "port", "magic" describing the
35
42
 * server.
54
61
    console_body = document.getElementById("console_body");
55
62
    console_filler = document.getElementById("console_filler");
56
63
    if (windowpane)
 
64
    {
 
65
        windowpane_mode = true;
57
66
        console_minimize();
 
67
    }
58
68
    /* Start the server */
59
69
    var server_info = start_server();
60
70
    server_host = server_info.host;
66
76
 *  at the page bottom. */
67
77
function console_minimize()
68
78
{
 
79
    if (!windowpane_mode) return;
69
80
    console_body.setAttribute("class", "windowpane minimal");
70
81
    console_filler.setAttribute("class", "windowpane minimal");
71
82
}
74
85
 */
75
86
function console_maximize()
76
87
{
 
88
    if (!windowpane_mode) return;
77
89
    console_body.setAttribute("class", "windowpane maximal");
78
90
    console_filler.setAttribute("class", "windowpane maximal");
79
91
}
221
233
function catch_input(key)
222
234
{
223
235
    var inp = document.getElementById('console_inputText');
224
 
    if (key == 13)
 
236
    switch (key)
225
237
    {
 
238
    case 9:                 /* Tab key */
 
239
        var selstart = inp.selectionStart;
 
240
        var selend = inp.selectionEnd;
 
241
        if (selstart == selend)
 
242
        {
 
243
            /* No selection, just a carat. Insert a tab here. */
 
244
            inp.value = inp.value.substr(0, selstart)
 
245
                + TAB_STRING + inp.value.substr(selstart);
 
246
        }
 
247
        else
 
248
        {
 
249
            /* Text is selected. Just indent the whole line
 
250
             * by inserting a tab at the start */
 
251
            inp.value = TAB_STRING + inp.value;
 
252
        }
 
253
        /* Update the selection so the same characters as before are selected
 
254
         */
 
255
        inp.selectionStart = selstart + TAB_STRING.length;
 
256
        inp.selectionEnd = inp.selectionStart + (selend - selstart);
 
257
        /* Cancel the event, so the TAB key doesn't move focus away from this
 
258
         * box */
 
259
        return false;
 
260
        /* Note: If it happens that some browsers don't support event
 
261
         * cancelling properly, this hack might work instead:
 
262
        setTimeout(
 
263
            "document.getElementById('console_inputText').focus()",
 
264
            0);
 
265
         */
 
266
        break;
 
267
    case 13:                /* Enter key */
 
268
        /* Send the line of text to the server */
226
269
        console_enter_line(inp.value);
227
270
        hist.add(inp.value);
228
271
        inp.value = hist.curr();
229
 
    }
230
 
    if (key == 38)
231
 
    {
 
272
        break;
 
273
    case 38:                /* Up arrow */
232
274
        hist.up();
233
275
        inp.value = hist.curr();
234
 
    }
235
 
    if (key == 40)
236
 
    {
 
276
        break;
 
277
    case 40:                /* Down arrow */
237
278
        hist.down();
238
279
        inp.value = hist.curr();
 
280
        break;
239
281
    }
240
282
}