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 | */ |
8 | var marked_row = new Array; |
9 | var 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 | */ |
17 | function 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 | } |
e3812cb2 |
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 | */ |
32 | function 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 | |
49db257d |
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 | */ |
e3812cb2 |
53 | function rowOver(chkboxName) { |
49db257d |
54 | chkbox = document.getElementById(chkboxName); |
55 | if (chkbox) { |
56 | if (!orig_row_colors[chkboxName]) { |
e3812cb2 |
57 | rowClass = getCSSClass(chkbox.parentNode.parentNode); |
58 | orig_row_colors[chkboxName] = rowClass; |
49db257d |
59 | } else { |
e3812cb2 |
60 | rowClass = orig_row_colors[chkboxName]; |
49db257d |
61 | } |
62 | j = chkbox.name.length - 1 |
e3812cb2 |
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); |
49db257d |
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 | */ |
e3812cb2 |
81 | function toggle_all(formname, fancy) { |
49db257d |
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]) { |
e3812cb2 |
91 | rowClass = getCSSClass(TargetForm.elements[i].parentNode.parentNode); |
92 | orig_row_colors[array_key] = rowClass; |
49db257d |
93 | } |
94 | } |
e3812cb2 |
95 | origClass = orig_row_colors[array_key]; |
96 | clickedClass = 'clicked'; |
97 | setPointer(TargetForm.elements[i].parentNode.parentNode, j,'click' , origClass, origClass, clickedClass); |
49db257d |
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) |
e3812cb2 |
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 |
49db257d |
114 | * |
115 | * @return boolean whether pointer is set or not |
116 | */ |
e3812cb2 |
117 | function setPointer(theRow, theRowNum, theAction, theDefaultClass, thePointerClass, theMarkClass) |
49db257d |
118 | { |
49db257d |
119 | // 1. Pointer and mark feature are disabled or the browser can't get the |
120 | // row -> exits |
e3812cb2 |
121 | if ((thePointerClass == '' && theMarkClass == '') |
122 | || typeof(theRow.className) == 'undefined') { |
49db257d |
123 | return false; |
124 | } |
125 | |
e3812cb2 |
126 | // 2. Verify we can get the current row or exit |
49db257d |
127 | if (typeof(document.getElementsByTagName) != 'undefined') { |
e3812cb2 |
128 | // We are ok |
49db257d |
129 | } |
e3812cb2 |
130 | else if (typeof(theRow) != 'undefined') { |
131 | // We are ok |
49db257d |
132 | } |
133 | else { |
134 | return false; |
135 | } |
136 | |
e3812cb2 |
137 | // 3. Gets the current CSS class... |
49db257d |
138 | var domDetect = null; |
e3812cb2 |
139 | var newClass = null; |
140 | var currentClass = getCSSClass(theRow); |
141 | |
142 | // domDetect is needed later... |
49db257d |
143 | // 3.1 ... with DOM compatible browsers except Opera that does not return |
144 | // valid values with "getAttribute" |
145 | if (typeof(window.opera) == 'undefined' |
e3812cb2 |
146 | && typeof(theRow.getAttribute) != 'undefined' |
147 | && theRow.getAttribute('className') ) { |
49db257d |
148 | domDetect = true; |
149 | } |
150 | // 3.2 ... with other browsers |
151 | else { |
49db257d |
152 | domDetect = false; |
153 | } // end 3 |
154 | |
e3812cb2 |
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; |
49db257d |
161 | } |
e3812cb2 |
162 | else if (theAction == 'click' && theMarkClass != '') { |
163 | newClass = theMarkClass; |
49db257d |
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 | } |
e3812cb2 |
173 | // 4.1.2 Current class is the pointer one |
174 | else if (currentClass.toLowerCase() == thePointerClass.toLowerCase() |
49db257d |
175 | && (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])) { |
176 | if (theAction == 'out') { |
e3812cb2 |
177 | newClass = theDefaultClass; |
49db257d |
178 | } |
e3812cb2 |
179 | else if (theAction == 'click' && theMarkClass != '') { |
180 | newClass = theMarkClass; |
49db257d |
181 | marked_row[theRowNum] = true; |
182 | //document.getElementById('msg[' + theRowNum + ']').checked = true; |
183 | } |
184 | } |
185 | // 4.1.3 Current color is the marker one |
e3812cb2 |
186 | else if (currentClass.toLowerCase() == theMarkClass.toLowerCase()) { |
49db257d |
187 | if (theAction == 'click') { |
e3812cb2 |
188 | newClass = (thePointerClass != '') |
189 | ? thePointerClass |
190 | : theDefaultClass; |
49db257d |
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... |
e3812cb2 |
199 | if (newClass) { |
49db257d |
200 | // 5.1 ... with DOM compatible browsers except Opera |
201 | if (domDetect) { |
e3812cb2 |
202 | theRow.setAttribute('className', newClass, 0); |
49db257d |
203 | } |
204 | // 5.2 ... with other browsers |
205 | else { |
e3812cb2 |
206 | theRow.className = newClass; |
49db257d |
207 | } |
208 | } // end 5 |
209 | |
210 | return true; |
211 | } // end of the 'setPointer()' function |
212 | |
213 | function 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 | |
225 | function 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 | */ |
235 | function sendMDN() { |
236 | mdnuri=window.location+'&sendreceipt=1'; |
237 | var newwin = window.open(mdnuri,'right'); |
238 | } |
239 | |
87745b9c |
240 | var alreadyFocused = false; |
49db257d |
241 | function checkForm(smaction) { |
87745b9c |
242 | |
243 | if (alreadyFocused) return; |
244 | |
49db257d |
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 | } |
4b4abf93 |
276 | } |