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

« back to all changes in this revision

Viewing changes to console/console.js

  • Committer: drtomc
  • Date: 2007-12-21 00:20:24 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:111
Checkpoint work on the console.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
var magic;
 
2
 
 
3
function make_query_string(pagename, args)
 
4
{
 
5
    var first = true;
 
6
    var qs = pagename;
 
7
    for (key in obj)
 
8
    {
 
9
        vals = obj[key];
 
10
        // vals can be an array, to make multiple args with the same name
 
11
        // To handle this, make non-array objects into an array, then loop
 
12
        if (!(vals instanceof Array))
 
13
            vals = [vals];
 
14
        for each (val in vals)
 
15
        {
 
16
            if (true)
 
17
            {
 
18
                qs += "?";
 
19
                first = false;
 
20
            }
 
21
            else
 
22
            {
 
23
                qs += "&";
 
24
            }
 
25
            qs += encodeURI(key) + "=" + encodeURI(val);
 
26
        }
 
27
    }
 
28
    return qs;
 
29
}
 
30
 
 
31
function enter_line(inp)
 
32
{
 
33
    var digest = hex_md5(inp + magic);
 
34
    var url = make_query_string("chat", {"digest":digest, "text":inp});
 
35
    var xmlhttp = XMLHttpRequest();
 
36
    xmlhttp.open("POST", url, false);
 
37
    xmlhttp.send("")
 
38
    var res = JSON.parse(xmlhttp..responseText);
 
39
    if (res && res[0])
 
40
    {
 
41
        // Success!
 
42
        // print out the output (res[0])
 
43
        // print out the return value (res[1])
 
44
        // set the prompt to >>>
 
45
    }
 
46
    else if (res)
 
47
    {
 
48
        // Failure!
 
49
        // print out the error message (res[2])
 
50
    }
 
51
    else
 
52
    {
 
53
        // Need more input, so set the prompt to ...
 
54
    }
 
55
}