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/list.js |   52 ++++++++++++++++++++++++++++++++++++++++------------
 1 files changed, 40 insertions(+), 12 deletions(-)

diff --git a/program/js/list.js b/program/js/list.js
index b2d4f8a..f33be87 100644
--- a/program/js/list.js
+++ b/program/js/list.js
@@ -91,8 +91,7 @@
     var r, len, rows = this.tbody.childNodes;
 
     for (r=0, len=rows.length; r<len; r++) {
-      this.init_row(rows[r]);
-      this.rowcount++;
+      this.rowcount += this.init_row(rows[r]) ? 1 : 0;
     }
 
     this.init_header();
@@ -148,6 +147,8 @@
 
     this.row_init(this.rows[uid]);  // legacy support
     this.triggerEvent('initrow', this.rows[uid]);
+
+    return true;
   }
 },
 
@@ -248,6 +249,9 @@
   // reset scroll position (in Opera)
   if (this.frame)
     this.frame.scrollTop = 0;
+
+  // fix list header after removing any rows
+  this.resize();
 },
 
 
@@ -256,7 +260,7 @@
  */
 remove_row: function(uid, sel_next)
 {
-  var node = this.rows[uid] ? this.rows[uid].obj : null;
+  var self = this, node = this.rows[uid] ? this.rows[uid].obj : null;
 
   if (!node)
     return;
@@ -268,6 +272,10 @@
 
   delete this.rows[uid];
   this.rowcount--;
+
+  // fix list header after removing any rows
+  clearTimeout(this.resize_timeout)
+  this.resize_timeout = setTimeout(function() { self.resize(); }, 50);
 },
 
 
@@ -276,7 +284,7 @@
  */
 insert_row: function(row, before)
 {
-  var tbody = this.tbody;
+  var self = this, tbody = this.tbody;
 
   // create a real dom node first
   if (row.nodeName === undefined) {
@@ -304,6 +312,10 @@
 
   this.init_row(row);
   this.rowcount++;
+
+  // fix list header after adding any rows
+  clearTimeout(this.resize_timeout)
+  this.resize_timeout = setTimeout(function() { self.resize(); }, 50);
 },
 
 /**
@@ -412,15 +424,18 @@
   if (rcube_event.get_button(e) == 2)
     return true;
 
+  this.in_selection_before = e && e.istouch || this.in_selection(id) ? id : false;
+
   // selects currently unselected row
-  if (!(e && e.istouch || this.in_selection(id))) {
+  if (!this.in_selection_before) {
     var mod_key = rcube_event.get_modifier(e);
-    this.select_row(id, mod_key, false);
+    this.select_row(id, mod_key, true);
   }
 
   if (this.draggable && this.selection.length && this.in_selection(id)) {
     this.drag_start = true;
     this.drag_mouse_start = rcube_event.get_mouse_pos(e);
+
     rcube_event.add_listener({event:'mousemove', object:this, method:'drag_mouse_move'});
     rcube_event.add_listener({event:'mouseup', object:this, method:'drag_mouse_up'});
     if (bw.touch) {
@@ -448,11 +463,12 @@
   var now = new Date().getTime(),
     dblclicked = now - this.rows[id].clicked < this.dblclick_time;
 
-  // selects (or unselects currently selected) row
-  if (!this.drag_active && !dblclicked)
+  // unselects currently selected row
+  if (!this.drag_active && !dblclicked && this.in_selection_before == id)
     this.select_row(id, rcube_event.get_modifier(e), true);
 
   this.drag_start = false;
+  this.in_selection_before = false;
 
   // row was double clicked
   if (this.rowcount && dblclicked && this.in_selection(id)) {
@@ -772,6 +788,7 @@
 select_row: function(id, mod_key, with_mouse)
 {
   var select_before = this.selection.join(',');
+
   if (!this.multiselect)
     mod_key = 0;
 
@@ -790,8 +807,10 @@
         break;
 
       case CONTROL_KEY:
-        if (with_mouse)
+        if (with_mouse) {
+          this.shift_start = id;
           this.highlight_row(id, true);
+        }
         break;
 
       case CONTROL_SHIFT_KEY:
@@ -802,6 +821,7 @@
         this.highlight_row(id, false);
         break;
     }
+
     this.multi_selecting = true;
   }
 
@@ -887,7 +907,7 @@
 
   for (i=0; i<len; i++)
     if (!this.in_selection(children[i]))
-      this.select_row(children[i], CONTROL_KEY);
+      this.select_row(children[i], CONTROL_KEY, true);
 },
 
 
@@ -1127,13 +1147,15 @@
       // Stop propagation so that the browser doesn't scroll
       rcube_event.cancel(e);
       return this.use_arrow_key(keyCode, mod_key);
+
     case 32:
       rcube_event.cancel(e);
       return this.select_row(this.last_selected, mod_key, true);
+
     case 37: // Left arrow key
     case 39: // Right arrow key
     case 107: // Plus sign on a numeric keypad
-    case 109: // Minus sign on a numeric keypad      
+    case 109: // Minus sign on a numeric keypad
       // Stop propagation
       rcube_event.cancel(e);
       var ret = this.use_plusminus_key(keyCode, mod_key);
@@ -1142,20 +1164,26 @@
       this.triggerEvent('keypress');
       this.modkey = 0;
       return ret;
+
     case 36: // Home
       this.select_first(mod_key);
       return rcube_event.cancel(e);
+
     case 35: // End
       this.select_last(mod_key);
       return rcube_event.cancel(e);
+
     case 27:
       if (this.drag_active)
         return this.drag_mouse_up(e);
+
       if (this.col_drag_active) {
         this.selected_column = null;
         return this.column_drag_mouse_up(e);
       }
+
       return rcube_event.cancel(e);
+
     default:
       this.key_pressed = keyCode;
       this.modkey = mod_key;
@@ -1548,7 +1576,7 @@
  */
 del_dragfix: function()
 {
-  $('div.iframe-dragdrop-fix').each(function() { this.parentNode.removeChild(this); });
+  $('div.iframe-dragdrop-fix').remove();
 },
 
 

--
Gitblit v1.9.1