Sha256: 644e299f37ae0d3cac42270d01ad5bfdb061736c2ebffbe240db7a4bb7cfc633
Contents?: true
Size: 1.77 KB
Versions: 15
Compression:
Stored size: 1.77 KB
Contents
app.directive('menuItem', function($compile, $stateParams) { function checkIfShouldShow(scope, params) { var currentId = params.action ? params.controller + '_action_' + params.action : (params.controller || params.type || params.trait); scope.isActive = scope.link.id === currentId; function checkLink(link) { if (link.id === currentId || link.parent === currentId) { return true; } else { if (link.parentRef) { var matches = function(r) { return r.id === currentId; }; if (!link.isAction) { if ((link.parentRef.childResources || []).some(matches)) return true; } if ((link.parentRef.actions || []).some(matches)) return true; } return (link.childResources || []).some(checkLink) || (link.actions || []).some(checkLink); } } scope.shouldShow = scope.toplevel || checkLink(scope.link); } function link(scope) { scope.$on('$stateChangeSuccess', function(e, state, params) { checkIfShouldShow(scope, params); }); checkIfShouldShow(scope, $stateParams); } return { restrict: 'E', templateUrl: 'views/directives/menu_item.html', scope: { link: '=', toplevel: '=' }, // hackery to make a recursive directive compile: function(element) { var contents = element.contents().remove(); var compiledContents; return { post: function(scope, element){ // Compile the contents if(!compiledContents) { compiledContents = $compile(contents); } // Re-add the compiled contents to the element compiledContents(scope, function(clone) { element.append(clone); }); link(scope, element); } }; } }; });
Version data entries
15 entries across 15 versions & 1 rubygems