You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

list.min.js 26KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /**
  2. * Roundcube List Widget
  3. *
  4. * This file is part of the Roundcube Webmail client
  5. *
  6. * @licstart The following is the entire license notice for the
  7. * JavaScript code in this file.
  8. *
  9. * Copyright (c) 2005-2014, The Roundcube Dev Team
  10. *
  11. * The JavaScript code in this page is free software: you can
  12. * redistribute it and/or modify it under the terms of the GNU
  13. * General Public License (GNU GPL) as published by the Free Software
  14. * Foundation, either version 3 of the License, or (at your option)
  15. * any later version. The code is distributed WITHOUT ANY WARRANTY;
  16. * without even the implied warranty of MERCHANTABILITY or FITNESS
  17. * FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
  18. *
  19. * As additional permission under GNU GPL version 3 section 7, you
  20. * may distribute non-source (e.g., minimized or compacted) forms of
  21. * that code without the copy of the GNU GPL normally required by
  22. * section 4, provided you include this license notice and a URL
  23. * through which recipients can access the Corresponding Source.
  24. *
  25. * @licend The above is the entire license notice
  26. * for the JavaScript code in this file.
  27. *
  28. * @author Thomas Bruederli <roundcube@gmail.com>
  29. * @author Charles McNulty <charles@charlesmcnulty.com>
  30. *
  31. * @requires jquery.js, common.js
  32. */
  33. function rcube_list_widget(a,b){this.ENTER_KEY=13;this.DELETE_KEY=46;this.BACKSPACE_KEY=8;this.tagname=(this.list=a?a:null)?this.list.nodeName.toLowerCase():"table";this.id_regexp=/^rcmrow([a-z0-9\-_=\+\/]+)/i;this.rows={};this.selection=[];this.modkey=this.subject_col=this.colcount=this.rowcount=0;this.aria_listbox=this.toggleselect=this.keyboard=this.column_movable=this.draggable=this.multi_selecting=this.multiexpand=this.multiselect=!1;this.parent_focus=!0;this.col_drag_active=this.drag_active=
  34. !1;this.shift_start=this.last_selected=this.column_fixed=null;this.focused=!1;this.drag_mouse_start=null;this.dblclick_time=500;this.row_init=function(){};if(b&&"object"===typeof b)for(var c in b)this[c]=b[c];rcube_list_widget._instances.push(this)}
  35. rcube_list_widget.prototype={init:function(){"table"==this.tagname&&this.list&&this.list.tBodies[0]?(this.thead=this.list.tHead,this.tbody=this.list.tBodies[0]):"table"!=this.tagname&&this.list&&(this.tbody=this.list);"listbox"==$(this.list).attr("role")&&(this.aria_listbox=!0,this.multiselect&&$(this.list).attr("aria-multiselectable","true"));var a=this;if(this.tbody){this.rows={};this.rowcount=0;var b,c,d=this.tbody.childNodes;b=0;for(c=d.length;b<c;b++)1==d[b].nodeType&&(this.rowcount+=this.init_row(d[b])?
  36. 1:0);this.init_header();this.frame=this.list.parentNode;this.keyboard&&(rcube_event.add_listener({event:"keydown",object:this,method:"key_press"}),$(this.list).attr("tabindex","0").on("focus",function(b){a.focus(b)}))}this.parent_focus&&(this.list.parentNode.onclick=function(b){a.focus()});return this},init_row:function(a){a.uid=this.get_row_uid(a);if(a&&a.uid){var b=this,c=a.uid;this.rows[c]={uid:c,id:a.id,obj:a};$(a).data("uid",c).mousedown(function(a){return b.drag_row(a,this.uid)}).mouseup(function(a){return 1!=
  37. a.which||b.drag_active?!0:b.click_row(a,this.uid)});bw.touch&&a.addEventListener&&(a.addEventListener("touchstart",function(a){1==a.touches.length&&(b.touchmoved=!1,b.drag_row(rcube_event.touchevent(a.touches[0]),this.uid))},!1),a.addEventListener("touchend",function(a){1==a.changedTouches.length&&(b.touchmoved||b.click_row(rcube_event.touchevent(a.changedTouches[0]),this.uid)||a.preventDefault())},!1),a.addEventListener("touchmove",function(a){1==a.changedTouches.length&&(b.touchmoved=!0,b.drag_active&&
  38. a.preventDefault())},!1));if(this.aria_listbox){var d="l:"+a.id;$(a).attr("role","option").attr("aria-labelledby",d).find(this.col_tagname()).eq(this.subject_col).attr("id",d)}document.all&&(a.onselectstart=function(){return!1});this.row_init(this.rows[c]);this.triggerEvent("initrow",this.rows[c]);return!0}},init_header:function(){if(this.thead){this.colcount=0;this.fixed_header?($(this.list.tHead).replaceWith($(this.fixed_header).find("thead").clone()),$(this.list.tHead).find("th,td").attr("style",
  39. "").find("a").attr("tabindex","-1")):!bw.touch&&0<=this.list.className.indexOf("fixedheader")&&this.init_fixed_header();var a,b,c=this;if(this.column_movable&&this.thead&&this.thead.rows)for(b=0;b<this.thead.rows[0].cells.length;b++)this.column_fixed!=b&&(a=this.thead.rows[0].cells[b],a.onmousedown=function(a){return c.drag_column(a,this)},this.colcount++)}},init_fixed_header:function(){var a=$(this.list.tHead).clone();if(this.fixed_header)$(this.fixed_header).find("thead").replaceWith(a);else{this.fixed_header=
  40. $("<table>").attr("class",this.list.className+" fixedcopy").attr("role","presentation").css({position:"fixed"}).append(a).append("<tbody></tbody>");$(this.list).before(this.fixed_header);var b=this;$(window).resize(function(){b.resize()});$(window).scroll(function(){var a=$(window);b.fixed_header.css({marginLeft:-a.scrollLeft()+"px",marginTop:-a.scrollTop()+"px"})})}$(this.list.tHead).find("a.sortcol").attr("tabindex","-1");a.find("a.sortcol").attr("tabindex","0");this.thead=a.get(0);this.resize()},
  41. resize:function(){if(this.fixed_header){var a=[];$(this.tbody).parent().find("thead th,thead td").each(function(b){a[b]=$(this).width()});$(this.thead).parent().width($(this.tbody).parent().width());$(this.thead).find("th,td").each(function(b){$(this).width(a[b])});$(window).scroll()}},clear:function(a){if("table"==this.tagname){var b=document.createElement("tbody");this.list.insertBefore(b,this.tbody);this.list.removeChild(this.list.tBodies[1]);this.tbody=b}else $(this.row_tagname()+":not(.thead)",
  42. this.tbody).remove();this.rows={};this.rowcount=0;this.last_selected=null;a&&this.clear_selection();this.frame&&(this.frame.scrollTop=0);this.resize()},remove_row:function(a,b){var c=this,d=this.rows[a]?this.rows[a].obj:null;d&&(d.style.display="none",b&&this.select_next(),delete this.rows[a],this.rowcount--,clearTimeout(this.resize_timeout),this.resize_timeout=setTimeout(function(){c.resize()},50))},insert_row:function(a,b){var c=this,d=this.tbody;if(void 0===a.nodeName){var e=document.createElement(this.row_tagname());
  43. a.id&&(e.id=a.id);a.uid&&(e.uid=a.uid);a.className&&(e.className=a.className);a.style&&$.extend(e.style,a.style);for(var f,g,h,k=0;a.cols&&k<a.cols.length;k++){h=a.cols[k];g=document.createElement(this.col_tagname());h.className&&(g.className=h.className);h.innerHTML&&(g.innerHTML=h.innerHTML);for(f in h.events)g["on"+f]=h.events[f];e.appendChild(g)}a=e}b&&d.childNodes.length?d.insertBefore(a,"object"==typeof b&&b.parentNode==d?b:d.firstChild):d.appendChild(a);this.init_row(a);this.rowcount++;clearTimeout(this.resize_timeout);
  44. this.resize_timeout=setTimeout(function(){c.resize()},50)},update_row:function(a,b,c,d){var e=this.rows[a];if(!e)return!1;for(var f=e.obj,e=0;b&&e<b.length;e++)this.get_cell(f,e).html(b[e]);c&&(delete this.rows[a],f.uid=c,f.id="rcmrow"+c,this.init_row(f),d&&(this.selection[0]=c),this.last_selected==a&&(this.last_selected=c))},focus:function(a){this.focused||(this.focused=!0,a&&rcube_event.cancel(a),a=null,this.last_selected&&this.rows[this.last_selected]&&(a=$(this.rows[this.last_selected].obj).find(this.col_tagname()).eq(this.subject_col).attr("tabindex",
  45. "0")),a&&a.length?this.focus_noscroll(a):($("iframe,:focus:not(body)").blur(),window.focus()),$(this.list).addClass("focus").removeAttr("tabindex"),this.last_selected||this.select_first(CONTROL_KEY))},blur:function(a){this.focused=!1;var b=this;setTimeout(function(){$(b.list).removeClass("focus").attr("tabindex","0")},20);this.last_selected&&this.rows[this.last_selected]&&$(this.rows[this.last_selected].obj).find(this.col_tagname()).eq(this.subject_col).removeAttr("tabindex")},focus_noscroll:function(a){var b=
  46. this.frame.scrollTop||this.frame.scrollY;a.focus();this.frame.scrollTop=b},hide_column:function(a,b){var c=b?"addClass":"removeClass";if(this.fixed_header)$(this.row_tagname()+" "+this.col_tagname()+"."+a,this.fixed_header)[c]("hidden");$(this.row_tagname()+" "+this.col_tagname()+"."+a,this.list)[c]("hidden")},drag_column:function(a,b){if(1<this.colcount){this.drag_start=!0;this.drag_mouse_start=rcube_event.get_mouse_pos(a);rcube_event.add_listener({event:"mousemove",object:this,method:"column_drag_mouse_move"});
  47. rcube_event.add_listener({event:"mouseup",object:this,method:"column_drag_mouse_up"});this.add_dragfix();for(var c=0;c<this.thead.rows[0].cells.length;c++)if(b==this.thead.rows[0].cells[c]){this.selected_column=c;break}}return!1},drag_row:function(a,b){if(!this.is_event_target(a)||2==rcube_event.get_button(a))return!0;this.in_selection_before=a&&a.istouch||this.in_selection(b)?b:!1;if(!this.in_selection_before){var c=rcube_event.get_modifier(a);this.select_row(b,c,!0)}this.draggable&&this.selection.length&&
  48. this.in_selection(b)&&(this.drag_start=!0,this.drag_mouse_start=rcube_event.get_mouse_pos(a),rcube_event.add_listener({event:"mousemove",object:this,method:"drag_mouse_move"}),rcube_event.add_listener({event:"mouseup",object:this,method:"drag_mouse_up"}),bw.touch&&(rcube_event.add_listener({event:"touchmove",object:this,method:"drag_mouse_move"}),rcube_event.add_listener({event:"touchend",object:this,method:"drag_mouse_up"})),this.add_dragfix());return!1},click_row:function(a,b){if(!b||!this.rows[b])return!1;
  49. if(!this.is_event_target(a))return!0;var c=(new Date).getTime(),d=c-this.rows[b].clicked<this.dblclick_time;this.drag_active||d||this.in_selection_before!=b||this.select_row(b,rcube_event.get_modifier(a),!0);this.in_selection_before=this.drag_start=!1;this.rowcount&&d&&this.in_selection(b)?(this.triggerEvent("dblclick"),c=0):this.triggerEvent("click");this.drag_active||(this.del_dragfix(),rcube_event.cancel(a));this.rows[b].clicked=c;this.focus();return!1},is_event_target:function(a){a=rcube_event.get_target(a);
  50. var b=a.tagName.toLowerCase();return!(a&&("input"==b||"img"==b||"a"!=b&&a.onclick))},find_root:function(a){var b=this.rows[a];return b&&b.parent_uid?this.find_root(b.parent_uid):a},expand_row:function(a,b){var c=this.rows[b],d=rcube_event.get_target(a),e=rcube_event.get_modifier(a);c.clicked=0;c.expanded?(d.className="collapsed",e==CONTROL_KEY||this.multiexpand?this.collapse_all(c):this.collapse(c)):(d.className="expanded",e==CONTROL_KEY||this.multiexpand?this.expand_all(c):this.expand(c))},collapse:function(a){var b=
  51. a.depth,c=a?a.obj.nextSibling:null;a.expanded=!1;for(this.triggerEvent("expandcollapse",{uid:a.uid,expanded:a.expanded,obj:a.obj});c;){if(1==c.nodeType){if((a=this.rows[c.uid])&&a.depth<=b)break;$(c).css("display","none");a.expanded&&(a.expanded=!1,this.triggerEvent("expandcollapse",{uid:a.uid,expanded:a.expanded,obj:c}))}c=c.nextSibling}this.resize();this.triggerEvent("listupdate");return!1},expand:function(a){var b,c,d,e,f;a?(a.expanded=!0,d=a.depth,e=a.obj.nextSibling,this.update_expando(a.id,
  52. !0),this.triggerEvent("expandcollapse",{uid:a.uid,expanded:a.expanded,obj:a.obj})):(e=this.tbody.firstChild,f=d=0);for(;e;){if(1==e.nodeType&&(b=this.rows[e.uid])){if(a&&(!b.depth||b.depth<=d))break;if(b.parent_uid)if((c=this.rows[b.parent_uid])&&c.expanded){if(a&&c==a||f>=c.depth-1)f=c.depth,$(e).css("display",""),b.expanded=!0,this.triggerEvent("expandcollapse",{uid:b.uid,expanded:b.expanded,obj:e})}else if(a&&(!c||c.depth<=d))break}e=e.nextSibling}this.resize();this.triggerEvent("listupdate");
  53. return!1},collapse_all:function(a){var b,c,d;if(a){if(a.expanded=!1,b=a.depth,c=a.obj.nextSibling,this.update_expando(a.id),this.triggerEvent("expandcollapse",{uid:a.uid,expanded:a.expanded,obj:a.obj}),b&&this.multiexpand)return!1}else c=this.tbody.firstChild,b=0;for(;c;){if(1==c.nodeType&&(d=this.rows[c.uid])){if(a&&(!d.depth||d.depth<=b))break;(a||d.depth)&&$(c).css("display","none");d.has_children&&d.expanded&&(d.expanded=!1,this.update_expando(d.id,!1),this.triggerEvent("expandcollapse",{uid:d.uid,
  54. expanded:d.expanded,obj:c}))}c=c.nextSibling}this.resize();this.triggerEvent("listupdate");return!1},expand_all:function(a){var b,c,d;a?(a.expanded=!0,b=a.depth,c=a.obj.nextSibling,this.update_expando(a.id,!0),this.triggerEvent("expandcollapse",{uid:a.uid,expanded:a.expanded,obj:a.obj})):(c=this.tbody.firstChild,b=0);for(;c;){if(1==c.nodeType&&(d=this.rows[c.uid])){if(a&&d.depth<=b)break;$(c).css("display","");d.has_children&&!d.expanded&&(d.expanded=!0,this.update_expando(d.id,!0),this.triggerEvent("expandcollapse",
  55. {uid:d.uid,expanded:d.expanded,obj:c}))}c=c.nextSibling}this.resize();this.triggerEvent("listupdate");return!1},update_expando:function(a,b){var c=document.getElementById("rcmexpando"+a);c&&(c.className=b?"expanded":"collapsed")},get_row_uid:function(a){if(a){if(!a.uid){var b=$(a).data("uid");b?a.uid=b:String(a.id).match(this.id_regexp)&&(a.uid=RegExp.$1)}return a.uid}},get_next_row:function(){if(!this.rowcount)return!1;for(var a=this.rows[this.last_selected],a=a?a.obj.nextSibling:null;a&&(1!=a.nodeType||
  56. "none"==a.style.display);)a=a.nextSibling;return a},get_prev_row:function(){if(!this.rowcount)return!1;for(var a=this.rows[this.last_selected],a=a?a.obj.previousSibling:null;a&&(1!=a.nodeType||"none"==a.style.display);)a=a.previousSibling;return a},get_first_row:function(){if(this.rowcount){var a,b,c=this.tbody.childNodes;for(a=0;a<c.length;a++)if(c[a].id&&(b=this.get_row_uid(c[a])))return b}return null},get_last_row:function(){if(this.rowcount){var a,b,c=this.tbody.childNodes;for(a=c.length-1;0<=
  57. a;a--)if(c[a].id&&(b=this.get_row_uid(c[a])))return b}return null},row_tagname:function(){var a={table:"tr",ul:"li","*":"div"};return a[this.tagname]||a["*"]},col_tagname:function(){var a={table:"td","*":"span"};return a[this.tagname]||a["*"]},get_cell:function(a,b){return $(this.col_tagname(),a).eq(b)},select_row:function(a,b,c){var d=this.selection.join(","),e=this.in_selection(a);!this.multiselect&&c&&(b=0);this.shift_start||(this.shift_start=a);if(b){switch(b){case SHIFT_KEY:this.shift_select(a,
  58. !1);break;case CONTROL_KEY:c&&(this.shift_start=a,this.highlight_row(a,!0));break;case CONTROL_SHIFT_KEY:this.shift_select(a,!0);break;default:this.highlight_row(a,!1)}this.multi_selecting=!0}else this.shift_start=a,this.highlight_row(a,!1),this.multi_selecting=!1;this.last_selected&&this.rows[this.last_selected]&&$(this.rows[this.last_selected].obj).removeClass("focused").find(this.col_tagname()).eq(this.subject_col).removeAttr("tabindex");this.toggleselect&&e&&!b?this.clear_selection():this.selection.join(",")!=
  59. d&&this.triggerEvent("select");this.rows[a]&&($(this.rows[a].obj).addClass("focused"),this.focused&&this.focus_noscroll($(this.rows[a].obj).find(this.col_tagname()).eq(this.subject_col).attr("tabindex","0")));this.selection.length||(this.shift_start=null);this.last_selected=a},select:function(a){this.select_row(a,!1);this.scrollto(a)},select_next:function(){var a=this.get_next_row(),b=this.get_prev_row();(a=a?a:b)&&this.select_row(a.uid,!1,!1)},select_first:function(a){var b=this.get_first_row();
  60. b&&(this.select_row(b,a,!1),this.scrollto(b))},select_last:function(a){var b=this.get_last_row();b&&(this.select_row(b,a,!1),this.scrollto(b))},select_children:function(a){var b=this.row_children(a),c=b.length;for(a=0;a<c;a++)this.in_selection(b[a])||this.select_row(b[a],CONTROL_KEY,!0)},shift_select:function(a,b){this.rows[this.shift_start]&&this.selection.length||(this.shift_start=a);var c,d,e;d=this.rows[a];e=this._rowIndex(this.rows[this.shift_start].obj);var f=this._rowIndex(d.obj);e<f&&!d.expanded&&
  61. d.has_children&&(d=this.rows[this.row_children(a).pop()])&&(f=this._rowIndex(d.obj));d=e<f?e:f;e=e>f?e:f;for(c in this.rows)this._rowIndex(this.rows[c].obj)>=d&&this._rowIndex(this.rows[c].obj)<=e?this.in_selection(c)||this.highlight_row(c,!0):this.in_selection(c)&&!b&&this.highlight_row(c,!0)},_rowIndex:function(a){return void 0!==a.rowIndex?a.rowIndex:$(a).prevAll().length},in_selection:function(a,b){for(var c in this.selection)if(this.selection[c]==a)return b?parseInt(c):!0;return!1},select_all:function(a){if(!this.rowcount)return!1;
  62. var b,c=this.selection.join(",");this.selection=[];for(b in this.rows)a&&!0!=this.rows[b][a]?$(this.rows[b].obj).removeClass("selected").removeAttr("aria-selected"):(this.last_selected=b,this.highlight_row(b,!0,!0));this.selection.join(",")!=c&&this.triggerEvent("select");this.focus();return!0},invert_selection:function(){if(!this.rowcount)return!1;var a,b=this.selection.join(",");for(a in this.rows)this.highlight_row(a,!0);this.selection.join(",")!=b&&this.triggerEvent("select");this.focus();return!0},
  63. clear_selection:function(a,b){var c,d=this.selection.length;if(a)for(c in this.selection){if(this.selection[c]==a){this.selection.splice(c,1);break}}else{for(c in this.selection)this.rows[this.selection[c]]&&$(this.rows[this.selection[c]].obj).removeClass("selected").removeAttr("aria-selected");this.selection=[]}!d||this.selection.length||b||(this.triggerEvent("select"),this.last_selected=null)},get_selection:function(a){var b=$.merge([],this.selection);if(!1!==a&&b.length)for(var c,d=0,e=b.length;d<
  64. e;d++)if(a=b[d],this.rows[a]&&this.rows[a].has_children&&!this.rows[a].expanded){c=this.row_children(a);for(var f=0,g=c.length;f<g;f++)a=c[f],this.in_selection(a)||b.push(a)}return b},get_single_selection:function(){return 1==this.selection.length?this.selection[0]:null},highlight_row:function(a,b,c){if(this.rows[a])if(b){var d;d=this.in_selection(a,!0);!1===d?(this.selection.push(a),$(this.rows[a].obj).addClass("selected").attr("aria-selected","true"),c||this.rows[a].expanded||this.highlight_children(a,
  65. !0)):(b=this.selection.slice(0,d),d=this.selection.slice(d+1,this.selection.length),this.selection=b.concat(d),$(this.rows[a].obj).removeClass("selected").removeAttr("aria-selected"),c||this.rows[a].expanded||this.highlight_children(a,!1))}else if(1<this.selection.length||!this.in_selection(a))this.clear_selection(null,!0),this.selection[0]=a,$(this.rows[a].obj).addClass("selected").attr("aria-selected","true")},highlight_children:function(a,b){var c,d,e=this.row_children(a),f=e.length;for(c=0;c<
  66. f;c++)d=this.in_selection(e[c]),(b&&!d||!b&&d)&&this.highlight_row(e[c],!0,!0)},key_press:function(a){var b=a.target||{};if(!0!=this.focused||"INPUT"==b.nodeName||"TEXTAREA"==b.nodeName||"SELECT"==b.nodeName)return!0;var b=rcube_event.get_keycode(a),c=rcube_event.get_modifier(a);switch(b){case 40:case 38:case 63233:case 63232:return rcube_event.cancel(a),this.use_arrow_key(b,c);case 32:return rcube_event.cancel(a),this.select_row(this.last_selected,c,!0);case 37:case 39:return rcube_event.cancel(a),
  67. a=this.use_arrow_key(b,c),this.key_pressed=b,this.modkey=c,this.triggerEvent("keypress"),this.modkey=0,a;case 36:return this.select_first(c),rcube_event.cancel(a);case 35:return this.select_last(c),rcube_event.cancel(a);case 27:return this.drag_active?this.drag_mouse_up(a):this.col_drag_active?(this.selected_column=null,this.column_drag_mouse_up(a)):rcube_event.cancel(a);case 9:this.blur();break;case 13:this.selection.length||this.select_row(this.last_selected,c,!1);default:if(this.key_pressed=b,
  68. this.modkey=c,this.triggerEvent("keypress"),this.modkey=0,this.key_pressed==this.BACKSPACE_KEY)return rcube_event.cancel(a)}return!0},use_arrow_key:function(a,b){var c,d=this.rows[this.last_selected];if(40==a||63233==a)c=this.get_next_row();else if(38==a||63232==a)c=this.get_prev_row();else{if(!d||!d.has_children)return;if(39==a){if(d.expanded)return;b==CONTROL_KEY||this.multiexpand?this.expand_all(d):this.expand(d)}else{if(!d.expanded)return;b==CONTROL_KEY||this.multiexpand?this.collapse_all(d):
  69. this.collapse(d)}this.update_expando(d.id,d.expanded);return!1}c?(b||this.selection.length||(b=CONTROL_KEY),this.select_row(c.uid,b,!1),this.scrollto(c.uid)):c||d||this.select_first(CONTROL_KEY);return!1},scrollto:function(a){var b=this.rows[a]?this.rows[a].obj:null;if(b&&this.frame){var c=Number(b.offsetTop),d=0;!c&&this.rows[a].parent_uid&&(a=this.find_root(this.rows[a].uid),this.expand_all(this.rows[a]),c=Number(b.offsetTop));this.fixed_header&&(d=Number(this.thead.offsetHeight));c<Number(this.frame.scrollTop)+
  70. d?this.frame.scrollTop=c-d:c+Number(b.offsetHeight)>Number(this.frame.scrollTop)+Number(this.frame.offsetHeight)&&(this.frame.scrollTop=c+Number(b.offsetHeight)-Number(this.frame.offsetHeight))}},drag_mouse_move:function(a){if("touchmove"==a.type)if(1==a.touches.length&&1==a.changedTouches.length)a=rcube_event.touchevent(a.changedTouches[0]);else return rcube_event.cancel(a);if(this.drag_start){var b=rcube_event.get_mouse_pos(a),c=[],d=this;if(!this.drag_mouse_start||3>Math.abs(b.x-this.drag_mouse_start.x)&&
  71. 3>Math.abs(b.y-this.drag_mouse_start.y))return!1;this.drag_start_pos={left:b.x,top:b.y};this.draglayer?this.draglayer.html(""):this.draglayer=$("<div>").attr("id","rcmdraglayer").css({position:"absolute",display:"none","z-index":2E3}).appendTo(document.body);$(this.row_tagname()+".selected",this.tbody).each(function(){var a=d.get_row_uid(this),b=d.rows[a];if(b&&!(-1<$.inArray(a,c))&&(c.push(a),b.has_children&&!b.expanded&&$.each(d.row_children(a),function(){-1<$.inArray(this,c)||c.push(this)}),11<
  72. c.length))return!1});$.each(c,function(a,b){if(10<a)return d.draglayer.append("..."),!1;$("> "+d.col_tagname(),d.rows[b].obj).each(function(a,b){if(0>d.subject_col||0<=d.subject_col&&d.subject_col==a){b=$(b).clone();$(b).find(".skip-on-drag").remove();var c=b.text();if(c)return c=$.trim(c),c=50<c.length?c.substring(0,50)+"...":c,d.draglayer.append($("<div>").text(c)),!1}})});this.draglayer.show();this.drag_active=!0;this.triggerEvent("dragstart")}this.drag_active&&this.draglayer&&(b=rcube_event.get_mouse_pos(a),
  73. this.draglayer.css({left:b.x+20+"px",top:b.y-5+(bw.ie?document.documentElement.scrollTop:0)+"px"}),this.triggerEvent("dragmove",a?a:window.event));return this.drag_start=!1},drag_mouse_up:function(a){document.onmousemove=null;if("touchend"==a.type&&1!=a.changedTouches.length)return rcube_event.cancel(a);this.draglayer&&this.draglayer.is(":visible")&&(this.drag_start_pos?this.draglayer.animate(this.drag_start_pos,300,"swing").hide(20):this.draglayer.hide());this.drag_active&&this.focus();this.drag_active=
  74. !1;rcube_event.remove_listener({event:"mousemove",object:this,method:"drag_mouse_move"});rcube_event.remove_listener({event:"mouseup",object:this,method:"drag_mouse_up"});bw.touch&&(rcube_event.remove_listener({event:"touchmove",object:this,method:"drag_mouse_move"}),rcube_event.remove_listener({event:"touchend",object:this,method:"drag_mouse_up"}));this.del_dragfix();this.triggerEvent("dragend",a);return rcube_event.cancel(a)},column_drag_mouse_move:function(a){if(this.drag_start){var b;b=rcube_event.get_mouse_pos(a);
  75. if(!this.drag_mouse_start||3>Math.abs(b.x-this.drag_mouse_start.x)&&3>Math.abs(b.y-this.drag_mouse_start.y))return!1;if(!this.col_draglayer){b=$(this.list).offset();var c=this.thead.rows[0].cells;b.top+=this.list.scrollTop+this.list.parentNode.scrollTop;this.col_draglayer=$("<div>").attr("id","rcmcoldraglayer").css(b).css({position:"absolute","z-index":2001,"background-color":"white",opacity:0.75,height:this.frame.offsetHeight-2+"px",width:this.frame.offsetWidth-2+"px"}).appendTo(document.body).append($("<div>").attr("id",
  76. "rcmcolumnindicator").css({position:"absolute","border-right":"2px dotted #555","z-index":2002,height:this.frame.offsetHeight-2+"px"}));this.cols=[];this.list_pos=this.list_min_pos=b.left;for(b=0;b<c.length;b++)this.cols[b]=c[b].offsetWidth,null!==this.column_fixed&&b<=this.column_fixed&&(this.list_min_pos+=this.cols[b])}this.col_draglayer.show();this.col_drag_active=!0;this.triggerEvent("column_dragstart")}if(this.col_drag_active&&this.col_draglayer){var c=0,d=rcube_event.get_mouse_pos(a);for(b=
  77. 0;b<this.cols.length;b++)if(d.x>=this.cols[b]/2+this.list_pos+c)c+=this.cols[b];else break;0==b&&this.list_min_pos>d.x?c=this.list_min_pos-this.list_pos:this.list.rowcount||b!=this.cols.length||(c-=2);$("#rcmcolumnindicator").css({width:c+"px"});this.triggerEvent("column_dragmove",a?a:window.event)}return this.drag_start=!1},column_drag_mouse_up:function(a){document.onmousemove=null;this.col_draglayer&&(this.col_draglayer.remove(),this.col_draglayer=null);rcube_event.remove_listener({event:"mousemove",
  78. object:this,method:"column_drag_mouse_move"});rcube_event.remove_listener({event:"mouseup",object:this,method:"column_drag_mouse_up"});this.del_dragfix();if(this.col_drag_active&&(this.col_drag_active=!1,this.focus(),this.triggerEvent("column_dragend",a),null!==this.selected_column&&this.cols&&this.cols.length)){var b,c=0,d=rcube_event.get_mouse_pos(a);for(b=0;b<this.cols.length;b++)if(d.x>=this.cols[b]/2+this.list_pos+c)c+=this.cols[b];else break;b!=this.selected_column&&b!=this.selected_column+
  79. 1&&this.column_replace(this.selected_column,b)}return rcube_event.cancel(a)},row_children:function(a){if(!this.rows[a]||!this.rows[a].has_children)return[];var b=[],c=this.rows[a].depth;for(a=this.rows[a].obj.nextSibling;a;){if(1==a.nodeType&&(r=this.rows[a.uid])){if(!r.depth||r.depth<=c)break;b.push(r.uid)}a=a.nextSibling}return b},add_dragfix:function(){$("iframe").each(function(){$('<div class="iframe-dragdrop-fix"></div>').css({background:"#fff",width:this.offsetWidth+"px",height:this.offsetHeight+
  80. "px",position:"absolute",opacity:"0.001",zIndex:1E3}).css($(this).offset()).appendTo(document.body)})},del_dragfix:function(){$("div.iframe-dragdrop-fix").remove()},column_replace:function(a,b){if(this.thead&&this.thead.rows){var c;c=this.thead.rows[0].cells;var d=c[a],e=c[b],f=document.createElement("td");e?c[0].parentNode.insertBefore(f,e):c[0].parentNode.appendChild(f);c[0].parentNode.replaceChild(d,f);r=0;for(c=this.tbody.rows.length;r<c;r++)row=this.tbody.rows[r],d=row.cells[a],e=row.cells[b],
  81. f=document.createElement("td"),e?row.insertBefore(f,e):row.appendChild(f),row.replaceChild(d,f);this.subject_col==a?this.subject_col=b>a?b-1:b:this.subject_col<a&&b<=this.subject_col?this.subject_col++:this.subject_col>a&&b>=this.subject_col&&this.subject_col--;this.fixed_header&&this.init_header();this.triggerEvent("column_replace")}}};rcube_list_widget.prototype.addEventListener=rcube_event_engine.prototype.addEventListener;rcube_list_widget.prototype.removeEventListener=rcube_event_engine.prototype.removeEventListener;
  82. rcube_list_widget.prototype.triggerEvent=rcube_event_engine.prototype.triggerEvent;rcube_list_widget._instances=[];