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

Version Path
praxis-2.0.pre.9 lib/api_browser/app/js/directives/menu_item.js
praxis-2.0.pre.8 lib/api_browser/app/js/directives/menu_item.js
praxis-2.0.pre.7 lib/api_browser/app/js/directives/menu_item.js
praxis-2.0.pre.6 lib/api_browser/app/js/directives/menu_item.js
praxis-2.0.pre.5 lib/api_browser/app/js/directives/menu_item.js
praxis-2.0.pre.4 lib/api_browser/app/js/directives/menu_item.js
praxis-2.0.pre.3 lib/api_browser/app/js/directives/menu_item.js
praxis-2.0.pre.2 lib/api_browser/app/js/directives/menu_item.js
praxis-2.0.pre.1 lib/api_browser/app/js/directives/menu_item.js
praxis-0.22.pre.2 lib/api_browser/app/js/directives/menu_item.js
praxis-0.22.pre.1 lib/api_browser/app/js/directives/menu_item.js
praxis-0.21 lib/api_browser/app/js/directives/menu_item.js
praxis-0.20.1 lib/api_browser/app/js/directives/menu_item.js
praxis-0.20.0 lib/api_browser/app/js/directives/menu_item.js
praxis-0.19.0 lib/api_browser/app/js/directives/menu_item.js