/** * Roundcube Treelist Widget * * This file is part of the Roundcube Webmail client * * @licstart The following is the entire license notice for the * JavaScript code in this file. * * Copyright (c) The Roundcube Dev Team * * The JavaScript code in this page is free software: you can * redistribute it and/or modify it under the terms of the GNU * General Public License (GNU GPL) as published by the Free Software * Foundation, either version 3 of the License, or (at your option) * any later version. The code is distributed WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU GPL for more details. * * As additional permission under GNU GPL version 3 section 7, you * may distribute non-source (e.g., minimized or compacted) forms of * that code without the copy of the GNU GPL normally required by * section 4, provided you include this license notice and a URL * through which recipients can access the Corresponding Source. * * @licend The above is the entire license notice * for the JavaScript code in this file. * * @author Thomas Bruederli * @requires jquery.js, common.js */ function rcube_treelist_widget(e,s){s=$.extend({id_prefix:"",autoexpand:1e3,selectable:!1,scroll_delay:500,scroll_step:5,scroll_speed:20,save_state:!1,keyboard:!0,tabexit:!0,parent_focus:!1,check_droptarget:function(e){return!e.virtual}},s||{});var d,c,l,t,o,u,r,i,n,f=$(e),a=s.data||[],p={},h=null,g=!1,v=!1,_="",m=!1,x={},b=[],y=0,T=0,w=f.attr("id")||s.id_prefix||"0",C=this;function E(e,t,r){var i,n,l;if(i=p[e]){if(i.collapsed=void 0===r||r,(l=F((n=i).id,!0)).attr("aria-expanded",n.collapsed?"false":"true"),l.children("ul").first()[n.collapsed?"hide":"show"](),l.children("div.treetoggle").removeClass("collapsed expanded").addClass(n.collapsed?"collapsed":"expanded"),C.triggerEvent("toggle",n),t&&i.children)for(var a=0;a=$(t).children().first().text().toUpperCase()))return!1;i=t}}),i?e.insertAfter(i):r&&r.id!=n&&e.insertBefore(r),N()}function N(){a=function l(e,a){var o=[];e.children("li").each(function(e,t){var r=$(t),i=r.children("ul"),n={id:j(r),classes:String(r.attr("class")).split(" "),virtual:r.hasClass("virtual"),level:a,html:r.children().first().get(0).outerHTML,text:r.children().first().text(),children:l(i,a+1)};i.length&&(n.childlistclass=i.attr("class")),n.children.length&&(void 0===n.collapsed&&(n.collapsed="none"==i.css("display")),void 0!==(t=U(n.id,n.collapsed))&&(n.collapsed=t,i[t?"hide":"show"]()),r.children("div.treetoggle").length||$('
 
').appendTo(r),r.attr("aria-expanded",n.collapsed?"false":"true")),r.hasClass("selected")&&(r.attr("aria-selected","true"),h=n.id),r.data("id",n.id),r.attr("role","treeitem").attr("aria-level",n.level+1),n.virtual&&r.children("a").first().attr("tabindex","0"),o.push(n),p[n.id]=n});e.attr("role",0==a?"tree":"group");return o}(f,0)}function O(i,e){if(!(i=String(i).toLowerCase()).length)return P(),0;if(i!=_||e){function n(e){$.each(e,function(e,t){var r;if(!t.virtual&&!t.deleted&&0<=String(t.text).toLowerCase().indexOf(i)&&l.indexOf(t.id)<0){if((r=F(t.id)).data("filtered"))return;r=$("
  • ").attr("id",r.attr("id")+"--xsR").attr("class",r.attr("class")).addClass("searchresult__").append(r.children(":not(div.treetoggle,ul)").clone(!0,!0)).appendTo(f),rcmail.triggerEvent("clonerow",{id:t.id,row:r.get(0)}),l.push(t.id)}t.children&&t.children.length&&n(t.children)})}var l=[];return v&&($(f).children("li.searchresult__").remove(),v=!1),$(f).children("li").hide().removeClass("selected"),n(a),v=!0,C.triggerEvent("search",{query:i,last:_,count:l.length,ids:l,execute:e||!1}),_=i,l.count}}function P(e){t&&t.val(""),$(f).children("li.searchresult__").remove(),$(f).children("li").filter(function(){return!$(this).data("filtered")}).show(),v=!1,C.triggerEvent("search",{query:!1,last:_}),_="",h&&!e&&A(h)}function Y(e,t,r){if(!e.deleted){var i=$("
  • ").attr("id",s.id_prefix+(s.id_encode?s.id_encode(e.id):e.id)).attr("role","treeitem").addClass((e.classes||[]).join(" ")).data("id",e.id);if(r?(r.replaceWith(i),t&&i.appendTo(t)):i.appendTo(t),"string"==typeof e.html?i.html(e.html):"object"==typeof e.html&&i.append(e.html),e.text||(e.text=i.children().first().text()),e.virtual&&i.addClass("virtual"),e.id==h&&i.addClass("selected"),e.children&&e.children.length){i.attr("aria-expanded",e.collapsed?"false":"true"),$('
     
    ').appendTo(i);var n=$("
      ").appendTo(i).attr("class",e.childlistclass).attr("role","group");e.collapsed&&n.hide();for(var l=0;lt.height())&&t.scrollTop(i+r)}function U(e){if(s.save_state&&window.rcmail)return(o=o||rcmail.local_storage_get_item("treelist-"+w,{}))[e]}function q(e){if(e||!g){g=!0;var t,r,i,n=f.offset();for(i in y=bw.ie?0:window.pageYOffset,T=f.parent().scrollTop(),n.top+=T,x={x1:n.left,y1:n.top,x2:n.left+f.width(),y2:n.top+f.height()},b=[],p)(t=F(i).children().first().get(0))&&(r=t.offsetHeight)&&((n=$(t).offset()).top+=T,b[i]={x1:n.left,y1:n.top,x2:n.left+t.offsetWidth,y2:n.top+r,on:i==c});f.height()>f.parent().height()&&f.parent().on("mousemove.treelist",function(e){var t=0,e=rcube_event.get_mouse_pos(e);e.y-=f.parent().offset().top,e.y<25&&0f.parent().height()-25&&(t=1),g&&0!=t?l=l||setTimeout(function(){!function e(t){if(!g)return;var r=T;f.parent().get(0).scrollTop+=s.scroll_step*t;T=f.parent().scrollTop();l=null;T!=r&&(l=setTimeout(function(){e(t)},s.scroll_speed))}(t)},s.scroll_delay):l&&(window.clearTimeout(l),l=null)}).on("mouseleave.treelist",function(){l&&(window.clearTimeout(l),l=null)})}}function B(){f.parent().off(".treelist"),$("li.droptarget",f).removeClass("droptarget"),g&&(g=!1,l=null,d&&(clearTimeout(d),c=d=null))}function K(e,t){var r,i,n,l=bw.ie?-document.documentElement.scrollTop:y,a=f.parent().scrollTop(),o=null;if(e.top=e.y+a-l,e.x=x.x2||e.top=x.y2)return t&&$("li.droptarget",f).removeClass("droptarget"),o;for(r in b)i=b[r],e.x>=i.x1&&e.x=i.y1&&e.top").attr("id","rcmdraglayer").text($(e.target).first().text().trim())}},e);return $("li:not(.virtual)",f).draggable(e),this}this.container=f,this.expand=k,this.collapse=E,this.expand_all=function(){$.each(p,function(e,t){0").attr("id",i.attr("id")+"--xsR").attr("class",i.attr("class")).addClass("searchresult__").append(i.children().first().clone(!0,!0)).appendTo(f))):(e.level=0,a.push(e),i=Y(e,f)),"object"==typeof(p[e.id]=e).html&&(p[e.id].html=F(e.id,!0).children()),r&&H(i,"string"==typeof r?'[class~="'+r+'"]':""))},this.remove=function(e){var t,r,i;if(t=p[e])return r=F(e,!0),i=r.parent(),r.remove(),t.deleted=!0,delete p[e],v&&F(e,!1).remove(),i.children().length||(i.parent("li").find("div.treetoggle").remove(),i[0]!=f[0]&&i.remove()),!0;return!1},this.get_item=R,this.get_node=function(e){return p[e]},this.get_selection=S,this.in_selection=function(e){return h==e},this.get_next=function(){var e,t;if(h&&(e=F(h))){if((t=e.children("ul").children("li").first()).length)return j(t);if((t=e.next()).length)return j(t);for(;(e=e.parent("ul").parent("li"))&&e.length;)if((t=e.next()).length)return j(t)}},this.get_prev=function(){var e,t,r;if(h&&(e=F(h)))return t=e.prev(),(r=t.find("li").last()).length?j(r):t.length?j(t):(e=e.parent().parent()).length&&e.is("li")?j(e):void 0},this.get_single_selection=S,this.is_search=function(){return v},this.reset_search=P,f.length&&(s.data?function e(t){t.id&&(p[t.id]=t);for(var r=0;t.children&&r