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.substring(j+1);
36 j = extracted_string.indexOf(delimiter);
38 extracted_string = extracted_string.substring(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;
153 // Now select (or de-select) the message
154 if ( (evt.ctrlKey) && (already_selected == 1) ) {
155 $('m'+msgnum).style.backgroundColor = '#fff';
156 $('m'+msgnum).style.color = '#000';
159 $('m'+msgnum).style.backgroundColor='#69aaff';
160 $('m'+msgnum).style.color='#fff';
161 CtdlNumMsgsSelected = CtdlNumMsgsSelected + 1;
162 CtdlMsgsSelected[CtdlNumMsgsSelected-1] = msgnum;
165 // Update the preview pane
166 new Ajax.Updater('preview_pane', 'msg/'+msgnum, { method: 'get' } );
168 // Mark the message as read
172 parameters: 'g_cmd=SEEN '+msgnum+'|1',
173 onComplete: CtdlRemoveTheUnseenBold(msgnum)
177 return false; // try to defeat the default click behavior
180 // Delete selected messages.
181 function CtdlDeleteSelectedMessages(evt) {
183 if (CtdlNumMsgsSelected < 1) {
184 // Nothing to delete, so exit silently.
187 for (i=0; i<CtdlNumMsgsSelected; ++i) {
188 if (parseInt(room_is_trash) > 0) {
192 parameters: 'g_cmd=DELE ' + CtdlMsgsSelected[i],
193 onComplete: CtdlClearDeletedMsg(CtdlMsgsSelected[i])
201 parameters: 'g_cmd=MOVE ' + CtdlMsgsSelected[i] + '|_TRASH_|0',
202 onComplete: CtdlClearDeletedMsg(CtdlMsgsSelected[i])
207 CtdlNumMsgsSelected = 0;
209 // Clear the preview pane too.
210 $('preview_pane').innerHTML = '';
214 // Move selected messages.
215 function CtdlMoveSelectedMessages(evt, target_roomname) {
217 if (CtdlNumMsgsSelected < 1) {
218 // Nothing to delete, so exit silently.
221 for (i=0; i<CtdlNumMsgsSelected; ++i) {
225 parameters:'g_cmd=MOVE ' + CtdlMsgsSelected[i] + '|' + target_roomname + '|0',
226 onComplete:CtdlClearDeletedMsg(CtdlMsgsSelected[i])
230 CtdlNumMsgsSelected = 0;
232 // Clear the preview pane too.
233 $('preview_pane').innerHTML = '';
238 // This gets called when the user touches the keyboard after selecting messages...
239 function CtdlMsgListKeyPress(evt) {
240 if(document.all) { // aIEeee
241 var whichKey = window.event.keyCode;
243 else { // non-sux0r browsers
244 var whichKey = evt.which;
246 if (whichKey == 46) { // DELETE key
247 CtdlDeleteSelectedMessages(evt);
252 // Take the boldface away from a message to indicate that it has been seen.
253 function CtdlRemoveTheUnseenBold(msgnum) {
254 $('m'+msgnum).style.fontWeight='normal';
257 // A message has been deleted, so yank it from the list.
258 // (IE barfs on m9999.innerHTML='' so we use a script.aculo.us effect instead.)
259 function CtdlClearDeletedMsg(msgnum) {
260 new Effect.Squish('m'+msgnum);
264 // These functions called when the user down-clicks on the message list resizer bar
269 function CtdlResizeMsgListMouseUp(evt) {
270 document.onmouseup = null;
271 document.onmousemove = null;
272 if (document.layers) {
273 document.releaseEvents(Event.MOUSEUP | Event.MOUSEMOVE);
278 function CtdlResizeMsgListMouseMove(evt) {
279 y = (ns6 ? evt.clientY : event.clientY);
280 increment = y - saved_y;
282 // First move the bottom of the message list...
283 d = $('message_list');
285 divHeight = d.offsetHeight;
287 else if (d.style.pixelHeight) {
288 divHeight = d.style.pixelHeight;
290 d.style.height = (divHeight + increment) + 'px';
292 // Then move the top of the preview pane...
293 d = $('preview_pane');
295 divTop = d.offsetTop;
297 else if (d.style.pixelTop) {
298 divTop = d.style.pixelTop;
300 d.style.top = (divTop + increment) + 'px';
302 // Resize the bottom of the preview pane...
303 d = $('preview_pane');
305 divHeight = d.offsetHeight;
307 else if (d.style.pixelHeight) {
308 divHeight = d.style.pixelHeight;
310 d.style.height = (divHeight - increment) + 'px';
312 // Then move the top of the slider bar.
313 d = $('resize_msglist');
315 divTop = d.offsetTop;
317 else if (d.style.pixelTop) {
318 divTop = d.style.pixelTop;
320 d.style.top = (divTop + increment) + 'px';
326 function CtdlResizeMsgListMouseDown(evt) {
327 saved_y = (ns6 ? evt.clientY : event.clientY);
328 document.onmouseup = CtdlResizeMsgListMouseUp;
329 document.onmousemove = CtdlResizeMsgListMouseMove;
330 if (document.layers) {
331 document.captureEvents(Event.MOUSEUP | Event.MOUSEMOVE);
333 return false; // disable the default action
338 // These functions handle drag and drop message moving
342 function CtdlMoveMsgMouseDown(evt, msgnum) {
344 // do the highlight first
345 CtdlSingleClickMsg(evt, msgnum);
347 // Now handle the possibility of dragging
348 saved_x = (ns6 ? evt.clientX : event.clientX);
349 saved_y = (ns6 ? evt.clientY : event.clientY);
350 document.onmouseup = CtdlMoveMsgMouseUp;
351 document.onmousemove = CtdlMoveMsgMouseMove;
352 if (document.layers) {
353 document.captureEvents(Event.MOUSEUP | Event.MOUSEMOVE);
359 function CtdlMoveMsgMouseMove(evt) {
360 x = (ns6 ? evt.clientX : event.clientX);
361 y = (ns6 ? evt.clientY : event.clientY);
363 if ( (x == saved_x) && (y == saved_y) ) {
367 if (CtdlNumMsgsSelected < 1) {
374 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>";
375 for (i=0; i<CtdlNumMsgsSelected; ++i) {
376 drag_o_text = drag_o_text +
377 ctdl_ts_getInnerText(
378 $('m'+CtdlMsgsSelected[i]).cells[0]
381 drag_o_text = drag_o_text + "<div>";
383 mm_div = document.createElement("DIV");
384 mm_div.style.position='absolute';
385 mm_div.style.top = y + 'px';
386 mm_div.style.left = x + 'px';
387 mm_div.style.pixelHeight = '300';
388 mm_div.style.pixelWidth = '300';
389 mm_div.innerHTML = drag_o_text;
390 document.body.appendChild(mm_div);
393 mm_div.style.top = y + 'px';
394 mm_div.style.left = x + 'px';
397 return false; // prevent the default mouse action from happening?
400 function CtdlMoveMsgMouseUp(evt) {
401 document.onmouseup = null;
402 document.onmousemove = null;
403 if (document.layers) {
404 document.releaseEvents(Event.MOUSEUP | Event.MOUSEMOVE);
408 document.body.removeChild(mm_div);
412 if (num_drop_targets < 1) { // nowhere to drop
416 // Did we release the mouse button while hovering over a drop target?
417 // NOTE: this only works cross-browser because the iconbar div is always
418 // positioned at 0,0. Browsers differ in whether the 'offset'
419 // functions return pos relative to the document or parent.
421 for (i=0; i<num_drop_targets; ++i) {
423 x = (ns6 ? evt.clientX : event.clientX);
424 y = (ns6 ? evt.clientY : event.clientY);
426 l = parseInt(drop_targets_elements[i].offsetLeft);
427 t = parseInt(drop_targets_elements[i].offsetTop);
428 r = parseInt(drop_targets_elements[i].offsetLeft)
429 + parseInt(drop_targets_elements[i].offsetWidth);
430 b = parseInt(drop_targets_elements[i].offsetTop)
431 + parseInt(drop_targets_elements[i].offsetHeight);
433 /* alert('Offsets are: ' + l + ' ' + t + ' ' + r + ' ' + b + '.'); */
435 if ( (x >= l) && (x <= r) && (y >= t) && (y <= b) ) {
436 // Yes, we dropped it on a hotspot.
437 CtdlMoveSelectedMessages(evt, drop_targets_roomnames[i]);
446 function ctdl_ts_getInnerText(el) {
447 if (typeof el == "string") return el;
448 if (typeof el == "undefined") { return el };
449 if (el.innerText) return el.innerText; //Not needed but it is faster
452 var cs = el.childNodes;
454 for (var i = 0; i < l; i++) {
455 switch (cs[i].nodeType) {
456 case 1: //ELEMENT_NODE
457 str += ts_getInnerText(cs[i]);
460 str += cs[i].nodeValue;
469 // This function handles the creation of new notes in the "Notes" view.
471 function add_new_note() {
473 new_eid = Math.random() + '';
474 new_eid = new_eid.substr(3);
476 $('new_notes_here').innerHTML = $('new_notes_here').innerHTML
477 + '<IMG ALIGN=MIDDLE src=\"static/storenotes_48x.gif\">'
478 + '<span id=\"note' + new_eid + '\">' + Date() + '</span><br />'
481 new Ajax.InPlaceEditor('note' + new_eid,
482 'updatenote?eid=' + new_eid , {rows:5,cols:72});