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', {} );
55 // Static variables for mailbox view...
57 var CtdlNumMsgsSelected = 0;
58 var CtdlMsgsSelected = new Array();
60 // This gets called when you single click on a message in the mailbox view.
61 // We know that the element id of the table row will be the letter 'm' plus the message number.
63 function CtdlSingleClickMsg(evt, msgnum) {
65 // Clear the preview pane until we load the new message
66 $('preview_pane').innerHTML = '';
68 // De-select any messages that were already selected, *unless* the Ctrl key
69 // is being pressed, in which case the user wants multi select.
71 if (CtdlNumMsgsSelected > 0) {
72 for (i=0; i<CtdlNumMsgsSelected; ++i) {
73 $('m'+CtdlMsgsSelected[i]).style.backgroundColor = '#fff';
74 $('m'+CtdlMsgsSelected[i]).style.color = '#000';
76 CtdlNumMsgsSelected = 0;
80 // For multi select ... is the message being clicked already selected?
82 if ( (evt.ctrlKey) && (CtdlNumMsgsSelected > 0) ) {
83 for (i=0; i<CtdlNumMsgsSelected; ++i) {
84 if (CtdlMsgsSelected[i] == msgnum) {
90 // Now select (or de-select) the message
91 if ( (evt.ctrlKey) && (already_selected == 1) ) {
92 $('m'+msgnum).style.backgroundColor = '#fff';
93 $('m'+msgnum).style.color = '#000';
96 $('m'+msgnum).style.backgroundColor='#69aaff';
97 $('m'+msgnum).style.color='#fff';
98 CtdlNumMsgsSelected = CtdlNumMsgsSelected + 1;
99 CtdlMsgsSelected[CtdlNumMsgsSelected-1] = msgnum;
102 // Update the preview pane
103 new Ajax.Updater('preview_pane', 'msg/'+msgnum, { method: 'get' } );
105 // Mark the message as read
109 parameters: 'g_cmd=SEEN '+msgnum+'|1',
110 onComplete: CtdlRemoveTheUnseenBold(msgnum)
114 return false; // try to defeat the default click behavior
117 // Delete selected messages.
118 function CtdlDeleteSelectedMessages(evt) {
120 if (CtdlNumMsgsSelected < 1) {
121 // Nothing to delete, so exit silently.
124 for (i=0; i<CtdlNumMsgsSelected; ++i) {
128 parameters: 'g_cmd=MOVE ' + CtdlMsgsSelected[i] + '|_TRASH_|0',
129 onComplete: CtdlClearDeletedMsg(CtdlMsgsSelected[i])
133 CtdlNumMsgsSelected = 0;
135 // Clear the preview pane too.
136 $('preview_pane').innerHTML = '';
139 // This gets called when the user touches the keyboard after selecting messages...
140 function CtdlMsgListKeyPress(evt) {
141 if(document.all) { // aIEeee
142 var whichKey = window.event.keyCode;
144 else { // non-sux0r browsers
145 var whichKey = evt.which;
147 if (whichKey == 46) { // DELETE key
148 CtdlDeleteSelectedMessages(evt);
153 // Take the boldface away from a message to indicate that it has been seen.
154 function CtdlRemoveTheUnseenBold(msgnum) {
155 $('m'+msgnum).style.fontWeight='normal';
158 // A message has been deleted, so yank it from the list.
159 // (IE barfs on m9999.innerHTML='' so we use a script.aculo.us effect instead.)
160 function CtdlClearDeletedMsg(msgnum) {
161 new Effect.Squish('m'+msgnum);
165 // These functions called when the user down-clicks on the message list resizer bar
170 function CtdlResizeMsgListMouseUp(evt) {
171 document.onmouseup = null;
172 document.onmousemove = null;
173 if (document.layers) {
174 document.releaseEvents(Event.MOUSEUP | Event.MOUSEMOVE);
179 function CtdlResizeMsgListMouseMove(evt) {
180 y = (ns6 ? evt.clientY : event.clientY);
181 increment = y - saved_y;
183 // First move the bottom of the message list...
184 d = $('message_list');
186 divHeight = d.offsetHeight;
188 else if (d.style.pixelHeight) {
189 divHeight = d.style.pixelHeight;
191 d.style.height = (divHeight + increment) + 'px';
193 // Then move the top of the preview pane...
194 d = $('preview_pane');
196 divTop = d.offsetTop;
198 else if (d.style.pixelTop) {
199 divTop = d.style.pixelTop;
201 d.style.top = (divTop + increment) + 'px';
203 // Resize the bottom of the preview pane...
204 d = $('preview_pane');
206 divHeight = d.offsetHeight;
208 else if (d.style.pixelHeight) {
209 divHeight = d.style.pixelHeight;
211 d.style.height = (divHeight - increment) + 'px';
213 // Then move the top of the slider bar.
214 d = $('resize_msglist');
216 divTop = d.offsetTop;
218 else if (d.style.pixelTop) {
219 divTop = d.style.pixelTop;
221 d.style.top = (divTop + increment) + 'px';
227 function CtdlResizeMsgListMouseDown(evt) {
228 saved_y = (ns6 ? evt.clientY : event.clientY);
229 document.onmouseup = CtdlResizeMsgListMouseUp;
230 document.onmousemove = CtdlResizeMsgListMouseMove;
231 if (document.layers) {
232 document.captureEvents(Event.MOUSEUP | Event.MOUSEMOVE);
234 return false; // disable the default action
239 // These functions handle drag and drop message moving
243 function CtdlMoveMsgMouseDown(evt, msgnum) {
245 // do the highlight first
246 CtdlSingleClickMsg(evt, msgnum);
248 // Now handle the possibility of dragging
249 saved_x = (ns6 ? evt.clientX : event.clientX);
250 saved_y = (ns6 ? evt.clientY : event.clientY);
251 document.onmouseup = CtdlMoveMsgMouseUp;
252 document.onmousemove = CtdlMoveMsgMouseMove;
253 if (document.layers) {
254 document.captureEvents(Event.MOUSEUP | Event.MOUSEMOVE);
260 function CtdlMoveMsgMouseMove(evt) {
261 x = (ns6 ? evt.clientX : event.clientX);
262 y = (ns6 ? evt.clientY : event.clientY);
264 if ( (x == saved_x) && (y == saved_y) ) {
268 if (CtdlNumMsgsSelected < 1) {
275 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>";
276 for (i=0; i<CtdlNumMsgsSelected; ++i) {
277 drag_o_text = drag_o_text +
278 ctdl_ts_getInnerText(
279 $('m'+CtdlMsgsSelected[i]).cells[0]
282 drag_o_text = drag_o_text + "<div>";
284 mm_div = document.createElement("DIV");
285 mm_div.style.position='absolute';
286 mm_div.style.top = y + 'px';
287 mm_div.style.left = x + 'px';
288 mm_div.style.pixelHeight = '300';
289 mm_div.style.pixelWidth = '300';
290 mm_div.innerHTML = drag_o_text;
291 document.body.appendChild(mm_div);
294 mm_div.style.top = y + 'px';
295 mm_div.style.left = x + 'px';
298 return false; // prevent the default mouse action from happening?
301 function CtdlMoveMsgMouseUp(evt) {
302 document.onmouseup = null;
303 document.onmousemove = null;
304 if (document.layers) {
305 document.releaseEvents(Event.MOUSEUP | Event.MOUSEMOVE);
309 document.body.removeChild(mm_div);
313 // Did we release the mouse button while hovering over a drop target?
314 // NOTE: this only works cross-browser because the iconbar div is always
315 // positioned at 0,0. Browsers differ in whether the 'offset'
316 // functions return pos relative to the document or parent.
318 x = (ns6 ? evt.clientX : event.clientX);
319 y = (ns6 ? evt.clientY : event.clientY);
321 l = parseInt($('dropstuff').offsetLeft);
322 t = parseInt($('dropstuff').offsetTop);
323 r = parseInt($('dropstuff').offsetLeft) + parseInt($('dropstuff').offsetWidth);
324 b = parseInt($('dropstuff').offsetTop) + parseInt($('dropstuff').offsetHeight);
326 // alert('Offsets are: ' + l + ' ' + t + ' ' + r + ' ' + b + '.');
328 if ( (x >= l) && (x <= r) && (y >= t) && (y <= b) ) {
329 // Yes, we dropped it on a hotspot. Just delete for now... FIXME
330 CtdlDeleteSelectedMessages(evt);
337 function ctdl_ts_getInnerText(el) {
338 if (typeof el == "string") return el;
339 if (typeof el == "undefined") { return el };
340 if (el.innerText) return el.innerText; //Not needed but it is faster
343 var cs = el.childNodes;
345 for (var i = 0; i < l; i++) {
346 switch (cs[i].nodeType) {
347 case 1: //ELEMENT_NODE
348 str += ts_getInnerText(cs[i]);
351 str += cs[i].nodeValue;
359 // icon bar toggler tabs...
361 var which_div_expanded = null;
363 function switch_to_room_list() {
364 new Ajax.Updater('iconbar', 'iconbar_ajax_rooms', { method: 'get' } );
367 function expand_floor(floor_div) {
368 if (which_div_expanded != null) {
369 $(which_div_expanded).style.display = 'none' ;
371 $(floor_div).style.display = 'block';
372 which_div_expanded = floor_div;
375 function switch_to_menu_buttons() {
376 which_div_expanded = null;
377 new Ajax.Updater('iconbar', 'iconbar_ajax_menu', { method: 'get' } );