Skip to content

Commit

Permalink
chore: release 0.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ncuillery committed Nov 14, 2016
1 parent e6e92aa commit 301df63
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 21 deletions.
17 changes: 16 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
<a name="0.5.0"></a>
## 0.5.0 (2016-11-14)


#### Bug Fixes

* 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))


#### Features

* 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))
* **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))


<a name="0.4.1"></a>
### 0.4.1 (2015-08-09)

Expand All @@ -20,7 +35,7 @@

#### Features

* Add force to ncyBreadcrumb options ([31125a38](http://github.com/ncuillery/angular-breadcrumb/commit/31125a386d706dd76df807b3b02e1fccea38fb59), closes [#77](http://github.com/ncuillery/angular-breadcrumb/issues/78))
* Add force to ncyBreadcrumb options ([31125a38](http://github.com/ncuillery/angular-breadcrumb/commit/31125a386d706dd76df807b3b02e1fccea38fb59), closes [#78](http://github.com/ncuillery/angular-breadcrumb/issues/78))
* **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))


Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "angular-breadcrumb",
"description": "AngularJS module that generates a breadcrumb from ui-router's states",
"version": "0.4.1",
"version": "0.5.0",
"main": "release/angular-breadcrumb.js",
"ignore": [
"sample",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "angular-breadcrumb",
"description": "AngularJS module that generates a breadcrumb from ui-router's states",
"version": "0.4.1",
"version": "0.5.0",
"homepage": "http://ncuillery.github.io/angular-breadcrumb",
"author": {
"name": "Nicolas Cuillery",
Expand Down
62 changes: 49 additions & 13 deletions release/angular-breadcrumb.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*! angular-breadcrumb - v0.4.1
/*! angular-breadcrumb - v0.5.0
* http://ncuillery.github.io/angular-breadcrumb
* Copyright (c) 2015 Nicolas Cuillery; Licensed MIT */
* Copyright (c) 2016 Nicolas Cuillery; Licensed MIT */

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

var $registeredListeners = {};
function registerListenerOnce(tag, $rootScope, event, fn) {
var deregisterListenerFn = $registeredListeners[tag];
if ( deregisterListenerFn !== undefined ) {
deregisterListenerFn();
}
deregisterListenerFn = $rootScope.$on(event, fn);
$registeredListeners[tag] = deregisterListenerFn;
}

function $Breadcrumb() {

var $$options = {
prefixStateName: null,
template: 'bootstrap3',
templateUrl: null,
templateLast: 'default',
templateLastUrl: null,
includeAbstract : false
};

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

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

conf.ncyBreadcrumbLink = $state.href(ref.state, parentParams || $stateParams || {});
conf.ncyBreadcrumbStateRef = stateRef;
chain.unshift(conf);
}
};
Expand Down Expand Up @@ -119,6 +132,22 @@ function $Breadcrumb() {
return $$options.templateUrl;
},

getTemplateLast: function(templates) {
if($$options.templateLastUrl) {
// templateUrl takes precedence over template
return null;
} else if(templates[$$options.templateLast]) {
// Predefined templates (default)
return templates[$$options.templateLast];
} else {
return $$options.templateLast;
}
},

getTemplateLastUrl: function() {
return $$options.templateLastUrl;
},

getStatesChain: function(exitOnFirst) { // Deliberately undocumented param, see getLastStep
var chain = [];

Expand Down Expand Up @@ -154,6 +183,7 @@ var getExpression = function(interpolationFunction) {
if(interpolationFunction.expressions) {
return interpolationFunction.expressions;
} else {
// Workaround for Angular 1.2.x
var expressions = [];
angular.forEach(interpolationFunction.parts, function(part) {
if(angular.isFunction(part)) {
Expand Down Expand Up @@ -210,7 +240,7 @@ function BreadcrumbDirective($interpolate, $breadcrumb, $rootScope) {
var renderBreadcrumb = function() {
deregisterWatchers(labelWatchers);
labelWatchers = [];

var viewScope = $breadcrumb.$getLastViewScope();
scope.steps = $breadcrumb.getStatesChain();
angular.forEach(scope.steps, function (step) {
Expand All @@ -225,7 +255,7 @@ function BreadcrumbDirective($interpolate, $breadcrumb, $rootScope) {
});
};

$rootScope.$on('$viewContentLoaded', function (event) {
registerListenerOnce('BreadcrumbDirective.$viewContentLoaded', $rootScope, '$viewContentLoaded', function (event) {
if(!event.targetScope.ncyBreadcrumbIgnore) {
renderBreadcrumb();
}
Expand All @@ -240,14 +270,20 @@ function BreadcrumbDirective($interpolate, $breadcrumb, $rootScope) {
BreadcrumbDirective.$inject = ['$interpolate', '$breadcrumb', '$rootScope'];

function BreadcrumbLastDirective($interpolate, $breadcrumb, $rootScope) {
var $$templates = {
'default': '{{ncyBreadcrumbLabel}}'
};

return {
restrict: 'A',
scope: {},
template: '{{ncyBreadcrumbLabel}}',
template: $breadcrumb.getTemplateLast($$templates),
templateUrl: $breadcrumb.getTemplateLastUrl(),
compile: function(cElement, cAttrs) {

// Override the default template if ncyBreadcrumbLast has a value
// This should likely be removed in a future version since global
// templating is now available for ncyBreadcrumbLast
var template = cElement.attr(cAttrs.$attr.ncyBreadcrumbLast);
if(template) {
cElement.html(template);
Expand All @@ -260,7 +296,7 @@ function BreadcrumbLastDirective($interpolate, $breadcrumb, $rootScope) {
var renderLabel = function() {
deregisterWatchers(labelWatchers);
labelWatchers = [];

var viewScope = $breadcrumb.$getLastViewScope();
var lastStep = $breadcrumb.getLastStep();
if(lastStep) {
Expand All @@ -277,7 +313,7 @@ function BreadcrumbLastDirective($interpolate, $breadcrumb, $rootScope) {
}
};

$rootScope.$on('$viewContentLoaded', function (event) {
registerListenerOnce('BreadcrumbLastDirective.$viewContentLoaded', $rootScope, '$viewContentLoaded', function (event) {
if(!event.targetScope.ncyBreadcrumbIgnore) {
renderLabel();
}
Expand Down Expand Up @@ -306,13 +342,13 @@ function BreadcrumbTextDirective($interpolate, $breadcrumb, $rootScope) {
if(template) {
cElement.html(template);
}

var separator = cElement.attr(cAttrs.$attr.ncyBreadcrumbTextSeparator) || ' / ';

return {
post: function postLink(scope) {
var labelWatchers = [];

var registerWatchersText = function(labelWatcherArray, interpolationFunction, viewScope) {
angular.forEach(getExpression(interpolationFunction), function(expression) {
var watcher = viewScope.$watch(expression, function(newValue, oldValue) {
Expand All @@ -327,7 +363,7 @@ function BreadcrumbTextDirective($interpolate, $breadcrumb, $rootScope) {
var renderLabel = function() {
deregisterWatchers(labelWatchers);
labelWatchers = [];

var viewScope = $breadcrumb.$getLastViewScope();
var steps = $breadcrumb.getStatesChain();
var combinedLabels = [];
Expand All @@ -341,11 +377,11 @@ function BreadcrumbTextDirective($interpolate, $breadcrumb, $rootScope) {
combinedLabels.push(step.name);
}
});

scope.ncyBreadcrumbChain = combinedLabels.join(separator);
};

$rootScope.$on('$viewContentLoaded', function (event) {
registerListenerOnce('BreadcrumbTextDirective.$viewContentLoaded', $rootScope, '$viewContentLoaded', function (event) {
if(!event.targetScope.ncyBreadcrumbIgnore) {
renderLabel();
}
Expand Down
6 changes: 3 additions & 3 deletions release/angular-breadcrumb.min.js

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

Binary file removed sample/angular-breadcrumb-0.4.1.zip
Binary file not shown.
Binary file added sample/angular-breadcrumb-0.5.0.zip
Binary file not shown.
Loading

1 comment on commit 301df63

@ptitdje45
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

expect(statesChain[0].ncyBreadcrumbStateRef).toBe('I({x: 'love', y: 'you'})');

awesome x) Great work thank you

Please sign in to comment.