forked from alvaroveliz/aCollapTable
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.aCollapTable.min.js
1 lines (1 loc) · 2.83 KB
/
jquery.aCollapTable.min.js
1
(function(e){e.fn.extend({aCollapTable:function(t){var n={startCollapsed:false,addColumn:true,plusButton:"+",minusButton:"-"};var t=e.extend(n,t);var r=this;var s=[];var o=function(n,i,s){parent=typeof i=="undefined"?n.parents("tr").data("id"):i;display=typeof s=="undefined"?n.hasClass("act-expanded")?"none":"table-row":s;table=r;e("tr[data-parent="+parent+"]",table).each(function(t,r){e(r).css("display",display);if(e(r).hasClass("act-tr-expanded")){o(n,e(r).data("id"),display)}});spacer=f(n.parents("tr"));if(display=="none"){n.html(spacer+t.plusButton).removeClass("act-expanded").addClass("act-collapsed");n.parents("tr").addClass("act-tr-collapsed").removeClass("act-tr-expanded")}else{n.html(spacer+t.minusButton).removeClass("act-collapsed").addClass("act-expanded");n.parents("tr").addClass("act-tr-expanded").removeClass("act-tr-collapsed")}};var u=function(t){e("tr",t).each(function(t,n){if(e(n).data("id")){parent={id:e(n).data("id"),parent:e(n).data("parent")};s.push(parent)}});e("tr",t).each(function(t,n){if(e(n).data("id")){level=a(e(n));e(n).attr("data-level",level)}})};var a=function(t,n){n=typeof n=="undefined"?0:n;if(t.data("parent")==""){return n}else{$parent=e("tr[data-id="+t.data("parent")+"]");return a($parent,n+1)}};var f=function(e){spacer="";for(i=0;i<e.data("level");i++){spacer+=" "}return spacer};var l=function(){e(document).on("click",".act-button-expand",function(){if(e("tr",r).length>0){expands=[];e("tr",r).each(function(t,n){if(e(n).hasClass("act-tr-collapsed")&&e(n).css("display")!="none"){expands.push(e(n))}});e.each(expands,function(t,n){o(e(".act-more",n))})}});e(document).on("click",".act-button-collapse",function(){if(e("tr",r).length>0){}});e(document).on("click",".act-button-expand-all",function(){if(e("tr",r).length>0){collapseds=[];e("tr",r).each(function(t,n){if(e(n).hasClass("act-tr-collapsed")){o(e(".act-more",e(n)))}})}});e(document).on("click",".act-button-collapse-all",function(){if(e("tr",r).length>0){collapseds=[];e("tr",r).each(function(t,n){if(e(n).hasClass("act-tr-expanded")){o(e(".act-more",e(n)))}})}})};return this.each(function(){var n=t;var r=e(this);u(r);l();if(e("tr",r).length>0){e("tr",r).each(function(t,r){spacer=f(e(r));$minus=e("<a />").attr("href","javascript:void(0)").addClass("act-more act-expanded").html(spacer+n.minusButton).bind("click",function(){o(e(this))});if(e("tr[data-parent="+e(r).data("id")+"]").length>0){$button=n.addColumn==true?e("<td />").html($minus):$minus;itemClass=n.startCollapsed?"act-tr-collapsed":"act-tr-expanded";e(r).addClass(itemClass)}else{$button=n.addColumn==true?e("<td />").html(spacer+" "):spacer+" "}if(n.addColumn==true){e(r).prepend($button)}else{e(r).children(":first").prepend($button)}e(r).addClass("act-tr-level-"+e(r).data("level"))});if(n.startCollapsed){e(".act-more").each(function(t,n){e(n).click()})}}})}})})(jQuery)