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