default.js 9.4 KB

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