text: /* commonjs package manager support (eg componentjs) */
  "undefined"!=typeof module&&"undefined"!=typeof exports&&module.exports===exports&&(module.exports="treeControl"),function(a){"use strict";a.module("treeControl",[]).constant("treeConfig",{templateUrl:null}).directive("treecontrol",["$compile",function(b){function c(a,b){return a?b?'class="'+a+'"':a:""}function d(a,b,c){a.hasOwnProperty(b)||(a[b]=c)}return{restrict:"EA",require:"treecontrol",transclude:!0,scope:{treeModel:"=",selectedNode:"=?",selectedNodes:"=?",expandedNodes:"=?",onSelection:"&",onNodeToggle:"&",options:"=?",orderBy:"@",reverseOrder:"@",filterExpression:"=?",filterComparator:"=?"},controller:["$scope","$templateCache","$interpolate","treeConfig",function(e,f,g,h){function i(a){return!a[e.options.nodeChildren]||0===a[e.options.nodeChildren].length}function j(b,c){if(a.isArray(b)){c=c||[];for(var d=0;d<b.length;d++)c[d]=b[d]}else if(a.isObject(b)){c=c||{};for(var e in b)!hasOwnProperty.call(b,e)||"$"===e.charAt(0)&&"$"===e.charAt(1)||(c[e]=b[e])}return c||b}function k(b,c){return void 0===b||void 0===c?!1:(b=j(b),b[e.options.nodeChildren]=[],c=j(c),c[e.options.nodeChildren]=[],a.equals(b,c))}function l(){return!0}function m(a){if(!e.options.multiSelection&&e.options.equality(a,e.selectedNode))return!0;if(e.options.multiSelection&&e.selectedNodes){for(var b=0;b<e.selectedNodes.length;b++)if(e.options.equality(a,e.selectedNodes[b]))return!0;return!1}}e.options=e.options||{},d(e.options,"multiSelection",!1),d(e.options,"nodeChildren","children"),d(e.options,"dirSelectable","true"),d(e.options,"injectClasses",{}),d(e.options.injectClasses,"ul",""),d(e.options.injectClasses,"li",""),d(e.options.injectClasses,"liSelected",""),d(e.options.injectClasses,"iExpanded",""),d(e.options.injectClasses,"iCollapsed",""),d(e.options.injectClasses,"iLeaf",""),d(e.options.injectClasses,"label",""),d(e.options.injectClasses,"labelSelected",""),d(e.options,"equality",k),d(e.options,"isLeaf",i),d(e.options,"allowDeselect",!0),d(e.options,"isSelectable",l),e.selectedNodes=e.selectedNodes||[],e.expandedNodes=e.expandedNodes||[],e.expandedNodesMap={};for(var n=0;n<e.expandedNodes.length;n++)e.expandedNodesMap[""+n]=e.expandedNodes[n];e.parentScopeOfTree=e.$parent,e.headClass=function(a){var b=c(e.options.injectClasses.liSelected,!1),d="";return b&&m(a)&&(d=" "+b),e.options.isLeaf(a)?"tree-leaf"+d:e.expandedNodesMap[this.$id]?"tree-expanded"+d:"tree-collapsed"+d},e.iBranchClass=function(){return c(e.expandedNodesMap[this.$id]?e.options.injectClasses.iExpanded:e.options.injectClasses.iCollapsed)},e.nodeExpanded=function(){return!!e.expandedNodesMap[this.$id]},e.selectNodeHead=function(){var a=this,b=void 0===e.expandedNodesMap[a.$id];if(e.expandedNodesMap[a.$id]=b?a.node:void 0,b)e.expandedNodes.push(a.node);else{for(var c,d=0;d<e.expandedNodes.length&&!c;d++)e.options.equality(e.expandedNodes[d],a.node)&&(c=d);void 0!==c&&e.expandedNodes.splice(c,1)}if(e.onNodeToggle){var f=a.$parent.node===a.synteticRoot?null:a.$parent.node;e.onNodeToggle({node:a.node,$parentNode:f,$index:a.$index,$first:a.$first,$middle:a.$middle,$last:a.$last,$odd:a.$odd,$even:a.$even,expanded:b})}},e.selectNodeLabel=function(a){var b=this;if(e.options.isLeaf(a)||e.options.dirSelectable&&e.options.isSelectable(a)){if(e.options.isLeaf(a)&&!e.options.isSelectable(a))return;var c=!1;if(e.options.multiSelection){for(var d=-1,f=0;f<e.selectedNodes.length;f++)if(e.options.equality(a,e.selectedNodes[f])){d=f;break}-1===d?(e.selectedNodes.push(a),c=!0):e.selectedNodes.splice(d,1)}else e.options.equality(a,e.selectedNode)&&e.options.allowDeselect?e.selectedNode=void 0:(e.selectedNode=a,c=!0);if(e.onSelection){var g=b.$parent.node===b.synteticRoot?null:b.$parent.node;e.onSelection({node:a,selected:c,$parentNode:g,$index:b.$index,$first:b.$first,$middle:b.$middle,$last:b.$last,$odd:b.$odd,$even:b.$even})}}else this.selectNodeHead()},e.selectedClass=function(){var a=m(this.node),b=c(e.options.injectClasses.labelSelected,!1),d="";return b&&a&&(d=" "+b),a?"tree-selected"+d:""},e.unselectableClass=function(){var a=!e.options.isSelectable(this.node),b=c(e.options.injectClasses.labelUnselectable,!1);return a?"tree-unselectable "+b:""},e.isReverse=function(){return!("false"===e.reverseOrder||"False"===e.reverseOrder||""===e.reverseOrder||e.reverseOrder===!1)},e.orderByFunc=function(){return"'"+e.orderBy+"'"};var o,p={orderBy:e.orderBy?" | orderBy:orderByFunc():isReverse()":"",ulClass:c(e.options.injectClasses.ul,!0),nodeChildren:e.options.nodeChildren,liClass:c(e.options.injectClasses.li,!0),iLeafClass:c(e.options.injectClasses.iLeaf,!1),labelClass:c(e.options.injectClasses.label,!1)},q=e.options.templateUrl||h.templateUrl;q&&(o=f.get(q)),o||(o='<ul {{options.ulClass}} ><li ng-repeat="node in node.{{options.nodeChildren}} | filter:filterExpression:filterComparator {{options.orderBy}}" ng-class="headClass(node)" {{options.liClass}}set-node-to-data><i class="tree-branch-head" ng-class="iBranchClass()" ng-click="selectNodeHead(node)"></i><i class="tree-leaf-head {{options.iLeafClass}}"></i><div class="tree-label {{options.labelClass}}" ng-class="[selectedClass(), unselectableClass()]" ng-click="selectNodeLabel(node)" tree-transclude></div><treeitem ng-if="nodeExpanded()"></treeitem></li></ul>'),this.template=b(g(o)({options:p}))}],compile:function(b,c,d){return function(b,c,e,f){b.$watch("treeModel",function(c){if(a.isArray(c)){if(a.isDefined(b.node)&&a.equals(b.node[b.options.nodeChildren],c))return;b.node={},b.synteticRoot=b.node,b.node[b.options.nodeChildren]=c}else{if(a.equals(b.node,c))return;b.node=c}}),b.$watchCollection("expandedNodes",function(d,e){var f=0,g={},h=c.find("li"),i=[];a.forEach(h,function(b){var c=a.element(b),d={$id:c.data("scope-id"),node:c.data("node")};i.push(d)}),a.forEach(d,function(a){for(var c=!1,d=0;d<i.length&&!c;d++){var e=i[d];b.options.equality(a,e.node)&&(g[e.$id]=e.node,c=!0)}c||(g[f++]=a)}),b.expandedNodesMap=g}),f.template(b,function(a){c.html("").append(a)}),b.$treeTransclude=d}}}}]).directive("setNodeToData",["$parse",function(a){return{restrict:"A",link:function(a,b,c){b.data("node",a.node),b.data("scope-id",a.$id)}}}]).directive("treeitem",function(){return{restrict:"E",require:"^treecontrol",link:function(a,b,c,d){d.template(a,function(a){b.html("").append(a)})}}}).directive("treeTransclude",function(){return{link:function(b,c,d,e){if(b.options.isLeaf(b.node)||a.forEach(b.expandedNodesMap,function(a,c){b.options.equality(a,b.node)&&(b.expandedNodesMap[b.$id]=b.node,b.expandedNodesMap[c]=void 0)}),!b.options.multiSelection&&b.options.equality(b.node,b.selectedNode))b.selectedNode=b.node;else if(b.options.multiSelection){for(var f=[],g=0;g<b.selectedNodes.length;g++)b.options.equality(b.node,b.selectedNodes[g])&&f.push(b.node);b.selectedNodes=f}b.transcludeScope=b.parentScopeOfTree.$new(),b.transcludeScope.node=b.node,b.transcludeScope.$parentNode=b.$parent.node===b.synteticRoot?null:b.$parent.node,b.transcludeScope.$index=b.$index,b.transcludeScope.$first=b.$first,b.transcludeScope.$middle=b.$middle,b.transcludeScope.$last=b.$last,b.transcludeScope.$odd=b.$odd,b.transcludeScope.$even=b.$even,b.$on("$destroy",function(){b.transcludeScope.$destroy()}),b.$treeTransclude(b.transcludeScope,function(a){c.empty(),c.append(a)})}}})}(angular);