default.js 9.0 KB

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