default.js 11 KB

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