Add method to make a treelist widget become a jQuery UI droppable with support for auto-scrolling and auto-expanding

pull/193/head^2
Thomas Bruederli 10 years ago
parent 809f9d11bd
commit 586ed69aa8

@ -64,6 +64,7 @@ function rcube_treelist_widget(node, p)
scroll_timer, scroll_timer,
searchfield, searchfield,
tree_state, tree_state,
ui_droppable,
list_id = (container.attr('id') || p.id_prefix || '0'), list_id = (container.attr('id') || p.id_prefix || '0'),
me = this; me = this;
@ -79,6 +80,7 @@ function rcube_treelist_widget(node, p)
this.drag_start = drag_start; this.drag_start = drag_start;
this.drag_end = drag_end; this.drag_end = drag_end;
this.intersects = intersects; this.intersects = intersects;
this.droppable = droppable;
this.update = update_node; this.update = update_node;
this.insert = insert; this.insert = insert;
this.remove = remove; this.remove = remove;
@ -521,7 +523,8 @@ function rcube_treelist_widget(node, p)
var li = $('<li>') var li = $('<li>')
.attr('id', p.id_prefix + (p.id_encode ? p.id_encode(node.id) : node.id)) .attr('id', p.id_prefix + (p.id_encode ? p.id_encode(node.id) : node.id))
.addClass((node.classes || []).join(' ')); .addClass((node.classes || []).join(' '))
.data('id', node.id);
if (replace) if (replace)
replace.replaceWith(li); replace.replaceWith(li);
@ -594,6 +597,7 @@ function rcube_treelist_widget(node, p)
selection = node.id; selection = node.id;
} }
li.data('id', node.id);
result.push(node); result.push(node);
indexbyid[node.id] = node; indexbyid[node.id] = node;
}) })
@ -802,7 +806,8 @@ function rcube_treelist_widget(node, p)
// no intersection with list bounding box // no intersection with list bounding box
if (mouse.x < box_coords.x1 || mouse.x >= box_coords.x2 || mouse.top < box_coords.y1 || mouse.top >= box_coords.y2) { if (mouse.x < box_coords.x1 || mouse.x >= box_coords.x2 || mouse.top < box_coords.y1 || mouse.top >= box_coords.y2) {
// TODO: optimize performance for this operation // TODO: optimize performance for this operation
$('li.droptarget', container).removeClass('droptarget'); if (highlight)
$('li.droptarget', container).removeClass('droptarget');
return result; return result;
} }
@ -823,6 +828,8 @@ function rcube_treelist_widget(node, p)
expand(autoexpand_item); expand(autoexpand_item);
drag_start(); // re-calculate item coords drag_start(); // re-calculate item coords
autoexpand_item = null; autoexpand_item = null;
if (ui_droppable)
$.ui.ddmanager.prepareOffsets($.ui.ddmanager.current, null);
}, p.autoexpand); }, p.autoexpand);
} }
else if (autoexpand_timer && autoexpand_item != id) { else if (autoexpand_timer && autoexpand_item != id) {
@ -851,6 +858,38 @@ function rcube_treelist_widget(node, p)
return result; return result;
} }
/**
* Wrapper for jQuery.UI.droppable() activation on this widget
*
* @param object Options as passed to regular .droppable() function
*/
function droppable(opts)
{
var my_opts = $.extend({ greedy: true, hoverClass: 'droptarget', addClasses:false }, opts);
my_opts.activate = function(e, ui) {
drag_start();
ui_droppable = ui;
if (opts.activate)
opts.activate(e, ui);
};
my_opts.deactivate = function(e, ui) {
drag_end();
ui_droppable = null;
if (opts.deactivate)
opts.deactivate(e, ui);
};
my_opts.over = function(e, ui) {
intersects(rcube_event.get_mouse_pos(e), false);
if (opts.over)
opts.over(e, ui);
};
$('li:not(.virtual)', container).droppable(my_opts);
}
} }
// use event processing functions from Roundcube's rcube_event_engine // use event processing functions from Roundcube's rcube_event_engine

Loading…
Cancel
Save