2 // $Id: wclib.js,v 625.2 2005/09/18 04:04:32 ajc Exp $
4 // JavaScript function library for WebCit.
10 var room_is_trash = 0;
12 if (document.layers) {browserType = "nn4"}
13 if (document.all) {browserType = "ie"}
14 if (window.navigator.userAgent.toLowerCase().match("gecko")) {
18 var ns6=document.getElementById&&!document.all;
22 // We love string tokenizers.
23 function extract_token(source_string, token_num, delimiter) {
25 var extracted_string = source_string;
28 for (i=0; i<token_num; ++i) {
29 var j = extracted_string.indexOf(delimiter);
31 extracted_string = extracted_string.substr(j+1);
36 j = extracted_string.indexOf(delimiter);
38 extracted_string = extracted_string.substr(0, j);
41 return extracted_string;
46 // This code handles the popups for important-messages.
47 function hide_imsg_popup() {
48 if (browserType == "gecko" )
49 document.poppedLayer = eval('document.getElementById(\'important_message\')');
50 else if (browserType == "ie")
51 document.poppedLayer = eval('document.all[\'important_message\']');
53 document.poppedLayer = eval('document.layers[\'`important_message\']');
55 document.poppedLayer.style.visibility = "hidden";
59 // This function activates the ajax-powered recipient autocompleters on the message entry screen.
60 function activate_entmsg_autocompleters() {
61 new Ajax.Autocompleter('cc_id', 'cc_name_choices', 'cc_autocomplete', {} );
62 new Ajax.Autocompleter('bcc_id', 'bcc_name_choices', 'bcc_autocomplete', {} );
63 new Ajax.Autocompleter('recp_id', 'recp_name_choices', 'recp_autocomplete', {} );
68 // Toggle the icon bar between menu/roomlist...
69 var which_div_expanded = null;
70 var num_drop_targets = 0;
71 var drop_targets_elements = new Array();
72 var drop_targets_roomnames = new Array();
74 function switch_to_room_list() {
75 $('iconbar').innerHTML = $('iconbar').innerHTML.substr(0, $('iconbar').innerHTML.indexOf('switch'));
76 new Ajax.Updater('iconbar', 'iconbar_ajax_rooms', { method: 'get' } );
79 function expand_floor(floor_div) {
80 if (which_div_expanded != null) {
81 if ($(which_div_expanded) != null) {
82 $(which_div_expanded).style.display = 'none' ;
86 // clicking on the already-expanded floor causes the whole list to collapse
87 if (which_div_expanded == floor_div) {
88 which_div_expanded = null;
90 // notify the server that no floors are expanded
92 'set_floordiv_expanded/-1', {
99 // expand the requested floor
100 $(floor_div).style.display = 'block';
101 which_div_expanded = floor_div;
103 // notify the server of which floor is expanded
105 'set_floordiv_expanded/'+floor_div, {
111 function switch_to_menu_buttons() {
112 which_div_expanded = null;
113 num_drop_targets = 0;
114 new Ajax.Updater('iconbar', 'iconbar_ajax_menu', { method: 'get' } );
118 // Static variables for mailbox view...
120 var CtdlNumMsgsSelected = 0;
121 var CtdlMsgsSelected = new Array();
123 // This gets called when you single click on a message in the mailbox view.
124 // We know that the element id of the table row will be the letter 'm' plus the message number.
126 function CtdlSingleClickMsg(evt, msgnum) {
128 // Clear the preview pane until we load the new message
129 $('preview_pane').innerHTML = '';
131 // De-select any messages that were already selected, *unless* the Ctrl key
132 // is being pressed, in which case the user wants multi select.
134 if (CtdlNumMsgsSelected > 0) {
135 for (i=0; i<CtdlNumMsgsSelected; ++i) {
136 $('m'+CtdlMsgsSelected[i]).style.backgroundColor = '#fff';
137 $('m'+CtdlMsgsSelected[i]).style.color = '#000';
139 CtdlNumMsgsSelected = 0;
143 // For multi select ... is the message being clicked already selected?
144 already_selected = 0;
145 if ( (evt.ctrlKey) && (CtdlNumMsgsSelected > 0) ) {
146 for (i=0; i<CtdlNumMsgsSelected; ++i) {
147 if (CtdlMsgsSelected[i] == msgnum) {
148 already_selected = 1;
149 already_selected_pos = i;
154 // Now select (or de-select) the message
155 if ( (evt.ctrlKey) && (already_selected == 1) ) {
157 // Deselect: first un-highlight it...
158 $('m'+msgnum).style.backgroundColor = '#fff';
159 $('m'+msgnum).style.color = '#000';
161 // Then remove it from the selected messages list.
162 for (i=already_selected_pos; i<(CtdlNumMsgsSelected-1); ++i) {
163 CtdlMsgsSelected[i] = CtdlMsgsSelected[i+1];
165 CtdlNumMsgsSelected = CtdlNumMsgsSelected - 1;
169 // Select: first highlight it...
170 $('m'+msgnum).style.backgroundColor='#69aaff';
171 $('m'+msgnum).style.color='#fff';
173 // Then add it to the selected messages list.
174 CtdlNumMsgsSelected = CtdlNumMsgsSelected + 1;
175 CtdlMsgsSelected[CtdlNumMsgsSelected-1] = msgnum;
178 // Update the preview pane
179 new Ajax.Updater('preview_pane', 'msg/'+msgnum, { method: 'get' } );
181 // Mark the message as read
185 parameters: 'g_cmd=SEEN '+msgnum+'|1',
186 onComplete: CtdlRemoveTheUnseenBold(msgnum)
190 return false; // try to defeat the default click behavior
193 // Delete selected messages.
194 function CtdlDeleteSelectedMessages(evt) {
196 if (CtdlNumMsgsSelected < 1) {
197 // Nothing to delete, so exit silently.
200 for (i=0; i<CtdlNumMsgsSelected; ++i) {
201 if (parseInt(room_is_trash) > 0) {
205 parameters: 'g_cmd=DELE ' + CtdlMsgsSelected[i],
206 onComplete: CtdlClearDeletedMsg(CtdlMsgsSelected[i])
214 parameters: 'g_cmd=MOVE ' + CtdlMsgsSelected[i] + '|_TRASH_|0',
215 onComplete: CtdlClearDeletedMsg(CtdlMsgsSelected[i])
220 CtdlNumMsgsSelected = 0;
222 // Clear the preview pane too.
223 $('preview_pane').innerHTML = '';
227 // Move selected messages.
228 function CtdlMoveSelectedMessages(evt, target_roomname) {
230 if (CtdlNumMsgsSelected < 1) {
231 // Nothing to delete, so exit silently.
234 for (i=0; i<CtdlNumMsgsSelected; ++i) {
238 parameters:'g_cmd=MOVE ' + CtdlMsgsSelected[i] + '|' + target_roomname + '|0',
239 onComplete:CtdlClearDeletedMsg(CtdlMsgsSelected[i])
243 CtdlNumMsgsSelected = 0;
245 // Clear the preview pane too.
246 $('preview_pane').innerHTML = '';
251 // This gets called when the user touches the keyboard after selecting messages...
252 function CtdlMsgListKeyPress(evt) {
253 if(document.all) { // aIEeee
254 var whichKey = window.event.keyCode;
256 else { // non-sux0r browsers
257 var whichKey = evt.which;
259 if (whichKey == 46) { // DELETE key
260 CtdlDeleteSelectedMessages(evt);
265 // Take the boldface away from a message to indicate that it has been seen.
266 function CtdlRemoveTheUnseenBold(msgnum) {
267 $('m'+msgnum).style.fontWeight='normal';
270 // A message has been deleted, so yank it from the list.
271 function CtdlClearDeletedMsg(msgnum) {
274 // Traverse the table looking for a row whose ID contains the desired msgnum
275 var table = $('summary_headers');
277 for (var r = 0; r < table.rows.length; r++) {
278 var thename = table.rows[r].id;
279 if (thename.substr(1) == msgnum) {
284 alert('error: browser failed to clear row ' + r);
289 else { // if we can't delete it,
290 new Effect.Squish('m'+msgnum); // just hide it.
296 // These functions called when the user down-clicks on the message list resizer bar
301 function CtdlResizeMsgListMouseUp(evt) {
302 document.onmouseup = null;
303 document.onmousemove = null;
304 if (document.layers) {
305 document.releaseEvents(Event.MOUSEUP | Event.MOUSEMOVE);
310 function CtdlResizeMsgListMouseMove(evt) {
311 y = (ns6 ? evt.clientY : event.clientY);
312 increment = y - saved_y;
314 // First move the bottom of the message list...
315 d = $('message_list');
317 divHeight = d.offsetHeight;
319 else if (d.style.pixelHeight) {
320 divHeight = d.style.pixelHeight;
322 d.style.height = (divHeight + increment) + 'px';
324 // Then move the top of the preview pane...
325 d = $('preview_pane');
327 divTop = d.offsetTop;
329 else if (d.style.pixelTop) {
330 divTop = d.style.pixelTop;
332 d.style.top = (divTop + increment) + 'px';
334 // Resize the bottom of the preview pane...
335 d = $('preview_pane');
337 divHeight = d.offsetHeight;
339 else if (d.style.pixelHeight) {
340 divHeight = d.style.pixelHeight;
342 d.style.height = (divHeight - increment) + 'px';
344 // Then move the top of the slider bar.
345 d = $('resize_msglist');
347 divTop = d.offsetTop;
349 else if (d.style.pixelTop) {
350 divTop = d.style.pixelTop;
352 d.style.top = (divTop + increment) + 'px';
358 function CtdlResizeMsgListMouseDown(evt) {
359 saved_y = (ns6 ? evt.clientY : event.clientY);
360 document.onmouseup = CtdlResizeMsgListMouseUp;
361 document.onmousemove = CtdlResizeMsgListMouseMove;
362 if (document.layers) {
363 document.captureEvents(Event.MOUSEUP | Event.MOUSEMOVE);
365 return false; // disable the default action
370 // These functions handle drag and drop message moving
374 function CtdlMoveMsgMouseDown(evt, msgnum) {
376 // do the highlight first
377 CtdlSingleClickMsg(evt, msgnum);
379 // Now handle the possibility of dragging
380 saved_x = (ns6 ? evt.clientX : event.clientX);
381 saved_y = (ns6 ? evt.clientY : event.clientY);
382 document.onmouseup = CtdlMoveMsgMouseUp;
383 document.onmousemove = CtdlMoveMsgMouseMove;
384 if (document.layers) {
385 document.captureEvents(Event.MOUSEUP | Event.MOUSEMOVE);
391 function CtdlMoveMsgMouseMove(evt) {
392 x = (ns6 ? evt.clientX : event.clientX);
393 y = (ns6 ? evt.clientY : event.clientY);
395 if ( (x == saved_x) && (y == saved_y) ) {
399 if (CtdlNumMsgsSelected < 1) {
406 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>";
407 for (i=0; i<CtdlNumMsgsSelected; ++i) {
408 drag_o_text = drag_o_text +
409 ctdl_ts_getInnerText(
410 $('m'+CtdlMsgsSelected[i]).cells[0]
413 drag_o_text = drag_o_text + "<div>";
415 mm_div = document.createElement("DIV");
416 mm_div.style.position='absolute';
417 mm_div.style.top = y + 'px';
418 mm_div.style.left = x + 'px';
419 mm_div.style.pixelHeight = '300';
420 mm_div.style.pixelWidth = '300';
421 mm_div.innerHTML = drag_o_text;
422 document.body.appendChild(mm_div);
425 mm_div.style.top = y + 'px';
426 mm_div.style.left = x + 'px';
429 return false; // prevent the default mouse action from happening?
432 function CtdlMoveMsgMouseUp(evt) {
433 document.onmouseup = null;
434 document.onmousemove = null;
435 if (document.layers) {
436 document.releaseEvents(Event.MOUSEUP | Event.MOUSEMOVE);
440 document.body.removeChild(mm_div);
444 if (num_drop_targets < 1) { // nowhere to drop
448 // Did we release the mouse button while hovering over a drop target?
449 // NOTE: this only works cross-browser because the iconbar div is always
450 // positioned at 0,0. Browsers differ in whether the 'offset'
451 // functions return pos relative to the document or parent.
453 for (i=0; i<num_drop_targets; ++i) {
455 x = (ns6 ? evt.clientX : event.clientX);
456 y = (ns6 ? evt.clientY : event.clientY);
458 l = parseInt(drop_targets_elements[i].offsetLeft);
459 t = parseInt(drop_targets_elements[i].offsetTop);
460 r = parseInt(drop_targets_elements[i].offsetLeft)
461 + parseInt(drop_targets_elements[i].offsetWidth);
462 b = parseInt(drop_targets_elements[i].offsetTop)
463 + parseInt(drop_targets_elements[i].offsetHeight);
465 /* alert('Offsets are: ' + l + ' ' + t + ' ' + r + ' ' + b + '.'); */
467 if ( (x >= l) && (x <= r) && (y >= t) && (y <= b) ) {
468 // Yes, we dropped it on a hotspot.
469 CtdlMoveSelectedMessages(evt, drop_targets_roomnames[i]);
478 function ctdl_ts_getInnerText(el) {
479 if (typeof el == "string") return el;
480 if (typeof el == "undefined") { return el };
481 if (el.innerText) return el.innerText; //Not needed but it is faster
484 var cs = el.childNodes;
486 for (var i = 0; i < l; i++) {
487 switch (cs[i].nodeType) {
488 case 1: //ELEMENT_NODE
489 str += ts_getInnerText(cs[i]);
492 str += cs[i].nodeValue;
501 // This function handles the creation of new notes in the "Notes" view.
503 function add_new_note() {
505 new_eid = Math.random() + '';
506 new_eid = new_eid.substr(3);
508 $('new_notes_here').innerHTML = $('new_notes_here').innerHTML
509 + '<IMG ALIGN=MIDDLE src=\"static/storenotes_48x.gif\">'
510 + '<span id=\"note' + new_eid + '\">' + Date() + '</span><br />'
513 new Ajax.InPlaceEditor('note' + new_eid,
514 'updatenote?eid=' + new_eid , {rows:5,cols:72});