diff --git a/dist/angular-breadcrumb.js b/dist/angular-breadcrumb.js
index e20ca15..e773f87 100644
--- a/dist/angular-breadcrumb.js
+++ b/dist/angular-breadcrumb.js
@@ -1,4 +1,4 @@
-/*! angular-breadcrumb - v0.4.0-dev-2015-08-07
+/*! angular-breadcrumb - v0.4.1-dev-2015-09-08
* http://ncuillery.github.io/angular-breadcrumb
* Copyright (c) 2015 Nicolas Cuillery; Licensed MIT */
@@ -180,7 +180,7 @@ var deregisterWatchers = function(labelWatcherArray) {
});
};
-function BreadcrumbDirective($interpolate, $breadcrumb, $rootScope) {
+function BreadcrumbDirective($interpolate, $breadcrumb, $rootScope, $injector) {
var $$templates = {
bootstrap2: '
' +
'- ' +
@@ -210,15 +210,21 @@ 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) {
if (step.ncyBreadcrumb && step.ncyBreadcrumb.label) {
- var parseLabel = $interpolate(step.ncyBreadcrumb.label);
- step.ncyBreadcrumbLabel = parseLabel(viewScope);
- // Watcher for further viewScope updates
- registerWatchers(labelWatchers, parseLabel, viewScope, step);
+ var type = Object.prototype.toString.call(step.ncyBreadcrumb.label);
+ if (type === '[object Function]' ||
+ type === '[object Array]') {
+ step.ncyBreadcrumbLabel = $injector.invoke(step.ncyBreadcrumb.label);
+ } else {
+ var parseLabel = $interpolate(step.ncyBreadcrumb.label);
+ step.ncyBreadcrumbLabel = parseLabel(viewScope);
+ // Watcher for further viewScope updates
+ registerWatchers(labelWatchers, parseLabel, viewScope, step);
+ }
} else {
step.ncyBreadcrumbLabel = step.name;
}
@@ -237,9 +243,9 @@ function BreadcrumbDirective($interpolate, $breadcrumb, $rootScope) {
}
};
}
-BreadcrumbDirective.$inject = ['$interpolate', '$breadcrumb', '$rootScope'];
+BreadcrumbDirective.$inject = ['$interpolate', '$breadcrumb', '$rootScope', '$injector'];
-function BreadcrumbLastDirective($interpolate, $breadcrumb, $rootScope) {
+function BreadcrumbLastDirective($interpolate, $breadcrumb, $rootScope, $injector) {
return {
restrict: 'A',
@@ -260,17 +266,22 @@ function BreadcrumbLastDirective($interpolate, $breadcrumb, $rootScope) {
var renderLabel = function() {
deregisterWatchers(labelWatchers);
labelWatchers = [];
-
+
var viewScope = $breadcrumb.$getLastViewScope();
var lastStep = $breadcrumb.getLastStep();
if(lastStep) {
scope.ncyBreadcrumbLink = lastStep.ncyBreadcrumbLink;
if (lastStep.ncyBreadcrumb && lastStep.ncyBreadcrumb.label) {
- var parseLabel = $interpolate(lastStep.ncyBreadcrumb.label);
- scope.ncyBreadcrumbLabel = parseLabel(viewScope);
- // Watcher for further viewScope updates
- // Tricky last arg: the last step is the entire scope of the directive !
- registerWatchers(labelWatchers, parseLabel, viewScope, scope);
+ var type = Object.prototype.toString.call(lastStep.ncyBreadcrumb.label);
+ if (type === '[object Function]' ||
+ type === '[object Array]') {
+ lastStep.ncyBreadcrumbLabel = $injector.invoke(lastStep.ncyBreadcrumb.label);
+ } else {
+ var parseLabel = $interpolate(lastStep.ncyBreadcrumb.label);
+ lastStep.ncyBreadcrumbLabel = parseLabel(viewScope);
+ // Watcher for further viewScope updates
+ registerWatchers(labelWatchers, parseLabel, viewScope, lastStep);
+ }
} else {
scope.ncyBreadcrumbLabel = lastStep.name;
}
@@ -291,9 +302,9 @@ function BreadcrumbLastDirective($interpolate, $breadcrumb, $rootScope) {
}
};
}
-BreadcrumbLastDirective.$inject = ['$interpolate', '$breadcrumb', '$rootScope'];
+BreadcrumbLastDirective.$inject = ['$interpolate', '$breadcrumb', '$rootScope', '$injector'];
-function BreadcrumbTextDirective($interpolate, $breadcrumb, $rootScope) {
+function BreadcrumbTextDirective($interpolate, $breadcrumb, $rootScope, $injector) {
return {
restrict: 'A',
@@ -306,13 +317,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) {
@@ -327,21 +338,27 @@ function BreadcrumbTextDirective($interpolate, $breadcrumb, $rootScope) {
var renderLabel = function() {
deregisterWatchers(labelWatchers);
labelWatchers = [];
-
+
var viewScope = $breadcrumb.$getLastViewScope();
var steps = $breadcrumb.getStatesChain();
var combinedLabels = [];
angular.forEach(steps, function (step) {
if (step.ncyBreadcrumb && step.ncyBreadcrumb.label) {
- var parseLabel = $interpolate(step.ncyBreadcrumb.label);
- combinedLabels.push(parseLabel(viewScope));
- // Watcher for further viewScope updates
- registerWatchersText(labelWatchers, parseLabel, viewScope);
+ var type = Object.prototype.toString.call(step.ncyBreadcrumb.label);
+ if (type === '[object Function]' ||
+ type === '[object Array]') {
+ step.ncyBreadcrumbLabel = $injector.invoke(step.ncyBreadcrumb.label);
+ } else {
+ var parseLabel = $interpolate(step.ncyBreadcrumb.label);
+ step.ncyBreadcrumbLabel = parseLabel(viewScope);
+ // Watcher for further viewScope updates
+ registerWatchersText(labelWatchers, parseLabel, viewScope, step);
+ }
} else {
combinedLabels.push(step.name);
}
});
-
+
scope.ncyBreadcrumbChain = combinedLabels.join(separator);
};
@@ -359,7 +376,7 @@ function BreadcrumbTextDirective($interpolate, $breadcrumb, $rootScope) {
}
};
}
-BreadcrumbTextDirective.$inject = ['$interpolate', '$breadcrumb', '$rootScope'];
+BreadcrumbTextDirective.$inject = ['$interpolate', '$breadcrumb', '$rootScope', '$injector'];
angular.module('ncy-angular-breadcrumb', ['ui.router.state'])
.provider('$breadcrumb', $Breadcrumb)
diff --git a/dist/angular-breadcrumb.min.js b/dist/angular-breadcrumb.min.js
index 1da045d..af5a81b 100644
--- a/dist/angular-breadcrumb.min.js
+++ b/dist/angular-breadcrumb.min.js
@@ -1,4 +1,4 @@
-/*! angular-breadcrumb - v0.4.0-dev-2015-08-07
+/*! angular-breadcrumb - v0.4.1-dev-2015-09-08
* http://ncuillery.github.io/angular-breadcrumb
* Copyright (c) 2015 Nicolas Cuillery; Licensed MIT */
-!function(a,b,c){"use strict";function d(a,c){return b.equals(a.length,c.length)?a>c:a.length>c.length}function e(a){var b=a.replace(/\n/g," ").match(/^([^(]+?)\s*(\((.*)\))?$/);if(!b||4!==b.length)throw new Error("Invalid state ref '"+a+"'");return{state:b[1],paramExpr:b[3]||null}}function f(){var a={prefixStateName:null,template:"bootstrap3",templateUrl:null,includeAbstract:!1};this.setOptions=function(c){b.extend(a,c)},this.$get=["$state","$stateParams","$rootScope",function(b,f,g){var h=g;g.$on("$viewContentLoaded",function(a){!a.targetScope.ncyBreadcrumbIgnore&&d(a.targetScope.$id,h.$id)&&(h=a.targetScope)});var i=function(a){var b=a.parent||(/^(.+)\.[^.]+$/.exec(a.name)||[])[1],c="object"==typeof b;return c?b.name:b},j=function(c,d){for(var g,i,j=e(d),k=!1,l=!1,m=0,n=c.length;n>m;m+=1)if(c[m].name===j.state)return;g=b.get(j.state),g.ncyBreadcrumb&&(g.ncyBreadcrumb.force&&(k=!0),g.ncyBreadcrumb.skip&&(l=!0)),g["abstract"]&&!a.includeAbstract&&!k||l||(j.paramExpr&&(i=h.$eval(j.paramExpr)),g.ncyBreadcrumbLink=b.href(j.state,i||f||{}),c.unshift(g))},k=function(a){var c=e(a),d=b.get(c.state);if(d.ncyBreadcrumb&&d.ncyBreadcrumb.parent){var f="function"==typeof d.ncyBreadcrumb.parent,g=f?d.ncyBreadcrumb.parent(h):d.ncyBreadcrumb.parent;if(g)return g}return i(d)};return{getTemplate:function(b){return a.templateUrl?null:b[a.template]?b[a.template]:a.template},getTemplateUrl:function(){return a.templateUrl},getStatesChain:function(c){for(var d=[],e=b.$current.self.name;e;e=k(e))if(j(d,e),c&&d.length)return d;return a.prefixStateName&&j(d,a.prefixStateName),d},getLastStep:function(){var a=this.getStatesChain(!0);return a.length?a[0]:c},$getLastViewScope:function(){return h}}}]}function g(a,c,d){var e={bootstrap2:'',bootstrap3:'
- {{step.ncyBreadcrumbLabel}}{{step.ncyBreadcrumbLabel}}
'};return{restrict:"AE",replace:!0,scope:{},template:c.getTemplate(e),templateUrl:c.getTemplateUrl(),link:{post:function(e){var f=[],g=function(){l(f),f=[];var d=c.$getLastViewScope();e.steps=c.getStatesChain(),b.forEach(e.steps,function(b){if(b.ncyBreadcrumb&&b.ncyBreadcrumb.label){var c=a(b.ncyBreadcrumb.label);b.ncyBreadcrumbLabel=c(d),k(f,c,d,b)}else b.ncyBreadcrumbLabel=b.name})};d.$on("$viewContentLoaded",function(a){a.targetScope.ncyBreadcrumbIgnore||g()}),g()}}}}function h(a,b,c){return{restrict:"A",scope:{},template:"{{ncyBreadcrumbLabel}}",compile:function(d,e){var f=d.attr(e.$attr.ncyBreadcrumbLast);return f&&d.html(f),{post:function(d){var e=[],f=function(){l(e),e=[];var c=b.$getLastViewScope(),f=b.getLastStep();if(f)if(d.ncyBreadcrumbLink=f.ncyBreadcrumbLink,f.ncyBreadcrumb&&f.ncyBreadcrumb.label){var g=a(f.ncyBreadcrumb.label);d.ncyBreadcrumbLabel=g(c),k(e,g,c,d)}else d.ncyBreadcrumbLabel=f.name};c.$on("$viewContentLoaded",function(a){a.targetScope.ncyBreadcrumbIgnore||f()}),f()}}}}}function i(a,c,d){return{restrict:"A",scope:{},template:"{{ncyBreadcrumbChain}}",compile:function(e,f){var g=e.attr(f.$attr.ncyBreadcrumbText);g&&e.html(g);var h=e.attr(f.$attr.ncyBreadcrumbTextSeparator)||" / ";return{post:function(e){var f=[],g=function(a,c,d){b.forEach(j(c),function(b){var c=d.$watch(b,function(a,b){a!==b&&i()});a.push(c)})},i=function(){l(f),f=[];var d=c.$getLastViewScope(),i=c.getStatesChain(),j=[];b.forEach(i,function(b){if(b.ncyBreadcrumb&&b.ncyBreadcrumb.label){var c=a(b.ncyBreadcrumb.label);j.push(c(d)),g(f,c,d)}else j.push(b.name)}),e.ncyBreadcrumbChain=j.join(h)};d.$on("$viewContentLoaded",function(a){a.targetScope.ncyBreadcrumbIgnore||i()}),i()}}}}}var j=function(a){if(a.expressions)return a.expressions;var c=[];return b.forEach(a.parts,function(a){b.isFunction(a)&&c.push(a.exp)}),c},k=function(a,c,d,e){b.forEach(j(c),function(b){var f=d.$watch(b,function(){e.ncyBreadcrumbLabel=c(d)});a.push(f)})},l=function(a){b.forEach(a,function(a){a()})};g.$inject=["$interpolate","$breadcrumb","$rootScope"],h.$inject=["$interpolate","$breadcrumb","$rootScope"],i.$inject=["$interpolate","$breadcrumb","$rootScope"],b.module("ncy-angular-breadcrumb",["ui.router.state"]).provider("$breadcrumb",f).directive("ncyBreadcrumb",g).directive("ncyBreadcrumbLast",h).directive("ncyBreadcrumbText",i)}(window,window.angular);
\ No newline at end of file
+!function(a,b,c){"use strict";function d(a,c){return b.equals(a.length,c.length)?a>c:a.length>c.length}function e(a){var b=a.replace(/\n/g," ").match(/^([^(]+?)\s*(\((.*)\))?$/);if(!b||4!==b.length)throw new Error("Invalid state ref '"+a+"'");return{state:b[1],paramExpr:b[3]||null}}function f(){var a={prefixStateName:null,template:"bootstrap3",templateUrl:null,includeAbstract:!1};this.setOptions=function(c){b.extend(a,c)},this.$get=["$state","$stateParams","$rootScope",function(b,f,g){var h=g;g.$on("$viewContentLoaded",function(a){!a.targetScope.ncyBreadcrumbIgnore&&d(a.targetScope.$id,h.$id)&&(h=a.targetScope)});var i=function(a){var b=a.parent||(/^(.+)\.[^.]+$/.exec(a.name)||[])[1],c="object"==typeof b;return c?b.name:b},j=function(c,d){for(var g,i,j=e(d),k=!1,l=!1,m=0,n=c.length;n>m;m+=1)if(c[m].name===j.state)return;g=b.get(j.state),g.ncyBreadcrumb&&(g.ncyBreadcrumb.force&&(k=!0),g.ncyBreadcrumb.skip&&(l=!0)),g["abstract"]&&!a.includeAbstract&&!k||l||(j.paramExpr&&(i=h.$eval(j.paramExpr)),g.ncyBreadcrumbLink=b.href(j.state,i||f||{}),c.unshift(g))},k=function(a){var c=e(a),d=b.get(c.state);if(d.ncyBreadcrumb&&d.ncyBreadcrumb.parent){var f="function"==typeof d.ncyBreadcrumb.parent,g=f?d.ncyBreadcrumb.parent(h):d.ncyBreadcrumb.parent;if(g)return g}return i(d)};return{getTemplate:function(b){return a.templateUrl?null:b[a.template]?b[a.template]:a.template},getTemplateUrl:function(){return a.templateUrl},getStatesChain:function(c){for(var d=[],e=b.$current.self.name;e;e=k(e))if(j(d,e),c&&d.length)return d;return a.prefixStateName&&j(d,a.prefixStateName),d},getLastStep:function(){var a=this.getStatesChain(!0);return a.length?a[0]:c},$getLastViewScope:function(){return h}}}]}function g(a,c,d,e){var f={bootstrap2:'',bootstrap3:'- {{step.ncyBreadcrumbLabel}}{{step.ncyBreadcrumbLabel}}
'};return{restrict:"AE",replace:!0,scope:{},template:c.getTemplate(f),templateUrl:c.getTemplateUrl(),link:{post:function(f){var g=[],h=function(){l(g),g=[];var d=c.$getLastViewScope();f.steps=c.getStatesChain(),b.forEach(f.steps,function(b){if(b.ncyBreadcrumb&&b.ncyBreadcrumb.label){var c=Object.prototype.toString.call(b.ncyBreadcrumb.label);if("[object Function]"===c||"[object Array]"===c)b.ncyBreadcrumbLabel=e.invoke(b.ncyBreadcrumb.label);else{var f=a(b.ncyBreadcrumb.label);b.ncyBreadcrumbLabel=f(d),k(g,f,d,b)}}else b.ncyBreadcrumbLabel=b.name})};d.$on("$viewContentLoaded",function(a){a.targetScope.ncyBreadcrumbIgnore||h()}),h()}}}}function h(a,b,c,d){return{restrict:"A",scope:{},template:"{{ncyBreadcrumbLabel}}",compile:function(e,f){var g=e.attr(f.$attr.ncyBreadcrumbLast);return g&&e.html(g),{post:function(e){var f=[],g=function(){l(f),f=[];var c=b.$getLastViewScope(),g=b.getLastStep();if(g)if(e.ncyBreadcrumbLink=g.ncyBreadcrumbLink,g.ncyBreadcrumb&&g.ncyBreadcrumb.label){var h=Object.prototype.toString.call(g.ncyBreadcrumb.label);if("[object Function]"===h||"[object Array]"===h)g.ncyBreadcrumbLabel=d.invoke(g.ncyBreadcrumb.label);else{var i=a(g.ncyBreadcrumb.label);g.ncyBreadcrumbLabel=i(c),k(f,i,c,g)}}else e.ncyBreadcrumbLabel=g.name};c.$on("$viewContentLoaded",function(a){a.targetScope.ncyBreadcrumbIgnore||g()}),g()}}}}}function i(a,c,d,e){return{restrict:"A",scope:{},template:"{{ncyBreadcrumbChain}}",compile:function(f,g){var h=f.attr(g.$attr.ncyBreadcrumbText);h&&f.html(h);var i=f.attr(g.$attr.ncyBreadcrumbTextSeparator)||" / ";return{post:function(f){var g=[],h=function(a,c,d){b.forEach(j(c),function(b){var c=d.$watch(b,function(a,b){a!==b&&k()});a.push(c)})},k=function(){l(g),g=[];var d=c.$getLastViewScope(),j=c.getStatesChain(),k=[];b.forEach(j,function(b){if(b.ncyBreadcrumb&&b.ncyBreadcrumb.label){var c=Object.prototype.toString.call(b.ncyBreadcrumb.label);if("[object Function]"===c||"[object Array]"===c)b.ncyBreadcrumbLabel=e.invoke(b.ncyBreadcrumb.label);else{var f=a(b.ncyBreadcrumb.label);b.ncyBreadcrumbLabel=f(d),h(g,f,d,b)}}else k.push(b.name)}),f.ncyBreadcrumbChain=k.join(i)};d.$on("$viewContentLoaded",function(a){a.targetScope.ncyBreadcrumbIgnore||k()}),k()}}}}}var j=function(a){if(a.expressions)return a.expressions;var c=[];return b.forEach(a.parts,function(a){b.isFunction(a)&&c.push(a.exp)}),c},k=function(a,c,d,e){b.forEach(j(c),function(b){var f=d.$watch(b,function(){e.ncyBreadcrumbLabel=c(d)});a.push(f)})},l=function(a){b.forEach(a,function(a){a()})};g.$inject=["$interpolate","$breadcrumb","$rootScope","$injector"],h.$inject=["$interpolate","$breadcrumb","$rootScope","$injector"],i.$inject=["$interpolate","$breadcrumb","$rootScope","$injector"],b.module("ncy-angular-breadcrumb",["ui.router.state"]).provider("$breadcrumb",f).directive("ncyBreadcrumb",g).directive("ncyBreadcrumbLast",h).directive("ncyBreadcrumbText",i)}(window,window.angular);
\ No newline at end of file
diff --git a/release/angular-breadcrumb.js b/release/angular-breadcrumb.js
index ba6e5dc..e773f87 100644
--- a/release/angular-breadcrumb.js
+++ b/release/angular-breadcrumb.js
@@ -1,4 +1,4 @@
-/*! angular-breadcrumb - v0.4.1
+/*! angular-breadcrumb - v0.4.1-dev-2015-09-08
* http://ncuillery.github.io/angular-breadcrumb
* Copyright (c) 2015 Nicolas Cuillery; Licensed MIT */
@@ -180,7 +180,7 @@ var deregisterWatchers = function(labelWatcherArray) {
});
};
-function BreadcrumbDirective($interpolate, $breadcrumb, $rootScope) {
+function BreadcrumbDirective($interpolate, $breadcrumb, $rootScope, $injector) {
var $$templates = {
bootstrap2: '' +
'- ' +
@@ -210,15 +210,21 @@ 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) {
if (step.ncyBreadcrumb && step.ncyBreadcrumb.label) {
- var parseLabel = $interpolate(step.ncyBreadcrumb.label);
- step.ncyBreadcrumbLabel = parseLabel(viewScope);
- // Watcher for further viewScope updates
- registerWatchers(labelWatchers, parseLabel, viewScope, step);
+ var type = Object.prototype.toString.call(step.ncyBreadcrumb.label);
+ if (type === '[object Function]' ||
+ type === '[object Array]') {
+ step.ncyBreadcrumbLabel = $injector.invoke(step.ncyBreadcrumb.label);
+ } else {
+ var parseLabel = $interpolate(step.ncyBreadcrumb.label);
+ step.ncyBreadcrumbLabel = parseLabel(viewScope);
+ // Watcher for further viewScope updates
+ registerWatchers(labelWatchers, parseLabel, viewScope, step);
+ }
} else {
step.ncyBreadcrumbLabel = step.name;
}
@@ -237,9 +243,9 @@ function BreadcrumbDirective($interpolate, $breadcrumb, $rootScope) {
}
};
}
-BreadcrumbDirective.$inject = ['$interpolate', '$breadcrumb', '$rootScope'];
+BreadcrumbDirective.$inject = ['$interpolate', '$breadcrumb', '$rootScope', '$injector'];
-function BreadcrumbLastDirective($interpolate, $breadcrumb, $rootScope) {
+function BreadcrumbLastDirective($interpolate, $breadcrumb, $rootScope, $injector) {
return {
restrict: 'A',
@@ -260,17 +266,22 @@ function BreadcrumbLastDirective($interpolate, $breadcrumb, $rootScope) {
var renderLabel = function() {
deregisterWatchers(labelWatchers);
labelWatchers = [];
-
+
var viewScope = $breadcrumb.$getLastViewScope();
var lastStep = $breadcrumb.getLastStep();
if(lastStep) {
scope.ncyBreadcrumbLink = lastStep.ncyBreadcrumbLink;
if (lastStep.ncyBreadcrumb && lastStep.ncyBreadcrumb.label) {
- var parseLabel = $interpolate(lastStep.ncyBreadcrumb.label);
- scope.ncyBreadcrumbLabel = parseLabel(viewScope);
- // Watcher for further viewScope updates
- // Tricky last arg: the last step is the entire scope of the directive !
- registerWatchers(labelWatchers, parseLabel, viewScope, scope);
+ var type = Object.prototype.toString.call(lastStep.ncyBreadcrumb.label);
+ if (type === '[object Function]' ||
+ type === '[object Array]') {
+ lastStep.ncyBreadcrumbLabel = $injector.invoke(lastStep.ncyBreadcrumb.label);
+ } else {
+ var parseLabel = $interpolate(lastStep.ncyBreadcrumb.label);
+ lastStep.ncyBreadcrumbLabel = parseLabel(viewScope);
+ // Watcher for further viewScope updates
+ registerWatchers(labelWatchers, parseLabel, viewScope, lastStep);
+ }
} else {
scope.ncyBreadcrumbLabel = lastStep.name;
}
@@ -291,9 +302,9 @@ function BreadcrumbLastDirective($interpolate, $breadcrumb, $rootScope) {
}
};
}
-BreadcrumbLastDirective.$inject = ['$interpolate', '$breadcrumb', '$rootScope'];
+BreadcrumbLastDirective.$inject = ['$interpolate', '$breadcrumb', '$rootScope', '$injector'];
-function BreadcrumbTextDirective($interpolate, $breadcrumb, $rootScope) {
+function BreadcrumbTextDirective($interpolate, $breadcrumb, $rootScope, $injector) {
return {
restrict: 'A',
@@ -306,13 +317,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) {
@@ -327,21 +338,27 @@ function BreadcrumbTextDirective($interpolate, $breadcrumb, $rootScope) {
var renderLabel = function() {
deregisterWatchers(labelWatchers);
labelWatchers = [];
-
+
var viewScope = $breadcrumb.$getLastViewScope();
var steps = $breadcrumb.getStatesChain();
var combinedLabels = [];
angular.forEach(steps, function (step) {
if (step.ncyBreadcrumb && step.ncyBreadcrumb.label) {
- var parseLabel = $interpolate(step.ncyBreadcrumb.label);
- combinedLabels.push(parseLabel(viewScope));
- // Watcher for further viewScope updates
- registerWatchersText(labelWatchers, parseLabel, viewScope);
+ var type = Object.prototype.toString.call(step.ncyBreadcrumb.label);
+ if (type === '[object Function]' ||
+ type === '[object Array]') {
+ step.ncyBreadcrumbLabel = $injector.invoke(step.ncyBreadcrumb.label);
+ } else {
+ var parseLabel = $interpolate(step.ncyBreadcrumb.label);
+ step.ncyBreadcrumbLabel = parseLabel(viewScope);
+ // Watcher for further viewScope updates
+ registerWatchersText(labelWatchers, parseLabel, viewScope, step);
+ }
} else {
combinedLabels.push(step.name);
}
});
-
+
scope.ncyBreadcrumbChain = combinedLabels.join(separator);
};
@@ -359,7 +376,7 @@ function BreadcrumbTextDirective($interpolate, $breadcrumb, $rootScope) {
}
};
}
-BreadcrumbTextDirective.$inject = ['$interpolate', '$breadcrumb', '$rootScope'];
+BreadcrumbTextDirective.$inject = ['$interpolate', '$breadcrumb', '$rootScope', '$injector'];
angular.module('ncy-angular-breadcrumb', ['ui.router.state'])
.provider('$breadcrumb', $Breadcrumb)
diff --git a/release/angular-breadcrumb.min.js b/release/angular-breadcrumb.min.js
index ceb49da..c2c1b4b 100644
--- a/release/angular-breadcrumb.min.js
+++ b/release/angular-breadcrumb.min.js
@@ -1,4 +1,4 @@
-/*! angular-breadcrumb - v0.4.1
+/*! angular-breadcrumb - v0.4.1-dev-2015-09-08
* http://ncuillery.github.io/angular-breadcrumb
* Copyright (c) 2015 Nicolas Cuillery; Licensed MIT */
-!function(a,b,c){"use strict";function d(a,c){return b.equals(a.length,c.length)?a>c:a.length>c.length}function e(a){var b=a.replace(/\n/g," ").match(/^([^(]+?)\s*(\((.*)\))?$/);if(!b||4!==b.length)throw new Error("Invalid state ref '"+a+"'");return{state:b[1],paramExpr:b[3]||null}}function f(){var a={prefixStateName:null,template:"bootstrap3",templateUrl:null,includeAbstract:!1};this.setOptions=function(c){b.extend(a,c)},this.$get=["$state","$stateParams","$rootScope",function(b,f,g){var h=g;g.$on("$viewContentLoaded",function(a){!a.targetScope.ncyBreadcrumbIgnore&&d(a.targetScope.$id,h.$id)&&(h=a.targetScope)});var i=function(a){var b=a.parent||(/^(.+)\.[^.]+$/.exec(a.name)||[])[1],c="object"==typeof b;return c?b.name:b},j=function(c,d){for(var g,i,j=e(d),k=!1,l=!1,m=0,n=c.length;n>m;m+=1)if(c[m].name===j.state)return;g=b.get(j.state),g.ncyBreadcrumb&&(g.ncyBreadcrumb.force&&(k=!0),g.ncyBreadcrumb.skip&&(l=!0)),g["abstract"]&&!a.includeAbstract&&!k||l||(j.paramExpr&&(i=h.$eval(j.paramExpr)),g.ncyBreadcrumbLink=b.href(j.state,i||f||{}),c.unshift(g))},k=function(a){var c=e(a),d=b.get(c.state);if(d.ncyBreadcrumb&&d.ncyBreadcrumb.parent){var f="function"==typeof d.ncyBreadcrumb.parent,g=f?d.ncyBreadcrumb.parent(h):d.ncyBreadcrumb.parent;if(g)return g}return i(d)};return{getTemplate:function(b){return a.templateUrl?null:b[a.template]?b[a.template]:a.template},getTemplateUrl:function(){return a.templateUrl},getStatesChain:function(c){for(var d=[],e=b.$current.self.name;e;e=k(e))if(j(d,e),c&&d.length)return d;return a.prefixStateName&&j(d,a.prefixStateName),d},getLastStep:function(){var a=this.getStatesChain(!0);return a.length?a[0]:c},$getLastViewScope:function(){return h}}}]}function g(a,c,d){var e={bootstrap2:'',bootstrap3:'
- {{step.ncyBreadcrumbLabel}}{{step.ncyBreadcrumbLabel}}
'};return{restrict:"AE",replace:!0,scope:{},template:c.getTemplate(e),templateUrl:c.getTemplateUrl(),link:{post:function(e){var f=[],g=function(){l(f),f=[];var d=c.$getLastViewScope();e.steps=c.getStatesChain(),b.forEach(e.steps,function(b){if(b.ncyBreadcrumb&&b.ncyBreadcrumb.label){var c=a(b.ncyBreadcrumb.label);b.ncyBreadcrumbLabel=c(d),k(f,c,d,b)}else b.ncyBreadcrumbLabel=b.name})};d.$on("$viewContentLoaded",function(a){a.targetScope.ncyBreadcrumbIgnore||g()}),g()}}}}function h(a,b,c){return{restrict:"A",scope:{},template:"{{ncyBreadcrumbLabel}}",compile:function(d,e){var f=d.attr(e.$attr.ncyBreadcrumbLast);return f&&d.html(f),{post:function(d){var e=[],f=function(){l(e),e=[];var c=b.$getLastViewScope(),f=b.getLastStep();if(f)if(d.ncyBreadcrumbLink=f.ncyBreadcrumbLink,f.ncyBreadcrumb&&f.ncyBreadcrumb.label){var g=a(f.ncyBreadcrumb.label);d.ncyBreadcrumbLabel=g(c),k(e,g,c,d)}else d.ncyBreadcrumbLabel=f.name};c.$on("$viewContentLoaded",function(a){a.targetScope.ncyBreadcrumbIgnore||f()}),f()}}}}}function i(a,c,d){return{restrict:"A",scope:{},template:"{{ncyBreadcrumbChain}}",compile:function(e,f){var g=e.attr(f.$attr.ncyBreadcrumbText);g&&e.html(g);var h=e.attr(f.$attr.ncyBreadcrumbTextSeparator)||" / ";return{post:function(e){var f=[],g=function(a,c,d){b.forEach(j(c),function(b){var c=d.$watch(b,function(a,b){a!==b&&i()});a.push(c)})},i=function(){l(f),f=[];var d=c.$getLastViewScope(),i=c.getStatesChain(),j=[];b.forEach(i,function(b){if(b.ncyBreadcrumb&&b.ncyBreadcrumb.label){var c=a(b.ncyBreadcrumb.label);j.push(c(d)),g(f,c,d)}else j.push(b.name)}),e.ncyBreadcrumbChain=j.join(h)};d.$on("$viewContentLoaded",function(a){a.targetScope.ncyBreadcrumbIgnore||i()}),i()}}}}}var j=function(a){if(a.expressions)return a.expressions;var c=[];return b.forEach(a.parts,function(a){b.isFunction(a)&&c.push(a.exp)}),c},k=function(a,c,d,e){b.forEach(j(c),function(b){var f=d.$watch(b,function(){e.ncyBreadcrumbLabel=c(d)});a.push(f)})},l=function(a){b.forEach(a,function(a){a()})};g.$inject=["$interpolate","$breadcrumb","$rootScope"],h.$inject=["$interpolate","$breadcrumb","$rootScope"],i.$inject=["$interpolate","$breadcrumb","$rootScope"],b.module("ncy-angular-breadcrumb",["ui.router.state"]).provider("$breadcrumb",f).directive("ncyBreadcrumb",g).directive("ncyBreadcrumbLast",h).directive("ncyBreadcrumbText",i)}(window,window.angular);
\ No newline at end of file
+!function(a,b,c){"use strict";function d(a,c){return b.equals(a.length,c.length)?a>c:a.length>c.length}function e(a){var b=a.replace(/\n/g," ").match(/^([^(]+?)\s*(\((.*)\))?$/);if(!b||4!==b.length)throw new Error("Invalid state ref '"+a+"'");return{state:b[1],paramExpr:b[3]||null}}function f(){var a={prefixStateName:null,template:"bootstrap3",templateUrl:null,includeAbstract:!1};this.setOptions=function(c){b.extend(a,c)},this.$get=["$state","$stateParams","$rootScope",function(b,f,g){var h=g;g.$on("$viewContentLoaded",function(a){!a.targetScope.ncyBreadcrumbIgnore&&d(a.targetScope.$id,h.$id)&&(h=a.targetScope)});var i=function(a){var b=a.parent||(/^(.+)\.[^.]+$/.exec(a.name)||[])[1],c="object"==typeof b;return c?b.name:b},j=function(c,d){for(var g,i,j=e(d),k=!1,l=!1,m=0,n=c.length;n>m;m+=1)if(c[m].name===j.state)return;g=b.get(j.state),g.ncyBreadcrumb&&(g.ncyBreadcrumb.force&&(k=!0),g.ncyBreadcrumb.skip&&(l=!0)),g["abstract"]&&!a.includeAbstract&&!k||l||(j.paramExpr&&(i=h.$eval(j.paramExpr)),g.ncyBreadcrumbLink=b.href(j.state,i||f||{}),c.unshift(g))},k=function(a){var c=e(a),d=b.get(c.state);if(d.ncyBreadcrumb&&d.ncyBreadcrumb.parent){var f="function"==typeof d.ncyBreadcrumb.parent,g=f?d.ncyBreadcrumb.parent(h):d.ncyBreadcrumb.parent;if(g)return g}return i(d)};return{getTemplate:function(b){return a.templateUrl?null:b[a.template]?b[a.template]:a.template},getTemplateUrl:function(){return a.templateUrl},getStatesChain:function(c){for(var d=[],e=b.$current.self.name;e;e=k(e))if(j(d,e),c&&d.length)return d;return a.prefixStateName&&j(d,a.prefixStateName),d},getLastStep:function(){var a=this.getStatesChain(!0);return a.length?a[0]:c},$getLastViewScope:function(){return h}}}]}function g(a,c,d,e){var f={bootstrap2:'',bootstrap3:'- {{step.ncyBreadcrumbLabel}}{{step.ncyBreadcrumbLabel}}
'};return{restrict:"AE",replace:!0,scope:{},template:c.getTemplate(f),templateUrl:c.getTemplateUrl(),link:{post:function(f){var g=[],h=function(){l(g),g=[];var d=c.$getLastViewScope();f.steps=c.getStatesChain(),b.forEach(f.steps,function(b){if(b.ncyBreadcrumb&&b.ncyBreadcrumb.label){var c=Object.prototype.toString.call(b.ncyBreadcrumb.label);if("[object Function]"===c||"[object Array]"===c)b.ncyBreadcrumbLabel=e.invoke(b.ncyBreadcrumb.label);else{var f=a(b.ncyBreadcrumb.label);b.ncyBreadcrumbLabel=f(d),k(g,f,d,b)}}else b.ncyBreadcrumbLabel=b.name})};d.$on("$viewContentLoaded",function(a){a.targetScope.ncyBreadcrumbIgnore||h()}),h()}}}}function h(a,b,c,d){return{restrict:"A",scope:{},template:"{{ncyBreadcrumbLabel}}",compile:function(e,f){var g=e.attr(f.$attr.ncyBreadcrumbLast);return g&&e.html(g),{post:function(e){var f=[],g=function(){l(f),f=[];var c=b.$getLastViewScope(),g=b.getLastStep();if(g)if(e.ncyBreadcrumbLink=g.ncyBreadcrumbLink,g.ncyBreadcrumb&&g.ncyBreadcrumb.label){var h=Object.prototype.toString.call(g.ncyBreadcrumb.label);if("[object Function]"===h||"[object Array]"===h)g.ncyBreadcrumbLabel=d.invoke(g.ncyBreadcrumb.label);else{var i=a(g.ncyBreadcrumb.label);g.ncyBreadcrumbLabel=i(c),k(f,i,c,g)}}else e.ncyBreadcrumbLabel=g.name};c.$on("$viewContentLoaded",function(a){a.targetScope.ncyBreadcrumbIgnore||g()}),g()}}}}}function i(a,c,d,e){return{restrict:"A",scope:{},template:"{{ncyBreadcrumbChain}}",compile:function(f,g){var h=f.attr(g.$attr.ncyBreadcrumbText);h&&f.html(h);var i=f.attr(g.$attr.ncyBreadcrumbTextSeparator)||" / ";return{post:function(f){var g=[],h=function(a,c,d){b.forEach(j(c),function(b){var c=d.$watch(b,function(a,b){a!==b&&k()});a.push(c)})},k=function(){l(g),g=[];var d=c.$getLastViewScope(),j=c.getStatesChain(),k=[];b.forEach(j,function(b){if(b.ncyBreadcrumb&&b.ncyBreadcrumb.label){var c=Object.prototype.toString.call(b.ncyBreadcrumb.label);if("[object Function]"===c||"[object Array]"===c)b.ncyBreadcrumbLabel=e.invoke(b.ncyBreadcrumb.label);else{var f=a(b.ncyBreadcrumb.label);b.ncyBreadcrumbLabel=f(d),h(g,f,d,b)}}else k.push(b.name)}),f.ncyBreadcrumbChain=k.join(i)};d.$on("$viewContentLoaded",function(a){a.targetScope.ncyBreadcrumbIgnore||k()}),k()}}}}}var j=function(a){if(a.expressions)return a.expressions;var c=[];return b.forEach(a.parts,function(a){b.isFunction(a)&&c.push(a.exp)}),c},k=function(a,c,d,e){b.forEach(j(c),function(b){var f=d.$watch(b,function(){e.ncyBreadcrumbLabel=c(d)});a.push(f)})},l=function(a){b.forEach(a,function(a){a()})};g.$inject=["$interpolate","$breadcrumb","$rootScope","$injector"],h.$inject=["$interpolate","$breadcrumb","$rootScope","$injector"],i.$inject=["$interpolate","$breadcrumb","$rootScope","$injector"],b.module("ncy-angular-breadcrumb",["ui.router.state"]).provider("$breadcrumb",f).directive("ncyBreadcrumb",g).directive("ncyBreadcrumbLast",h).directive("ncyBreadcrumbText",i)}(window,window.angular);
diff --git a/src/angular-breadcrumb.js b/src/angular-breadcrumb.js
index a8f1415..828d92e 100644
--- a/src/angular-breadcrumb.js
+++ b/src/angular-breadcrumb.js
@@ -175,7 +175,7 @@ var deregisterWatchers = function(labelWatcherArray) {
});
};
-function BreadcrumbDirective($interpolate, $breadcrumb, $rootScope) {
+function BreadcrumbDirective($interpolate, $breadcrumb, $rootScope, $injector) {
var $$templates = {
bootstrap2: '' +
'- ' +
@@ -205,15 +205,21 @@ 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) {
if (step.ncyBreadcrumb && step.ncyBreadcrumb.label) {
- var parseLabel = $interpolate(step.ncyBreadcrumb.label);
- step.ncyBreadcrumbLabel = parseLabel(viewScope);
- // Watcher for further viewScope updates
- registerWatchers(labelWatchers, parseLabel, viewScope, step);
+ var type = Object.prototype.toString.call(step.ncyBreadcrumb.label);
+ if (type === '[object Function]' ||
+ type === '[object Array]') {
+ step.ncyBreadcrumbLabel = $injector.invoke(step.ncyBreadcrumb.label);
+ } else {
+ var parseLabel = $interpolate(step.ncyBreadcrumb.label);
+ step.ncyBreadcrumbLabel = parseLabel(viewScope);
+ // Watcher for further viewScope updates
+ registerWatchers(labelWatchers, parseLabel, viewScope, step);
+ }
} else {
step.ncyBreadcrumbLabel = step.name;
}
@@ -232,9 +238,9 @@ function BreadcrumbDirective($interpolate, $breadcrumb, $rootScope) {
}
};
}
-BreadcrumbDirective.$inject = ['$interpolate', '$breadcrumb', '$rootScope'];
+BreadcrumbDirective.$inject = ['$interpolate', '$breadcrumb', '$rootScope', '$injector'];
-function BreadcrumbLastDirective($interpolate, $breadcrumb, $rootScope) {
+function BreadcrumbLastDirective($interpolate, $breadcrumb, $rootScope, $injector) {
return {
restrict: 'A',
@@ -255,17 +261,22 @@ function BreadcrumbLastDirective($interpolate, $breadcrumb, $rootScope) {
var renderLabel = function() {
deregisterWatchers(labelWatchers);
labelWatchers = [];
-
+
var viewScope = $breadcrumb.$getLastViewScope();
var lastStep = $breadcrumb.getLastStep();
if(lastStep) {
scope.ncyBreadcrumbLink = lastStep.ncyBreadcrumbLink;
if (lastStep.ncyBreadcrumb && lastStep.ncyBreadcrumb.label) {
- var parseLabel = $interpolate(lastStep.ncyBreadcrumb.label);
- scope.ncyBreadcrumbLabel = parseLabel(viewScope);
- // Watcher for further viewScope updates
- // Tricky last arg: the last step is the entire scope of the directive !
- registerWatchers(labelWatchers, parseLabel, viewScope, scope);
+ var type = Object.prototype.toString.call(lastStep.ncyBreadcrumb.label);
+ if (type === '[object Function]' ||
+ type === '[object Array]') {
+ lastStep.ncyBreadcrumbLabel = $injector.invoke(lastStep.ncyBreadcrumb.label);
+ } else {
+ var parseLabel = $interpolate(lastStep.ncyBreadcrumb.label);
+ lastStep.ncyBreadcrumbLabel = parseLabel(viewScope);
+ // Watcher for further viewScope updates
+ registerWatchers(labelWatchers, parseLabel, viewScope, lastStep);
+ }
} else {
scope.ncyBreadcrumbLabel = lastStep.name;
}
@@ -286,9 +297,9 @@ function BreadcrumbLastDirective($interpolate, $breadcrumb, $rootScope) {
}
};
}
-BreadcrumbLastDirective.$inject = ['$interpolate', '$breadcrumb', '$rootScope'];
+BreadcrumbLastDirective.$inject = ['$interpolate', '$breadcrumb', '$rootScope', '$injector'];
-function BreadcrumbTextDirective($interpolate, $breadcrumb, $rootScope) {
+function BreadcrumbTextDirective($interpolate, $breadcrumb, $rootScope, $injector) {
return {
restrict: 'A',
@@ -301,13 +312,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) {
@@ -322,21 +333,27 @@ function BreadcrumbTextDirective($interpolate, $breadcrumb, $rootScope) {
var renderLabel = function() {
deregisterWatchers(labelWatchers);
labelWatchers = [];
-
+
var viewScope = $breadcrumb.$getLastViewScope();
var steps = $breadcrumb.getStatesChain();
var combinedLabels = [];
angular.forEach(steps, function (step) {
if (step.ncyBreadcrumb && step.ncyBreadcrumb.label) {
- var parseLabel = $interpolate(step.ncyBreadcrumb.label);
- combinedLabels.push(parseLabel(viewScope));
- // Watcher for further viewScope updates
- registerWatchersText(labelWatchers, parseLabel, viewScope);
+ var type = Object.prototype.toString.call(step.ncyBreadcrumb.label);
+ if (type === '[object Function]' ||
+ type === '[object Array]') {
+ step.ncyBreadcrumbLabel = $injector.invoke(step.ncyBreadcrumb.label);
+ } else {
+ var parseLabel = $interpolate(step.ncyBreadcrumb.label);
+ step.ncyBreadcrumbLabel = parseLabel(viewScope);
+ // Watcher for further viewScope updates
+ registerWatchersText(labelWatchers, parseLabel, viewScope, step);
+ }
} else {
combinedLabels.push(step.name);
}
});
-
+
scope.ncyBreadcrumbChain = combinedLabels.join(separator);
};
@@ -354,7 +371,7 @@ function BreadcrumbTextDirective($interpolate, $breadcrumb, $rootScope) {
}
};
}
-BreadcrumbTextDirective.$inject = ['$interpolate', '$breadcrumb', '$rootScope'];
+BreadcrumbTextDirective.$inject = ['$interpolate', '$breadcrumb', '$rootScope', '$injector'];
angular.module('ncy-angular-breadcrumb', ['ui.router.state'])
.provider('$breadcrumb', $Breadcrumb)