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

« back to all changes in this revision

Viewing changes to console/console.js

  • Committer: mattgiuca
  • Date: 2008-01-29 23:52:19 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:329
Converted Console from an "app" into a "plugin". It can now be plugged in to
any app.
Added "plugins" directory in www. Added "console" plugin. This contains all of
the functionality of what was previously the console app, but modularized so
it can be imported by another app.

apps/console: Removed most of the logic (moved to plugins/console). Replaced
with a simple import of the console plugin. Should behave exactly the same.
apps/tutorial: As proof of concept, imported the console plugin. It now
appears at the bottom of the page (yet to make it have "pop up" behaviour).

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
function historyAdd(text)
29
29
{
30
30
    this.items[this.items.length] = text;
31
 
    this.cursor = this.items.length
 
31
    this.cursor = this.items.length;
32
32
}
33
33
 
34
34
function historyShow()
71
71
 
72
72
var hist = new History();
73
73
 
74
 
function make_query_string(pagename, args)
75
 
{
76
 
    var first = true;
77
 
    var qs = pagename;
78
 
    for (key in args)
79
 
    {
80
 
        vals = args[key];
81
 
        // vals can be an array, to make multiple args with the same name
82
 
        // To handle this, make non-array objects into an array, then loop
83
 
        if (!(vals instanceof Array))
84
 
            vals = [vals];
85
 
        for each (val in vals)
86
 
        {
87
 
            if (first)
88
 
            {
89
 
                qs += "?";
90
 
                first = false;
91
 
            }
92
 
            else
93
 
            {
94
 
                qs += "&";
95
 
            }
96
 
            qs += encodeURI(key) + "=" + encodeURI(val);
97
 
        }
98
 
    }
99
 
    return qs;
100
 
}
101
 
 
102
74
function make_post_body(args)
103
75
{
104
 
    var first = true;
105
76
    var qs = '';
106
77
    for (key in args)
107
78
    {
110
81
        // To handle this, make non-array objects into an array, then loop
111
82
        if (!(vals instanceof Array))
112
83
            vals = [vals];
113
 
        for each (val in vals)
 
84
        var i;
 
85
        for (i=0; i<vals.length; i++)
114
86
        {
115
 
            if (first)
116
 
            {
117
 
                first = false;
118
 
            }
119
 
            else
 
87
            if (i > 0)
120
88
            {
121
89
                qs += "&";
122
90
            }
123
 
            qs += encodeURI(key) + "=" + encodeURI(val);
 
91
            qs += encodeURIComponent(key) + "=" + encodeURIComponent(vals[i]);
124
92
        }
125
93
    }
126
94
    return qs;
131
99
    var inp = document.getElementById('inputText');
132
100
    var digest = hex_md5(inp.value + magic);
133
101
    var xmlhttp = new XMLHttpRequest();
134
 
    alert(inp.value);
135
102
    xmlhttp.open("POST", "chat", false);
136
103
    xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
137
104
    xmlhttp.send(make_post_body({"digest":digest, "text":inp.value}))
138
105
    var res = JSON.parse(xmlhttp.responseText);
139
 
    var output = document.getElementById("output")
 
106
    var output = document.getElementById("output");
140
107
    {
141
108
        var pre = document.createElement("pre");
142
109
        pre.setAttribute("class", "inputMsg");
143
110
        pre.appendChild(document.createTextNode(inp.value + "\n"));
144
111
        output.appendChild(pre);
145
112
    }
146
 
    if (res && res[0])
 
113
    if (res.hasOwnProperty('okay'))
147
114
    {
148
115
        // Success!
149
 
        // print out the output (res[0])
 
116
        // print out the output (res.okay[0])
150
117
        var pre = document.createElement("pre");
151
118
        pre.setAttribute("class", "outputMsg");
152
 
        pre.appendChild(document.createTextNode(res[0]));
 
119
        pre.appendChild(document.createTextNode(res.okay[0]));
153
120
        output.appendChild(pre);
154
 
        // print out the return value (res[1])
155
 
        if (res[1])
 
121
        // print out the return value (res.okay[1])
 
122
        if (res.okay[1])
156
123
        {
157
124
            var pre = document.createElement("pre");
158
125
            pre.setAttribute("class", "outputMsg");
159
 
            pre.appendChild(document.createTextNode(res[1] + "\n"));
 
126
            pre.appendChild(document.createTextNode(res.okay[1] + "\n"));
160
127
            output.appendChild(pre);
161
128
        }
162
129
        // set the prompt to >>>
163
130
        var prompt = document.getElementById("prompt");
164
131
        prompt.replaceChild(document.createTextNode(">>> "), prompt.firstChild);
165
132
    }
166
 
    else if (res)
 
133
    else if (res.hasOwnProperty('exc'))
167
134
    {
168
135
        // Failure!
169
 
        // print out the error message (res[2])
 
136
        // print out the error message (res.exc)
170
137
        var pre = document.createElement("pre");
171
138
        pre.setAttribute("class", "errorMsg");
172
 
        pre.appendChild(document.createTextNode(res[2]));
 
139
        pre.appendChild(document.createTextNode(res.exc));
173
140
        output.appendChild(pre);
174
141
    }
175
 
    else
 
142
    else if (res.hasOwnProperty('more'))
176
143
    {
177
144
        // Need more input, so set the prompt to ...
178
145
        var prompt = document.getElementById("prompt");
179
146
        prompt.replaceChild(document.createTextNode("... "), prompt.firstChild);
180
147
    }
 
148
    else {
 
149
        // assert res.hasOwnProperty('input')
 
150
        var prompt = document.getElementById("prompt");
 
151
        prompt.replaceChild(document.createTextNode("+++ "), prompt.firstChild);
 
152
    }
181
153
}
182
154
 
183
155
function catch_input(key)