jellyfin-web/dashboard-ui/bower_components/jstree/dist/jstree.js

5 lines
134 KiB
JavaScript
Raw Normal View History

2017-01-27 16:07:14 -07:00
!function(factory){"use strict";"function"==typeof define&&define.amd?define(["jquery"],factory):factory("object"==typeof exports?require("jquery"):jQuery)}(function($,undefined){"use strict";if(!$.jstree){var _temp1,_temp2,instance_counter=0,ccp_node=!1,ccp_mode=!1,ccp_inst=!1,themes_loaded=[],src=$("script:last").attr("src"),document=window.document,_node=document.createElement("LI");_node.setAttribute("role","treeitem"),_temp1=document.createElement("I"),_temp1.className="jstree-icon jstree-ocl",_temp1.setAttribute("role","presentation"),_node.appendChild(_temp1),_temp1=document.createElement("A"),_temp1.className="jstree-anchor",_temp1.setAttribute("href","#"),_temp1.setAttribute("tabindex","-1"),_temp2=document.createElement("I"),_temp2.className="jstree-icon jstree-themeicon",_temp2.setAttribute("role","presentation"),_temp1.appendChild(_temp2),_node.appendChild(_temp1),_temp1=_temp2=null,$.jstree={version:"3.1.1",defaults:{plugins:[]},plugins:{},path:src&&src.indexOf("/")!==-1?src.replace(/\/[^\/]+$/,""):"",idregex:/[\\:&!^|()\[\]<>@*'+~#";.,=\- \/${}%?`]/g},$.jstree.create=function(el,options){var tmp=new $.jstree.core(++instance_counter),opt=options;return options=$.extend(!0,{},$.jstree.defaults,options),opt&&opt.plugins&&(options.plugins=opt.plugins),$.each(options.plugins,function(i,k){"core"!==i&&(tmp=tmp.plugin(k,options[k]))}),$(el).data("jstree",tmp),tmp.init(el,options),tmp},$.jstree.destroy=function(){$(".jstree:jstree").jstree("destroy"),$(document).off(".jstree")},$.jstree.core=function(id){this._id=id,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}}},$.jstree.reference=function(needle){var tmp=null,obj=null;if(!needle||!needle.id||needle.tagName&&needle.nodeType||(needle=needle.id),!obj||!obj.length)try{obj=$(needle)}catch(ignore){}if(!obj||!obj.length)try{obj=$("#"+needle.replace($.jstree.idregex,"\\$&"))}catch(ignore){}return obj&&obj.length&&(obj=obj.closest(".jstree")).length&&(obj=obj.data("jstree"))?tmp=obj:$(".jstree").each(function(){var inst=$(this).data("jstree");if(inst&&inst._model.data[needle])return tmp=inst,!1}),tmp},$.fn.jstree=function(arg){var is_method="string"==typeof arg,args=Array.prototype.slice.call(arguments,1),result=null;return!(arg===!0&&!this.length)&&(this.each(function(){var instance=$.jstree.reference(this),method=is_method&&instance?instance[arg]:null;if(result=is_method&&method?method.apply(instance,args):null,instance||is_method||arg!==undefined&&!$.isPlainObject(arg)||$.jstree.create(this,arg),(instance&&!is_method||arg===!0)&&(result=instance||!1),null!==result&&result!==undefined)return!1}),null!==result&&result!==undefined?result:this)},$.expr[":"].jstree=$.expr.createPseudo(function(search){return function(a){return $(a).hasClass("jstree")&&$(a).data("jstree")!==undefined}}),$.jstree.defaults.core={data:!1,strings:!1,check_callback:!1,error:$.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,dblclick_toggle:!0},$.jstree.core.prototype={plugin:function(deco,opts){var Child=$.jstree.plugins[deco];return Child?(this._data[deco]={},Child.prototype=this,new Child(opts,this)):this},init:function(el,options){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=$(el).addClass("jstree jstree-"+this._id),this.settings=options,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._d
if(d&&d.children&&d.children.length){for(i=0,j=d.children.length;i<j;i++)c=this._parse_model_from_json(d.children[i],tmp.id,ps),e=m[c],tmp.children.push(c),e.children_d.length&&(tmp.children_d=tmp.children_d.concat(e.children_d));tmp.children_d=tmp.children_d.concat(tmp.children)}return d&&d.children&&d.children===!0&&(tmp.state.loaded=!1,tmp.children=[],tmp.children_d=[]),delete d.data,delete d.children,tmp.original=d,m[tmp.id]=tmp,tmp.state.selected&&this._data.core.selected.push(tmp.id),tmp.id},_redraw:function(){var tmp,i,j,nodes=this._model.force_full_redraw?this._model.data["#"].children.concat([]):this._model.changed.concat([]),f=document.createElement("UL"),fe=this._data.core.focused;for(i=0,j=nodes.length;i<j;i++)tmp=this.redraw_node(nodes[i],!0,this._model.force_full_redraw),tmp&&this._model.force_full_redraw&&f.appendChild(tmp);this._model.force_full_redraw&&(f.className=this.get_container_ul()[0].className,f.setAttribute("role","group"),this.element.empty().append(f)),null!==fe&&(tmp=this.get_node(fe,!0),tmp&&tmp.length&&tmp.children(".jstree-anchor")[0]!==document.activeElement?tmp.children(".jstree-anchor").focus():this._data.core.focused=null),this._model.force_full_redraw=!1,this._model.changed=[],this.trigger("redraw",{nodes:nodes})},redraw:function(full){full&&(this._model.force_full_redraw=!0),this._redraw()},draw_children:function(node){var obj=this.get_node(node),i=!1,j=!1,k=!1,d=document;if(!obj)return!1;if("#"===obj.id)return this.redraw(!0);if(node=this.get_node(node,!0),!node||!node.length)return!1;if(node.children(".jstree-children").remove(),node=node[0],obj.children.length&&obj.state.loaded){for(k=d.createElement("UL"),k.setAttribute("role","group"),k.className="jstree-children",i=0,j=obj.children.length;i<j;i++)k.appendChild(this.redraw_node(obj.children[i],!0,!0));node.appendChild(k)}},redraw_node:function(node,deep,is_callback,force_render){var obj=this.get_node(node),par=!1,ind=!1,old=!1,i=!1,j=!1,k=!1,c="",d=document,m=this._model.data,f=!1,tmp=null,t=0,l=0;if(!obj)return!1;if("#"===obj.id)return this.redraw(!0);if(deep=deep||0===obj.children.length,node=document.querySelector?this.element[0].querySelector("#"+("0123456789".indexOf(obj.id[0])!==-1?"\\3"+obj.id[0]+" "+obj.id.substr(1).replace($.jstree.idregex,"\\$&"):obj.id.replace($.jstree.idregex,"\\$&"))):document.getElementById(obj.id))node=$(node),is_callback||(par=node.parent().parent()[0],par===this.element[0]&&(par=null),ind=node.index()),deep||!obj.children.length||node.children(".jstree-children").length||(deep=!0),deep||(old=node.children(".jstree-children")[0]),f=node.children(".jstree-anchor")[0]===document.activeElement,node.remove();else if(deep=!0,!is_callback){if(par="#"!==obj.parent?$("#"+obj.parent.replace($.jstree.idregex,"\\$&"),this.element)[0]:null,!(null===par||par&&m[obj.parent].state.opened))return!1;ind=$.inArray(obj.id,null===par?m["#"].children:m[obj.parent].children)}node=_node.cloneNode(!0),c="jstree-node ";for(i in obj.li_attr)if(obj.li_attr.hasOwnProperty(i)){if("id"===i)continue;"class"!==i?node.setAttribute(i,obj.li_attr[i]):c+=obj.li_attr[i]}obj.a_attr.id||(obj.a_attr.id=obj.id+"_anchor"),node.setAttribute("aria-selected",!!obj.state.selected),node.setAttribute("aria-level",obj.parents.length),node.setAttribute("aria-labelledby",obj.a_attr.id),obj.state.disabled&&node.setAttribute("aria-disabled",!0),obj.state.loaded&&!obj.children.length?c+=" jstree-leaf":(c+=obj.state.opened&&obj.state.loaded?" jstree-open":" jstree-closed",node.setAttribute("aria-expanded",obj.state.opened&&obj.state.loaded)),null!==obj.parent&&m[obj.parent].children[m[obj.parent].children.length-1]===obj.id&&(c+=" jstree-last"),node.id=obj.id,node.className=c,c=(obj.state.selected?" jstree-clicked":"")+(obj.state.disabled?" jstree-disabled":"");for(j in obj.a_attr)if(obj.a_attr.hasOwnProperty(j)){if("href"===j&&"#"===obj.a_attr[j])continue;"class"!==j?node.childNodes[1].setAttribute(j,obj.a_attr[j]):c+=" "+obj.a_attr[j]}if(c.length&&(node.childNodes[1].className="jstree-anchor "+c),(obj.icon&&obj.icon!==!0||obj.icon===!1)&&(obj.icon
i=0,j=new_par.children.length;i<j;i++)dpc[i>=pos?i+1:i]=new_par.children[i];return dpc[pos]=tmp.id,new_par.children=dpc,new_par.children_d.push(tmp.id),new_par.children_d=new_par.children_d.concat(tmp.children_d),"#"===new_par.id&&(this._model.force_full_redraw=!0),this._model.force_full_redraw||this._node_changed(new_par.id),skip_redraw||this.redraw("#"===new_par.id),callback&&callback.call(this,tmp,new_par,pos),this.trigger("copy_node",{node:tmp,original:obj,parent:new_par.id,position:pos,old_parent:old_par,old_position:old_ins&&old_ins._id&&old_par&&old_ins._model.data[old_par]&&old_ins._model.data[old_par].children?$.inArray(obj.id,old_ins._model.data[old_par].children):-1,is_multi:old_ins&&old_ins._id&&old_ins._id!==this._id,is_foreign:!old_ins||!old_ins._id,old_instance:old_ins,new_instance:this}),tmp.id},cut:function(obj){if(obj||(obj=this._data.core.selected.concat()),$.isArray(obj)||(obj=[obj]),!obj.length)return!1;var o,t1,t2,tmp=[];for(t1=0,t2=obj.length;t1<t2;t1++)o=this.get_node(obj[t1]),o&&o.id&&"#"!==o.id&&tmp.push(o);return!!tmp.length&&(ccp_node=tmp,ccp_inst=this,ccp_mode="move_node",void this.trigger("cut",{node:obj}))},copy:function(obj){if(obj||(obj=this._data.core.selected.concat()),$.isArray(obj)||(obj=[obj]),!obj.length)return!1;var o,t1,t2,tmp=[];for(t1=0,t2=obj.length;t1<t2;t1++)o=this.get_node(obj[t1]),o&&o.id&&"#"!==o.id&&tmp.push(o);return!!tmp.length&&(ccp_node=tmp,ccp_inst=this,ccp_mode="copy_node",void this.trigger("copy",{node:obj}))},get_buffer:function(){return{mode:ccp_mode,node:ccp_node,inst:ccp_inst}},can_paste:function(){return ccp_mode!==!1&&ccp_node!==!1},paste:function(obj,pos){return obj=this.get_node(obj),!!(obj&&ccp_mode&&ccp_mode.match(/^(copy_node|move_node)$/)&&ccp_node)&&(this[ccp_mode](ccp_node,obj,pos,!1,!1,!1,ccp_inst)&&this.trigger("paste",{parent:obj.id,node:ccp_node,mode:ccp_mode}),ccp_node=!1,ccp_mode=!1,void(ccp_inst=!1))},clear_buffer:function(){ccp_node=!1,ccp_mode=!1,ccp_inst=!1,this.trigger("clear_buffer")},edit:function(obj,default_text,callback){var rtl,w,a,s,t,h1,h2,fn,tmp;return!!(obj=this.get_node(obj))&&(this.settings.core.check_callback===!1?(this._data.core.last_error={error:"check",plugin:"core",id:"core_07",reason:"Could not edit node because of check_callback"},this.settings.core.error.call(this,this._data.core.last_error),!1):(tmp=obj,default_text="string"==typeof default_text?default_text:obj.text,this.set_text(obj,""),obj=this._open_to(obj),tmp.text=default_text,rtl=this._data.core.rtl,w=this.element.width(),a=obj.children(".jstree-anchor"),s=$("<span>"),t=default_text,h1=$("<div />",{css:{position:"absolute",top:"-200px",left:rtl?"0px":"-1000px",visibility:"hidden"}}).appendTo("body"),h2=$("<input />",{value:t,class:"jstree-rename-input",css:{padding:"0",border:"1px solid silver","box-sizing":"border-box",display:"inline-block",height:this._data.core.li_height+"px",lineHeight:this._data.core.li_height+"px",width:"150px"},blur:$.proxy(function(){var nv,i=s.children(".jstree-rename-input"),v=i.val(),f=this.settings.core.force_text;""===v&&(v=t),h1.remove(),s.replaceWith(a),s.remove(),t=f?t:$("<div></div>").append($.parseHTML(t)).html(),this.set_text(obj,t),nv=!!this.rename_node(obj,f?$("<div></div>").text(v).text():$("<div></div>").append($.parseHTML(v)).html()),nv||this.set_text(obj,t),callback&&callback.call(this,tmp,nv)},this),keydown:function(event){var key=event.which;27===key&&(this.value=t),27!==key&&13!==key&&37!==key&&38!==key&&39!==key&&40!==key&&32!==key||event.stopImmediatePropagation(),27!==key&&13!==key||(event.preventDefault(),this.blur())},click:function(e){e.stopImmediatePropagation()},mousedown:function(e){e.stopImmediatePropagation()},keyup:function(event){h2.width(Math.min(h1.text("pW"+this.value).width(),w))},keypress:function(event){if(13===event.which)return!1}}),fn={fontFamily:a.css("fontFamily")||"",fontSize:a.css("fontSize")||"",fontWeight:a.css("fontWeight")||"",fontStyle:a.css("fontStyle")||"",fontStretch:a.css("fontStretch")||"",fontVariant:a.css("fontVariant")||"",letterSpacing:a.css("letterSpacing")||"",wordSpacing:a.
y+h+10>dh&&e.css("bottom","-1px"),e.show()}},show:function(reference,position,data){var o,e,x,y,w,h,dw,dh,cond=!0;switch(vakata_context.element&&vakata_context.element.length&&vakata_context.element.width(""),cond){case!position&&!reference:return!1;case!!position&&!!reference:vakata_context.reference=reference,vakata_context.position_x=position.x,vakata_context.position_y=position.y;break;case!position&&!!reference:vakata_context.reference=reference,o=reference.offset(),vakata_context.position_x=o.left+reference.outerHeight(),vakata_context.position_y=o.top;break;case!!position&&!reference:vakata_context.position_x=position.x,vakata_context.position_y=position.y}reference&&!data&&$(reference).data("vakata_contextmenu")&&(data=$(reference).data("vakata_contextmenu")),$.vakata.context._parse(data)&&vakata_context.element.html(vakata_context.html),vakata_context.items.length&&(vakata_context.element.appendTo("body"),e=vakata_context.element,x=vakata_context.position_x,y=vakata_context.position_y,w=e.width(),h=e.height(),dw=$(window).width()+$(window).scrollLeft(),dh=$(window).height()+$(window).scrollTop(),right_to_left&&(x-=e.outerWidth()-$(reference).outerWidth(),x<$(window).scrollLeft()+20&&(x=$(window).scrollLeft()+20)),x+w+20>dw&&(x=dw-(w+20)),y+h+20>dh&&(y=dh-(h+20)),vakata_context.element.css({left:x,top:y}).show().find("a").first().focus().parent().addClass("vakata-context-hover"),vakata_context.is_visible=!0,$.vakata.context._trigger("show"))},hide:function(){vakata_context.is_visible&&(vakata_context.element.hide().find("ul").hide().end().find(":focus").blur().end().detach(),vakata_context.is_visible=!1,$.vakata.context._trigger("hide"))}},$(function(){right_to_left="rtl"===$("body").css("direction");var to=!1;vakata_context.element=$("<ul class='vakata-context'></ul>"),vakata_context.element.on("mouseenter","li",function(e){e.stopImmediatePropagation(),$.contains(this,e.relatedTarget)||(to&&clearTimeout(to),vakata_context.element.find(".vakata-context-hover").removeClass("vakata-context-hover").end(),$(this).siblings().find("ul").hide().end().end().parentsUntil(".vakata-context","li").addBack().addClass("vakata-context-hover"),$.vakata.context._show_submenu(this))}).on("mouseleave","li",function(e){$.contains(this,e.relatedTarget)||$(this).find(".vakata-context-hover").addBack().removeClass("vakata-context-hover")}).on("mouseleave",function(e){$(this).find(".vakata-context-hover").removeClass("vakata-context-hover"),$.vakata.context.settings.hide_onmouseleave&&(to=setTimeout(function(t){return function(){$.vakata.context.hide()}}(this),$.vakata.context.settings.hide_onmouseleave))}).on("click","a",function(e){e.preventDefault(),$(this).blur().parent().hasClass("vakata-context-disabled")||$.vakata.context._execute($(this).attr("rel"))===!1||$.vakata.context.hide()}).on("keydown","a",function(e){var o=null;switch(e.which){case 13:case 32:e.type="mouseup",e.preventDefault(),$(e.currentTarget).trigger(e);break;case 37:vakata_context.is_visible&&(vakata_context.element.find(".vakata-context-hover").last().closest("li").first().find("ul").hide().find(".vakata-context-hover").removeClass("vakata-context-hover").end().end().children("a").focus(),e.stopImmediatePropagation(),e.preventDefault());break;case 38:vakata_context.is_visible&&(o=vakata_context.element.find("ul:visible").addBack().last().children(".vakata-context-hover").removeClass("vakata-context-hover").prevAll("li:not(.vakata-context-separator)").first(),o.length||(o=vakata_context.element.find("ul:visible").addBack().last().children("li:not(.vakata-context-separator)").last()),o.addClass("vakata-context-hover").children("a").focus(),e.stopImmediatePropagation(),e.preventDefault());break;case 39:vakata_context.is_visible&&(vakata_context.element.find(".vakata-context-hover").last().children("ul").show().children("li:not(.vakata-context-separator)").removeClass("vakata-context-hover").first().addClass("vakata-context-hover").children("a").focus(),e.stopImmediatePropagation(),e.preventDefault());break;case 40:vakata_context.is_visible&&(o=vakata_context.elemen
tmp[i].a_attr&&tmp[i].a_attr.id&&delete tmp[i].a_attr.id);else tmp.type=tmp.id&&m[tmp.id]&&m[tmp.id].type?m[tmp.id].type:"default",options&&options.no_id&&(tmp=this._delete_ids(tmp));return tmp},this._delete_ids=function(tmp){if($.isArray(tmp)){for(var i=0,j=tmp.length;i<j;i++)tmp[i]=this._delete_ids(tmp[i]);return tmp}return delete tmp.id,tmp.li_attr&&tmp.li_attr.id&&delete tmp.li_attr.id,tmp.a_attr&&tmp.a_attr.id&&delete tmp.a_attr.id,tmp.children&&$.isArray(tmp.children)&&(tmp.children=this._delete_ids(tmp.children)),tmp},this.check=function(chk,obj,par,pos,more){if(parent.check.call(this,chk,obj,par,pos,more)===!1)return!1;obj=obj&&obj.id?obj:this.get_node(obj),par=par&&par.id?par:this.get_node(par);var tmp,d,i,j,m=obj&&obj.id?more&&more.origin?more.origin:$.jstree.reference(obj.id):null;switch(m=m&&m._model&&m._model.data?m._model.data:null,chk){case"create_node":case"move_node":case"copy_node":if("move_node"!==chk||$.inArray(obj.id,par.children)===-1){if(tmp=this.get_rules(par),tmp.max_children!==undefined&&tmp.max_children!==-1&&tmp.max_children===par.children.length)return this._data.core.last_error={error:"check",plugin:"types",id:"types_01",reason:"max_children prevents function: "+chk,data:JSON.stringify({chk:chk,pos:pos,obj:!(!obj||!obj.id)&&obj.id,par:!(!par||!par.id)&&par.id})},!1;if(tmp.valid_children!==undefined&&tmp.valid_children!==-1&&$.inArray(obj.type||"default",tmp.valid_children)===-1)return this._data.core.last_error={error:"check",plugin:"types",id:"types_02",reason:"valid_children prevents function: "+chk,data:JSON.stringify({chk:chk,pos:pos,obj:!(!obj||!obj.id)&&obj.id,par:!(!par||!par.id)&&par.id})},!1;if(m&&obj.children_d&&obj.parents){for(d=0,i=0,j=obj.children_d.length;i<j;i++)d=Math.max(d,m[obj.children_d[i]].parents.length);d=d-obj.parents.length+1}(d<=0||d===undefined)&&(d=1);do{if(tmp.max_depth!==undefined&&tmp.max_depth!==-1&&tmp.max_depth<d)return this._data.core.last_error={error:"check",plugin:"types",id:"types_03",reason:"max_depth prevents function: "+chk,data:JSON.stringify({chk:chk,pos:pos,obj:!(!obj||!obj.id)&&obj.id,par:!(!par||!par.id)&&par.id})},!1;par=this.get_node(par.parent),tmp=this.get_rules(par),d++}while(par)}}return!0},this.get_rules=function(obj){if(obj=this.get_node(obj),!obj)return!1;var tmp=this.get_type(obj,!0);return tmp.max_depth===undefined&&(tmp.max_depth=-1),tmp.max_children===undefined&&(tmp.max_children=-1),tmp.valid_children===undefined&&(tmp.valid_children=-1),tmp},this.get_type=function(obj,rules){return obj=this.get_node(obj),!!obj&&(rules?$.extend({type:obj.type},this.settings.types[obj.type]):obj.type)},this.set_type=function(obj,type){var t,t1,t2,old_type,old_icon;if($.isArray(obj)){for(obj=obj.slice(),t1=0,t2=obj.length;t1<t2;t1++)this.set_type(obj[t1],type);return!0}return t=this.settings.types,obj=this.get_node(obj),!(!t[type]||!obj)&&(old_type=obj.type,old_icon=this.get_icon(obj),obj.type=type,(old_icon===!0||t[old_type]&&t[old_type].icon!==undefined&&old_icon===t[old_type].icon)&&this.set_icon(obj,t[type].icon===undefined||t[type].icon),!0)}},$.jstree.defaults.unique={case_sensitive:!1,duplicate:function(name,counter){return name+" ("+counter+")"}},$.jstree.plugins.unique=function(options,parent){this.check=function(chk,obj,par,pos,more){if(parent.check.call(this,chk,obj,par,pos,more)===!1)return!1;if(obj=obj&&obj.id?obj:this.get_node(obj),par=par&&par.id?par:this.get_node(par),!par||!par.children)return!0;var i,j,n="rename_node"===chk?pos:obj.text,c=[],s=this.settings.unique.case_sensitive,m=this._model.data;for(i=0,j=par.children.length;i<j;i++)c.push(s?m[par.children[i]].text:m[par.children[i]].text.toLowerCase());switch(s||(n=n.toLowerCase()),chk){case"delete_node":return!0;case"rename_node":return i=$.inArray(n,c)===-1||obj.text&&obj.text[s?"toString":"toLowerCase"]()===n,i||(this._data.core.last_error={error:"check",plugin:"unique",id:"unique_01",reason:"Child with name "+n+" already exists. Preventing: "+chk,data:JSON.stringify({chk:chk,pos:pos,obj:!(!obj||!obj.id)&&obj.id,par:!(!par||!par.id)&&par.id})}),i;case"create_node":return i=$