Aleksander Machniak
2016-02-12 d686b57c72c574bca7349a7ddfe0425f50a0122a
program/js/treelist.js
@@ -110,37 +110,43 @@
  else
    update_data();
  // register click handlers on list
  container.on('click', 'div.treetoggle', function(e){
    toggle(dom2id($(this).parent()));
    e.stopPropagation();
  });
  container.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);
  container.attr('role', 'tree')
    .on('focusin', function(e) {
      // TODO: only accept focus on virtual nodes from keyboard events
      has_focus = true;
    })
    .on('focusout', function(e) {
      has_focus = false;
    })
    // register click handlers on list
    .on('click', 'div.treetoggle', function(e) {
      toggle(dom2id($(this).parent()));
      e.stopPropagation();
    }
  });
    })
    .on('click', 'li', function(e) {
      // do not select record on checkbox/input click
      if ($(e.target).is('input'))
        return true;
  // 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();
      return false;
    }
  });
      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
  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),
        mod = rcube_event.get_modifier(e);
@@ -169,24 +175,13 @@
    }).attr('autocomplete', 'off');
    // 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();
      return false;
    })
  }
  container.on('focusin', function(e){
      // 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);
  $(document.body).on('keydown', keypress);
  // catch focus when clicking the list container area
  if (p.parent_focus) {
@@ -248,6 +243,11 @@
   */
  function select(id)
  {
    // allow subscribes to prevent selection change
    if (me.triggerEvent('beforeselect', indexbyid[id]) === false) {
      return;
    }
    if (selection) {
      id2dom(selection, true).removeClass('selected').removeAttr('aria-selected');
      if (search_active)
@@ -329,7 +329,7 @@
      // re-render the entire subtree
      if (parent_node.children.length == 1) {
        render_node(parent_node, parent_li.parent(), parent_li);
        render_node(parent_node, null, parent_li);
        li = id2dom(node.id);
      }
      else {
@@ -360,6 +360,12 @@
    }
    indexbyid[node.id] = node;
    // set new reference to node.html after insert
    // will otherwise vanish in Firefox 3.6
    if (typeof node.html == 'object') {
        indexbyid[node.id].html = id2dom(node.id, true).children();
    }
    if (sort) {
      resort_node(li, typeof sort == 'string' ? '[class~="' + sort + '"]' : '');
@@ -457,6 +463,10 @@
      node.deleted = true;
      delete indexbyid[id];
      if (search_active) {
        id2dom(id, false).remove();
      }
      return true;
    }
@@ -568,9 +578,10 @@
    // search recursively in tree (to keep sorting order)
    search_tree(data);
    search_active = true;
    last_search = q;
    me.triggerEvent('search', { query: q, last: last_search, count: hits.length, ids: hits, execute: enter||false });
    last_search = q;
    return hits.count;
  }
@@ -907,9 +918,9 @@
   * When dragging starts, compute absolute bounding boxes of the list and it's items
   * for faster comparisons while mouse is moving
   */
  function drag_start()
  function drag_start(force)
  {
    if (drag_active)
    if (!force && drag_active)
      return;
    drag_active = true;
@@ -932,7 +943,7 @@
    for (var id in indexbyid) {
      li = id2dom(id);
      item = li.children().first().get(0);
      if (height = item.offsetHeight) {
      if (item && (height = item.offsetHeight)) {
        pos = $(item).offset();
        pos.top += list_scroll_top;
        item_coords[id] = {
@@ -1050,7 +1061,7 @@
          autoexpand_item = id;
          autoexpand_timer = setTimeout(function() {
            expand(autoexpand_item);
            drag_start();  // re-calculate item coords
            drag_start(true);  // re-calculate item coords
            autoexpand_item = null;
            if (ui_droppable)
              $.ui.ddmanager.prepareOffsets($.ui.ddmanager.current, null);