From aa30cf8f3c05ab4fd69f7ab2dea39e56d8bf1976 Mon Sep 17 00:00:00 2001
From: Aleksander Machniak <alec@alec.pl>
Date: Tue, 26 Mar 2013 14:17:05 -0400
Subject: [PATCH] Better fix for "saving draft just after entering compose window (#1489012)"

---
 program/js/app.js |   12 +++++++++---
 1 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/program/js/app.js b/program/js/app.js
index 329bd77..eb8644a 100644
--- a/program/js/app.js
+++ b/program/js/app.js
@@ -178,6 +178,11 @@
       parent.rcmail.env.frame_lock = null;
     }
 
+    // Makes that reference to document.activeElement do not throw
+    // "unspecified error" in IE9 (#1489008)
+    if (this.env.framed && bw.ie)
+      document.documentElement.focus();
+
     // enable general commands
     this.enable_command('close', 'logout', 'mail', 'addressbook', 'settings', 'save-pref', 'compose', 'undo', 'about', 'switch-task', true);
 
@@ -821,7 +826,7 @@
 
         // open attachment in frame if it's of a supported mimetype
         if (this.env.uid && props.mimetype && this.env.mimetypes && $.inArray(props.mimetype, this.env.mimetypes) >= 0) {
-          var attachment_win = window.open(this.env.comm_path+'&_action=get&'+qstring+'&_frame=1', 'rcubemailattachment'+this.env.uid+props.part);
+          var attachment_win = window.open(this.env.comm_path+'&_action=get&'+qstring+'&_frame=1', this.html_identifier('rcubemailattachment'+this.env.uid+props.part));
           if (attachment_win) {
             setTimeout(function(){ attachment_win.focus(); }, 10);
             break;
@@ -944,8 +949,8 @@
         // Reset the auto-save timer
         clearTimeout(this.save_timer);
 
-        // compose form did not change
-        if (this.cmp_hash == this.compose_field_hash()) {
+        // compose form did not change (and draft wasn't saved already)
+        if (this.env.draft_id && this.cmp_hash == this.compose_field_hash()) {
           this.auto_save_start();
           break;
         }
@@ -3340,6 +3345,7 @@
 
   this.set_draft_id = function(id)
   {
+    this.env.draft_id = id;
     $("input[name='_draft_saveid']").val(id);
   };
 

--
Gitblit v1.9.1