]> code.citadel.org Git - citadel.git/blob - webcit/static/instant_messenger.html
* More updates to instant messenger:
[citadel.git] / webcit / static / instant_messenger.html
1 <html>
2 <head>
3         <title>Citadel Instant Messenger</title>
4         <script type="text/javascript" src="prototype.js"></script>
5         <script type="text/javascript" src="wclib.js"></script>
6 </head>
7 <body onLoad='FetchNewMsgs();'>
8
9 <div id="thetop" style="position:fixed;width:100%;height:15%;top:0%;left:0%">
10 <div id="spacer1" style="background:#aaaaaa"><br></div>
11 <div id="tab_bar" style="background:#aaaaaa">&nbsp;&nbsp;</div>
12 <div id="spacer2" style="background:#aaaaaa"><br></div>
13 </div>
14
15 <div id="main" style="position:fixed;width:100%;height:85%;top:15%;left:0%;overflow:auto;background:#ffffff"></div>
16
17 <script type="text/javascript">
18
19 var gexp_divs = new Array();
20 var num_gexp_divs = 0;
21 var shown_div = '';
22 var my_name = '';
23
24 function SendSomething(which_div, sendform, recipient) {
25         thetext = document.forms[sendform].elements['sendthis'].value;
26
27         // If the user didn't type anything, don't do anything.
28         if (thetext == '') {
29                 return false;
30         }
31
32         // Clear the box
33         document.forms[sendform].elements['sendthis'].value = '';
34
35         // Write it to the tab
36         $(which_div).innerHTML = $(which_div).innerHTML
37                                 + '<b>'
38                                 + '<font color=\"#FF0000\">'
39                                 + my_name
40                                 + '</font>'
41                                 + ':</b> '
42                                 + thetext
43                                 + '<br />\n';
44
45         // Scroll to the bottom of the tab
46         $('main').scrollTop = 999999;
47
48         // Send the text to the server
49         parms = 'r=' + Math.random()
50                 + '&g_cmd=SEXP ' + recipient + '|' + thetext;
51         new Ajax.Request('../ajax_servcmd',
52                 {
53                         method: 'get',
54                         parameters: parms
55                 }
56         );
57
58         // Refocus to the text box
59         document.forms[sendform].elements['sendthis'].focus();
60
61         // Don't submit the form
62         return false;
63 }
64
65 function TabSelect(which_div) {
66         if (shown_div != '') {
67                 $(shown_div).style.display = 'none' ;
68                 if ($('select_'+shown_div)) {
69                         $('select_'+shown_div).style.fontWeight = 'normal';
70                         $('select_'+shown_div).style.backgroundColor = '#cccccc';
71                 }
72         }
73         shown_div = 'tab_' + which_div;
74         $(shown_div).style.display = 'block' ;
75         if ($('select_'+shown_div)) {
76                 $('select_'+shown_div).style.fontWeight='bold';
77                 $('select_'+shown_div).style.backgroundColor = '#ffffff';
78         }
79 }
80
81
82 function ShowNewMsg(gexp_xmlresponse) {
83
84         // It isn't really XML.  It's a Citadel server response.
85         gexp_response = gexp_xmlresponse.responseText;
86
87         if (gexp_response.substring(0, 1) != '1') {
88                 return;
89         }
90
91         // Extract fields...
92         breakpos = gexp_response.indexOf('\n');
93         result = gexp_response.substring(0, breakpos-1);
94         the_message = gexp_response.substring(breakpos+1);
95         the_message = the_message.substring(0, the_message.indexOf('\n000'));
96         sender = extract_token(result.substring(4), 3, '|');
97
98         // Figure out which div to write it to...
99         which_div = '';
100         if (num_gexp_divs > 0) {
101                 for (i=0; i<num_gexp_divs; ++i) {
102                         if (gexp_divs[i] == sender) {
103                                 which_div = 'gexp' + i ;
104                         }
105                 }
106         }
107
108         // Not found?  Create it.
109         if (which_div == '') {
110                 gexp_divs[num_gexp_divs] = sender;
111                 which_div = 'gexp' + num_gexp_divs;
112                 ++num_gexp_divs;
113                 $('main').innerHTML =
114                           $('main').innerHTML
115                         + '<div id=\"tab_' + which_div + '\" style=\"display:none;cursor:pointer\">'
116                         + '<div id=\"' + which_div + '\">'
117                         + '</div>'
118                         + '<div id=\"response_' + which_div + '\" style=\"background:#ddddee\">'
119                         + '<br><form method=\"post\" action=\"null\" name=\"sendform_' + which_div + '\" '
120                         + 'onSubmit=\"return SendSomething(\'' + which_div + '\', \'sendform_'
121                         + which_div + '\', \'' + sender + '\');\">'
122                         + '<img src=\"citadelchat_16x.gif\">&nbsp;'
123                         + '<input type=\"text\" size=\"72\" maxlength=\"72\" name=\"sendthis\">'
124                         + '</form>'
125                         + '<br></div>'
126                         + '</div>\n';
127                 $('tab_bar').innerHTML =
128                           $('tab_bar').innerHTML
129                         + '<span id=\"select_tab_' + which_div + '\" onClick=\"TabSelect(\'' + which_div + '\');\">'
130                         + '&nbsp;' + sender + '&nbsp;'
131                         + '</span>&nbsp;&nbsp;&nbsp;';
132
133                 // Raise the window in case it was buried
134                 window.focus();
135         }
136
137         // Switch tabs
138         TabSelect(which_div);
139
140         // Write it to the tab
141         $(which_div).innerHTML = $(which_div).innerHTML
142                                 + '<b>'
143                                 + '<font color=\"#0000FF\">'
144                                 + sender
145                                 + '</font>'
146                                 + ':</b> '
147                                 + the_message
148                                 + '<br />\n';
149
150         // Scroll to the bottom of the tab
151         $('main').scrollTop = 999999;
152
153         // Refocus to the send box
154         document.forms['sendform_'+which_div].elements['sendthis'].focus();
155
156         // Keep trying for new messages until the server tells us to stop.
157         FetchNewMsgs();
158 }
159
160 // This is called periodically to check for new incoming messages
161 function FetchNewMsgs() {
162         parms = 'g_cmd=GEXP&r=' + Math.random();
163         new Ajax.Request('../ajax_servcmd',
164                 {
165                         method: 'get',
166                         parameters: parms,
167                         onSuccess: ShowNewMsg
168                 }
169         );
170 }
171
172 // Perform some initialization.
173 parms = 'g_cmd=GREG _SELF_&r=' + Math.random();
174 new Ajax.Request('../ajax_servcmd',
175         {
176                 method: 'get',
177                 parameters: parms,
178                 onSuccess: GrabMyName
179         }
180 );
181
182 // Learn my name.
183 function GrabMyName(greg_xmlresponse) {
184
185         // It isn't really XML.  It's a Citadel server response.
186         greg_response = greg_xmlresponse.responseText;
187
188         if (greg_response.substring(0, 1) != '1') {
189                 return;
190         }
191
192         // Extract fields...
193         breakpos = greg_response.indexOf('\n');
194         result = greg_response.substring(0, breakpos);
195         my_name = result.substring(4);
196 }
197
198
199 // Cause FetchNewMsgs() to be called periodically.
200 new PeriodicalExecuter(FetchNewMsgs, 5);
201
202 </script>
203
204
205 </body>
206 </html>