Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions dist/angular-breadcrumb.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*! angular-breadcrumb - v0.3.3-dev-2015-03-27
/*! angular-breadcrumb - v0.3.3-dev-2015-04-07
* http://ncuillery.github.io/angular-breadcrumb
* Copyright (c) 2015 Nicolas Cuillery; Licensed MIT */

Expand Down Expand Up @@ -47,9 +47,10 @@ function $Breadcrumb() {
// Get the parent state
var $$parentState = function(state) {
// Check if state has explicit parent OR we try guess parent from its name
var name = state.parent || (/^(.+)\.[^.]+$/.exec(state.name) || [])[1];
// If we were able to figure out parent name then get this state
return name;
var parent = state.parent || (/^(.+)\.[^.]+$/.exec(state.name) || [])[1];
var isObjectParent = typeof parent === "object";
// if parent is a object reference, then extract the name
return isObjectParent ? parent.name : parent;
};

// Add the state in the chain if not already in and if not abstract
Expand Down Expand Up @@ -183,14 +184,14 @@ function BreadcrumbDirective($interpolate, $breadcrumb, $rootScope) {
var $$templates = {
bootstrap2: '<ul class="breadcrumb">' +
'<li ng-repeat="step in steps" ng-switch="$last || !!step.abstract" ng-class="{active: $last}">' +
'<a ng-switch-when="false" href="{{step.ncyBreadcrumbLink}}">{{step.ncyBreadcrumbLabel}}</a> ' +
'<a ng-switch-when="false" href="{{step.ncyBreadcrumbLink}}">{{step.ncyBreadcrumbLabel}}</a>' +
'<span ng-switch-when="true">{{step.ncyBreadcrumbLabel}}</span>' +
'<span class="divider" ng-hide="$last">/</span>' +
'</li>' +
'</ul>',
bootstrap3: '<ol class="breadcrumb">' +
'<li ng-repeat="step in steps" ng-class="{active: $last}" ng-switch="$last || !!step.abstract">' +
'<a ng-switch-when="false" href="{{step.ncyBreadcrumbLink}}">{{step.ncyBreadcrumbLabel}}</a> ' +
'<a ng-switch-when="false" href="{{step.ncyBreadcrumbLink}}">{{step.ncyBreadcrumbLabel}}</a>' +
'<span ng-switch-when="true">{{step.ncyBreadcrumbLabel}}</span>' +
'</li>' +
'</ol>'
Expand Down
4 changes: 2 additions & 2 deletions dist/angular-breadcrumb.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions src/angular-breadcrumb.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,10 @@ function $Breadcrumb() {
// Get the parent state
var $$parentState = function(state) {
// Check if state has explicit parent OR we try guess parent from its name
var name = state.parent || (/^(.+)\.[^.]+$/.exec(state.name) || [])[1];
// If we were able to figure out parent name then get this state
return name;
var parent = state.parent || (/^(.+)\.[^.]+$/.exec(state.name) || [])[1];
var isObjectParent = typeof parent === "object";
// if parent is a object reference, then extract the name
return isObjectParent ? parent.name : parent;
};

// Add the state in the chain if not already in and if not abstract
Expand Down
20 changes: 20 additions & 0 deletions test/mock/test-modules.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,26 @@ angular.module('ncy-abstract-conf', []).config(function($stateProvider) {
.state('K.L', {url: '/l', ncyBreadcrumb: {label: 'State L'}});
});

/**
* Module including parents defined by objects.
*/
angular.module('ncy-object-parent-conf', []).config(function($stateProvider) {
var A = {
name: 'A',
url: '/a',
ncyBreadcrumb: {label: 'State A'}
};
var A_B = {
name: 'B',
url: '/b',
ncyBreadcrumb: {label: 'State B'},
parent: A
};
$stateProvider
.state(A)
.state(A_B);
});

/**
* Module with dynamic parent configuration.
*/
Expand Down
30 changes: 30 additions & 0 deletions test/spec/directive-object-parent-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*jshint undef: false */

describe('Breadcrumb directive with object parent conf', function() {

var element, scope;

beforeEach(function() {
module('ncy-object-parent-conf');
});

beforeEach(inject(function($rootScope, $compile) {
element = angular.element('<ncy-breadcrumb />');
var compile = $compile(element);
scope = $rootScope.$new();
compile(scope);
scope.$digest();
}));

it('should handle parents provided by object reference', inject(function() {
goToState('B');
scope.$emit('$viewContentLoaded');
scope.$digest();

console.info('Directive content : ' + element.text());
expect(element.text()).toContain('State A');
expect(element.text()).toContain('State B');
}));


});