1
0
Fork 0
mirror of https://github.com/Radarr/Radarr synced 2024-12-28 10:51:48 +00:00
Radarr/NzbDrone.Web/Scripts/2011.3.1115/telerik.treeview.min.js
2011-11-22 17:51:44 -08:00

1 line
No EOL
14 KiB
JavaScript

(function(a){var b=a.telerik;b.scripts.push("telerik.treeview.js");function c(d){d.find(".t-plus").each(function(){var e=a(this.parentNode);e.parent().data("loaded",e.next(".t-group").length>0)})}b.treeview=function(f,g){this.element=f;var d=a(f);a.extend(this,g);var e=".t-in:not(.t-state-selected,.t-state-disabled)";a(".t-in.t-state-selected",f).live("mouseenter",b.preventDefault);d.delegate(e,"mouseenter",b.hover).delegate(e,"mouseleave",b.leave).delegate(e,"click",b.delegate(this,this.nodeSelect)).delegate("div:not(.t-state-disabled) .t-in","dblclick",b.delegate(this,this.nodeClick)).delegate(":checkbox","click",a.proxy(this.checkboxClick,this)).delegate(".t-plus, .t-minus",b.isTouch?"touchend":"click",b.delegate(this,this.nodeClick));if(this.isAjax()){c(d)}if(this.dragAndDrop){b.bind(this,{nodeDragStart:this.onNodeDragStart,nodeDragging:this.onNodeDragging,nodeDragCancelled:this.onNodeDragCancelled,nodeDrop:this.onNodeDrop,nodeDropped:this.onNodeDropped});(function(m){var h=a("<div class='t-drop-clue' />");var i;function k(n){if(b.trigger(m.element,"nodeDragStart",{item:n.$draggable.closest(".t-item")[0]})){return false}h.appendTo(m.element)}function j(p){var y;i=a(b.eventTarget(p));if(m.dragAndDrop.dropTargets&&i.closest(m.dragAndDrop.dropTargets).length>0){y="t-add"}else{if(!a.contains(m.element,i[0])){y="t-denied"}else{if(a.contains(p.$draggable.closest(".t-item")[0],i[0])){y="t-denied"}else{y="t-insert-middle";h.css("visibility","visible");var q=i.closest(".t-top,.t-mid,.t-bot");if(q.length){var v=q.outerHeight(),w=q.offset().top,u=i.closest(".t-in"),o=v/(u.length>0?4:2),x=b.touchLocation(p),t=x.y<(w+o),s=(w+v-o)<x.y,n=u.length>0&&!t&&!s;q.siblings(".t-top,.t-mid,.t-bot").children(".t-state-hover").removeClass("t-state-hover");u.toggleClass("t-state-hover",n);h.css("visibility",n?"hidden":"visible");if(n){y="t-add"}else{var r=q.position();r.top+=t?0:v;h.css(r)[t?"prependTo":"appendTo"](i.closest(".t-item").find("> div:first"));if(t&&q.hasClass("t-top")){y="t-insert-top"}if(s&&q.hasClass("t-bot")){y="t-insert-bottom"}}}}}}b.trigger(m.element,"nodeDragging",{pageY:p.pageY,pageX:p.pageX,dropTarget:i[0],status:y.substring(2),setStatusClass:function(z){y=z},item:p.$draggable.closest(".t-item")[0]});if(y.indexOf("t-insert")!=0){h.css("visibility","hidden")}b.dragCueStatus(p.$cue,y)}function l(p){if(p.keyCode==27){b.trigger(m.element,"nodeDragCancelled",{item:p.$draggable.closest(".t-item")[0]})}else{var o="over",n,x=b.eventTarget(p);if(h.css("visibility")=="visible"){o=h.prevAll(".t-in").length>0?"after":"before";n=h.closest(".t-item").find("> div")}else{if(i){n=i.closest(".t-top,.t-mid,.t-bot")}}var r=!p.$cue.find(".t-drag-status").hasClass("t-denied"),q=b.trigger(m.element,"nodeDrop",{isValid:r,dropTarget:x,destinationItem:n.parent()[0],dropPosition:o,item:p.$draggable.closest(".t-item")[0]});if(!r){return false}if(q||!a.contains(m.element,x)){return !q}var w=p.$draggable.closest(".t-top,.t-mid,.t-bot");var t=w.parent();var v=w.closest(".t-group");if(a.contains(t[0],x)){return false}if(t.hasClass("t-last")){t.removeClass("t-last").prev().addClass("t-last").find("> div").removeClass("t-top t-mid").addClass("t-bot")}if(h.css("visibility")=="visible"){n.parent()[o](t)}else{var y=n.next(".t-group");if(y.length===0){y=a('<ul class="t-group" />').appendTo(n.parent());if(!m.isAjax()){n.prepend('<span class="t-icon t-minus" />')}else{y.hide();m.nodeToggle(null,n.parent(),true);y.show()}}y.append(t);if(n.find("> .t-icon").hasClass("t-plus")){m.nodeToggle(null,n.parent(),true)}}var s=t.parents(".t-group").length;function u(B){var z=B.prev().length===0;var A=B.next().length===0;B.toggleClass("t-first",z&&s===1).toggleClass("t-last",A).find("> div").toggleClass("t-top",z&&!A).toggleClass("t-mid",!z&&!A).toggleClass("t-bot",A)}u(t);u(t.prev());u(t.next());if(v.children().length===0){v.prev("div").find(".t-plus,.t-minus").remove();v.remove()}if(b.isTouch){n.children(".t-in").removeClass("t-state-hover")}b.trigger(m.element,"nodeDropped",{destinationItem:n.closest(".t-item")[0],dropPosition:o,item:w.parent(".t-item")[0]});return false}}new b.draggable({owner:m.element,selector:"div:not(.t-state-disabled) .t-in",scope:m.element.id,cue:function(n){return b.dragCue(n.$draggable.text())},start:k,drag:j,stop:l,destroy:function(n){h.remove();n.$cue.remove()}})})(this)}b.bind(this,{expand:this.onExpand,collapse:this.onCollapse,select:a.proxy(function(h){if(h.target==this.element&&this.onSelect){a.proxy(this.onSelect,this.element)(h)}},this),checked:this.onChecked,error:this.onError,load:this.onLoad,dataBinding:this.onDataBinding,dataBound:this.onDataBound})};b.treeview.prototype={expand:function(d){a(d,this.element).each(a.proxy(function(g,h){var e=a(h);var f=e.find("> .t-group, > .t-content");if((f.length>0&&!f.is(":visible"))||this.isAjax()){this.nodeToggle(null,e)}},this))},collapse:function(d){a(d,this.element).each(a.proxy(function(g,h){var e=a(h),f=e.find("> .t-group, > .t-content");if(f.length>0&&f.is(":visible")){this.nodeToggle(null,e)}},this))},enable:function(d){this.toggle(d,true)},disable:function(d){this.toggle(d,false)},toggle:function(e,d){a(e,this.element).each(a.proxy(function(h,j){var f=a(j),i=!f.find("> .t-group, > .t-content").is(":visible");if(!d){this.collapse(f);i=true}f.find("> div > .t-in").toggleClass("t-state-default",d).toggleClass("t-state-disabled",!d).end().find("> div > .t-icon").toggleClass("t-plus",i&&d).toggleClass("t-plus-disabled",i&&!d).toggleClass("t-minus",!i&&d).toggleClass("t-minus-disabled",!i&&!d);var g=f.find("> div > .t-checkbox > :checkbox");if(d){g.removeAttr("disabled")}else{g.attr("disabled","disabled")}},this))},reload:function(d){var e=this;a(d).each(function(){var f=a(this);f.find(".t-group").remove();e.ajaxRequest(f)})},shouldNavigate:function(e){var d=a(e).closest(".t-item").find("> .t-content, > .t-group");var f=a(e).attr("href");return !((f&&(f.charAt(f.length-1)=="#"||f.indexOf("#"+this.element.id+"-")!=-1))||(d.length>0&&d.children().length==0))},nodeSelect:function(f,g){if(!this.shouldNavigate(g)){f.preventDefault()}var d=a(g);if(!d.hasClass(".t-state-selected")&&!b.trigger(this.element,"select",{item:d.closest(".t-item")[0]})){a(".t-in",this.element).removeClass("t-state-hover t-state-selected");d.addClass("t-state-selected")}},nodeToggle:function(g,d,i){if(d.find(".t-minus").length==0&&d.find(".t-plus").length==0){return}if(g!=null){g.preventDefault()}if(d.data("animating")||d.find("> div > .t-in").hasClass("t-state-disabled")){return}d.data("animating",!i);var f=d.find(">.t-group, >.t-content, >.t-animation-container>.t-group, >.t-animation-container>.t-content"),h=!f.is(":visible");if(f.children().length>0&&d.data("loaded")!==false){if(!b.trigger(this.element,h?"expand":"collapse",{item:d[0]})){d.find("> div > .t-icon").toggleClass("t-minus",h).toggleClass("t-plus",!h);if(!i){b.fx[h?"play":"rewind"](this.effects,f,{direction:"bottom"},function(){d.data("animating",false)})}else{f[h?"show":"hide"]()}}else{d.data("animating",false)}}else{if(h&&this.isAjax()&&(f.length==0||d.data("loaded")===false)){if(!b.trigger(this.element,h?"expand":"collapse",{item:d[0]})){this.ajaxRequest(d)}else{d.data("animating",false)}}}},nodeClick:function(g,h){var d=a(h),f=d.closest(".t-item");if(d.hasClass("t-plus-disabled")||d.hasClass("t-minus-disabled")){return}this.nodeToggle(g,f)},isAjax:function(){return this.ajax||this.ws||this.onDataBinding},url:function(d){return(this.ajax||this.ws)[d]},ajaxOptions:function(d,g){var h={type:"POST",dataType:"text",error:a.proxy(function(j,i){if(b.ajaxError(this.element,"error",j,i)){return}if(i=="parsererror"){alert("Error! The requested URL did not return JSON.")}},this),success:a.proxy(function(i){i=eval("("+i+")");i=i.d||i;this.dataBind(d,i)},this),complete:function(){d.data("animating",false)}};h=a.extend(h,g);var f=this.ws?h.data.node={}:h.data;if(d.hasClass("t-item")){f[this.queryString.value]=this.getItemValue(d);f[this.queryString.text]=this.getItemText(d);var e=d.find(".t-checkbox:first :checkbox");if(e.length){f[this.queryString.checked]=e.is(":checked")}}if(this.ws){h.data=b.toJson(h.data);h.contentType="application/json; charset=utf-8"}return h},ajaxRequest:function(d){d=d||a(this.element);var f={item:d[0]};if(b.trigger(this.element,"dataBinding",f)||(!this.ajax&&!this.ws)){return}d.data("loadingIconTimeout",setTimeout(function(){d.find("> div > .t-icon").addClass("t-loading")},100));a.ajax(this.ajaxOptions(d,{data:a.extend({},f.data),url:this.url("selectUrl")}))},bindTo:function(d){this.dataBind(this.element,d)},dataBind:function(d,e){d=a(d);var f=d.find("> .t-group"),i=d.find("> div > .t-icon");hasData=e.length>0;if(e.length==0){i.remove();f.remove();return}else{if(i.length==0){d.find("> div").prepend('<span class="t-icon t-plus" />')}}var g=new b.stringBuilder(),k=f.length==0,h=d.find('> div > .t-checkbox :input[name="'+this.element.id+'_checkedNodes.Index"]').val();if(!h&&d[0]!=this.element){var l=d.parentsUntil(".t-treeview",".t-item").andSelf().map(function(n,m){return a(m).index()});h=Array.prototype.join.call(l,":")}var j=(k?d.eq(0).is(".t-treeview")?true:e[0].Expanded:false);b.treeview.getGroupHtml({data:e,html:g,isAjax:this.isAjax(),isFirstLevel:d.hasClass("t-treeview"),showCheckBoxes:this.showCheckBox,groupLevel:h,isExpanded:j,renderGroup:k,elementId:this.element.id});if(f.length>0&&d.data("loaded")===false){a(g.string()).prependTo(f)}else{if(f.length>0&&d.data("loaded")!==false){f.html(g.string())}else{if(f.length==0){f=a(g.string()).appendTo(d)}}}d.data("animating",true);b.fx.play(this.effects,f,{direction:"bottom"},function(){d.data("animating",false)});clearTimeout(d.data("loadingIconTimeout"));if(d.hasClass("t-item")){d.data("loaded",true).find(".t-icon:first").removeClass("t-loading").removeClass("t-plus").addClass("t-minus")}if(this.isAjax()){c(d)}b.trigger(this.element,"dataBound",{item:d[0]})},checkboxClick:function(d){var f=a(d.target),g=f.is(":checked");var h=b.trigger(this.element,"checked",{item:f.closest(".t-item")[0],checked:g});if(!h){this.nodeCheck(f,g)}else{d.preventDefault()}},nodeCheck:function(e,d){a(e,this.element).each(a.proxy(function(j,k){var g=a(k).closest(".t-item"),f=a("> div > .t-checkbox",g),h=this.element.id+"_checkedNodes",j=f.find(':input[name="'+h+'.Index"]').val(),i=f.find(":checkbox");f.find("[type=hidden]").filter(function(){return(a(this).attr("name").indexOf(h+"["+j+"].")>-1)}).remove();i.attr("value",d?"True":"False");if(d){i.attr("checked","checked");a(b.treeview.getNodeInputsHtml(this.getItemValue(g),this.getItemText(g),h,j)).appendTo(f)}else{i.attr("checked",false)}},this))},getItemText:function(d){return a(d).find("> div > .t-in").text()},getItemValue:function(d){return a(d).find('>div>:input[name="itemValue"]').val()||this.getItemText(d)},findByText:function(d){return a(this.element).find(".t-in").filter(function(f,e){return a(e).text()==d}).closest(".t-item")},findByValue:function(d){return a(this.element).find("input[name='itemValue']").filter(function(f,e){return a(e).val()==d}).closest(".t-item")}};a.extend(b.treeview,{getNodeInputsHtml:function(f,e,d,g){return new b.stringBuilder().cat('<input type="hidden" value="').cat(f).cat('" name="'+d+"[").cat(g).cat('].Value" class="t-input">').cat('<input type="hidden" value="').cat(e).cat('" name="'+d+"[").cat(g).cat('].Text" class="t-input">').string()},getItemHtml:function(m){var i=m.item,g=m.html,h=m.isFirstLevel,f=m.groupLevel,j=m.itemIndex,k=m.itemsCount,d=new b.stringBuilder().cat(f).catIf(":",f).cat(j).string();g.cat('<li class="t-item').catIf(" t-first",h&&j==0).catIf(" t-last",j==k-1).cat('">').cat('<div class="').catIf("t-top ",h&&j==0).catIf("t-top",j!=k-1&&j==0).catIf("t-mid",j!=k-1&&j!=0).catIf("t-bot",j==k-1).cat('">');if((m.isAjax&&i.LoadOnDemand)||(i.Items&&i.Items.length>0)){g.cat('<span class="t-icon').catIf(" t-plus",i.Expanded!==true).catIf(" t-minus",i.Expanded===true).catIf("-disabled",i.Enabled===false).cat('"></span>')}if(m.showCheckBoxes&&i.Checkable!==false){var e=m.elementId+"_checkedNodes";g.cat('<span class="t-checkbox">').cat('<input type="hidden" value="').cat(d).cat('" name="').cat(e).cat(".Index").cat('" class="t-input"/>').cat('<input type="checkbox" value="').cat(i.Checked===true?"True":"False").cat('" class="t-input').cat('" name="').cat(e).cat("[").cat(d).cat('].Checked"').catIf(' disabled="disabled"',i.Enabled===false).catIf(' checked="checked"',i.Checked).cat("/>");if(i.Checked){g.cat(b.treeview.getNodeInputsHtml(i.Value,i.Text,e,d))}g.cat("</span>")}var l=i.NavigateUrl||i.Url;g.cat(l?'<a href="'+l+'" class="t-link ':'<span class="').cat("t-in").catIf(" t-state-disabled",i.Enabled===false).catIf(" t-state-selected",i.Selected===true).cat('">');if(i.ImageUrl!=null){g.cat('<img class="t-image" alt="" src="').cat(i.ImageUrl).cat('" />')}if(i.SpriteCssClasses!=null){g.cat('<span class="t-sprite ').cat(i.SpriteCssClasses).cat('"></span>')}g.catIf(i.Text,i.Encoded===false).catIf(i.Text.replace(/</g,"&lt;").replace(/>/g,"&gt;"),i.Encoded!==false).cat(l?"</a>":"</span>");if(i.Value){g.cat('<input type="hidden" class="t-input" name="itemValue" value="').cat(i.Value).cat('" />')}g.cat("</div>");if(i.Items&&i.Items.length>0){b.treeview.getGroupHtml({data:i.Items,html:g,isAjax:m.isAjax,isFirstLevel:false,showCheckBoxes:m.showCheckBoxes,groupLevel:d,isExpanded:i.Expanded,elementId:m.elementId})}g.cat("</li>")},getGroupHtml:function(k){var d=k.data;var f=k.html;var h=k.isFirstLevel;var l=k.renderGroup;if(l!==false){f.cat('<ul class="t-group').catIf(" t-treeview-lines",h).cat('"').catIf(' style="display:none"',k.isExpanded!==true).cat(">")}if(d&&d.length>0){var e=b.treeview.getItemHtml;for(var g=0,j=d.length;g<j;g++){e({item:d[g],html:f,isAjax:k.isAjax,isFirstLevel:h,showCheckBoxes:k.showCheckBoxes,groupLevel:k.groupLevel,itemIndex:g,itemsCount:j,elementId:k.elementId})}}if(l!==false){f.cat("</ul>")}}});a.fn.tTreeView=function(d){return b.create(this,{name:"tTreeView",init:function(e,f){return new b.treeview(e,f)},options:d,success:function(e){if(e.isAjax()&&a(e.element).find(".t-item").length==0){e.ajaxRequest()}}})};a.fn.tTreeView.defaults={effects:b.fx.property.defaults("height"),queryString:{text:"Text",value:"Value",checked:"Checked"}}})(jQuery);