Fix resetting search input events when the treelist is re-initialized, some CS improvements

pull/300/head
Aleksander Machniak 9 years ago
parent e524680a13
commit 1484d5fb7f

@ -110,37 +110,43 @@ function rcube_treelist_widget(node, p)
else else
update_data(); update_data();
// register click handlers on list container.attr('role', 'tree')
container.on('click', 'div.treetoggle', function(e){ .on('focusin', function(e) {
toggle(dom2id($(this).parent())); // TODO: only accept focus on virtual nodes from keyboard events
e.stopPropagation(); has_focus = true;
}); })
.on('focusout', function(e) {
container.on('click', 'li', function(e) { has_focus = false;
// do not select record on checkbox/input click })
if ($(e.target).is('input')) // register click handlers on list
return true; .on('click', 'div.treetoggle', function(e) {
toggle(dom2id($(this).parent()));
var node = p.selectable ? indexbyid[dom2id($(this))] : null;
if (node && !node.virtual) {
select(node.id);
e.stopPropagation();
}
});
// mute clicks on virtual folder links (they need tabindex="0" in order to be selectable by keyboard)
container.on('mousedown', 'a', function(e) {
var link = $(e.target), node = indexbyid[dom2id(link.closest('li'))];
if (node && node.virtual && !link.attr('href')) {
e.preventDefault();
e.stopPropagation(); e.stopPropagation();
return false; })
} .on('click', 'li', function(e) {
}); // do not select record on checkbox/input click
if ($(e.target).is('input'))
return true;
var node = p.selectable ? indexbyid[dom2id($(this))] : null;
if (node && !node.virtual) {
select(node.id);
e.stopPropagation();
}
})
// mute clicks on virtual folder links (they need tabindex="0" in order to be selectable by keyboard)
.on('mousedown', 'a', function(e) {
var link = $(e.target), node = indexbyid[dom2id(link.closest('li'))];
if (node && node.virtual && !link.attr('href')) {
e.preventDefault();
e.stopPropagation();
return false;
}
});
// activate search function // activate search function
if (p.searchbox) { if (p.searchbox) {
searchfield = $(p.searchbox).on('keyup', function(e) { searchfield = $(p.searchbox).off('keyup.treelist').on('keyup.treelist', function(e) {
var key = rcube_event.get_keycode(e), var key = rcube_event.get_keycode(e),
mod = rcube_event.get_modifier(e); mod = rcube_event.get_modifier(e);
@ -169,24 +175,13 @@ function rcube_treelist_widget(node, p)
}).attr('autocomplete', 'off'); }).attr('autocomplete', 'off');
// find the reset button for this search field // find the reset button for this search field
searchfield.parent().find('a.reset').click(function(e) { searchfield.parent().find('a.reset').off('click.treelist').on('click.treelist', function(e) {
reset_search(); reset_search();
return false; return false;
}) })
} }
container.on('focusin', function(e){ $(document.body).on('keydown', keypress);
// TODO: only accept focus on virtual nodes from keyboard events
has_focus = true;
})
.on('focusout', function(e){
has_focus = false;
});
container.attr('role', 'tree');
$(document.body)
.bind('keydown', keypress);
// catch focus when clicking the list container area // catch focus when clicking the list container area
if (p.parent_focus) { if (p.parent_focus) {

Loading…
Cancel
Save