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 $(which_div_expanded).style.display = 'none' ;
71 if (which_div_expanded == floor_div) {
72 which_div_expanded = null;
75 $(floor_div).style.display = 'block';
76 which_div_expanded = floor_div;
79 function switch_to_menu_buttons() {
80 which_div_expanded = null;
82 new Ajax.Updater('iconbar', 'iconbar_ajax_menu', { method: 'get' } );
86 // Static variables for mailbox view...
88 var CtdlNumMsgsSelected = 0;
89 var CtdlMsgsSelected = new Array();
91 // This gets called when you single click on a message in the mailbox view.
92 // We know that the element id of the table row will be the letter 'm' plus the message number.
94 function CtdlSingleClickMsg(evt, msgnum) {
96 // Clear the preview pane until we load the new message
97 $('preview_pane').innerHTML = '';
99 // De-select any messages that were already selected, *unless* the Ctrl key
100 // is being pressed, in which case the user wants multi select.
102 if (CtdlNumMsgsSelected > 0) {
103 for (i=0; i<CtdlNumMsgsSelected; ++i) {
104 $('m'+CtdlMsgsSelected[i]).style.backgroundColor = '#fff';
105 $('m'+CtdlMsgsSelected[i]).style.color = '#000';
107 CtdlNumMsgsSelected = 0;
111 // For multi select ... is the message being clicked already selected?
112 already_selected = 0;
113 if ( (evt.ctrlKey) && (CtdlNumMsgsSelected > 0) ) {
114 for (i=0; i<CtdlNumMsgsSelected; ++i) {
115 if (CtdlMsgsSelected[i] == msgnum) {
116 already_selected = 1;
121 // Now select (or de-select) the message
122 if ( (evt.ctrlKey) && (already_selected == 1) ) {
123 $('m'+msgnum).style.backgroundColor = '#fff';
124 $('m'+msgnum).style.color = '#000';
127 $('m'+msgnum).style.backgroundColor='#69aaff';
128 $('m'+msgnum).style.color='#fff';
129 CtdlNumMsgsSelected = CtdlNumMsgsSelected + 1;
130 CtdlMsgsSelected[CtdlNumMsgsSelected-1] = msgnum;
133 // Update the preview pane
134 new Ajax.Updater('preview_pane', 'msg/'+msgnum, { method: 'get' } );
136 // Mark the message as read
140 parameters: 'g_cmd=SEEN '+msgnum+'|1',
141 onComplete: CtdlRemoveTheUnseenBold(msgnum)
145 return false; // try to defeat the default click behavior
148 // Delete selected messages.
149 function CtdlDeleteSelectedMessages(evt) {
151 if (CtdlNumMsgsSelected < 1) {
152 // Nothing to delete, so exit silently.
155 for (i=0; i<CtdlNumMsgsSelected; ++i) {
159 parameters: 'g_cmd=MOVE ' + CtdlMsgsSelected[i] + '|_TRASH_|0',
160 onComplete: CtdlClearDeletedMsg(CtdlMsgsSelected[i])
164 CtdlNumMsgsSelected = 0;
166 // Clear the preview pane too.
167 $('preview_pane').innerHTML = '';
171 // Move selected messages.
172 function CtdlMoveSelectedMessages(evt, target_roomname) {
174 if (CtdlNumMsgsSelected < 1) {
175 // Nothing to delete, so exit silently.
178 for (i=0; i<CtdlNumMsgsSelected; ++i) {
182 parameters:'g_cmd=MOVE ' + CtdlMsgsSelected[i] + '|' + target_roomname + '|0',
183 onComplete:CtdlClearDeletedMsg(CtdlMsgsSelected[i])
187 CtdlNumMsgsSelected = 0;
189 // Clear the preview pane too.
190 $('preview_pane').innerHTML = '';
195 // This gets called when the user touches the keyboard after selecting messages...
196 function CtdlMsgListKeyPress(evt) {
197 if(document.all) { // aIEeee
198 var whichKey = window.event.keyCode;
200 else { // non-sux0r browsers
201 var whichKey = evt.which;
203 if (whichKey == 46) { // DELETE key
204 CtdlDeleteSelectedMessages(evt);
209 // Take the boldface away from a message to indicate that it has been seen.
210 function CtdlRemoveTheUnseenBold(msgnum) {
211 $('m'+msgnum).style.fontWeight='normal';
214 // A message has been deleted, so yank it from the list.
215 // (IE barfs on m9999.innerHTML='' so we use a script.aculo.us effect instead.)
216 function CtdlClearDeletedMsg(msgnum) {
217 new Effect.Squish('m'+msgnum);
221 // These functions called when the user down-clicks on the message list resizer bar
226 function CtdlResizeMsgListMouseUp(evt) {
227 document.onmouseup = null;
228 document.onmousemove = null;
229 if (document.layers) {
230 document.releaseEvents(Event.MOUSEUP | Event.MOUSEMOVE);
235 function CtdlResizeMsgListMouseMove(evt) {
236 y = (ns6 ? evt.clientY : event.clientY);
237 increment = y - saved_y;
239 // First move the bottom of the message list...
240 d = $('message_list');
242 divHeight = d.offsetHeight;
244 else if (d.style.pixelHeight) {
245 divHeight = d.style.pixelHeight;
247 d.style.height = (divHeight + increment) + 'px';
249 // Then move the top of the preview pane...
250 d = $('preview_pane');
252 divTop = d.offsetTop;
254 else if (d.style.pixelTop) {
255 divTop = d.style.pixelTop;
257 d.style.top = (divTop + increment) + 'px';
259 // Resize the bottom of the preview pane...
260 d = $('preview_pane');
262 divHeight = d.offsetHeight;
264 else if (d.style.pixelHeight) {
265 divHeight = d.style.pixelHeight;
267 d.style.height = (divHeight - increment) + 'px';
269 // Then move the top of the slider bar.
270 d = $('resize_msglist');
272 divTop = d.offsetTop;
274 else if (d.style.pixelTop) {
275 divTop = d.style.pixelTop;
277 d.style.top = (divTop + increment) + 'px';
283 function CtdlResizeMsgListMouseDown(evt) {
284 saved_y = (ns6 ? evt.clientY : event.clientY);
285 document.onmouseup = CtdlResizeMsgListMouseUp;
286 document.onmousemove = CtdlResizeMsgListMouseMove;
287 if (document.layers) {
288 document.captureEvents(Event.MOUSEUP | Event.MOUSEMOVE);
290 return false; // disable the default action
295 // These functions handle drag and drop message moving
299 function CtdlMoveMsgMouseDown(evt, msgnum) {
301 // do the highlight first
302 CtdlSingleClickMsg(evt, msgnum);
304 // Now handle the possibility of dragging
305 saved_x = (ns6 ? evt.clientX : event.clientX);
306 saved_y = (ns6 ? evt.clientY : event.clientY);
307 document.onmouseup = CtdlMoveMsgMouseUp;
308 document.onmousemove = CtdlMoveMsgMouseMove;
309 if (document.layers) {
310 document.captureEvents(Event.MOUSEUP | Event.MOUSEMOVE);
316 function CtdlMoveMsgMouseMove(evt) {
317 x = (ns6 ? evt.clientX : event.clientX);
318 y = (ns6 ? evt.clientY : event.clientY);
320 if ( (x == saved_x) && (y == saved_y) ) {
324 if (CtdlNumMsgsSelected < 1) {
331 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>";
332 for (i=0; i<CtdlNumMsgsSelected; ++i) {
333 drag_o_text = drag_o_text +
334 ctdl_ts_getInnerText(
335 $('m'+CtdlMsgsSelected[i]).cells[0]
338 drag_o_text = drag_o_text + "<div>";
340 mm_div = document.createElement("DIV");
341 mm_div.style.position='absolute';
342 mm_div.style.top = y + 'px';
343 mm_div.style.left = x + 'px';
344 mm_div.style.pixelHeight = '300';
345 mm_div.style.pixelWidth = '300';
346 mm_div.innerHTML = drag_o_text;
347 document.body.appendChild(mm_div);
350 mm_div.style.top = y + 'px';
351 mm_div.style.left = x + 'px';
354 return false; // prevent the default mouse action from happening?
357 function CtdlMoveMsgMouseUp(evt) {
358 document.onmouseup = null;
359 document.onmousemove = null;
360 if (document.layers) {
361 document.releaseEvents(Event.MOUSEUP | Event.MOUSEMOVE);
365 document.body.removeChild(mm_div);
369 if (num_drop_targets < 1) { // nowhere to drop
373 // Did we release the mouse button while hovering over a drop target?
374 // NOTE: this only works cross-browser because the iconbar div is always
375 // positioned at 0,0. Browsers differ in whether the 'offset'
376 // functions return pos relative to the document or parent.
378 for (i=0; i<num_drop_targets; ++i) {
380 x = (ns6 ? evt.clientX : event.clientX);
381 y = (ns6 ? evt.clientY : event.clientY);
383 l = parseInt(drop_targets_elements[i].offsetLeft);
384 t = parseInt(drop_targets_elements[i].offsetTop);
385 r = parseInt(drop_targets_elements[i].offsetLeft)
386 + parseInt(drop_targets_elements[i].offsetWidth);
387 b = parseInt(drop_targets_elements[i].offsetTop)
388 + parseInt(drop_targets_elements[i].offsetHeight);
390 /* alert('Offsets are: ' + l + ' ' + t + ' ' + r + ' ' + b + '.'); */
392 if ( (x >= l) && (x <= r) && (y >= t) && (y <= b) ) {
393 // Yes, we dropped it on a hotspot.
394 CtdlMoveSelectedMessages(evt, drop_targets_roomnames[i]);
403 function ctdl_ts_getInnerText(el) {
404 if (typeof el == "string") return el;
405 if (typeof el == "undefined") { return el };
406 if (el.innerText) return el.innerText; //Not needed but it is faster
409 var cs = el.childNodes;
411 for (var i = 0; i < l; i++) {
412 switch (cs[i].nodeType) {
413 case 1: //ELEMENT_NODE
414 str += ts_getInnerText(cs[i]);
417 str += cs[i].nodeValue;