Carry event object for click events into called JS code
[squirrelmail.git] / templates / default / js / default.js
CommitLineData
49db257d 1/**
2 * This array is used to remember mark status of rows in browse mode
4b4abf93 3 *
47ccfad4 4 * @copyright © 2005-2006 The SquirrelMail Project Team
4b4abf93 5 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
6 * @version $Id$
49db257d 7 */
8var marked_row = new Array;
9var orig_row_colors = new Array();
10
49db257d 11/*
12 * (un)Checks checkbox for the row that the current table cell is in
13 * when it gets clicked.
14 *
15 * @param string the name of the checkbox that should be (un)checked
16 */
a4cca6e2 17function row_click(chkboxName, event) {
684f1a88 18 var chkbox = document.getElementById(chkboxName);
49db257d 19 if (chkbox) {
20 // initialize orig_row_color if not defined already
21 if (!orig_row_colors[chkboxName]) {
22 orig_row_colors[chkboxName] = chkbox.parentNode.getAttribute('bgcolor');
e0a6645e 23 if (orig_row_colors[chkboxName].indexOf("clicked_") == 0)
24 orig_row_colors[chkboxName] = orig_row_colors[chkboxName].substring(8, orig_row_colors[chkboxName].length);
49db257d 25 }
26 chkbox.checked = (chkbox.checked ? false : true);
27 }
28}
e3812cb2 29
30/*
31 * Gets the current class of the requested row. This is a browser specific function.
32 * Code shamelessly ripped from setPointer() below.
33 */
34function getCSSClass (theRow)
35{
684f1a88 36 var rowClass;
e3812cb2 37 // 3.1 ... with DOM compatible browsers except Opera that does not return
38 // valid values with "getAttribute"
39 if (typeof(window.opera) == 'undefined'
40 && typeof(theRow.getAttribute) != 'undefined'
41 && theRow.getAttribute('className') ) {
42 rowClass = theRow.getAttribute('className');
43 }
44 // 3.2 ... with other browsers
45 else {
46 rowClass = theRow.className;
47 }
48
49 return rowClass;
50}
51
49db257d 52/*
e89c305d 53 * Sets a new CSS class for the given row. Browser-specific.
54 */
55function setCSSClass (obj, newClass) {
56 if (typeof(window.opera) == 'undefined' && typeof(obj.getAttribute) != 'undefined' && obj.getAttribute('className') ) {
57 obj.setAttribute('className', newClass, 0);
58 }
59 else {
60 obj.className = newClass;
61 }
62}
63
64/*
49db257d 65 * This function is used to initialize the orig_row_color array so we do not
66 * need to predefine the entire array
67 */
e3812cb2 68function rowOver(chkboxName) {
684f1a88 69 var chkbox = document.getElementById(chkboxName);
70 var rowClass, rowNum, overClass, clickedClass;
49db257d 71 if (chkbox) {
72 if (!orig_row_colors[chkboxName]) {
e0a6645e 73 rowClass = getCSSClass(chkbox.parentNode.parentNode);
74 if (rowClass.indexOf("clicked_") == 0)
75 rowClass = rowClass.substring(8, rowClass.length);
e3812cb2 76 orig_row_colors[chkboxName] = rowClass;
49db257d 77 } else {
e3812cb2 78 rowClass = orig_row_colors[chkboxName];
49db257d 79 }
e0a6645e 80 rowNum = chkboxName.substring(chkboxName.length - 1, chkboxName.length);
e3812cb2 81
82/*
83 * The mouseover and clicked CSS classes are always the same name!
84 */
85 overClass = 'mouse_over';
86 clickedClass = 'clicked';
e0a6645e 87 setPointer(chkbox.parentNode.parentNode, rowNum, 'over' , rowClass, overClass, clickedClass);
49db257d 88 }
89}
90
91/*
92 * (un)Checks all checkboxes for the message list from a specific form
93 * when it gets clicked.
94 *
95 * @param string the id of the form where all checkboxes should be (un)checked
96 * @param boolean use fancy row coloring when a checkbox is checked
97 * @param string new color of the checked rows
98 */
e3812cb2 99function toggle_all(formname, fancy) {
684f1a88 100 var TargetForm = document.getElementById(formname);
101 var j = 0;
9dfab515 102 for (var i = 0; i < TargetForm.elements.length; i++) {
103 if (TargetForm.elements[i].type == 'checkbox' && TargetForm.elements[i].name.substring(0,3) == 'msg') {
104 if (fancy) {
49db257d 105 array_key = TargetForm.elements[i].getAttribute('id');
e0a6645e 106 // initialize orig_row_color if not defined already
107 if (!orig_row_colors[array_key]) {
108 rowClass = getCSSClass(TargetForm.elements[i].parentNode.parentNode);
109 if (rowClass.indexOf("clicked_") == 0)
110 rowClass = rowClass.substring(8, rowClass.length);
111 orig_row_colors[array_key] = rowClass;
49db257d 112 }
e3812cb2 113 origClass = orig_row_colors[array_key];
e0a6645e 114 clickedClass = 'clicked';
e3812cb2 115 setPointer(TargetForm.elements[i].parentNode.parentNode, j,'click' , origClass, origClass, clickedClass);
49db257d 116 j++
117 }
118 TargetForm.elements[i].checked = !(TargetForm.elements[i].checked);
9dfab515 119 }
120 }
49db257d 121}
122
123/*
124 * Sets/unsets the pointer and marker in browse mode
125 *
e0a6645e 126 * @param object theRow the table row
127 * @param integer theRowNum the row number
128 * @param string theAction the action calling this script (over, out or click)
129 * @param string defaultClass the default background CSS class
130 * @param string mouseoverClass the CSS class to use for mouseover
131 * @param string clickedClass the CSS class to use for marking a row
49db257d 132 *
133 * @return boolean whether pointer is set or not
134 */
e0a6645e 135function setPointer(theRow, theRowNum, theAction, defaultClass, mouseoverClass, clickedClass)
49db257d 136{
49db257d 137 // 1. Pointer and mark feature are disabled or the browser can't get the
138 // row -> exits
e0a6645e 139 if ((mouseoverClass == '' && clickedClass == '')
e3812cb2 140 || typeof(theRow.className) == 'undefined') {
49db257d 141 return false;
142 }
143
e3812cb2 144 // 2. Verify we can get the current row or exit
49db257d 145 if (typeof(document.getElementsByTagName) != 'undefined') {
e3812cb2 146 // We are ok
49db257d 147 }
e3812cb2 148 else if (typeof(theRow) != 'undefined') {
149 // We are ok
49db257d 150 }
151 else {
152 return false;
153 }
154
e3812cb2 155 // 3. Gets the current CSS class...
e3812cb2 156 var newClass = null;
157 var currentClass = getCSSClass(theRow);
e0a6645e 158 if (currentClass.indexOf("clicked_") == 0)
159 currentClass = 'clicked';
e3812cb2 160
e3812cb2 161 // 4. Defines the new class
162 // 4.1 Current class is the default one
163 if (currentClass == ''
e0a6645e 164 || currentClass.toLowerCase() == defaultClass.toLowerCase()) {
165 if (theAction == 'over' && mouseoverClass != '') {
166 newClass = mouseoverClass;
49db257d 167 }
e0a6645e 168 else if (theAction == 'click' && clickedClass != '') {
169 newClass = clickedClass;
49db257d 170 marked_row[theRowNum] = true;
171 // deactivated onclick marking of the checkbox because it's also executed
172 // when an action (clicking on the checkbox itself) on a single item is
173 // performed. Then the checkbox would get deactived, even though we need
174 // it activated. Maybe there is a way to detect if the row was clicked,
175 // and not an item therein...
176 //document.getElementById('msg[' + theRowNum + ']').checked = true;
177 }
178 }
e0a6645e 179 // 4.1.2 Current class is the mouseover one
180 else if (currentClass.toLowerCase() == mouseoverClass.toLowerCase()
49db257d 181 && (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])) {
182 if (theAction == 'out') {
e0a6645e 183 newClass = defaultClass;
49db257d 184 }
e0a6645e 185 else if (theAction == 'click' && clickedClass != '') {
186 newClass = clickedClass;
49db257d 187 marked_row[theRowNum] = true;
188 //document.getElementById('msg[' + theRowNum + ']').checked = true;
189 }
190 }
e0a6645e 191 // 4.1.3 Current color is the clicked one
192 else if (currentClass.toLowerCase() == clickedClass.toLowerCase()) {
49db257d 193 if (theAction == 'click') {
e0a6645e 194 newClass = (mouseoverClass != '')
195 ? mouseoverClass
196 : defaultClass;
197 marked_row[theRowNum] = false;
49db257d 198 //document.getElementById('msg[' + theRowNum + ']').checked = false;
199 }
200 } // end 4
201
202 // 5. Sets the new color...
e3812cb2 203 if (newClass) {
e89c305d 204 setCSSClass(theRow, newClass);
205 }
49db257d 206
207 return true;
208} // end of the 'setPointer()' function
209
210function comp_in_new_form(comp_uri, button, myform, iWidth, iHeight) {
211 comp_uri += "&" + button.name + "=1";
212 for ( var i=0; i < myform.elements.length; i++ ) {
213 if ( myform.elements[i].type == "checkbox" && myform.elements[i].checked )
214 comp_uri += "&" + myform.elements[i].name + "=1";
215 }
216 if (!iWidth) iWidth = 640;
217 if (!iHeight) iHeight = 550;
684f1a88 218 var sArg = "width=" + iWidth + ",height=" + iHeight + ",scrollbars=yes,resizable=yes,status=yes";
49db257d 219 var newwin = window.open(comp_uri, "_blank", sArg);
220}
221
222function comp_in_new(comp_uri, iWidth, iHeight) {
223 if (!iWidth) iWidth = 640;
224 if (!iHeight) iHeight = 550;
225 sArg = "width=" + iWidth + ",height=" + iHeight + ",scrollbars=yes,resizable=yes,status=yes";
226 var newwin = window.open(comp_uri , "_blank", sArg);
227}
228
229/*
230 * Reload the read_body screen on sending an mdn receipt
231 */
232function sendMDN() {
684f1a88 233 var mdnuri=window.location+'&sendreceipt=1';
5ab2aff6 234 window.location = mdnuri;
49db257d 235}
236
87745b9c 237var alreadyFocused = false;
49db257d 238function checkForm(smaction) {
87745b9c 239
240 if (alreadyFocused) return;
241
49db257d 242 /*
243 * this part is used for setting the focus in the compose screen
244 */
245 if (smaction) {
246 if (smaction == "select") {
247 document.forms['compose'].body.select();
248 } else if (smaction == "focus") {
249 document.forms['compose'].body.focus();
250 }
251 } else {
252 /*
253 * All other forms that need to set the focus
254 */
255 var f = document.forms.length;
256 var i = 0;
257 var pos = -1;
258 while( pos == -1 && i < f ) {
259 var e = document.forms[i].elements.length;
260 var j = 0;
261 while( pos == -1 && j < e ) {
262 if ( document.forms[i].elements[j].type == 'text' || document.forms[i].elements[j].type == 'password' ) {
263 pos = j;
264 }
265 j++;
266 }
267 i++;
268 }
269 if( pos >= 0 ) {
270 document.forms[i-1].elements[pos].focus();
271 }
272 }
5ab2aff6 273}