default.js 9.4 KB

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