From 32ca1f9fc8a78e092565b51cc97faa724bb4e6cf Mon Sep 17 00:00:00 2001
From: alecpl <alec@alec.pl>
Date: Sat, 30 May 2009 05:09:57 -0400
Subject: [PATCH] - css fixes (#1485869)

---
 program/js/app.js |  113 ++++++++++++++++++++++++++++++++++++++++----------------
 1 files changed, 81 insertions(+), 32 deletions(-)

diff --git a/program/js/app.js b/program/js/app.js
index 8ac0e72..4a90bf2 100644
--- a/program/js/app.js
+++ b/program/js/app.js
@@ -165,7 +165,7 @@
           this.message_list.addEventListener('select', function(o){ p.msglist_select(o); });
           this.message_list.addEventListener('dragstart', function(o){ p.drag_start(o); });
           this.message_list.addEventListener('dragmove', function(o, e){ p.drag_move(e); });
-          this.message_list.addEventListener('dragend', function(o){ p.drag_active = false; });
+          this.message_list.addEventListener('dragend', function(o, e){ p.drag_end(e); });
           document.onmouseup = function(e){ return p.doc_mouse_up(e); };
 
           this.message_list.init();
@@ -188,7 +188,9 @@
         
         if (this.env.action=='show' || this.env.action=='preview')
           {
-          this.enable_command('show', 'reply', 'reply-all', 'forward', 'moveto', 'delete', 'mark', 'viewsource', 'print', 'load-attachment', 'load-headers', true);
+          this.enable_command('show', 'reply', 'reply-all', 'forward', 'moveto', 'delete',
+	    'open', 'mark', 'viewsource', 'download', 'print', 'load-attachment', 'load-headers', true);
+
           if (this.env.next_uid)
             {
             this.enable_command('nextmessage', true);
@@ -198,6 +200,13 @@
             {
             this.enable_command('previousmessage', true);
             this.enable_command('firstmessage', true);
+            }
+        
+	  if (this.env.blockedobjects)
+            {
+            if (this.gui_objects.remoteobjectsmsg)
+              this.gui_objects.remoteobjectsmsg.style.display = 'block';
+            this.enable_command('load-images', 'always-load', true);
             }
           }
 
@@ -209,13 +218,6 @@
           {
           this.enable_command('compose', 'add-contact', false);
           parent.rcmail.show_contentframe(true);
-          }
-
-        if ((this.env.action=='show' || this.env.action=='preview') && this.env.blockedobjects)
-          {
-          if (this.gui_objects.remoteobjectsmsg)
-            this.gui_objects.remoteobjectsmsg.style.display = 'block';
-          this.enable_command('load-images', 'always-load', true);
           }
 
         if (this.env.action=='compose')
@@ -279,7 +281,7 @@
           this.contact_list.addEventListener('select', function(o){ p.contactlist_select(o); });
           this.contact_list.addEventListener('dragstart', function(o){ p.drag_start(o); });
           this.contact_list.addEventListener('dragmove', function(o, e){ p.drag_move(e); });
-          this.contact_list.addEventListener('dragend', function(o){ p.drag_active = false; });
+          this.contact_list.addEventListener('dragend', function(o, e){ p.drag_end(e); });
           this.contact_list.init();
 
           if (this.env.cid)
@@ -472,7 +474,7 @@
     else if (input_subject.val() == '')
       input_subject.focus();
     else if (input_message)
-      this.set_caret2start(input_message);
+      input_message.focus();
 
     // get summary of all field values
     this.compose_field_hash(true);
@@ -484,7 +486,7 @@
   this.init_address_input_events = function(obj)
     {
     var handler = function(e){ return ref.ksearch_keypress(e,this); };
-    obj.bind((bw.safari ? 'keydown' : 'keypress'), handler);
+    obj.bind((bw.safari || bw.ie ? 'keydown' : 'keypress'), handler);
     obj.attr('autocomplete', 'off');
     };
 
@@ -565,7 +567,16 @@
           return true;
         else if (this.env.permaurl)
           parent.location.href = this.env.permaurl;
-          break;
+        break;
+
+      case 'open':
+        var uid;
+        if (uid = this.get_single_uid())
+        {
+          obj.href = '?_task='+this.env.task+'&_action=show&_mbox='+urlencode(this.env.mailbox)+'&_uid='+uid;
+          return true;
+        }
+        break;
 
       // misc list commands
       case 'list':
@@ -992,10 +1003,16 @@
         var uid;
         if (uid = this.get_single_uid())
           {
-          ref.sourcewin = window.open(this.env.comm_path+'&_action=viewsource&_uid='+this.env.uid+'&_mbox='+urlencode(this.env.mailbox));
+          ref.sourcewin = window.open(this.env.comm_path+'&_action=viewsource&_uid='+uid+'&_mbox='+urlencode(this.env.mailbox));
           if (this.sourcewin)
             window.setTimeout(function(){ ref.sourcewin.focus(); }, 20);
           }
+        break;
+
+      case 'download':
+        var uid;
+        if (uid = this.get_single_uid())
+          this.goto_url('viewsource', '&_uid='+uid+'&_mbox='+urlencode(this.env.mailbox)+'&_save=1');
         break;
 
       case 'add-contact':
@@ -1251,6 +1268,21 @@
     }
   };
 
