From fd0c123e44391aa01a85c5aeebbd0cea418f0808 Mon Sep 17 00:00:00 2001
From: Aleksander Machniak <alec@alec.pl>
Date: Sun, 08 Dec 2013 04:57:44 -0500
Subject: [PATCH] Fix fixed header issue after removing rows (1295420)

---
 program/js/app.js |   78 +++++++++++++++++++++++---------------
 1 files changed, 47 insertions(+), 31 deletions(-)

diff --git a/program/js/app.js b/program/js/app.js
index 257c109..398417a 100644
--- a/program/js/app.js
+++ b/program/js/app.js
@@ -34,7 +34,7 @@
 
   // webmail client settings
   this.dblclick_time = 500;
-  this.message_time = 4000;
+  this.message_time = 5000;
   this.identifier_expr = new RegExp('[^0-9a-z\-_]', 'gi');
 
   // environment defaults
@@ -186,8 +186,6 @@
 
     if (this.env.permaurl)
       this.enable_command('permaurl', 'extwin', true);
-
-    this.local_storage_prefix = 'roundcube.' + (this.env.user_id || 'anonymous') + '.';
 
     switch (this.task) {
 
@@ -1708,7 +1706,7 @@
     url += (url.match(/\?/) ? '&' : '?') + '_extwin=1';
 
     if (this.env.standard_windows)
-      extwin = window.open(url, wname);
+      var extwin = window.open(url, wname);
     else {
       var win = this.is_framed() ? parent.window : window,
         page = $(win),
@@ -1728,8 +1726,11 @@
       extwin.document.write('<html><body>' + this.get_label('loading') + '</body></html>');
     }
 
+    // allow plugins to grab the window reference (#1489413)
+    this.triggerEvent('openwindow', { url:url, handle:extwin });
+
     // focus window, delayed to bring to front
-    window.setTimeout(function() { extwin.focus(); }, 10);
+    window.setTimeout(function() { extwin && extwin.focus(); }, 10);
 
     return extwin;
   };
@@ -3199,7 +3200,7 @@
   {
     this.env.recipients_delimiter = this.env.recipients_separator + ' ';
 
-    obj[bw.ie || bw.safari || bw.chrome ? 'keydown' : 'keypress'](function(e) { return ref.ksearch_keydown(e, this, props); })
+    obj.keydown(function(e) { return ref.ksearch_keydown(e, this, props); })
       .attr('autocomplete', 'off');
   };
 
@@ -3682,13 +3683,13 @@
       formdata.draft_id = this.env.draft_id;
     }
 
