jquery.treeTable.min.js 3.36 KB
(function(a){a.fn.treeTable=function(b){b=a.extend({path:"",theme:"default",expandLevel:1,column:0,onSelect:function(m,n){},beforeExpand:function(m,n){}},b);var l=this;l.addClass("tree_table");var g={N:b.theme+"_node",AN:b.theme+"_active_node",O:b.theme+"_open",LO:b.theme+"_last_open",S:b.theme+"_shut",LS:b.theme+"_last_shut",HO:b.theme+"_hover_open",HS:b.theme+"_hover_shut",HLO:b.theme+"_hover_last_open",HLS:b.theme+"_hover_last_shut",L:b.theme+"_leaf",LL:b.theme+"_last_leaf",B:b.theme+"_blank",V:b.theme+"_vertline"};var j={},d={};var c=l.find("tr");e(c,true);l.click(function(o){var m=a(o.target);if(m.attr("controller")){m=m.parents("tr[haschild]").find("[arrow]");if(m.attr("class").indexOf(g.AN)==-1&&m.attr("class").indexOf(g.N)==-1){return}var p=m.parents("tr[haschild]")[0].id;if(b.onSelect&&b.onSelect(l,p)===false){return}}if(m.attr("arrow")){var n=m.attr("class");if(n==g.AN+" "+g.HLO||n==g.AN+" "+g.HO){var p=m.parents("tr[haschild]")[0].id;m.attr("class",g.AN+" "+(n.indexOf(g.HO)!=-1?g.HS:g.HLS));i(p);return}else{if(n==g.AN+" "+g.HLS||n==g.AN+" "+g.HS){var p=m.parents("tr")[0].id;m.attr("class",g.AN+" "+(n.indexOf(g.HS)!=-1?g.HO:g.HLO));b.beforeExpand(l,p);f(p);return}}}});l.mouseover(h).mouseout(h);function h(p){var n=a(p.target);if(n.attr("controller")){n=n.parents("tr[haschild]").find("[arrow]")}if(n.attr("arrow")){var o=n.attr("class");if(o&&!o.indexOf(g.AN)){var m=b.theme.length+1;o=o.split(" ")[1].substr(m);if(o.indexOf("hover_")===0){o=b.theme+"_"+o.substr(6)}else{o=b.theme+"_hover_"+o}n.attr("class",g.AN+" "+o);return}}}function e(n,m){n.each(function(q){var p=a(this).attr("pId")||0;j[p]||(j[p]=[]);j[p].push(this.id);d[this.id]=p;a(this).addClass(p)}).find("[controller]").css("cursor","pointer");n.each(function(q){if(!this.id){return}var s=a(this);j[this.id]&&s.attr("hasChild",true);var p=j[d[this.id]];if(p[0]==this.id){s.attr("isFirstOne",true)}else{var u=0;for(var q=0;q<p.length;q++){if(p[q]==this.id){break}u=p[q]}s.attr("prevId",u)}p[p.length-1]==this.id&&s.attr("isLastOne",true);var t=o(this.id);s.attr("depth",t);
k(this);if(m){t>b.expandLevel&&s.hide();if(s.attr("hasChild")&&s.attr("depth")<b.expandLevel){var r=s.attr("isLastOne")?g.LO:g.O;s.find("."+g.AN).attr("class",g.AN+" "+r)}}});function o(q){if(d[q]==0){return 1}var p=o(d[q]);return p+1}}function i(n){if(!j[n]){return false}for(var m=0;m<j[n].length;m++){i(j[n][m])}a("tr."+n,l).hide()}function f(p){a("tr."+p,l).show();if(!j[p]){return false}for(var n=0;n<j[p].length;n++){var m=j[p][n];if(j[m]){var o=a("#"+m,l).find("."+g.AN).attr("class");(o==g.AN+" "+g.O||o==g.AN+" "+g.LO)&&f(m)}}}function k(o){var m=a(o);var s=o.id;if(d[s]==0){var q=a('<span class="prev_sp"></span>')}else{if(!m.attr("isFirstOne")){var q=a("#"+m.attr("prevId"),l).children("td").eq(b.column).find(".prev_sp").clone()}else{var p=a("#"+d[s],l);var q=p.children("td").eq(b.column).find(".prev_sp").clone();if(p.attr("isLastOne")){q.append('<span class="'+g.N+" "+g.B+'"></span>')}else{q.append('<span class="'+g.N+" "+g.V+'"></span>')}}}if(m.attr("hasChild")){var n=m.attr("isLastOne")?g.LS:g.S;n=g.AN+" "+n}else{var n=g.N+" "+(m.attr("isLastOne")?g.LL:g.L)}var r=m.children("td").eq(b.column);r.prepend('<span arrow="true" class="'+n+'"></span>').prepend(q)}l.addChilds=function(p){var m=a(p);if(!m.length){return false}var o=a(m[0]).attr("pId");if(!o){return false}var n=j[o]&&j[o][j[o].length-1]||o;a("#"+n,l).after(m);e(m)};return l}})(jQuery);