sonarr-repo-only/NzbDrone.Web/Scripts/2010.2.825/telerik.treeview.min.js

1 line
12 KiB
JavaScript

(function(a){var b=a.telerik;b.treeview=function(e,f){this.element=e;var g=a(e);a.extend(this,f);var c=".t-in:not(.t-state-selected,.t-state-disabled)";a(".t-in.t-state-selected",e).live("mouseenter",b.preventDefault);g.delegate(c,"mouseenter",b.hover).delegate(c,"mouseleave",b.leave).delegate(c,"click",b.delegate(this,this.nodeSelect)).delegate("div:not(.t-state-disabled) .t-in","dblclick",b.delegate(this,this.nodeClick)).delegate(":checkbox","click",b.delegate(this,this.checkboxClick)).delegate(".t-plus, .t-minus","click",b.delegate(this,this.nodeClick));if(this.isAjax()){g.find(".t-plus").each(function(){var h=a(this.parentNode);h.parent().data("loaded",h.next(".t-group").length>0)})}if(this.dragAndDrop){b.bind(this,{nodeDragStart:this.onNodeDragStart,nodeDragging:this.onNodeDragging,nodeDragCancelled:this.onNodeDragCancelled,nodeDrop:this.onNodeDrop,nodeDropped:this.onNodeDropped});b.draganddrop(this.element.id,a.extend({useDragClue:true,draggables:a("div:not(.t-state-disabled) .t-in",e)},b.draganddrop.applyContext(b.draganddrop.treeview,this)))}var d=g.find(".t-item > .t-content");if(d.length>0&&a(d[0]).children().length==0){g.find(".t-icon").hide()}b.bind(this,{expand:this.onExpand,collapse:this.onCollapse,select:a.proxy(function(h){if(h.target==this.element&&this.onSelect){this.onSelect(h)}},this),checked:this.onChecked,error:this.onError,load:this.onLoad,dataBinding:this.onDataBinding,dataBound:this.onDataBound})};b.treeview.prototype={expand:function(c){a(c,this.element).each(a.proxy(function(f,g){var e=a(g);var d=e.find("> .t-group, > .t-content");if((d.length>0&&!d.is(":visible"))||this.isAjax()){this.nodeToggle(null,e)}},this))},collapse:function(c){a(c,this.element).each(a.proxy(function(f,g){var e=a(g);var d=e.find("> .t-group, > .t-content");if(d.length>0&&d.is(":visible")){this.nodeToggle(null,e)}},this))},enable:function(c){this.toggle(c,true)},disable:function(c){this.toggle(c,false)},toggle:function(d,c){a(d,this.element).each(a.proxy(function(f,g){var e=a(g);this.collapse(e);e.find("> div > .t-icon").toggleClass("t-state-default",c).toggleClass("t-state-disabled",!c);e.find("> div > .t-in").toggleClass("t-state-default",c).toggleClass("t-state-disabled",!c)},this))},reload:function(d){var c=this;a(d).each(function(){var e=a(this);e.find(".t-group").remove();c.ajaxRequest(e)})},shouldNavigate:function(d){var c=a(d).closest(".t-item").find("> .t-content, > .t-group");var e=a(d).attr("href");return !((e&&(e.charAt(e.length-1)=="#"||e.indexOf("#"+this.element.id+"-")!=-1))||(c.length>0&&c.children().length==0))},nodeSelect:function(f,d){if(!this.shouldNavigate(d)){f.preventDefault()}var c=a(d);if(!c.hasClass(".t-state-selected")&&!b.trigger(this.element,"select",{item:c.closest(".t-item")[0]})){a(".t-in",this.element).removeClass("t-state-hover t-state-selected");c.addClass("t-state-selected")}},nodeToggle:function(h,d,g){if(h!=null){h.preventDefault()}if(d.data("animating")||!d.find("> div > .t-icon").is(":visible")||d.find("> div > .t-in").hasClass("t-state-disabled")){return}d.data("animating",!g);var c=d.find("> .t-group, > .t-content");var f=!c.is(":visible");if(c.children().length>0&&d.data("loaded")!==false&&!b.trigger(this.element,f?"expand":"collapse",{item:d[0]})){d.find("> div > .t-icon").toggleClass("t-minus",f).toggleClass("t-plus",!f);if(!g){b.fx[f?"play":"rewind"](this.effects,c,{direction:"bottom"},function(){d.data("animating",false)})}else{c[f?"show":"hide"]()}}else{if(f&&this.isAjax()&&(c.length==0||d.data("loaded")===false)){this.ajaxRequest(d)}}},nodeClick:function(g,f){var d=a(f);var c=d.closest(".t-item");if(d.hasClass("t-plus-disabled")||d.hasClass("t-minus-disabled")){return}this.nodeToggle(g,c)},isAjax:function(){return this.ajax||this.ws||this.onDataBinding},url:function(c){return(this.ajax||this.ws)[c]},ajaxOptions:function(c,f){var d={type:"POST",dataType:"text",error:a.proxy(function(h,g){if(b.ajaxError(this.element,"error",h,g)){return}if(g=="parsererror"){alert("Error! The requested URL did not return JSON.")}},this),success:a.proxy(function(g){g=eval("("+g+")");g=g.d||g;this.dataBind(c,g)},this)};d=a.extend(d,f);var e=this.ws?d.data.node={}:d.data;if(c.hasClass("t-item")){e[this.queryString.value]=this.getItemValue(c);e[this.queryString.text]=this.getItemText(c)}if(this.ws){d.data=b.toJson(d.data);d.contentType="application/json; charset=utf-8"}return d},ajaxRequest:function(c){c=c||a(this.element);if(b.trigger(this.element,"dataBinding",{item:c[0]})||(!this.ajax&&!this.ws)){return}c.data("loadingIconTimeout",setTimeout(function(){c.find("> div > .t-icon").addClass("t-loading")},100));a.ajax(this.ajaxOptions(c,{data:{},url:this.url("selectUrl")}))},bindTo:function(c){var d=a(this.element);this.dataBind(d,c)},dataBind:function(c,g){c=a(c);if(g.length==0){a(".t-icon",c).hide();return}var d=c.find("> .t-group");var e=d.length==0;var f=new b.stringBuilder();b.treeview.getGroupHtml(g,f,this.isAjax(),c.hasClass("t-treeview"),this.showCheckBox,e?g[0].Expanded:false,e);c.data("animating",true);if(d.length>0&&c.data("loaded")===false){a(f.string()).prependTo(d)}else{if(d.length>0&&c.data("loaded")!==false){d.html(f.string())}else{if(d.length==0){d=a(f.string()).appendTo(c)}}}b.fx.play(this.effects,d,{direction:"bottom"},function(){c.data("animating",false)});clearTimeout(c.data("loadingIconTimeout"));if(c.hasClass("t-item")){c.data("loaded",true).find(".t-icon:first").removeClass("t-loading").removeClass("t-plus").addClass("t-minus")}b.trigger(this.element,"dataBound")},checkboxClick:function(g,d){var c=a(d).is(":checked");var f=b.trigger(this.element,"checked",{item:a(d).closest(".t-item")[0],checked:c});if(!f){this.nodeCheck(d,c)}else{g.preventDefault()}return f},nodeCheck:function(d,c){a(d,this.element).each(a.proxy(function(l,m){var h=a(m);var f=h.closest(".t-item");var k=a("> div > .t-checkbox",f);var j=this.element.id+"_checkedNodes";var g=k.find(':input[name="'+j+'.Index"]');var e=g.val();k.find(':input[name="'+j+"["+e+'].Text"]').remove();k.find(':input[name="'+j+"["+e+'].Value"]').remove();k.find(":checkbox").attr("checked",c?"checked":"");if(c){var i=new b.stringBuilder();i.cat('<input type="hidden" value="').cat(this.getItemValue(f)).cat('" name="'+j+"[").cat(e).cat('].Value" class="t-input">').cat('<input type="hidden" value="').cat(this.getItemText(f)).cat('" name="'+j+"[").cat(e).cat('].Text" class="t-input">');a(i.string()).appendTo(k)}},this))},getItemText:function(c){return a(c).find("> div > .t-in").text()},getItemValue:function(c){return a(c).find('>div>:input[name="itemValue"]').val()||this.getItemText(c)}};a.extend(b.draganddrop,{treeview:{shouldDrag:function(c){return true},createDragClue:function(c){return c.closest(".t-top,.t-mid,.t-bot").text()},onDragStart:function(d,f){var c=b.trigger(this.element,"nodeDragStart",{item:f.closest(".t-item")[0]});if(!c){this.$dropClue=a('<div class="t-drop-clue" />').appendTo(this.element)}return c},onDragMove:function(n,i){var o;b.trigger(this.element,"nodeDragging",{pageY:n.pageY,dropTarget:n.target,setStatusClass:function(e){o=e},item:i.closest(".t-item")[0]});if(o){this.$dropClue.css("visibility","hidden");return o}if(this.dragAndDrop.dropTargets&&a(n.target).closest(this.dragAndDrop.dropTargets).length>0){return"t-add"}if(!a.contains(this.element,n.target)){this.$dropClue.css("visibility","hidden");return}else{if(a.contains(i.closest(".t-item")[0],n.target)){this.$dropClue.css("visibility","hidden");return"t-denied"}}this.$dropClue.css("visibility","visible");var m="t-insert-middle";var c=a(n.target);var q=c.closest(".t-top,.t-mid,.t-bot");if(q.length>0){var f=q.outerHeight();var l=q.offset().top;var d=c.closest(".t-in");var h=f/(d.length>0?4:2);var p=n.pageY<(l+h);var k=(l+f-h)<n.pageY;var g=d.length>0&&!p&&!k;d.toggleClass("t-state-hover",g);this.$dropClue.css("visibility",g?"hidden":"visible");if(g){m="t-add";this.$dropTarget=c}else{var j=q.position();j.top+=p?0:f;this.$dropClue.css(j)[p?"prependTo":"appendTo"](c.closest(".t-item").find("> div:first"));m="t-insert-middle";if(p&&q.hasClass("t-top")){m="t-insert-top"}if(k&&q.hasClass("t-bot")){m="t-insert-bottom"}}}return m},onDragCancelled:function(c,d){b.trigger(this.element,"nodeDragCancelled",{item:d.closest(".t-item")[0]});this.$dropClue.remove()},onDrop:function(f,g,c){var d=b.trigger(this.element,"nodeDrop",{isValid:!c.find(".t-drag-status").hasClass("t-denied"),dropTarget:f.target,item:g.closest(".t-item")[0]});if(d||!a.contains(this.element,f.target)){this.$dropClue.remove();return d}return d?true:a.proxy(function(e){var l=g.closest(".t-top,.t-mid,.t-bot");var n=l.parent();var p=l.closest(".t-group");if(a.contains(n[0],f.target)){e();this.$dropClue.remove();return}if(n.hasClass("t-last")){n.removeClass("t-last").prev().addClass("t-last").find("> div").removeClass("t-top t-mid").addClass("t-bot")}var j="over";var i;if(this.$dropClue.css("visibility")=="visible"){var m=this.$dropClue.closest(".t-item");j=this.$dropClue.prevAll(".t-in").length>0?"after":"before";i=m.find("> div");m[j](n)}else{i=this.$dropTarget.closest(".t-top,.t-mid,.t-bot");var h=i.next(".t-group");if(h.length===0){h=a('<ul class="t-group" />').appendTo(i.parent());i.prepend('<span class="t-icon t-minus" />')}h.append(n);if(i.find("> .t-icon").hasClass("t-plus")){this.nodeToggle(null,i.parent(),true)}}b.trigger(this.element,"nodeDropped",{destinationItem:i.closest(".t-item")[0],dropPosition:j,item:l.parent(".t-item")[0]});var k=n.parents(".t-group").length;var o=function(r){var s=r.prev().length===0;var q=r.next().length===0;r.toggleClass("t-first",s&&k===1).toggleClass("t-last",q).find("> div").toggleClass("t-top",s&&!q).toggleClass("t-mid",!s&&!q).toggleClass("t-bot",q)};o(n);o(n.prev());o(n.next());if(p.children().length===0){p.prev("div").find(".t-plus,.t-minus").remove();p.remove()}e();this.$dropClue.remove()},this)}}});a.extend(b.treeview,{getItemHtml:function(i,f,g,d,h,e,c){f.cat('<li class="t-item').catIf(" t-first",d&&e==0).catIf(" t-last",e==c-1).cat('">').cat('<div class="').catIf("t-top ",d&&e==0).catIf("t-top",e!=c-1&&e==0).catIf("t-mid",e!=c-1&&e!=0).catIf("t-bot",e==c-1).cat('">');if((g&&i.LoadOnDemand)||(i.Items&&i.Items.length>0)){f.cat('<span class="t-icon').catIf(" t-plus",!i.Expanded).catIf(" t-minus",i.Expanded).catIf("-disabled",i.Enabled===false).cat('"></span>')}if(h&&i.Checkable!==false){f.cat('<input type="checkbox" value="').cat(i.Value).cat('" class="t-input').catIf(" t-state-disabled",i.Enabled===false).cat('"').catIf(' checked="checked"',i.Checked).cat("/>")}f.cat(i.NavigateUrl?'<a href="'+i.NavigateUrl+'" class="t-link ':'<span class="').cat("t-in").catIf(" t-state-disabled",i.Enabled===false).cat('">');if(i.ImageUrl!=null){f.cat('<img class="t-image" alt="" src="').cat(i.ImageUrl).cat('" />')}f.catIf(i.Text,i.Encoded===false).catIf(i.Text.replace(/</g,"&lt;").replace(/>/g,"&gt;"),i.Encoded!==false).cat(i.NavigateUrl?"</a>":"</span>");if(i.Value){f.cat('<input type="hidden" class="t-input" name="itemValue" value="').cat(i.Value).cat('" />')}f.cat("</div>");if(i.Items&&i.Items.length>0){b.treeview.getGroupHtml(i.Items,f,g,false,h,i.Expanded)}f.cat("</li>")},getGroupHtml:function(c,f,h,d,j,l,k){if(k!==false){f.cat('<ul class="t-group').catIf(" t-treeview-lines",d).cat('"').catIf(' style="display:none"',l===false).cat(">")}if(c&&c.length>0){var m=b.treeview.getItemHtml;for(var e=0,g=c.length;e<g;e++){m(c[e],f,h,d,j,e,g)}}if(k!==false){f.cat("</ul>")}}});a.fn.tTreeView=function(c){return b.create(this,{name:"tTreeView",init:function(d,e){return new b.treeview(d,e)},options:c,success:function(d){if(d.isAjax()&&a(d.element).find(".t-item").length==0){d.ajaxRequest()}}})};a.fn.tTreeView.defaults={effects:b.fx.property.defaults("height"),queryString:{text:"Text",value:"Value"}}})(jQuery);