Skip to content

Commit 4e0d649

Browse files
committed
Merge pull request #99 from kazinov/issue-42
feat: add the scope-based ncyBreadcrumbIgnore flag
2 parents da3fecd + 12d012d commit 4e0d649

File tree

5 files changed

+170
-17
lines changed

5 files changed

+170
-17
lines changed

dist/angular-breadcrumb.js

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*! angular-breadcrumb - v0.3.3-dev-2015-05-02
1+
/*! angular-breadcrumb - v0.4.0-dev-2015-08-07
22
* http://ncuillery.github.io/angular-breadcrumb
33
* Copyright (c) 2015 Nicolas Cuillery; Licensed MIT */
44

@@ -39,7 +39,8 @@ function $Breadcrumb() {
3939
// Early catch of $viewContentLoaded event
4040
$rootScope.$on('$viewContentLoaded', function (event) {
4141
// With nested views, the event occur several times, in "wrong" order
42-
if(isAOlderThanB(event.targetScope.$id, $lastViewScope.$id)) {
42+
if(!event.targetScope.ncyBreadcrumbIgnore &&
43+
isAOlderThanB(event.targetScope.$id, $lastViewScope.$id)) {
4344
$lastViewScope = event.targetScope;
4445
}
4546
});
@@ -224,8 +225,10 @@ function BreadcrumbDirective($interpolate, $breadcrumb, $rootScope) {
224225
});
225226
};
226227

