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