From 075574c81f6d8c1db3c2f2dba1a3f084fcb810d8 Mon Sep 17 00:00:00 2001
From: Aleksander Machniak <alec@alec.pl>
Date: Mon, 14 Oct 2013 06:11:09 -0400
Subject: [PATCH] Use onclick even for status, flag and expando actions to fix issue where mouse right click would invoke action where it shouldn't

---
 program/js/list.js |   50 +++++++++++++++++++++++++++++---------------------
 1 files changed, 29 insertions(+), 21 deletions(-)

diff --git a/program/js/list.js b/program/js/list.js
index e8f7210..f05ac1a 100644
--- a/program/js/list.js
+++ b/program/js/list.js
@@ -35,7 +35,7 @@
   this.tbody;
   this.fixed_header;
   this.frame = null;
-  this.rows = [];
+  this.rows = {};
   this.selection = [];
   this.rowcount = 0;
   this.colcount = 0;
@@ -86,7 +86,7 @@
   }
 
   if (this.tbody) {
-    this.rows = [];
+    this.rows = {};
     this.rowcount = 0;
 
     var r, len, rows = this.tbody.childNodes;
@@ -122,17 +122,25 @@
     row.onmousedown = function(e){ return self.drag_row(e, this.uid); };
     row.onmouseup = function(e){ return self.click_row(e, this.uid); };
 
-    if (bw.mobile) {
+    if (bw.touch) {
       row.addEventListener('touchstart', function(e) {
         if (e.touches.length == 1) {
-          if (!self.drag_row(rcube_event.touchevent(e.touches[0]), this.uid))
-            e.preventDefault();
+          self.touchmoved = false;
+          self.drag_row(rcube_event.touchevent(e.touches[0]), this.uid)
         }
       }, false);
       row.addEventListener('touchend', function(e) {
-        if (e.changedTouches.length == 1)
-          if (!self.click_row(rcube_event.touchevent(e.changedTouches[0]), this.uid))
+        if (e.changedTouches.length == 1) {
+          if (!self.touchmoved && !self.click_row(rcube_event.touchevent(e.changedTouches[0]), this.uid))
             e.preventDefault();
+        }
+      }, false);
+      row.addEventListener('touchmove', function(e) {
+        if (e.changedTouches.length == 1) {
+          self.touchmoved = true;
+          if (self.drag_active)
+            e.preventDefault();
+        }
       }, false);
     }
 
@@ -157,7 +165,7 @@
       $(this.list.tHead).replaceWith($(this.fixed_header).find('thead').clone());
       $(this.list.tHead).find('tr td').attr('style', '');  // remove fixed widths
     }
-    else if (!bw.ie7 && this.list.className.indexOf('fixedheader') >= 0) {
+    else if (!bw.touch && this.list.className.indexOf('fixedheader') >= 0) {
       this.init_fixed_header();
     }
 
@@ -181,7 +189,7 @@
 
   if (!this.fixed_header) {
     this.fixed_header = $('<table>')
-      .attr('class', this.list.className)
+      .attr('class', this.list.className + ' fixedcopy')
       .css({ position:'fixed' })
       .append(clone)
       .append('<tbody></tbody>');
@@ -232,7 +240,7 @@
     $(this.row_tagname() + ':not(.thead)', this.tbody).remove();
   }
 
-  this.rows = [];
+  this.rows = {};
   this.rowcount = 0;
 
   if (sel)
@@ -401,14 +409,14 @@
   var evtarget = rcube_event.get_target(e),
     tagname = evtarget.tagName.toLowerCase();
 
-  if (this.dont_select || (evtarget && (tagname == 'input' || tagname == 'img')))
+  if (this.dont_select || (evtarget && (tagname == 'input' || tagname == 'img' || evtarget.onclick)))
     return true;
 
   // accept right-clicks
   if (rcube_event.get_button(e) == 2)
     return true;
 
-  this.in_selection_before = this.in_selection(id) ? id : false;
+  this.in_selection_before = e && e.istouch || this.in_selection(id) ? id : false;
 
   // selects currently unselected row
   if (!this.in_selection_before) {
@@ -416,12 +424,12 @@
     this.select_row(id, mod_key, false);
   }
 
-  if (this.draggable && this.selection.length) {
+  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.mobile) {
+    if (bw.touch) {
       rcube_event.add_listener({event:'touchmove', object:this, method:'drag_mouse_move'});
       rcube_event.add_listener({event:'touchend', object:this, method:'drag_mouse_up'});
     }
@@ -463,7 +471,7 @@
   this.in_selection_before = false;
 
   // row was double clicked
-  if (this.rows && dblclicked && this.in_selection(id)) {
+  if (this.rowcount && dblclicked && this.in_selection(id)) {
     this.triggerEvent('dblclick');
     now = 0;
   }
@@ -695,7 +703,7 @@
  */
 get_next_row: function()
 {
-  if (!this.rows)
+  if (!this.rowcount)
     return false;
 
   var last_selected_row = this.rows[this.last_selected],
@@ -709,7 +717,7 @@
 
 get_prev_row: function()
 {
-  if (!this.rows)
+  if (!this.rowcount)
     return false;
 
   var last_selected_row = this.rows[this.last_selected],
@@ -961,7 +969,7 @@
  */
 select_all: function(filter)
 {
-  if (!this.rows || !this.rows.length)
+  if (!this.rowcount)
     return false;
 
   // reset but remember selection first
@@ -993,7 +1001,7 @@
  */
 invert_selection: function()
 {
-  if (!this.rows || !this.rows.length)
+  if (!this.rowcount)
     return false;
 
   // remember old selection
@@ -1256,7 +1264,7 @@
 {
   // convert touch event
   if (e.type == 'touchmove') {
-    if (e.changedTouches.length == 1)
+    if (e.touches.length == 1 && e.changedTouches.length == 1)
       e = rcube_event.touchevent(e.changedTouches[0]);
     else
       return rcube_event.cancel(e);
@@ -1362,7 +1370,7 @@
   rcube_event.remove_listener({event:'mousemove', object:this, method:'drag_mouse_move'});
   rcube_event.remove_listener({event:'mouseup', object:this, method:'drag_mouse_up'});
 
-  if (bw.mobile) {
+  if (bw.touch) {
     rcube_event.remove_listener({event:'touchmove', object:this, method:'drag_mouse_move'});
     rcube_event.remove_listener({event:'touchend', object:this, method:'drag_mouse_up'});
   }

--
Gitblit v1.9.1