Skip to content

Added support to use ncyBreadcrumb.label as an injector block #105

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
69 changes: 43 additions & 26 deletions dist/angular-breadcrumb.js
Original file line number Diff line number Diff line change
@@ -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 */

Expand Down Expand Up @@ -180,7 +180,7 @@ var deregisterWatchers = function(labelWatcherArray) {
});
};

function BreadcrumbDirective($interpolate, $breadcrumb, $rootScope) {
function BreadcrumbDirective($interpolate, $breadcrumb, $rootScope, $injector) {
var $$templates = {
bootstrap2: '<ul class="breadcrumb">' +
'<li ng-repeat="step in steps" ng-switch="$last || !!step.abstract" ng-class="{active: $last}">' +
Expand Down Expand Up @@ -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;
}
Expand All @@ -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',
Expand All @@ -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;
}
Expand All @@ -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',
Expand All @@ -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) {
Expand All @@ -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);
};

Expand All @@ -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)
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.

Loading