From 9489adc5936fd516f3f6df91cfce3697b36e2cf1 Mon Sep 17 00:00:00 2001 From: thomascube <thomas@roundcube.net> Date: Tue, 02 Jun 2009 11:46:14 -0400 Subject: [PATCH] Fix list events used in drag&drop functionality (#1485890) --- program/js/list.js | 77 ++++++++++++++++++++++++++++++-------- 1 files changed, 61 insertions(+), 16 deletions(-) diff --git a/program/js/list.js b/program/js/list.js index dabcecb..aa34546 100644 --- a/program/js/list.js +++ b/program/js/list.js @@ -98,7 +98,7 @@ /** - * + * Init list row and set mouse events on it */ init_row: function(row) { @@ -123,7 +123,7 @@ /** - * + * Remove all list rows */ clear: function(sel) { @@ -154,20 +154,21 @@ /** - * + * Add row to the list and initialize it */ insert_row: function(row, attop) { - var tbody = this.list.tBodies[0]; - if (!row.jquery) - row = $(row); + if (this.background) + var tbody = this.background; + else + var tbody = this.list.tBodies[0]; if (attop && tbody.rows.length) - row.prependTo(tbody) + tbody.insertBefore(row, tbody.firstChild); else - row.appendTo(tbody); + tbody.appendChild(row); - this.init_row(row[0]); + this.init_row(row); this.rowcount++; }, @@ -514,10 +515,33 @@ } else if (this.rows[n]) { - this.set_classname(this.rows[n].obj, 'selected', false); - this.set_classname(this.rows[n].obj, 'unfocused', false); + $(this.rows[n].obj).removeClass('selected').removeClass('unfocused'); } } + + // trigger event if selection changed + if (this.selection.join(',') != select_before) + this.triggerEvent('select'); + + this.focus(); + + return true; +}, + + +/** + * Invert selection + */ +invert_selection: function() +{ + if (!this.rows || !this.rows.length) + return false; + + // remember old selection + var select_before = this.selection.join(','); + + for (var n in this.rows) + this.highlight_row(n, true); // trigger event if selection changed if (this.selection.join(',') != select_before) @@ -625,6 +649,7 @@ var keyCode = rcube_event.get_keycode(e); var mod_key = rcube_event.get_modifier(e); + switch (keyCode) { case 40: @@ -653,6 +678,9 @@ { switch (rcube_event.get_keycode(e)) { + case 27: + if (this.drag_active) + this.drag_mouse_up(e); case 40: case 38: case 63233: @@ -723,7 +751,7 @@ if (!this.draglayer) this.draglayer = $('<div>').attr('id', 'rcmdraglayer').css({ position:'absolute', display:'none', 'z-index':2000 }).appendTo(document.body); - + // get subjects of selectedd messages var names = ''; var c, i, node, subject, obj; @@ -747,9 +775,12 @@ if (((node = obj.childNodes[i].firstChild) && (node.nodeType==3 || node.nodeName=='A')) && (this.subject_col < 0 || (this.subject_col >= 0 && this.subject_col == c))) { - if (n == 0) - this.drag_start_pos = $(node).offset(); - + if (n == 0) { + if (node.nodeType == 3) + this.drag_start_pos = $(obj.childNodes[i]).offset(); + else + this.drag_start_pos = $(node).offset(); + } subject = node.nodeType==3 ? node.data : node.innerHTML; // remove leading spaces subject = subject.replace(/^\s+/i, ''); @@ -774,7 +805,7 @@ { var pos = rcube_event.get_mouse_pos(e); this.draglayer.css({ left:(pos.x+20)+'px', top:(pos.y-5 + (bw.ie ? document.documentElement.scrollTop : 0))+'px' }); - this.triggerEvent('dragmove', e); + this.triggerEvent('dragmove', e?e:window.event); } this.drag_start = false; @@ -828,6 +859,20 @@ } return rcube_event.cancel(e); +}, + + +/** + * Creating the list in background + */ +set_background_mode: function(flag) +{ + if (flag) { + this.background = document.createElement('TBODY'); + } else if (this.background) { + this.list.replaceChild(this.background, this.list.tBodies[0]); + this.background = null; + } } }; -- Gitblit v1.9.1