-    $('input, select, textarea', this.gui_objects.messageform).each(function(i, elem){
+    $('input, select, textarea', this.gui_objects.messageform).each(function(i, elem) {
       switch (elem.tagName.toLowerCase()) {
         case 'input':
           if (elem.type == 'button' || elem.type == 'submit' || (elem.type == 'hidden' && elem.name != '_is_html')) {
             break;
           }
-          formdata[elem.name] = elem.type != 'checkbox' || elem.checked ? elem.value : '';
+          formdata[elem.name] = elem.type != 'checkbox' || elem.checked ? $(elem).val() : '';
 
           if (formdata[elem.name] != '' && elem.type != 'hidden')
             empty = false;
@@ -3709,7 +3710,7 @@
       var index = this.local_storage_get_item('compose.index', []),
         key = this.env.compose_id;
 
-        if (index.indexOf(key) < 0) {
+        if ($.inArray(key, index) < 0) {
           index.push(key);
         }
         this.local_storage_set_item('compose.' + key, formdata, true);
@@ -3723,7 +3724,7 @@
     var ed, formdata = this.local_storage_get_item('compose.' + key, true);
 
     if (formdata && typeof formdata == 'object') {
-      $.each(formdata, function(k, value){
+      $.each(formdata, function(k, value) {
         if (k[0] == '_') {
           var elem = $("*[name='"+k+"']");
           if (elem[0] && elem[0].type == 'checkbox') {
@@ -3755,9 +3756,9 @@
     if (window.localStorage) {
       var index = this.local_storage_get_item('compose.index', []);
 
-      if (index.indexOf(key) >= 0) {
+      if ($.inArray(key, index) >= 0) {
         this.local_storage_remove_item('compose.' + key);
-        this.local_storage_set_item('compose.index', $.grep(index, function(val,i){ return val != key; }));
+        this.local_storage_set_item('compose.index', $.grep(index, function(val,i) { return val != key; }));
       }
     }
   };
@@ -4208,7 +4209,7 @@
       case 38:  // arrow up
       case 40:  // arrow down
         if (!this.ksearch_visible())
-          break;
+          return;
 
         var dir = key==38 ? 1 : 0;
 
@@ -4243,8 +4244,7 @@
 
       case 37:  // left
       case 39:  // right
-        if (mod != SHIFT_KEY)
-          return;
+        return;
     }
 
     // start timer
@@ -5545,9 +5545,8 @@
       target = win;
     }
 
-    if (action && (id || action == 'add-identity')) {
-      this.set_busy(true);
-      this.location_href(url, target);
+    if (id || action == 'add-identity') {
+      this.location_href(url, target, true);
     }
 
     return true;
@@ -5733,7 +5732,7 @@
     if (!this.gui_objects.subscriptionlist)
       return false;
 
-    var row, n, i, tmp, tmp_name, folders, rowid, list = [], slist = [],
+    var row, n, i, tmp, tmp_name, rowid, folders = [], list = [], slist = [],
       tbody = this.gui_objects.subscriptionlist.tBodies[0],
       refrow = $('tr', tbody).get(1),
       id = 'rcmrow'+((new Date).getTime());
@@ -5748,8 +5747,7 @@
     row = $(refrow).clone(true);
 
     // set ID, reset css class
-    row.attr('id', id);
-    row.attr('class', class_name);
+    row.attr({id: id, 'class': class_name});
 
     // set folder name
     row.find('td:first').html(display_name);
@@ -5761,10 +5759,21 @@
     // add to folder/row-ID map
     this.env.subscriptionrows[id] = [name, display_name, 0];
 
-    // sort folders, to find a place where to insert the row
-    folders = [];
-    $.each(this.env.subscriptionrows, function(k,v){ folders.push(v) });
-    folders.sort(function(a,b){ return a[0] < b[0] ? -1 : (a[0] > b[0] ? 1 : 0) });
+    // sort folders (to find a place where to insert the row)
+    // replace delimiter with \0 character to fix sorting
+    // issue where 'Abc Abc' would be placed before 'Abc/def'
+    var replace_from = RegExp(RegExp.escape(this.env.delimiter), 'g'),
+      replace_to = String.fromCharCode(0);
+    $.each(this.env.subscriptionrows, function(k,v) {
+      var n = v[0];
+      n = n.replace(replace_from, replace_to);
+      v.push(n);
+      folders.push(v);
+    });
+    folders.sort(function(a, b) {
+      var len = a.length - 1; n1 = a[len], n2 = b[len];
+      return n1 < n2 ? -1 : 1;
+    });
 
     for (n in folders) {
       // protected folder
@@ -6200,7 +6209,7 @@
     this.triggerEvent('message', { message:msg, type:type, timeout:timeout, object:obj });
 
     if (timeout > 0)
-      setTimeout(function() { ref.hide_message(id, type == 'loading'); }, timeout);
+      setTimeout(function() { ref.hide_message(id, type != 'loading'); }, timeout);
     return id;
   };
 
@@ -6834,7 +6843,6 @@
 
           if ((response.action == 'list' || response.action == 'search') && this.message_list) {
             this.msglist_select(this.message_list);
-            this.message_list.resize();
             this.triggerEvent('listupdate', { folder:this.env.mailbox, rowcount:this.message_list.rowcount });
           }
         }
@@ -6845,7 +6853,6 @@
             this.enable_command('search-create', this.env.source == '');
             this.enable_command('search-delete', this.env.search_id);
             this.update_group_commands();
-            this.contact_list.resize();
             this.triggerEvent('listupdate', { folder:this.env.source, rowcount:this.contact_list.rowcount });
           }
         }
@@ -7436,11 +7443,20 @@
     setCookie(name, value, expires, this.env.cookie_path, this.env.cookie_domain, this.env.cookie_secure);
   };
 
+  this.get_local_storage_prefix = function()
+  {
+    if (!this.local_storage_prefix)
+      this.local_storage_prefix = 'roundcube.' + (this.env.user_id || 'anonymous') + '.';
+
+    return this.local_storage_prefix;
+  };
+
   // wrapper for localStorage.getItem(key)
   this.local_storage_get_item = function(key, deflt, encrypted)
   {
+
     // TODO: add encryption
-    var item = localStorage.getItem(this.local_storage_prefix + key);
+    var item = localStorage.getItem(this.get_local_storage_prefix() + key);
     return item !== null ? JSON.parse(item) : (deflt || null);
   };
 
@@ -7448,13 +7464,13 @@
   this.local_storage_set_item = function(key, data, encrypted)
   {
     // TODO: add encryption
-    return localStorage.setItem(this.local_storage_prefix + key, JSON.stringify(data));
+    return localStorage.setItem(this.get_local_storage_prefix() + key, JSON.stringify(data));
   };
 
   // wrapper for localStorage.removeItem(key)
   this.local_storage_remove_item = function(key)
   {
-    return localStorage.removeItem(this.local_storage_prefix + key);
+    return localStorage.removeItem(this.get_local_storage_prefix() + key);
   };
 
 }  // end object rcube_webmail

--
Gitblit v1.9.1