Your IP : 3.140.201.181


Current Path : /usr/share/roundcubemail/program/js/
Upload File :
Current File : //usr/share/roundcubemail/program/js/treelist.min.js

/**
 * 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 <roundcube@gmail.com>
 * @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,n,t,o,u,r,i,l,f=$(e),a=s.data||[],h={},p=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;if(i=h[e]){if(i.collapsed=void 0===r||r,(n=O((a=i).id,!0)).attr("aria-expanded",a.collapsed?"false":"true"),n.children("ul").first()[a.collapsed?"hide":"show"](),n.children("div.treetoggle").removeClass("collapsed expanded").addClass(a.collapsed?"collapsed":"expanded"),C.triggerEvent("toggle",a),t&&i.children)for(var l=0;l<i.children.length;l++)E(i.children[l].id,t,r);C.triggerEvent(i.collapsed?"collapse":"expand",i);var n=e,a=i.collapsed;s.save_state&&window.rcmail&&(e="treelist-"+w,(o=o||rcmail.local_storage_get_item(e,{}))[n]!=a)&&(o[n]=a,rcmail.local_storage_set_item(e,o))}}function k(e,t){E(e,t,!1)}function L(e,t){var r;(r=h[e])&&E(e,t,!r.collapsed)}function A(e){var t;!1!==C.triggerEvent("beforeselect",h[e])&&(p&&(O(p,!0).removeClass("selected").removeAttr("aria-selected"),v&&O(p).removeClass("selected").removeAttr("aria-selected"),p=null),e)&&((t=O(e,!0)).length&&(t.addClass("selected").attr("aria-selected","true"),p=e,v&&O(e).addClass("selected").attr("aria-selected","true"),B(t)),C.triggerEvent("select",h[e]))}function F(){return p}function I(e,t){return O(e,t).get(0)}function U(e,t){var r,i,l=e.get(0).id,n=e.children().first().text().toUpperCase();e.parent().children("li"+t).each(function(e,t){if(0==e&&(r=t),t.id!=l){if(!(t.id!=l&&n>=$(t).children().first().text().toUpperCase()))return!1;i=t}}),i?e.insertAfter(i):r&&r.id!=l&&e.insertBefore(r),S()}function S(){a=function n(e,a){var o=[];e.children("li").each(function(e,t){var r,t=$(t),i=t.children("ul"),l={id:N(t),classes:String(t.attr("class")).split(" "),virtual:t.hasClass("virtual"),level:a,html:t.children().first().get(0).outerHTML,text:t.children().first().text(),children:n(i,a+1)};i.length&&(l.childlistclass=i.attr("class")),l.children.length&&(void 0===l.collapsed&&(l.collapsed="none"==i.css("display")),void 0!==(r=K(l.id))&&i[(l.collapsed=r)?"hide":"show"](),t.children("div.treetoggle").length||$('<div class="treetoggle '+(l.collapsed?"collapsed":"expanded")+'">&nbsp;</div>').appendTo(t),t.attr("aria-expanded",l.collapsed?"false":"true")),t.hasClass("selected")&&(t.attr("aria-selected","true"),p=l.id),t.data("id",l.id),t.attr("role","treeitem").attr("aria-level",l.level+1),l.virtual&&t.children("a").first().attr("tabindex","0"),o.push(l),h[l.id]=l});e.attr("role",0==a?"tree":"group");return o}(f,0)}function q(i,e){if(!(i=String(i).toLowerCase()).length)return R();var l,n;i==_&&!e||(l=[],n=function(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=O(t.id)).data("filtered"))return;r=$("<li>").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)})},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)}function R(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:_}),_="",p&&!e&&A(p)}function H(e,t,r){if(!e.deleted){var i=$("<li>").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),"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==p&&i.addClass("selected"),e.children&&e.children.length){i.attr("aria-expanded",e.collapsed?"false":"true"),$('<div class="treetoggle '+(e.collapsed?"collapsed":"expanded")+'">&nbsp;</div>').appendTo(i);var l=$("<ul>").appendTo(i).attr("class",e.childlistclass).attr("role","group");e.collapsed&&l.hide();for(var n=0;n<e.children.length;n++)e.children[n].level=e.level+1,H(e.children[n],l)}return i}}function N(e){e=String(e.attr("id")).replace(new RegExp("^"+s.id_prefix||"%"),"").replace(/--xsR$/,"");return s.id_decode?s.id_decode(e):e}function O(e,t){e=s.id_encode?s.id_encode(e):e,t=v&&!t?"--xsR":"";return $("#"+s.id_prefix+e+t,f)}function B(e){var t=f.parent(),r=t.scrollTop(),i=e.offset().top-t.offset().top;(i<0||i+e.height()>t.height())&&t.scrollTop(i+r)}function K(e){if(s.save_state&&window.rcmail)return(o=o||rcmail.local_storage_get_item("treelist-"+w,{}))[e]}function P(e){if(e||!g){g=!0;var t,r,i,l=f.offset();for(i in y=bw.ie?0:window.pageYOffset,T=f.parent().scrollTop(),l.top+=T,x={x1:l.left,y1:l.top,x2:l.left+f.width(),y2:l.top+f.height()},b=[],h)(t=O(i).children().first().get(0))&&(r=t.offsetHeight)&&((l=$(t).offset()).top+=T,b[i]={x1:l.left,y1:l.top,x2:l.left+t.offsetWidth,y2:l.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&&0<T?t=-1:e.y>f.parent().height()-25&&(t=1),g&&0!=t?n=n||setTimeout(function(){!function e(t){if(!g)return;var r=T;f.parent().get(0).scrollTop+=s.scroll_step*t;T=f.parent().scrollTop();n=null;T!=r&&(n=setTimeout(function(){e(t)},s.scroll_speed))}(t)},s.scroll_delay):n&&(window.clearTimeout(n),n=null)}).on("mouseleave.treelist",function(){n&&(window.clearTimeout(n),n=null)})}}function W(){f.parent().off(".treelist"),$("li.droptarget",f).removeClass("droptarget"),g&&(g=!1,n=null,d)&&(clearTimeout(d),c=d=null)}function D(e,t){var r,i,l,n=bw.ie?-document.documentElement.scrollTop:y,a=f.parent().scrollTop(),o=null;if(e.top=e.y+a-n,e.x<x.x1||e.x>=x.x2||e.top<x.y1||e.top>=x.y2)t&&$("li.droptarget",f).removeClass("droptarget");else for(r in b)i=b[r],e.x>=i.x1&&e.x<i.x2&&e.top>=i.y1&&e.top<i.y2?((l=h[r]).children&&l.children.length&&l.collapsed&&s.autoexpand&&c!=r?(d&&clearTimeout(d),c=r,d=setTimeout(function(){k(c),P(!0),c=null,u&&$.ui.ddmanager.prepareOffsets($.ui.ddmanager.current,null)},s.autoexpand)):d&&c!=r&&(clearTimeout(d),d=c=null),o=s.check_droptarget(l)?(t&&(O(r).addClass("droptarget"),i.on=!0),r):null):i.on&&(O(r).removeClass("droptarget"),i.on=!1);return o}function Y(r){var e;return r=r||{},"string"==$.type(r)?("destroy"==r&&(u=null),$("li:not(.virtual)",f).droppable(r)):(l=r,(e=$.extend({greedy:!0,tolerance:"pointer",hoverClass:"droptarget",addClasses:!1},r)).activate=function(e,t){P(),u=t,r.activate&&r.activate(e,t)},e.deactivate=function(e,t){W(),u=null,r.deactivate&&r.deactivate(e,t)},e.over=function(e,t){D(rcube_event.get_mouse_pos(e),!1),r.over&&r.over(e,t)},$("li:not(.virtual)",f).droppable(e)),this}function j(e){return e=e||{},"string"==$.type(e)?("destroy"==e&&(r=null),$("li:not(.virtual)",f).draggable(e)):(i=e,e=$.extend({appendTo:"body",revert:"invalid",iframeFix:!0,addClasses:!1,cursorAt:{left:-20,top:5},create:function(e,t){r=t},helper:function(e){return $("<div>").attr("id","rcmdraglayer").text($(e.target).first().text().trim())}},e),$("li:not(.virtual)",f).draggable(e)),this}this.container=f,this.expand=k,this.collapse=E,this.expand_all=function(){$.each(h,function(e,t){0<t.children.length&&t.collapsed&&E(e,!1,!1)})},this.collapse_all=function(){$.each(h,function(e,t){0<t.children.length&&!t.collapsed&&E(e)})},this.select=A,this.render=function(){if(!1!==C.triggerEvent("renderBefore",a)){f.html("");for(var e=0;e<a.length;e++)a[e].level=0,H(a[e],f);C.triggerEvent("renderAfter",f)}},this.reset=function(e,t){t||A("");a=[],g=!(h={}),e?(i&&(r&&j("destroy"),j(i)),l&&(u&&Y("destroy"),Y(l)),S()):f.html("");R(t)},this.drag_start=P,this.drag_end=W,this.intersects=D,this.droppable=Y,this.draggable=j,this.is_draggable=function(){return!!r},this.update=function(e,t,r){var i,l,n,a,o=h[e];o&&(i=O(e),l=i.parent(),(t.id||t.html||t.children||t.classes||t.parent)&&(t.parent&&(n=h[t.parent])?(l.closest("li").length&&(a=h[N(l.closest("li"))])&&(a.children=$.grep(a.children,function(e,t){return e.id!=o.id})),l=O(t.parent).children("ul").first(),n.children||(n.children=[]),n.children.push(o)):void 0!==t.parent&&(l=f),$.extend(o,t),i=H(o,l,i)),o.id!=e&&(delete h[e],h[o.id]=o),r)&&U(i,"string"==typeof r?'[class~="'+r+'"]':"")},this.insert=function(e,t,r){var i,l=t?h[t]:null;search_=v,h[e.id]||(void 0!==(state=K(e.id,e.collapsed))&&(e.collapsed=state),l?(e.level=l.level+1,l.children?l.children=l.children.filter(function(e){return!e.deleted}):l.children=[],v=!1,l.children.push(e),t=O(t),i=1==l.children.length?(H(l,null,t),O(e.id)):H(e,t.children("ul").first()),search_&&(v=search_,i.is(":visible")||$("<li>").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=H(e,f)),"object"==typeof(h[e.id]=e).html&&(h[e.id].html=O(e.id,!0).children()),r&&U(i,"string"==typeof r?'[class~="'+r+'"]':""))},this.remove=function(e){var t,r,i;if(t=h[e])return r=O(e,!0),i=r.parent(),r.remove(),t.deleted=!0,delete h[e],v&&O(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=I,this.get_node=function(e){return h[e]},this.get_selection=F,this.in_selection=function(e){return p==e},this.get_next=function(){var e,t;if(p&&(e=O(p))){if((t=e.children("ul").children("li").first()).length)return N(t);if((t=e.next()).length)return N(t);for(;(e=e.parent("ul").parent("li"))&&e.length;)if((t=e.next()).length)return N(t)}},this.get_prev=function(){var e,t,r;if(p&&(e=O(p)))return t=e.prev(),(r=t.find("li").last()).length?N(r):t.length?N(t):(e=e.parent().parent()).length&&e.is("li")?N(e):void 0},this.get_single_selection=F,this.is_search=function(){return v},this.reset_search=R,f.length&&(s.data?function e(t){t.id&&(h[t.id]=t);for(var r=0;t.children&&r<t.children.length;r++)e(t.children[r])}({children:a}):S(),p&&B(O(p,!0)),f.attr("role","tree").on("focusin",function(e){m=!0}).on("focusout",function(e){m=!1}).on("click","div.treetoggle",function(e){L(N($(this).parent())),e.stopPropagation()}).on("click","li",function(e){if($(e.target).is("input"))return!0;var t=s.selectable?h[N($(this))]:null;t&&(t.virtual||A(t.id),e.stopPropagation())}).on("mousedown","a",function(e){var t=$(e.target),r=h[N(t.closest("li"))];if(r&&r.virtual&&!t.attr("href"))return e.preventDefault(),e.stopPropagation(),!1}),s.searchbox&&(t=$(s.searchbox).off("keyup.treelist").on("keyup.treelist",function(e){var t=rcube_event.get_keycode(e);rcube_event.get_modifier(e);switch(t){case 9:break;case 13:return q(this.value,!0),rcube_event.cancel(e);case 27:R();break;case 38:case 37:case 39:case 40:return;default:q(this.value,!1)}}).attr("autocomplete","off")).parent().find("a.reset").off("click.treelist").on("click.treelist",function(e){return R(),!1}),$(document.body).on("keydown",function(e){var t,r,i=e.target||{},l=rcube_event.get_keycode(e);if(m&&("INPUT"!=i.nodeName||38==l||40==l)&&"TEXTAREA"!=i.nodeName&&"SELECT"!=i.nodeName)switch(l){case 38:case 40:case 63232:case 63233:return(t=s.keyboard?f.find(":focus").closest("li"):[]).length&&function e(t,r,i){var l=r<0?"prev":"next",l=t[l]();0<r&&!i&&t.children("ul[role=group]:visible").length?t.children("ul").children("li").first().find("a").first().focus():r<0&&!i&&l.children("ul[role=group]:visible").length?l.children("ul").children("li").last().find("a").first().focus():l.length&&l.find("a").first().focus().length||(i=t.parent().closest("li[role=treeitem]")).length&&(r<0?i.find("a").first().focus():e(i,r,!0))}(t,mod=38==l||63232==l?-1:1),rcube_event.cancel(e);case 37:case 39:return(t=f.find(":focus").closest("li")).length&&(t=N(t),r=h[t])&&r.children.length&&r.collapsed!=(37==l)&&L(t,rcube_event.get_modifier(e)==SHIFT_KEY),!1;case 9:s.keyboard&&s.tabexit&&(r=rcube_event.get_modifier(e)==SHIFT_KEY?"first":"last",function(e){{var t,r;e.length&&(t=f.parent().get(0)||{scrollTop:0},r=t.scrollTop||t.scrollY,e.focus(),t.scrollTop=r)}}(f.find("li[role=treeitem]:has(a)")[r]().find("a:"+r)))}return!0}),s.parent_focus)&&f.parent(":not(body)").click(function(e){if($(e.target).is("input"))return!0;!m&&p?$(I(p)).find(":focusable").first().focus():m||f.children("li").find(":focusable").first().focus()})}rcube_treelist_widget.prototype.addEventListener=rcube_event_engine.prototype.addEventListener,rcube_treelist_widget.prototype.removeEventListener=rcube_event_engine.prototype.removeEventListener,rcube_treelist_widget.prototype.triggerEvent=rcube_event_engine.prototype.triggerEvent;