default.js 9.5 KB

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