227-
$rootScope.$on('$viewContentLoaded', function () {
228-
renderBreadcrumb();
228+
$rootScope.$on('$viewContentLoaded', function (event) {
229+
if(!event.targetScope.ncyBreadcrumbIgnore) {
230+
renderBreadcrumb();
231+
}
229232
});
230233

231234
// View(s) may be already loaded while the directive's linking
@@ -274,8 +277,10 @@ function BreadcrumbLastDirective($interpolate, $breadcrumb, $rootScope) {
274277
}
275278
};
276279

277-
$rootScope.$on('$viewContentLoaded', function () {
278-
renderLabel();
280+
$rootScope.$on('$viewContentLoaded', function (event) {
281+
if(!event.targetScope.ncyBreadcrumbIgnore) {
282+
renderLabel();
283+
}
279284
});
280285

281286
// View(s) may be already loaded while the directive's linking
@@ -340,8 +345,10 @@ function BreadcrumbTextDirective($interpolate, $breadcrumb, $rootScope) {
340345
scope.ncyBreadcrumbChain = combinedLabels.join(separator);
341346
};
342347

343-
$rootScope.$on('$viewContentLoaded', function () {
344-
renderLabel();
348+
$rootScope.$on('$viewContentLoaded', function (event) {
349+
if(!event.targetScope.ncyBreadcrumbIgnore) {
350+
renderLabel();
351+
}
345352
});
346353

347354
// View(s) may be already loaded while the directive's linking

dist/angular-breadcrumb.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/angular-breadcrumb.js

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ function $Breadcrumb() {
3434
// Early catch of $viewContentLoaded event
3535
$rootScope.$on('$viewContentLoaded', function (event) {
3636
// With nested views, the event occur several times, in "wrong" order
37-
if(isAOlderThanB(event.targetScope.$id, $lastViewScope.$id)) {
37+
if(!event.targetScope.ncyBreadcrumbIgnore &&
38+
isAOlderThanB(event.targetScope.$id, $lastViewScope.$id)) {
3839
$lastViewScope = event.targetScope;
3940
}
4041
});
@@ -219,8 +220,10 @@ function BreadcrumbDirective($interpolate, $breadcrumb, $rootScope) {
219220
});
220221
};
221222

222-
$rootScope.$on('$viewContentLoaded', function () {
223-
renderBreadcrumb();
223+
$rootScope.$on('$viewContentLoaded', function (event) {
224+
if(!event.targetScope.ncyBreadcrumbIgnore) {
225+
renderBreadcrumb();
226+
}
224227
});
225228

226229
// View(s) may be already loaded while the directive's linking
@@ -269,8 +272,10 @@ function BreadcrumbLastDirective($interpolate, $breadcrumb, $rootScope) {
269272
}
270273
};
271274

272-
$rootScope.$on('$viewContentLoaded', function () {
273-
renderLabel();
275+
$rootScope.$on('$viewContentLoaded', function (event) {
276+
if(!event.targetScope.ncyBreadcrumbIgnore) {
277+
renderLabel();
278+
}
274279
});
275280

276281
// View(s) may be already loaded while the directive's linking
@@ -335,8 +340,10 @@ function BreadcrumbTextDirective($interpolate, $breadcrumb, $rootScope) {
335340
scope.ncyBreadcrumbChain = combinedLabels.join(separator);
336341
};
337342

338-
$rootScope.$on('$viewContentLoaded', function () {
339-
renderLabel();
343+
$rootScope.$on('$viewContentLoaded', function (event) {
344+
if(!event.targetScope.ncyBreadcrumbIgnore) {
345+
renderLabel();
346+
}
340347
});
341348

342349
// View(s) may be already loaded while the directive's linking

test/mock/test-modules.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,3 +117,34 @@ angular.module('ncy-sample-conf', ['ncy-sample', 'ngMock']).config(function($url
117117
$httpBackend.when('GET', 'views/room_detail.html').respond('dummy room_detail view');
118118
$httpBackend.when('GET', 'views/room_form.html').respond('dummy room_form view');
119119
});
120+
121+
/**
122+
* Module with multiple views related to one state and interpolated labels
123+
*/
124+
angular.module('ncy-multiple-interpolation-conf', []).config(function($stateProvider) {
125+
$stateProvider
126+
.state('A', {
127+
url: '/a',
128+
views: {
129+
'a@': {
130+
template: '<div>View A</div>',
131+
controller: 'ACtrl'
132+
}
133+
}
134+
})
135+
.state('A.B', {
136+
url: '/b',
137+
views: {
138+
'b@': {
139+
template: '<div>View B</div>',
140+
controller: 'BCtrl'
141+
}
142+
},
143+
ncyBreadcrumb: {
144+
label: 'State {{tripleB}}'
145+
}
146+
});
147+
}).controller('ACtrl', function() {
148+
}).controller('BCtrl', function($scope) {
149+
$scope.tripleB = 'BBB';
150+
});
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
/*jshint undef: false */
2+
3+
4+
var element, scope;
5+
6+
describe('Breadcrumb directive with multiple-interpolation conf', function() {
7+
8+
beforeEach(function () {
9+
module('ncy-multiple-interpolation-conf');
10+
});
11+
12+
describe('when ncyBreadcrumbIgnore is undefined on parent view scope', function () {
13+
describe('when the parent view located before child view ', function () {
14+
beforeEach(inject(function ($rootScope, $compile) {
15+
element = angular.element('<div><div ncy-breadcrumb=""></div><div ui-view="a"></div><div ui-view="b"></div></div>');
16+
var compile = $compile(element);
17+
scope = $rootScope.$new();
18+
compile(scope);
19+
scope.$digest();
20+
}));
21+
22+
it('renders the correct state chain and views content', inject(function () {
23+
goToState('A.B');
24+
scope.$emit('$viewContentLoaded');
25+
scope.$digest();
26+
27+
console.info('Directive content : ' + element.text());
28+
29+
expect(element.text()).toContain('AState BBBView AView B');
30+
}));
31+
});
32+
33+
describe('when the parent view located after child view ', function () {
34+
beforeEach(inject(function ($rootScope, $compile) {
35+
element = angular.element('<div><div ncy-breadcrumb=""></div><div ui-view="b"></div><div ui-view="a"></div></div>');
36+
var compile = $compile(element);
37+
scope = $rootScope.$new();
38+
compile(scope);
39+
scope.$digest();
40+
}));
41+
42+
it('renders the incorrect state chain', inject(function () {
43+
goToState('A.B');
44+
scope.$emit('$viewContentLoaded');
45+
scope.$digest();
46+
47+
console.info('Directive content : ' + element.text());
48+
49+
expect(element.text()).not.toContain('State BBB');
50+
}));
51+
});
52+
});
53+
});
54+
55+
describe('Breadcrumb directive with multiple-interpolation conf', function() {
56+
beforeEach(function () {
57+
module('ncy-multiple-interpolation-conf', function ($controllerProvider) {
58+
$controllerProvider.register('ACtrl', function ($scope) {
59+
$scope.ncyBreadcrumbIgnore = true;
60+
});
61+
});
62+
});
63+
64+
describe('when ncyBreadcrumbIgnore property equals true on parent view scope', function () {
65+
describe('when the parent view located before child view ', function () {
66+
beforeEach(inject(function ($rootScope, $compile) {
67+
element = angular.element('<div><div ncy-breadcrumb=""></div><div ui-view="a"></div><div ui-view="b"></div></div>');
68+
var compile = $compile(element);
69+
scope = $rootScope.$new();
70+
71+
compile(scope);
72+
scope.$digest();
73+
}));
74+
75+
it('renders the correct state chain and views content', inject(function () {
76+
goToState('A.B');
77+
scope.$emit('$viewContentLoaded');
78+
scope.$digest();
79+
80+
console.info('Directive content : ' + element.text());
81+
82+
expect(element.text()).toContain('AState BBBView AView B');
83+
}));
84+
});
85+
86+
describe('when the parent view located after child view ', function () {
87+
beforeEach(inject(function ($rootScope, $compile) {
88+
element = angular.element('<div><div ncy-breadcrumb=""></div><div ui-view="b"></div><div ui-view="a"></div></div>');
89+
var compile = $compile(element);
90+
scope = $rootScope.$new();
91+
92+
compile(scope);
93+
scope.$digest();
94+
}));
95+
96+
it('renders the correct state chain and views content', inject(function () {
97+
goToState('A.B');
98+
scope.$emit('$viewContentLoaded');
99+
scope.$digest();
100+
101+
console.info('Directive content : ' + element.text());
102+
103+
expect(element.text()).toContain('AState BBBView BView A');
104+
}));
105+
});
106+
});
107+
108+
});

0 commit comments

Comments
 (0)