Happy New Year
[squirrelmail.git] / templates / default / js / default.js
index ca1321acc049e84faf823e6a18d3c3fe4b9be85f..109d5afa03819240c6727c76161512431433af88 100644 (file)
@@ -1,7 +1,7 @@
 /**
  * This array is used to remember mark status of rows in browse mode
  *
- * @copyright © 2005-2006 The SquirrelMail Project Team
+ * @copyright 2005-2020 The SquirrelMail Project Team
  * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  * @version $Id$
  */
@@ -104,14 +104,15 @@ function rowOver(chkboxName) {
  * when it gets clicked.
  *
  * @param   string   the id of the form where all checkboxes should be (un)checked
+ * @param   string   the first three characters of target checkboxes, if any
  * @param   boolean  use fancy row coloring when a checkbox is checked
  * @param   string   new color of the checked rows
  */
-function toggle_all(formname, fancy) {
+function toggle_all(formname, name_prefix, fancy) {
     var TargetForm = document.getElementById(formname);
     var j = 0;
     for (var i = 0; i < TargetForm.elements.length; i++) {
-        if (TargetForm.elements[i].type == 'checkbox' && TargetForm.elements[i].name.substring(0,3) == 'msg') {
+        if (TargetForm.elements[i].type == 'checkbox' && (name_prefix == '' || TargetForm.elements[i].name.substring(0,3) == name_prefix)) {
             if (fancy) {
                 array_key = TargetForm.elements[i].getAttribute('id');
                 // initialize orig_row_color if not defined already
@@ -246,6 +247,17 @@ function sendMDN() {
 }
 
 var alreadyFocused = false;
+
+function cursorToTop(element) {
+    if (typeof element.selectionStart == 'number')
+        element.selectionStart = element.selectionEnd = 0;
+    else if (typeof element.createTextRange != 'undefined') {
+        var selectionRange = element.createTextRange();
+        selectionRange.moveStart('character', 0);
+        selectionRange.select();
+    }
+}
+
 function checkForm(smaction) {
 
     if (alreadyFocused) return;
@@ -258,6 +270,7 @@ function checkForm(smaction) {
             document.forms['compose'].body.select();
         } else if (smaction == "focus") {
             document.forms['compose'].body.focus();
+            cursorToTop(document.forms['compose'].body);
         }
     } else {
     /*
@@ -265,13 +278,20 @@ function checkForm(smaction) {
      */
         var f = document.forms.length;
         var i = 0;
+        var remembered_form = -1;
         var pos = -1;
+        var remembered_pos = -1;
         while( pos == -1 && i < f ) {
             var e = document.forms[i].elements.length;
             var j = 0;
             while( pos == -1 && j < e ) {
-                if ( document.forms[i].elements[j].type == 'text' || document.forms[i].elements[j].type == 'password' ) {
-                    pos = j;
+                if ( document.forms[i].elements[j].type == 'text' || document.forms[i].elements[j].type == 'password' || document.forms[i].elements[j].type == 'textarea' ) {
+                    if ( document.forms[i].elements[j].id.substring(0, 13) == '__lastfocus__' ) {
+                        remembered_pos = j;
+                        remembered_form = i;
+                    } else if ( document.forms[i].elements[j].id.substring(0, 11) != '__nofocus__' ) {
+                        pos = j;
+                    }
                 }
                 j++;
             }
@@ -279,6 +299,28 @@ function checkForm(smaction) {
         }
         if( pos >= 0 ) {
             document.forms[i-1].elements[pos].focus();
+        } else if ( remembered_pos >= 0 ) {
+            document.forms[remembered_form].elements[remembered_pos].focus();
         }
     }
 }
+
+function printThis()
+{
+    parent.frames['right'].focus();
+    parent.frames['right'].print();
+}
+
+/* JS implementation of more/less links in To/CC. Could later be extended
+ * show/hide other interface items */
+function showhide (item, txtmore, txtless) {
+    var oTemp=document.getElementById("recpt_tail_" + item);
+    var oClick=document.getElementById("toggle_" + item);
+    if (oTemp.style.display=="inline") {
+        oTemp.style.display="none";
+        oClick.innerHTML=txtmore;
+    } else {
+        oTemp.style.display="inline";
+        oClick.innerHTML=txtless;
+    }
+}