+  this.drag_end = function(e)
+  {
+    this.drag_active = false;
+
+    // over the folders
+    if (this.gui_objects.folderlist && this.env.folder_coords) {
+      for (var k in this.env.folder_coords) {
+        if (k == this.env.last_folder_target) {
+          $(this.get_folder_li(k)).removeClass('droptarget');
+          this.env.last_folder_target = null;
+        }
+      }
+    }
+  };
+  
   this.drag_move = function(e)
   {
     if (this.gui_objects.folderlist && this.env.folder_coords) {
@@ -1357,12 +1389,12 @@
     if (this.env.mailbox == this.env.drafts_mailbox)
       {
       this.enable_command('reply', 'reply-all', 'forward', false);
-      this.enable_command('show', 'print', selected);
+      this.enable_command('show', 'print', 'open', 'download', 'viewsource', selected);
       this.enable_command('delete', 'moveto', 'mark', (list.selection.length > 0 ? true : false));
       }
     else
       {
-      this.enable_command('show', 'reply', 'reply-all', 'forward', 'print', selected);
+      this.enable_command('show', 'reply', 'reply-all', 'forward', 'print', 'open', 'download', 'viewsource', selected);
       this.enable_command('delete', 'moveto', 'mark', (list.selection.length > 0 ? true : false));
       }
 
@@ -2188,7 +2220,7 @@
     var input_message = $("[name='_message']");
     var message = input_message.val();
     var is_html = ($("input[name='_is_html']").val() == '1');
-    var sig, p;
+    var sig, p, len;
 
     if (!this.env.identity)
       this.env.identity = id
@@ -2212,7 +2244,8 @@
         }
 
       message = message.replace(/[\r\n]+$/, '');
-      
+      len = message.length;
+
       // add the new signature string
       if (this.env.signatures && this.env.signatures[id])
         {
@@ -2224,6 +2257,7 @@
         if (sig.indexOf('-- ')!=0)
           sig = '-- \n'+sig;
         message += '\n\n'+sig;
+	if (len) len += 1;
         }
       }
     else
@@ -2269,6 +2303,10 @@
       }
 
     input_message.val(message);
+
+    // move cursor before the signature
+    if (!is_html)
+      this.set_caret_pos(input_message.get(0), len);
 
     this.env.identity = id;
     return true;
@@ -2392,19 +2430,26 @@
     };
 
   // send remote request to search mail or contacts
-  this.qsearch = function(value, addurl)
+  this.qsearch = function(value)
     {
     if (value != '')
       {
-      if (this.message_list)
+      var addurl = '';
+      if (this.message_list) {
         this.message_list.clear();
-      else if (this.contact_list) {
+	if (this.env.search_mods) {
+          var head_arr = new Array();
+          for (var n in this.env.search_mods)
+	    head_arr.push(n);
+	  addurl += '&_headers='+head_arr.join(',');
+          }
+        } else if (this.contact_list) {
         this.contact_list.clear(true);
         this.show_contentframe(false);
         }
 
       if (this.gui_objects.search_filter)
-      addurl = '&_filter=' + this.gui_objects.search_filter.value;
+        addurl += '&_filter=' + this.gui_objects.search_filter.value;
 
       // reset vars
       this.env.current_page = 1;
@@ -2551,10 +2596,13 @@
     q = q.replace(/(^\s+|\s+$)/g, '').toLowerCase();
 
     // Don't (re-)search if string is empty or if the last results are still active
-    if (!q.length || q == this.ksearch_value)
+    if (q == this.ksearch_value)
       return;
-
+    
     this.ksearch_value = q;
+    
+    if (!q.length)
+      return;
     
     this.display_message(this.get_label('searching'), 'loading', true);
     this.http_post('autocomplete', '_search='+urlencode(q));
@@ -3929,7 +3977,8 @@
     this.set_busy(false);
     request.abort();
     
-    this.display_message('Unknown Server Error!' + (errmsg ? ' ('+errmsg+')' : ''), 'error');
+    if (errmsg)
+      this.display_message(this.get_label('servererror') + ' (' + errmsg + ')', 'error');
     };
 
   // use an image to send a keep-alive siganl to the server
@@ -4004,19 +4053,19 @@
       return obj.value.length;
     };
 
-  this.set_caret2start = function(obj)
+  this.set_caret_pos = function(obj, pos)
     {
-    if (obj.createTextRange)
+    if (obj.setSelectionRange)
+      obj.setSelectionRange(pos, pos);
+    else if (obj.createTextRange)
       {
       var range = obj.createTextRange();
       range.collapse(true);
+      range.moveEnd('character', pos);
+      range.moveStart('character', pos);
       range.select();
       }
-    else if (obj.setSelectionRange)
-      obj.setSelectionRange(0,0);
-
-    obj.focus();
-    };
+    }
 
   // set all fields of a form disabled
   this.lock_form = function(form, lock)

--
Gitblit v1.9.1