breadcrumb.js 887 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /**
  2. * @fileoverview
  3. *
  4. */
  5. 'use strict';
  6. angular.module('etcd.ui')
  7. .directive('coBreadcrumb', function(_, pathSvc) {
  8. return {
  9. templateUrl: '/ui/breadcrumb.html',
  10. restrict: 'E',
  11. replace: true,
  12. scope: {
  13. path: '=',
  14. callback: '&'
  15. },
  16. link: function postLink(scope, elem, attrs) {
  17. scope.goToRoot = function() {
  18. scope.callback({ path: '/' });
  19. };
  20. scope.onClick = function(part) {
  21. var selected, selectedPath;
  22. selected = scope.pathParts.slice(0, scope.pathParts.indexOf(part) + 1);
  23. selectedPath = pathSvc.make(_.pluck(selected, 'name'));
  24. scope.callback({ path: selectedPath });
  25. };
  26. scope.$watch('path', function(path) {
  27. scope.pathParts = pathSvc.explode(path).map(function(part) {
  28. return {
  29. name: part
  30. };
  31. });
  32. });
  33. }
  34. };
  35. });