Skip to content

Commit 301df63

Browse files
committed
chore: release 0.5.0
1 parent e6e92aa commit 301df63

File tree

8 files changed

+72
-21
lines changed

8 files changed

+72
-21
lines changed

CHANGELOG.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
<a name="0.5.0"></a>
2+
## 0.5.0 (2016-11-14)
3+
4+
5+
#### Bug Fixes
6+
7+
* Register listeners once to prevent scope being retained ([181f4c09](http://github.com/ncuillery/angular-breadcrumb/commit/181f4c0901007cbd72c7a9470cb9503eb6ab4d5a), closes [#98](http://github.com/ncuillery/angular-breadcrumb/issues/98))
8+
9+
10+
#### Features
11+
12+
* Expose ncyBreadcrumbStateRef for ui-sref usage in custom template ([56cec38b](http://github.com/ncuillery/angular-breadcrumb/commit/56cec38b1169ba91a766bb64f44ddff81d8af2a8), closes [#54](http://github.com/ncuillery/angular-breadcrumb/issues/54))
13+
* **ncyBreadcrumbLast:** Add custom templating ([974f99b5](http://github.com/ncuillery/angular-breadcrumb/commit/974f99b584c85e45b1c0eb1acb4081bf103de06f), closes [#123](http://github.com/ncuillery/angular-breadcrumb/issues/123), [#125](http://github.com/ncuillery/angular-breadcrumb/issues/125))
14+
15+
116
<a name="0.4.1"></a>
217
### 0.4.1 (2015-08-09)
318

@@ -20,7 +35,7 @@
2035

2136
#### Features
2237

23-
* Add force to ncyBreadcrumb options ([31125a38](http://github.com/ncuillery/angular-breadcrumb/commit/31125a386d706dd76df807b3b02e1fccea38fb59), closes [#77](http://github.com/ncuillery/angular-breadcrumb/issues/78))
38+
* Add force to ncyBreadcrumb options ([31125a38](http://github.com/ncuillery/angular-breadcrumb/commit/31125a386d706dd76df807b3b02e1fccea38fb59), closes [#78](http://github.com/ncuillery/angular-breadcrumb/issues/78))
2439
* **ncyBreadcrumbText:** Add ncyBreadcrumbText directive ([82b2b443](http://github.com/ncuillery/angular-breadcrumb/commit/82b2b443fab220cd9ac7d3a8c90c1edc4291e54a), closes [#71](http://github.com/ncuillery/angular-breadcrumb/issues/71), [#83](http://github.com/ncuillery/angular-breadcrumb/issues/83))
2540

2641

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "angular-breadcrumb",
33
"description": "AngularJS module that generates a breadcrumb from ui-router's states",
4-
"version": "0.4.1",
4+
"version": "0.5.0",
55
"main": "release/angular-breadcrumb.js",
66
"ignore": [
77
"sample",

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "angular-breadcrumb",
33
"description": "AngularJS module that generates a breadcrumb from ui-router's states",
4-
"version": "0.4.1",
4+
"version": "0.5.0",
55
"homepage": "http://ncuillery.github.io/angular-breadcrumb",
66
"author": {
77
"name": "Nicolas Cuillery",

release/angular-breadcrumb.js

Lines changed: 49 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
/*! angular-breadcrumb - v0.4.1
1+
/*! angular-breadcrumb - v0.5.0
22
* http://ncuillery.github.io/angular-breadcrumb
3-
* Copyright (c) 2015 Nicolas Cuillery; Licensed MIT */
3+
* Copyright (c) 2016 Nicolas Cuillery; Licensed MIT */
44

55
(function (window, angular, undefined) {
66
'use strict';
@@ -19,12 +19,24 @@ function parseStateRef(ref) {
1919
return { state: parsed[1], paramExpr: parsed[3] || null };
2020
}
2121

22+
var $registeredListeners = {};
23+
function registerListenerOnce(tag, $rootScope, event, fn) {
24+
var deregisterListenerFn = $registeredListeners[tag];
25+
if ( deregisterListenerFn !== undefined ) {
26+
deregisterListenerFn();
27+
}
28+
deregisterListenerFn = $rootScope.$on(event, fn);
29+
$registeredListeners[tag] = deregisterListenerFn;
30+
}
31+
2232
function $Breadcrumb() {
2333

2434
var $$options = {
2535
prefixStateName: null,
2636
template: 'bootstrap3',
2737
templateUrl: null,
38+
templateLast: 'default',
39+
templateLastUrl: null,
2840
includeAbstract : false
2941
};
3042

@@ -37,7 +49,7 @@ function $Breadcrumb() {
3749
var $lastViewScope = $rootScope;
3850

3951
// Early catch of $viewContentLoaded event
40-
$rootScope.$on('$viewContentLoaded', function (event) {
52+
registerListenerOnce('$Breadcrumb.$viewContentLoaded', $rootScope, '$viewContentLoaded', function (event) {
4153
// With nested views, the event occur several times, in "wrong" order
4254
if(!event.targetScope.ncyBreadcrumbIgnore &&
4355
isAOlderThanB(event.targetScope.$id, $lastViewScope.$id)) {
@@ -80,6 +92,7 @@ function $Breadcrumb() {
8092
}
8193

8294
conf.ncyBreadcrumbLink = $state.href(ref.state, parentParams || $stateParams || {});
95+
conf.ncyBreadcrumbStateRef = stateRef;
8396
chain.unshift(conf);
8497
}
8598
};
@@ -119,6 +132,22 @@ function $Breadcrumb() {
119132
return $$options.templateUrl;
120133
},
121134

135+
getTemplateLast: function(templates) {
136+
if($$options.templateLastUrl) {
137+
// templateUrl takes precedence over template
138+
return null;
139+
} else if(templates[$$options.templateLast]) {
140+
// Predefined templates (default)
141+
return templates[$$options.templateLast];
142+
} else {
143+
return $$options.templateLast;
144+
}
145+
},
146+
147+
getTemplateLastUrl: function() {
148+
return $$options.templateLastUrl;
149+
},
150+
122151
getStatesChain: function(exitOnFirst) { // Deliberately undocumented param, see getLastStep
123152
var chain = [];
124153

@@ -154,6 +183,7 @@ var getExpression = function(interpolationFunction) {
154183
if(interpolationFunction.expressions) {
155184
return interpolationFunction.expressions;
156185
} else {
186+
// Workaround for Angular 1.2.x
157187
var expressions = [];
158188
angular.forEach(interpolationFunction.parts, function(part) {
159189
if(angular.isFunction(part)) {
@@ -210,7 +240,7 @@ function BreadcrumbDirective($interpolate, $breadcrumb, $rootScope) {
210240
var renderBreadcrumb = function() {
211241
deregisterWatchers(labelWatchers);
212242
labelWatchers = [];
213-
243+
214244
var viewScope = $breadcrumb.$getLastViewScope();
215245
scope.steps = $breadcrumb.getStatesChain();
216246
angular.forEach(scope.steps, function (step) {
@@ -225,7 +255,7 @@ function BreadcrumbDirective($interpolate, $breadcrumb, $rootScope) {
225255
});
226256
};
227257

228-
$rootScope.$on('$viewContentLoaded', function (event) {
258+
registerListenerOnce('BreadcrumbDirective.$viewContentLoaded', $rootScope, '$viewContentLoaded', function (event) {
229259
if(!event.targetScope.ncyBreadcrumbIgnore) {
230260
renderBreadcrumb();
231261
}
@@ -240,14 +270,20 @@ function BreadcrumbDirective($interpolate, $breadcrumb, $rootScope) {
240270
BreadcrumbDirective.$inject = ['$interpolate', '$breadcrumb', '$rootScope'];
241271

242272
function BreadcrumbLastDirective($interpolate, $breadcrumb, $rootScope) {
273+
var $$templates = {
274+
'default': '{{ncyBreadcrumbLabel}}'
275+
};
243276

244277
return {
245278
restrict: 'A',
246279
scope: {},
247-
template: '{{ncyBreadcrumbLabel}}',
280+
template: $breadcrumb.getTemplateLast($$templates),
281+
templateUrl: $breadcrumb.getTemplateLastUrl(),
248282
compile: function(cElement, cAttrs) {
249283

250284
// Override the default template if ncyBreadcrumbLast has a value
285+
// This should likely be removed in a future version since global
286+
// templating is now available for ncyBreadcrumbLast
251287
var template = cElement.attr(cAttrs.$attr.ncyBreadcrumbLast);
252288
if(template) {
253289
cElement.html(template);
@@ -260,7 +296,7 @@ function BreadcrumbLastDirective($interpolate, $breadcrumb, $rootScope) {
260296
var renderLabel = function() {
261297
deregisterWatchers(labelWatchers);
262298
labelWatchers = [];
263-
299+
264300
var viewScope = $breadcrumb.$getLastViewScope();
265301
var lastStep = $breadcrumb.getLastStep();
266302
if(lastStep) {
@@ -277,7 +313,7 @@ function BreadcrumbLastDirective($interpolate, $breadcrumb, $rootScope) {
277313
}
278314
};
279315

280-
$rootScope.$on('$viewContentLoaded', function (event) {
316+
registerListenerOnce('BreadcrumbLastDirective.$viewContentLoaded', $rootScope, '$viewContentLoaded', function (event) {
281317
if(!event.targetScope.ncyBreadcrumbIgnore) {
282318
renderLabel();
283319
}
@@ -306,13 +342,13 @@ function BreadcrumbTextDirective($interpolate, $breadcrumb, $rootScope) {
306342
if(template) {
307343
cElement.html(template);
308344
}
309-
345+
310346
var separator = cElement.attr(cAttrs.$attr.ncyBreadcrumbTextSeparator) || ' / ';
311347

312348
return {
313349
post: function postLink(scope) {
314350
var labelWatchers = [];
315-
351+
316352
var registerWatchersText = function(labelWatcherArray, interpolationFunction, viewScope) {
317353
angular.forEach(getExpression(interpolationFunction), function(expression) {
318354
var watcher = viewScope.$watch(expression, function(newValue, oldValue) {
@@ -327,7 +363,7 @@ function BreadcrumbTextDirective($interpolate, $breadcrumb, $rootScope) {
327363
var renderLabel = function() {
328364
deregisterWatchers(labelWatchers);
329365
labelWatchers = [];
330-
366+
331367
var viewScope = $breadcrumb.$getLastViewScope();
332368
var steps = $breadcrumb.getStatesChain();
333369
var combinedLabels = [];
@@ -341,11 +377,11 @@ function BreadcrumbTextDirective($interpolate, $breadcrumb, $rootScope) {
341377
combinedLabels.push(step.name);
342378
}
343379
});
344-
380+
345381
scope.ncyBreadcrumbChain = combinedLabels.join(separator);
346382
};
347383

348-
$rootScope.$on('$viewContentLoaded', function (event) {
384+
registerListenerOnce('BreadcrumbTextDirective.$viewContentLoaded', $rootScope, '$viewContentLoaded', function (event) {
349385
if(!event.targetScope.ncyBreadcrumbIgnore) {
350386
renderLabel();
351387
}

release/angular-breadcrumb.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
-5.63 KB
Binary file not shown.
6.09 KB
Binary file not shown.

0 commit comments

Comments
 (0)