jellyfin-web/dashboard-ui/thirdparty/jstree3.0.8/jstree.min.js

5 lines
112 KiB
JavaScript
Raw Normal View History

2014-12-20 18:23:56 -07:00
/*! jsTree - v3.0.8 - 2014-10-23 - (MIT) */
(function(e){"use strict";"function"==typeof define&&define.amd?define(["jquery"],e):"object"==typeof exports?e(require("jquery")):e(jQuery)})(function(e,t){"use strict";if(!e.jstree){var i=0,r=!1,s=!1,n=!1,a=[],d=e("script:last").attr("src"),o=document,c=o.createElement("LI"),l,h;c.setAttribute("role","treeitem"),l=o.createElement("I"),l.className="jstree-icon jstree-ocl",l.setAttribute("role","presentation"),c.appendChild(l),l=o.createElement("A"),l.className="jstree-anchor",l.setAttribute("href","#"),l.setAttribute("tabindex","-1"),h=o.createElement("I"),h.className="jstree-icon jstree-themeicon",h.setAttribute("role","presentation"),l.appendChild(h),c.appendChild(l),l=h=null,e.jstree={version:"3.0.8",defaults:{plugins:[]},plugins:{},path:d&&-1!==d.indexOf("/")?d.replace(/\/[^\/]+$/,""):"",idregex:/[\\:&!^|()\[\]<>@*'+~#";.,=\- \/${}%]/g},e.jstree.create=function(t,r){var s=new e.jstree.core(++i),n=r;return r=e.extend(!0,{},e.jstree.defaults,r),n&&n.plugins&&(r.plugins=n.plugins),e.each(r.plugins,function(e,t){"core"!==e&&(s=s.plugin(t,r[t]))}),s.init(t,r),s},e.jstree.destroy=function(){e(".jstree:jstree").jstree("destroy"),e(document).off(".jstree")},e.jstree.core=function(e){this._id=e,this._cnt=0,this._wrk=null,this._data={core:{themes:{name:!1,dots:!1,icons:!1},selected:[],last_error:{},working:!1,worker_queue:[],focused:null}}},e.jstree.reference=function(i){var r=null,s=null;if(i&&i.id&&(i=i.id),!s||!s.length)try{s=e(i)}catch(n){}if(!s||!s.length)try{s=e("#"+i.replace(e.jstree.idregex,"\\$&"))}catch(n){}return s&&s.length&&(s=s.closest(".jstree")).length&&(s=s.data("jstree"))?r=s:e(".jstree").each(function(){var s=e(this).data("jstree");return s&&s._model.data[i]?(r=s,!1):t}),r},e.fn.jstree=function(i){var r="string"==typeof i,s=Array.prototype.slice.call(arguments,1),n=null;return i!==!0||this.length?(this.each(function(){var a=e.jstree.reference(this),d=r&&a?a[i]:null;return n=r&&d?d.apply(a,s):null,a||r||i!==t&&!e.isPlainObject(i)||e(this).data("jstree",new e.jstree.create(this,i)),(a&&!r||i===!0)&&(n=a||!1),null!==n&&n!==t?!1:t}),null!==n&&n!==t?n:this):!1},e.expr[":"].jstree=e.expr.createPseudo(function(i){return function(i){return e(i).hasClass("jstree")&&e(i).data("jstree")!==t}}),e.jstree.defaults.core={data:!1,strings:!1,check_callback:!1,error:e.noop,animation:200,multiple:!0,themes:{name:!1,url:!1,dir:!1,dots:!0,icons:!0,stripes:!1,variant:!1,responsive:!1},expand_selected_onload:!0,worker:!0,force_text:!1},e.jstree.core.prototype={plugin:function(t,i){var r=e.jstree.plugins[t];return r?(this._data[t]={},r.prototype=this,new r(i,this)):this},init:function(t,i){this._model={data:{"#":{id:"#",parent:null,parents:[],children:[],children_d:[],state:{loaded:!1}}},changed:[],force_full_redraw:!1,redraw_timeout:!1,default_state:{loaded:!0,opened:!1,selected:!1,disabled:!1}},this.element=e(t).addClass("jstree jstree-"+this._id),this.settings=i,this.element.bind("destroyed",e.proxy(this.teardown,this)),this._data.core.ready=!1,this._data.core.loaded=!1,this._data.core.rtl="rtl"===this.element.css("direction"),this.element[this._data.core.rtl?"addClass":"removeClass"]("jstree-rtl"),this.element.attr("role","tree"),this.settings.core.multiple&&this.element.attr("aria-multiselectable",!0),this.element.attr("tabindex")||this.element.attr("tabindex","0"),this.bind(),this.trigger("init"),this._data.core.original_container_html=this.element.find(" > ul > li").clone(!0),this._data.core.original_container_html.find("li").addBack().contents().filter(function(){return 3===this.nodeType&&(!this.nodeValue||/^\s+$/.test(this.nodeValue))}).remove(),this.element.html("<ul class='jstree-container-ul jstree-children' role='group'><li id='j"+this._id+"_loading' class='jstree-initial-node jstree-loading jstree-leaf jstree-last' role='tree-item'><i class='jstree-icon jstree-ocl'></i><"+"a class='jstree-anchor' href='#'><i class='jstree-icon jstree-themeicon-hidden'></i>"+this.get_string("Loading ...")+"</a></li></ul>"),this.element.attr("aria-activedescendant","j"+this._id+"_loading"),this._data.core.li_height=this.get_container_
}if(o&&t.appendChild(o),!r){for(a||(a=this.element[0]),l=0,h=a.childNodes.length;h>l;l++)if(a.childNodes[l]&&a.childNodes[l].className&&-1!==a.childNodes[l].className.indexOf("jstree-children")){v=a.childNodes[l];break}v||(v=g.createElement("UL"),v.setAttribute("role","group"),v.className="jstree-children",a.appendChild(v)),a=v,a.childNodes.length>d?a.insertBefore(t,a.childNodes[d]):a.appendChild(t),p&&t.childNodes[1].focus()}return n.state.opened&&!n.state.loaded&&(n.state.opened=!1,setTimeout(e.proxy(function(){this.open_node(n.id,!1,0)},this),0)),t},open_node:function(i,r,s){var n,a,d,o;if(e.isArray(i)){for(i=i.slice(),n=0,a=i.length;a>n;n++)this.open_node(i[n],r,s);return!0}if(i=this.get_node(i),!i||"#"===i.id)return!1;if(s=s===t?this.settings.core.animation:s,!this.is_closed(i))return r&&r.call(this,i,!1),!1;if(this.is_loaded(i))d=this.get_node(i,!0),o=this,d.length&&(i.children.length&&!this._firstChild(d.children(".jstree-children")[0])&&(this.redraw_node(i,!0,!1,!0),d=this.get_node(i,!0)),s?(this.trigger("before_open",{node:i}),d.children(".jstree-children").css("display","none").end().removeClass("jstree-closed").addClass("jstree-open").attr("aria-expanded",!0).children(".jstree-children").stop(!0,!0).slideDown(s,function(){this.style.display="",o.trigger("after_open",{node:i})})):(this.trigger("before_open",{node:i}),d[0].className=d[0].className.replace("jstree-closed","jstree-open"),d[0].setAttribute("aria-expanded",!0))),i.state.opened=!0,r&&r.call(this,i,!0),d.length||this.trigger("before_open",{node:i}),this.trigger("open_node",{node:i}),s&&d.length||this.trigger("after_open",{node:i});else{if(this.is_loading(i))return setTimeout(e.proxy(function(){this.open_node(i,r,s)},this),500);this.load_node(i,function(e,t){return t?this.open_node(e,r,s):r?r.call(this,e,!1):!1})}},_open_to:function(t){if(t=this.get_node(t),!t||"#"===t.id)return!1;var i,r,s=t.parents;for(i=0,r=s.length;r>i;i+=1)"#"!==i&&this.open_node(s[i],!1,0);return e("#"+t.id.replace(e.jstree.idregex,"\\$&"),this.element)},close_node:function(i,r){var s,n,a,d;if(e.isArray(i)){for(i=i.slice(),s=0,n=i.length;n>s;s++)this.close_node(i[s],r);return!0}return i=this.get_node(i),i&&"#"!==i.id?this.is_closed(i)?!1:(r=r===t?this.settings.core.animation:r,a=this,d=this.get_node(i,!0),d.length&&(r?d.children(".jstree-children").attr("style","display:block !important").end().removeClass("jstree-open").addClass("jstree-closed").attr("aria-expanded",!1).children(".jstree-children").stop(!0,!0).slideUp(r,function(){this.style.display="",d.children(".jstree-children").remove(),a.trigger("after_close",{node:i})}):(d[0].className=d[0].className.replace("jstree-open","jstree-closed"),d.attr("aria-expanded",!1).children(".jstree-children").remove())),i.state.opened=!1,this.trigger("close_node",{node:i}),r&&d.length||this.trigger("after_close",{node:i}),t):!1},toggle_node:function(i){var r,s;if(e.isArray(i)){for(i=i.slice(),r=0,s=i.length;s>r;r++)this.toggle_node(i[r]);return!0}return this.is_closed(i)?this.open_node(i):this.is_open(i)?this.close_node(i):t},open_all:function(e,t,i){if(e||(e="#"),e=this.get_node(e),!e)return!1;var r="#"===e.id?this.get_container_ul():this.get_node(e,!0),s,n,a;if(!r.length){for(s=0,n=e.children_d.length;n>s;s++)this.is_closed(this._model.data[e.children_d[s]])&&(this._model.data[e.children_d[s]].state.opened=!0);return this.trigger("open_all",{node:e})}i=i||r,a=this,r=this.is_closed(e)?r.find(".jstree-closed").addBack():r.find(".jstree-closed"),r.each(function(){a.open_node(this,function(e,r){r&&this.is_parent(e)&&this.open_all(e,t,i)},t||0)}),0===i.find(".jstree-closed").length&&this.trigger("open_all",{node:this.get_node(i)})},close_all:function(t,i){if(t||(t="#"),t=this.get_node(t),!t)return!1;var r="#"===t.id?this.get_container_ul():this.get_node(t,!0),s=this,n,a;if(!r.length){for(n=0,a=t.children_d.length;a>n;n++)this._model.data[t.children_d[n]].state.opened=!1;return this.trigger("close_all",{node:t})}r=this.is_open(t)?r.find(".jstree-open").addBack():r.find(".jstree-open"),e(r.get().reverse()).each(function(){s.close_node(this,i
if(-1!==u.indexOf("down"))if(s.state[g?"selected":"checked"]){for(o=0,c=n.length;c>o;o++)r[n[o]].state[g?"selected":"checked"]=!0;this._data[g?"core":"checkbox"].selected=this._data[g?"core":"checkbox"].selected.concat(n)}else for(o=0,c=n.length;c>o;o++)if(r[n[o]].state[g?"selected":"checked"]){for(l=0,h=r[n[o]].children_d.length;h>l;l++)r[r[n[o]].children_d[l]].state[g?"selected":"checked"]=!0;this._data[g?"core":"checkbox"].selected=this._data[g?"core":"checkbox"].selected.concat(r[n[o]].children_d)}if(-1!==u.indexOf("up")){for(o=0,c=s.children_d.length;c>o;o++)r[s.children_d[o]].children.length||a.push(r[s.children_d[o]].parent);for(a=e.vakata.array_unique(a),l=0,h=a.length;h>l;l++){s=r[a[l]];while(s&&"#"!==s.id){for(d=0,o=0,c=s.children.length;c>o;o++)d+=r[s.children[o]].state[g?"selected":"checked"];if(d!==c)break;s.state[g?"selected":"checked"]=!0,this._data[g?"core":"checkbox"].selected.push(s.id),_=this.get_node(s,!0),_&&_.length&&_.attr("aria-selected",!0).children(".jstree-anchor").addClass(g?"jstree-clicked":"jstree-checked"),s=this.get_node(s.parent)}}}this._data[g?"core":"checkbox"].selected=e.vakata.array_unique(this._data[g?"core":"checkbox"].selected)},this)).on(this.settings.checkbox.tie_selection?"select_node.jstree":"check_node.jstree",e.proxy(function(t,i){var r=i.node,s=this._model.data,n=this.get_node(r.parent),a=this.get_node(r,!0),d,o,c,l,h=this.settings.checkbox.cascade,_=this.settings.checkbox.tie_selection;if(-1!==h.indexOf("down"))for(this._data[_?"core":"checkbox"].selected=e.vakata.array_unique(this._data[_?"core":"checkbox"].selected.concat(r.children_d)),d=0,o=r.children_d.length;o>d;d++)l=s[r.children_d[d]],l.state[_?"selected":"checked"]=!0,l&&l.original&&l.original.state&&l.original.state.undetermined&&(l.original.state.undetermined=!1);if(-1!==h.indexOf("up"))while(n&&"#"!==n.id){for(c=0,d=0,o=n.children.length;o>d;d++)c+=s[n.children[d]].state[_?"selected":"checked"];if(c!==o)break;n.state[_?"selected":"checked"]=!0,this._data[_?"core":"checkbox"].selected.push(n.id),l=this.get_node(n,!0),l&&l.length&&l.attr("aria-selected",!0).children(".jstree-anchor").addClass(_?"jstree-clicked":"jstree-checked"),n=this.get_node(n.parent)}-1!==h.indexOf("down")&&a.length&&a.find(".jstree-anchor").addClass(_?"jstree-clicked":"jstree-checked").parent().attr("aria-selected",!0)},this)).on(this.settings.checkbox.tie_selection?"deselect_all.jstree":"uncheck_all.jstree",e.proxy(function(e,t){var i=this.get_node("#"),r=this._model.data,s,n,a;for(s=0,n=i.children_d.length;n>s;s++)a=r[i.children_d[s]],a&&a.original&&a.original.state&&a.original.state.undetermined&&(a.original.state.undetermined=!1)},this)).on(this.settings.checkbox.tie_selection?"deselect_node.jstree":"uncheck_node.jstree",e.proxy(function(t,i){var r=i.node,s=this.get_node(r,!0),n,a,d,o=this.settings.checkbox.cascade,c=this.settings.checkbox.tie_selection;if(r&&r.original&&r.original.state&&r.original.state.undetermined&&(r.original.state.undetermined=!1),-1!==o.indexOf("down"))for(n=0,a=r.children_d.length;a>n;n++)d=this._model.data[r.children_d[n]],d.state[c?"selected":"checked"]=!1,d&&d.original&&d.original.state&&d.original.state.undetermined&&(d.original.state.undetermined=!1);if(-1!==o.indexOf("up"))for(n=0,a=r.parents.length;a>n;n++)d=this._model.data[r.parents[n]],d.state[c?"selected":"checked"]=!1,d&&d.original&&d.original.state&&d.original.state.undetermined&&(d.original.state.undetermined=!1),d=this.get_node(r.parents[n],!0),d&&d.length&&d.attr("aria-selected",!1).children(".jstree-anchor").removeClass(c?"jstree-clicked":"jstree-checked");for(d=[],n=0,a=this._data[c?"core":"checkbox"].selected.length;a>n;n++)-1!==o.indexOf("down")&&-1!==e.inArray(this._data[c?"core":"checkbox"].selected[n],r.children_d)||-1!==o.indexOf("up")&&-1!==e.inArray(this._data[c?"core":"checkbox"].selected[n],r.parents)||d.push(this._data[c?"core":"checkbox"].selected[n]);this._data[c?"core":"checkbox"].selected=e.vakata.array_unique(d),-1!==o.indexOf("down")&&s.length&&s.find(".jstree-anchor").removeClass(c?"jstree-clicked":"jstree-checked").parent().at
}},stop:function(t){if("touchend"===t.type&&t.originalEvent&&t.originalEvent.changedTouches&&t.originalEvent.changedTouches[0]&&(t.pageX=t.originalEvent.changedTouches[0].pageX,t.pageY=t.originalEvent.changedTouches[0].pageY,t.target=document.elementFromPoint(t.originalEvent.changedTouches[0].pageX-window.pageXOffset,t.originalEvent.changedTouches[0].pageY-window.pageYOffset)),i.is_drag)e.vakata.dnd._trigger("stop",t);else if("touchend"===t.type&&t.target===i.target){var r=setTimeout(function(){e(t.target).click()},100);e(t.target).one("click",function(){r&&clearTimeout(r)})}return e.vakata.dnd._clean(),!1}}}(e),e.jstree.defaults.search={ajax:!1,fuzzy:!1,case_sensitive:!1,show_only_matches:!1,close_opened_onclear:!0,search_leaves_only:!1,search_callback:!1},e.jstree.plugins.search=function(i,r){this.bind=function(){r.bind.call(this),this._data.search.str="",this._data.search.dom=e(),this._data.search.res=[],this._data.search.opn=[],this._data.search.som=!1,this.element.on("before_open.jstree",e.proxy(function(t,i){var r,s,n,a=this._data.search.res,d=[],o=e();if(a&&a.length&&(this._data.search.dom=e(this.element[0].querySelectorAll("#"+e.map(a,function(t){return-1!=="0123456789".indexOf(t[0])?"\\3"+t[0]+" "+t.substr(1).replace(e.jstree.idregex,"\\$&"):t.replace(e.jstree.idregex,"\\$&")}).join(", #"))),this._data.search.dom.children(".jstree-anchor").addClass("jstree-search"),this._data.search.som&&this._data.search.res.length)){for(r=0,s=a.length;s>r;r++)d=d.concat(this.get_node(a[r]).parents);d=e.vakata.array_remove_item(e.vakata.array_unique(d),"#"),o=d.length?e(this.element[0].querySelectorAll("#"+e.map(d,function(t){return-1!=="0123456789".indexOf(t[0])?"\\3"+t[0]+" "+t.substr(1).replace(e.jstree.idregex,"\\$&"):t.replace(e.jstree.idregex,"\\$&")}).join(", #"))):e(),this.element.find(".jstree-node").hide().filter(".jstree-last").filter(function(){return this.nextSibling}).removeClass("jstree-last"),o=o.add(this._data.search.dom),o.parentsUntil(".jstree").addBack().show().filter(".jstree-children").each(function(){e(this).children(".jstree-node:visible").eq(-1).addClass("jstree-last")})}},this)).on("search.jstree",e.proxy(function(t,i){this._data.search.som&&i.nodes.length&&(this.element.find(".jstree-node").hide().filter(".jstree-last").filter(function(){return this.nextSibling}).removeClass("jstree-last"),i.nodes.parentsUntil(".jstree").addBack().show().filter(".jstree-children").each(function(){e(this).children(".jstree-node:visible").eq(-1).addClass("jstree-last")}))},this)).on("clear_search.jstree",e.proxy(function(e,t){this._data.search.som&&t.nodes.length&&this.element.find(".jstree-node").css("display","").filter(".jstree-last").filter(function(){return this.nextSibling}).removeClass("jstree-last")},this))},this.search=function(i,r,s){if(i===!1||""===e.trim(""+i))return this.clear_search();i=""+i;var n=this.settings.search,a=n.ajax?n.ajax:!1,d=null,o=[],c=[],l,h;return this._data.search.res.length&&this.clear_search(),s===t&&(s=n.show_only_matches),r||a===!1?(this._data.search.str=i,this._data.search.dom=e(),this._data.search.res=[],this._data.search.opn=[],this._data.search.som=s,d=new e.vakata.search(i,!0,{caseSensitive:n.case_sensitive,fuzzy:n.fuzzy}),e.each(this._model.data,function(e,t){t.text&&(n.search_callback&&n.search_callback.call(this,i,t)||!n.search_callback&&d.search(t.text).isMatch)&&(!n.search_leaves_only||t.state.loaded&&0===t.children.length)&&(o.push(e),c=c.concat(t.parents))}),o.length&&(c=e.vakata.array_unique(c),this._search_open(c),this._data.search.dom=e(this.element[0].querySelectorAll("#"+e.map(o,function(t){return-1!=="0123456789".indexOf(t[0])?"\\3"+t[0]+" "+t.substr(1).replace(e.jstree.idregex,"\\$&"):t.replace(e.jstree.idregex,"\\$&")}).join(", #"))),this._data.search.res=o,this._data.search.dom.children(".jstree-anchor").addClass("jstree-search")),this.trigger("search",{nodes:this._data.search.dom,str:i,res:this._data.search.res,show_only_matches:s}),t):e.isFunction(a)?a.call(this,i,e.proxy(function(t){t&&t.d&&(t=t.d),this._load_nodes(e.isArray(t)?e.vakata.array_unique(t):[],func