From da8f11ce163ffe3f88a359ae613aa144b16c73fc Mon Sep 17 00:00:00 2001 From: alecpl <alec@alec.pl> Date: Thu, 15 Apr 2010 07:28:15 -0400 Subject: [PATCH] - Fix messages list scrolling in FF3.6 (#1486472) - Fix quicksearch input focus (#1486637) - Small code cleanup + improvements --- program/js/list.js | 194 ++++++++++++++++++++++++++++++----------------- 1 files changed, 123 insertions(+), 71 deletions(-) diff --git a/program/js/list.js b/program/js/list.js index 3ab4b1a..3e7bc62 100644 --- a/program/js/list.js +++ b/program/js/list.js @@ -91,8 +91,8 @@ // set body events if (this.keyboard) { - rcube_event.add_listener({element:document, event:bw.opera?'keypress':'keydown', object:this, method:'key_press'}); - rcube_event.add_listener({element:document, event:'keydown', object:this, method:'key_down'}); + rcube_event.add_listener({event:bw.opera?'keypress':'keydown', object:this, method:'key_press'}); + rcube_event.add_listener({event:'keydown', object:this, method:'key_down'}); } } }, @@ -239,38 +239,19 @@ { this.drag_start = true; this.drag_mouse_start = rcube_event.get_mouse_pos(e); - rcube_event.add_listener({element:document, event:'mousemove', object:this, method:'drag_mouse_move'}); - rcube_event.add_listener({element:document, event:'mouseup', object:this, method:'drag_mouse_up'}); + rcube_event.add_listener({event:'mousemove', object:this, method:'drag_mouse_move'}); + rcube_event.add_listener({event:'mouseup', object:this, method:'drag_mouse_up'}); - // add listener for iframes - var iframes = document.getElementsByTagName('iframe'); - this.iframe_events = Object(); - for (var n in iframes) - { - var iframedoc = null; - if (iframes[n].contentDocument) - iframedoc = iframes[n].contentDocument; - else if (iframes[n].contentWindow) - iframedoc = iframes[n].contentWindow.document; - else if (iframes[n].document) - iframedoc = iframes[n].document; - - if (iframedoc) - { - var list = this; - var pos = $('#'+iframes[n].id).offset(); - this.iframe_events[n] = function(e) { e._offset = pos; return list.drag_mouse_move(e); } - - if (iframedoc.addEventListener) - iframedoc.addEventListener('mousemove', this.iframe_events[n], false); - else if (iframes[n].attachEvent) - iframedoc.attachEvent('onmousemove', this.iframe_events[n]); - else - iframedoc['onmousemove'] = this.iframe_events[n]; - - rcube_event.add_listener({element:iframedoc, event:'mouseup', object:this, method:'drag_mouse_up'}); - } - } + // enable dragging over iframes + $('iframe').each(function() { + $('<div class="iframe-dragdrop-fix"></div>') + .css({background: '#fff', + width: this.offsetWidth+'px', height: this.offsetHeight+'px', + position: 'absolute', opacity: '0.001', zIndex: 1000 + }) + .css($(this).offset()) + .appendTo('body'); + }); } return false; @@ -317,6 +298,20 @@ this.rows[id].clicked = now; return false; +}, + + +/* + * Returns thread root ID for specified row ID + */ +find_root: function(uid) +{ + var r = this.rows[uid]; + + if (r && r.parent_uid) + return this.find_root(r.parent_uid); + else + return uid; }, @@ -379,6 +374,7 @@ row.expanded = true; depth = row.depth; new_row = row.obj.nextSibling; + this.update_expando(row.uid, true); this.triggerEvent('expandcollapse', { uid:row.uid, expanded:row.expanded }); } else { @@ -427,6 +423,7 @@ row.expanded = false; depth = row.depth; new_row = row.obj.nextSibling; + this.update_expando(row.uid); this.triggerEvent('expandcollapse', { uid:row.uid, expanded:row.expanded }); // don't collapse sub-root tree in multiexpand mode @@ -450,9 +447,7 @@ $(new_row).hide(); if (r.has_children) { r.expanded = false; - var expando = document.getElementById('rcmexpando' + r.uid); - if (expando) - expando.className = 'collapsed'; + this.update_expando(r.uid); this.triggerEvent('expandcollapse', { uid:r.uid, expanded:r.expanded }); } } @@ -472,6 +467,7 @@ row.expanded = true; depth = row.depth; new_row = row.obj.nextSibling; + this.update_expando(row.uid, true); this.triggerEvent('expandcollapse', { uid:row.uid, expanded:row.expanded }); } else { @@ -490,9 +486,7 @@ $(new_row).show(); if (r.has_children) { r.expanded = true; - var expando = document.getElementById('rcmexpando' + r.uid); - if (expando) - expando.className = 'expanded'; + this.update_expando(r.uid, true); this.triggerEvent('expandcollapse', { uid:r.uid, expanded:r.expanded }); } } @@ -501,6 +495,14 @@ } return false; }, + +update_expando: function(uid, expanded) +{ + var expando = document.getElementById('rcmexpando' + uid); + if (expando) + expando.className = expanded ? 'expanded' : 'collapsed'; +}, + /** * get first/next/previous/last rows that are not hidden @@ -648,14 +650,60 @@ this.select_row(new_row.uid, false, false); }, + /** * Select first row */ -select_first: function() +select_first: function(mod_key) { - var first_row = this.get_first_row(); - if (first_row) - this.select_row(first_row, false, false); + var row = this.get_first_row(); + if (row && mod_key) { + this.shift_select(row, mod_key); + this.triggerEvent('select'); + this.scrollto(row); + } + else if (row) + this.select(row); +}, + + +/** + * Select last row + */ +select_last: function(mod_key) +{ + var row = this.get_last_row(); + if (row && mod_key) { + this.shift_select(row, mod_key); + this.triggerEvent('select'); + this.scrollto(row); + } + else if (row) + this.select(row); +}, + + +/** + * Add all childs of the given row to selection + */ +select_childs: function(uid) +{ + if (!this.rows[uid] || !this.rows[uid].has_children) + return; + + var depth = this.rows[uid].depth; + var row = this.rows[uid].obj.nextSibling; + while (row) { + if (row.nodeType == 1) { + if ((r = this.rows[row.uid])) { + if (!r.depth || r.depth <= depth) + break; + if (!this.in_selection(r.uid)) + this.select_row(r.uid, CONTROL_KEY); + } + } + row = row.nextSibling; + } }, @@ -840,7 +888,7 @@ } else // unselect row { - var p = find_in_array(id, this.selection); + var p = jQuery.inArray(id, this.selection); var a_pre = this.selection.slice(0, p); var a_post = this.selection.slice(p+1, this.selection.length); this.selection = a_pre.concat(a_post); @@ -880,6 +928,12 @@ this.key_pressed = keyCode; this.triggerEvent('keypress'); 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); default: this.shiftkey = e.shiftKey; this.key_pressed = keyCode; @@ -984,6 +1038,13 @@ { var scroll_to = Number(row.offsetTop); + // expand thread if target row is hidden (collapsed) + if (!scroll_to && this.rows[id].parent_uid) { + var parent = this.find_root(this.rows[id].uid); + this.expand_all(this.rows[parent]); + scroll_to = Number(row.offsetTop); + } + if (scroll_to < Number(this.frame.scrollTop)) this.frame.scrollTop = scroll_to; else if (scroll_to + Number(row.offsetHeight) > Number(this.frame.scrollTop) + Number(this.frame.offsetHeight)) @@ -1007,6 +1068,15 @@ if (!this.draglayer) this.draglayer = $('<div>').attr('id', 'rcmdraglayer').css({ position:'absolute', display:'none', 'z-index':2000 }).appendTo(document.body); + + // also select childs of (collapsed) threads for dragging + var selection = $.merge([], this.selection); + var depth, row, uid, r; + for (var n=0; n < selection.length; n++) { + uid = selection[n]; + if (this.rows[uid].has_children && !this.rows[uid].expanded) + this.select_childs(uid); + } // get subjects of selected messages var names = ''; @@ -1089,35 +1159,17 @@ this.draglayer.hide(); } + if (this.drag_active) + this.focus(); this.drag_active = false; + + rcube_event.remove_listener({event:'mousemove', object:this, method:'drag_mouse_move'}); + rcube_event.remove_listener({event:'mouseup', object:this, method:'drag_mouse_up'}); + + // remove temp divs + $('div.iframe-dragdrop-fix').each(function() { this.parentNode.removeChild(this); }); + this.triggerEvent('dragend'); - - rcube_event.remove_listener({element:document, event:'mousemove', object:this, method:'drag_mouse_move'}); - rcube_event.remove_listener({element:document, event:'mouseup', object:this, method:'drag_mouse_up'}); - - var iframes = document.getElementsByTagName('iframe'); - for (var n in iframes) { - var iframedoc; - - if (iframes[n].contentDocument) - iframedoc = iframes[n].contentDocument; - else if (iframes[n].contentWindow) - iframedoc = iframes[n].contentWindow.document; - else if (iframes[n].document) - iframedoc = iframes[n].document; - - if (iframedoc) { - if (this.iframe_events[n]) { - if (iframedoc.removeEventListener) - iframedoc.removeEventListener('mousemove', this.iframe_events[n], false); - else if (iframedoc.detachEvent) - iframedoc.detachEvent('onmousemove', this.iframe_events[n]); - else - iframedoc['onmousemove'] = null; - } - rcube_event.remove_listener({element:iframedoc, event:'mouseup', object:this, method:'drag_mouse_up'}); - } - } return rcube_event.cancel(e); }, -- Gitblit v1.9.1