Resources/Web/js/jquery.treeTable.min.js
author StephaneLenclud
Mon, 02 Feb 2015 20:58:28 +0100
branchMiniDisplay
changeset 448 10c04c79527e
permissions -rw-r--r--
Sync: Adding shamap and documentation to enable easier sync next time OHM is updated.
     1 /*
     2  * jQuery treeTable Plugin VERSION
     3  * http://ludo.cubicphuse.nl/jquery-plugins/treeTable/doc/
     4  *
     5  * Copyright 2011, Ludo van den Boom
     6  * Dual licensed under the MIT or GPL Version 2 licenses.
     7  */
     8 (function(a){function j(c){var d=c[0].className.split(" ");for(var e=0;e<d.length;e++)if(d[e].match(b.childPrefix))return a(c).siblings("#"+d[e].substring(b.childPrefix.length));return null}function i(b,c){b.insertAfter(c),e(b).reverse().each(function(){i(a(this),b[0])})}function h(c){if(!c.hasClass("initialized")){c.addClass("initialized");var d=e(c);!c.hasClass("parent")&&d.length>0&&c.addClass("parent");if(c.hasClass("parent")){var g=a(c.children("td")[b.treeColumn]),h=f(g)+b.indent;d.each(function(){a(this).children("td")[b.treeColumn].style.paddingLeft=h+"px"});if(b.expandable){g.prepend('<span style="margin-left: -'+b.indent+"px; padding-left: "+b.indent+'px" class="expander"></span>'),a(g[0].firstChild).click(function(){c.toggleBranch()}),b.clickableNodeNames&&(g[0].style.cursor="pointer",a(g).click(function(a){a.target.className!="expander"&&c.toggleBranch()}));if(b.persist){var i=b.persistCookiePrefix+c.attr("id");a.cookie(i)=="true"&&c.addClass("expanded")}!c.hasClass("expanded")&&!c.hasClass("collapsed")&&c.addClass(b.initialState),c.hasClass("expanded")&&c.expand()}}}}function g(c,d){var h=a(c.children("td")[b.treeColumn]);h[0].style.paddingLeft=f(h)+d+"px",e(c).each(function(){g(a(this),d)})}function f(a){var b=parseInt(a[0].style.paddingLeft,10);return isNaN(b)?c:b}function e(c){return a(c).siblings("tr."+b.childPrefix+c[0].id)}function d(a){var b=[];while(a=j(a))b[b.length]=a[0];return b}var b,c;a.fn.treeTable=function(d){b=a.extend({},a.fn.treeTable.defaults,d);return this.each(function(){a(this).addClass("treeTable").find("tbody tr").each(function(){if(!a(this).hasClass("initialized")){var d=a(this)[0].className.search(b.childPrefix)==-1;d&&isNaN(c)&&(c=parseInt(a(a(this).children("td")[b.treeColumn]).css("padding-left"),10)),!d&&b.expandable&&b.initialState=="collapsed"&&a(this).addClass("ui-helper-hidden"),(!b.expandable||d)&&h(a(this))}})})},a.fn.treeTable.defaults={childPrefix:"child-of-",clickableNodeNames:!1,expandable:!0,indent:19,initialState:"collapsed",onNodeShow:null,treeColumn:0,persist:!1,persistCookiePrefix:"treeTable_"},a.fn.collapse=function(){a(this).addClass("collapsed"),e(a(this)).each(function(){a(this).hasClass("collapsed")||a(this).collapse(),a(this).addClass("ui-helper-hidden")});return this},a.fn.expand=function(){a(this).removeClass("collapsed").addClass("expanded"),e(a(this)).each(function(){h(a(this)),a(this).is(".expanded.parent")&&a(this).expand(),a(this).removeClass("ui-helper-hidden"),a.isFunction(b.onNodeShow)&&b.onNodeShow.call()});return this},a.fn.reveal=function(){a(d(a(this)).reverse()).each(function(){h(a(this)),a(this).expand().show()});return this},a.fn.appendBranchTo=function(c){var e=a(this),f=j(e),h=a.map(d(a(c)),function(a){return a.id});a.inArray(e[0].id,h)==-1&&(!f||c.id!=f[0].id)&&c.id!=e[0].id&&(g(e,d(e).length*b.indent*-1),f&&e.removeClass(b.childPrefix+f[0].id),e.addClass(b.childPrefix+c.id),i(e,c),g(e,d(e).length*b.indent));return this},a.fn.reverse=function(){return this.pushStack(this.get().reverse(),arguments)},a.fn.toggleBranch=function(){a(this).hasClass("collapsed")?a(this).expand():a(this).removeClass("expanded").collapse();if(b.persist){var c=b.persistCookiePrefix+a(this).attr("id");a.cookie(c,a(this).hasClass("expanded")?"true":null)}return this}})(jQuery)