2 // $Id: wclib.js,v 625.2 2005/09/18 04:04:32 ajc Exp $
4 // JavaScript function library for WebCit.
11 if (document.layers) {browserType = "nn4"}
12 if (document.all) {browserType = "ie"}
13 if (window.navigator.userAgent.toLowerCase().match("gecko")) {
17 var ns6=document.getElementById&&!document.all;
21 // This code handles the popups for instant messages.
25 function hide_page_popup() {
26 if (browserType == "gecko" )
27 document.poppedLayer = eval('document.getElementById(\'page_popup\')');
28 else if (browserType == "ie")
29 document.poppedLayer = eval('document.all[\'page_popup\']');
31 document.poppedLayer = eval('document.layers[\'`page_popup\']');
33 document.poppedLayer.style.visibility = "hidden";
36 function hide_imsg_popup() {
37 if (browserType == "gecko" )
38 document.poppedLayer = eval('document.getElementById(\'important_message\')');
39 else if (browserType == "ie")
40 document.poppedLayer = eval('document.all[\'important_message\']');
42 document.poppedLayer = eval('document.layers[\'`important_message\']');
44 document.poppedLayer.style.visibility = "hidden";
47 // This function activates the ajax-powered recipient autocompleters on the message entry screen.
48 function activate_entmsg_autocompleters() {
49 new Ajax.Autocompleter('cc_id', 'cc_name_choices', 'cc_autocomplete', {} );
50 new Ajax.Autocompleter('bcc_id', 'bcc_name_choices', 'bcc_autocomplete', {} );
51 new Ajax.Autocompleter('recp_id', 'recp_name_choices', 'recp_autocomplete', {} );
56 // Toggle the icon bar between menu/roomlist...
57 var which_div_expanded = null;
58 var num_drop_targets = 0;
59 var drop_targets_elements = new Array();
60 var drop_targets_roomnames = new Array();
62 function switch_to_room_list() {
63 $('iconbar').innerHTML = $('iconbar').innerHTML.substr(0, $('iconbar').innerHTML.indexOf('switch'));
64 new Ajax.Updater('iconbar', 'iconbar_ajax_rooms', { method: 'get' } );
67 function expand_floor(floor_div) {
68 if (which_div_expanded != null) {
69 if ($(which_div_expanded) != null) {
70 $(which_div_expanded).style.display = 'none' ;
73 if (which_div_expanded == floor_div) {
74 which_div_expanded = null;
77 $(floor_div).style.display = 'block';
78 which_div_expanded = floor_div;
80 // notify the server of what we did
82 'set_floordiv_expanded/'+floor_div, {
88 function switch_to_menu_buttons() {
89 which_div_expanded = null;
91 new Ajax.Updater('iconbar', 'iconbar_ajax_menu', { method: 'get' } );
95 // Static variables for mailbox view...
97 var CtdlNumMsgsSelected = 0;
98 var CtdlMsgsSelected = new Array();
100 // This gets called when you single click on a message in the mailbox view.
101 // We know that the element id of the table row will be the letter 'm' plus the message number.
103 function CtdlSingleClickMsg(evt, msgnum) {
105 // Clear the preview pane until we load the new message
106 $('preview_pane').innerHTML = '';
108 // De-select any messages that were already selected, *unless* the Ctrl key
109 // is being pressed, in which case the user wants multi select.
111 if (CtdlNumMsgsSelected > 0) {
112 for (i=0; i<CtdlNumMsgsSelected; ++i) {
113 $('m'+CtdlMsgsSelected[i]).style.backgroundColor = '#fff';
114 $('m'+CtdlMsgsSelected[i]).style.color = '#000';
116 CtdlNumMsgsSelected = 0;
120 // For multi select ... is the message being clicked already selected?
121 already_selected = 0;
122 if ( (evt.ctrlKey) && (CtdlNumMsgsSelected > 0) ) {
123 for (i=0; i<CtdlNumMsgsSelected; ++i) {
124 if (CtdlMsgsSelected[i] == msgnum) {
125 already_selected = 1;
130 // Now select (or de-select) the message
131 if ( (evt.ctrlKey) && (already_selected == 1) ) {
132 $('m'+msgnum).style.backgroundColor = '#fff';
133 $('m'+msgnum).style.color = '#000';
136 $('m'+msgnum).style.backgroundColor='#69aaff';
137 $('m'+msgnum).style.color='#fff';
138 CtdlNumMsgsSelected = CtdlNumMsgsSelected + 1;
139 CtdlMsgsSelected[CtdlNumMsgsSelected-1] = msgnum;
142 // Update the preview pane
143 new Ajax.Updater('preview_pane', 'msg/'+msgnum, { method: 'get' } );
145 // Mark the message as read
149 parameters: 'g_cmd=SEEN '+msgnum+'|1',
150 onComplete: CtdlRemoveTheUnseenBold(msgnum)
154 return false; // try to defeat the default click behavior
157 // Delete selected messages.
158 function CtdlDeleteSelectedMessages(evt) {
160 if (CtdlNumMsgsSelected < 1) {
161 // Nothing to delete, so exit silently.
164 for (i=0; i<CtdlNumMsgsSelected; ++i) {
168 parameters: 'g_cmd=MOVE ' + CtdlMsgsSelected[i] + '|_TRASH_|0',
169 onComplete: CtdlClearDeletedMsg(CtdlMsgsSelected[i])
173 CtdlNumMsgsSelected = 0;
175 // Clear the preview pane too.
176 $('preview_pane').innerHTML = '';
180 // Move selected messages.
181 function CtdlMoveSelectedMessages(evt, target_roomname) {
183 if (CtdlNumMsgsSelected < 1) {
184 // Nothing to delete, so exit silently.
187 for (i=0; i<CtdlNumMsgsSelected; ++i) {
191 parameters:'g_cmd=MOVE ' + CtdlMsgsSelected[i] + '|' + target_roomname + '|0',
192 onComplete:CtdlClearDeletedMsg(CtdlMsgsSelected[i])
196 CtdlNumMsgsSelected = 0;
198 // Clear the preview pane too.
199 $('preview_pane').innerHTML = '';
204 // This gets called when the user touches the keyboard after selecting messages...
205 function CtdlMsgListKeyPress(evt) {
206 if(document.all) { // aIEeee
207 var whichKey = window.event.keyCode;
209 else { // non-sux0r browsers
210 var whichKey = evt.which;
212 if (whichKey == 46) { // DELETE key
213 CtdlDeleteSelectedMessages(evt);
218 // Take the boldface away from a message to indicate that it has been seen.
219 function CtdlRemoveTheUnseenBold(msgnum) {
220 $('m'+msgnum).style.fontWeight='normal';
223 // A message has been deleted, so yank it from the list.
224 // (IE barfs on m9999.innerHTML='' so we use a script.aculo.us effect instead.)
225 function CtdlClearDeletedMsg(msgnum) {
226 new Effect.Squish('m'+msgnum);
230 // These functions called when the user down-clicks on the message list resizer bar
235 function CtdlResizeMsgListMouseUp(evt) {
236 document.onmouseup = null;
237 document.onmousemove = null;
238 if (document.layers) {
239 document.releaseEvents(Event.MOUSEUP | Event.MOUSEMOVE);
244 function CtdlResizeMsgListMouseMove(evt) {
245 y = (ns6 ? evt.clientY : event.clientY);
246 increment = y - saved_y;
248 // First move the bottom of the message list...
249 d = $('message_list');
251 divHeight = d.offsetHeight;
253 else if (d.style.pixelHeight) {
254 divHeight = d.style.pixelHeight;
256 d.style.height = (divHeight + increment) + 'px';
258 // Then move the top of the preview pane...
259 d = $('preview_pane');
261 divTop = d.offsetTop;
263 else if (d.style.pixelTop) {
264 divTop = d.style.pixelTop;
266 d.style.top = (divTop + increment) + 'px';
268 // Resize the bottom of the preview pane...
269 d = $('preview_pane');
271 divHeight = d.offsetHeight;
273 else if (d.style.pixelHeight) {
274 divHeight = d.style.pixelHeight;
276 d.style.height = (divHeight - increment) + 'px';
278 // Then move the top of the slider bar.
279 d = $('resize_msglist');
281 divTop = d.offsetTop;
283 else if (d.style.pixelTop) {
284 divTop = d.style.pixelTop;
286 d.style.top = (divTop + increment) + 'px';
292 function CtdlResizeMsgListMouseDown(evt) {
293 saved_y = (ns6 ? evt.clientY : event.clientY);
294 document.onmouseup = CtdlResizeMsgListMouseUp;
295 document.onmousemove = CtdlResizeMsgListMouseMove;
296 if (document.layers) {
297 document.captureEvents(Event.MOUSEUP | Event.MOUSEMOVE);
299 return false; // disable the default action
304 // These functions handle drag and drop message moving
308 function CtdlMoveMsgMouseDown(evt, msgnum) {
310 // do the highlight first
311 CtdlSingleClickMsg(evt, msgnum);
313 // Now handle the possibility of dragging
314 saved_x = (ns6 ? evt.clientX : event.clientX);
315 saved_y = (ns6 ? evt.clientY : event.clientY);
316 document.onmouseup = CtdlMoveMsgMouseUp;
317 document.onmousemove = CtdlMoveMsgMouseMove;
318 if (document.layers) {
319 document.captureEvents(Event.MOUSEUP | Event.MOUSEMOVE);
325 function CtdlMoveMsgMouseMove(evt) {
326 x = (ns6 ? evt.clientX : event.clientX);
327 y = (ns6 ? evt.clientY : event.clientY);
329 if ( (x == saved_x) && (y == saved_y) ) {
333 if (CtdlNumMsgsSelected < 1) {
340 drag_o_text = "<div style=\"overflow:none; background-color:#fff; color:#000; border: 1px solid black; filter:alpha(opacity=75); -moz-opacity:.75; opacity:.75;\"><tr><td>";
341 for (i=0; i<CtdlNumMsgsSelected; ++i) {
342 drag_o_text = drag_o_text +
343 ctdl_ts_getInnerText(
344 $('m'+CtdlMsgsSelected[i]).cells[0]
347 drag_o_text = drag_o_text + "<div>";
349 mm_div = document.createElement("DIV");
350 mm_div.style.position='absolute';
351 mm_div.style.top = y + 'px';
352 mm_div.style.left = x + 'px';
353 mm_div.style.pixelHeight = '300';
354 mm_div.style.pixelWidth = '300';
355 mm_div.innerHTML = drag_o_text;
356 document.body.appendChild(mm_div);
359 mm_div.style.top = y + 'px';
360 mm_div.style.left = x + 'px';
363 return false; // prevent the default mouse action from happening?
366 function CtdlMoveMsgMouseUp(evt) {
367 document.onmouseup = null;
368 document.onmousemove = null;
369 if (document.layers) {
370 document.releaseEvents(Event.MOUSEUP | Event.MOUSEMOVE);
374 document.body.removeChild(mm_div);
378 if (num_drop_targets < 1) { // nowhere to drop
382 // Did we release the mouse button while hovering over a drop target?
383 // NOTE: this only works cross-browser because the iconbar div is always
384 // positioned at 0,0. Browsers differ in whether the 'offset'
385 // functions return pos relative to the document or parent.
387 for (i=0; i<num_drop_targets; ++i) {
389 x = (ns6 ? evt.clientX : event.clientX);
390 y = (ns6 ? evt.clientY : event.clientY);
392 l = parseInt(drop_targets_elements[i].offsetLeft);
393 t = parseInt(drop_targets_elements[i].offsetTop);
394 r = parseInt(drop_targets_elements[i].offsetLeft)
395 + parseInt(drop_targets_elements[i].offsetWidth);
396 b = parseInt(drop_targets_elements[i].offsetTop)
397 + parseInt(drop_targets_elements[i].offsetHeight);
399 /* alert('Offsets are: ' + l + ' ' + t + ' ' + r + ' ' + b + '.'); */
401 if ( (x >= l) && (x <= r) && (y >= t) && (y <= b) ) {
402 // Yes, we dropped it on a hotspot.
403 CtdlMoveSelectedMessages(evt, drop_targets_roomnames[i]);
412 function ctdl_ts_getInnerText(el) {
413 if (typeof el == "string") return el;
414 if (typeof el == "undefined") { return el };
415 if (el.innerText) return el.innerText; //Not needed but it is faster
418 var cs = el.childNodes;
420 for (var i = 0; i < l; i++) {
421 switch (cs[i].nodeType) {
422 case 1: //ELEMENT_NODE
423 str += ts_getInnerText(cs[i]);
426 str += cs[i].nodeValue;