angular-breadcrumb
Advanced tools
Comparing version
{ | ||
"name": "angular-breadcrumb", | ||
"description": "AngularJS module that generates a breadcrumb from ui-router's states", | ||
"version": "0.3.3", | ||
"version": "0.4.0", | ||
"main": "release/angular-breadcrumb.js", | ||
@@ -6,0 +6,0 @@ "ignore": [ |
@@ -0,1 +1,18 @@ | ||
<a name="0.3.4"></a> | ||
### 0.3.4 (2015-05-17) | ||
#### Bug Fixes | ||
* **$breadcrumb:** Handle parents provided by StateObject references ([f4288d37](http://github.com/ncuillery/angular-breadcrumb/commit/f4288d375fd1090ffec1d67e85c6300d74d86d37), closes [#82](http://github.com/ncuillery/angular-breadcrumb/issues/82)) | ||
* **ncyBreadcrumb:** | ||
* Prevent memory leak when label is a binding ([264e10f6](http://github.com/ncuillery/angular-breadcrumb/commit/264e10f680e1bbb8d1e00cf500de39cac4222cfd), closes [#88](http://github.com/ncuillery/angular-breadcrumb/issues/88)) | ||
* Removed trailing spaces from breadcrumb items([bc276ed5](http://github.com/ncuillery/angular-breadcrumb/commit/bc276ed5351a586d4a6dc83ada0687e6ca485344), closes [#77](http://github.com/ncuillery/angular-breadcrumb/issues/77)) | ||
#### 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)) | ||
* **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)) | ||
<a name="0.3.3"></a> | ||
@@ -2,0 +19,0 @@ ### 0.3.3 (2014-12-16) |
@@ -1,4 +0,4 @@ | ||
/*! angular-breadcrumb - v0.3.2-dev-2014-12-14 | ||
/*! angular-breadcrumb - v0.3.3-dev-2015-05-02 | ||
* http://ncuillery.github.io/angular-breadcrumb | ||
* Copyright (c) 2014 Nicolas Cuillery; Licensed MIT */ | ||
* Copyright (c) 2015 Nicolas Cuillery; Licensed MIT */ | ||
@@ -50,5 +50,6 @@ (function (window, angular, undefined) { | ||
// Check if state has explicit parent OR we try guess parent from its name | ||
var name = state.parent || (/^(.+)\.[^.]+$/.exec(state.name) || [])[1]; | ||
// If we were able to figure out parent name then get this state | ||
return name; | ||
var parent = state.parent || (/^(.+)\.[^.]+$/.exec(state.name) || [])[1]; | ||
var isObjectParent = typeof parent === "object"; | ||
// if parent is a object reference, then extract the name | ||
return isObjectParent ? parent.name : parent; | ||
}; | ||
@@ -60,3 +61,5 @@ | ||
parentParams, | ||
ref = parseStateRef(stateRef); | ||
ref = parseStateRef(stateRef), | ||
force = false, | ||
skip = false; | ||
@@ -70,3 +73,8 @@ for(var i=0, l=chain.length; i<l; i+=1) { | ||
conf = $state.get(ref.state); | ||
if((!conf.abstract || $$options.includeAbstract) && !(conf.ncyBreadcrumb && conf.ncyBreadcrumb.skip)) { | ||
// Get breadcrumb options | ||
if(conf.ncyBreadcrumb) { | ||
if(conf.ncyBreadcrumb.force){ force = true; } | ||
if(conf.ncyBreadcrumb.skip){ skip = true; } | ||
} | ||
if((!conf.abstract || $$options.includeAbstract || force) && !skip) { | ||
if(ref.paramExpr) { | ||
@@ -175,3 +183,2 @@ parentParams = $lastViewScope.$eval(ref.paramExpr); | ||
}); | ||
labelWatcherArray = []; | ||
}; | ||
@@ -183,3 +190,3 @@ | ||
'<li ng-repeat="step in steps" ng-switch="$last || !!step.abstract" ng-class="{active: $last}">' + | ||
'<a ng-switch-when="false" href="{{step.ncyBreadcrumbLink}}">{{step.ncyBreadcrumbLabel}}</a> ' + | ||
'<a ng-switch-when="false" href="{{step.ncyBreadcrumbLink}}">{{step.ncyBreadcrumbLabel}}</a>' + | ||
'<span ng-switch-when="true">{{step.ncyBreadcrumbLabel}}</span>' + | ||
@@ -191,3 +198,3 @@ '<span class="divider" ng-hide="$last">/</span>' + | ||
'<li ng-repeat="step in steps" ng-class="{active: $last}" ng-switch="$last || !!step.abstract">' + | ||
'<a ng-switch-when="false" href="{{step.ncyBreadcrumbLink}}">{{step.ncyBreadcrumbLabel}}</a> ' + | ||
'<a ng-switch-when="false" href="{{step.ncyBreadcrumbLink}}">{{step.ncyBreadcrumbLabel}}</a>' + | ||
'<span ng-switch-when="true">{{step.ncyBreadcrumbLabel}}</span>' + | ||
@@ -210,2 +217,4 @@ '</li>' + | ||
deregisterWatchers(labelWatchers); | ||
labelWatchers = []; | ||
var viewScope = $breadcrumb.$getLastViewScope(); | ||
@@ -257,2 +266,4 @@ scope.steps = $breadcrumb.getStatesChain(); | ||
deregisterWatchers(labelWatchers); | ||
labelWatchers = []; | ||
var viewScope = $breadcrumb.$getLastViewScope(); | ||
@@ -288,6 +299,73 @@ var lastStep = $breadcrumb.getLastStep(); | ||
function BreadcrumbTextDirective($interpolate, $breadcrumb, $rootScope) { | ||
return { | ||
restrict: 'A', | ||
scope: {}, | ||
template: '{{ncyBreadcrumbChain}}', | ||
compile: function(cElement, cAttrs) { | ||
// Override the default template if ncyBreadcrumbText has a value | ||
var template = cElement.attr(cAttrs.$attr.ncyBreadcrumbText); | ||
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) { | ||
if (newValue !== oldValue) { | ||
renderLabel(); | ||
} | ||
}); | ||
labelWatcherArray.push(watcher); | ||
}); | ||
}; | ||
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); | ||
} else { | ||
combinedLabels.push(step.name); | ||
} | ||
}); | ||
scope.ncyBreadcrumbChain = combinedLabels.join(separator); | ||
}; | ||
$rootScope.$on('$viewContentLoaded', function () { | ||
renderLabel(); | ||
}); | ||
// View(s) may be already loaded while the directive's linking | ||
renderLabel(); | ||
} | ||
}; | ||
} | ||
}; | ||
} | ||
BreadcrumbTextDirective.$inject = ['$interpolate', '$breadcrumb', '$rootScope']; | ||
angular.module('ncy-angular-breadcrumb', ['ui.router.state']) | ||
.provider('$breadcrumb', $Breadcrumb) | ||
.directive('ncyBreadcrumb', BreadcrumbDirective) | ||
.directive('ncyBreadcrumbLast', BreadcrumbLastDirective); | ||
.directive('ncyBreadcrumbLast', BreadcrumbLastDirective) | ||
.directive('ncyBreadcrumbText', BreadcrumbTextDirective); | ||
})(window, window.angular); |
@@ -1,4 +0,4 @@ | ||
/*! angular-breadcrumb - v0.3.2-dev-2014-12-14 | ||
/*! angular-breadcrumb - v0.3.3-dev-2015-05-02 | ||
* http://ncuillery.github.io/angular-breadcrumb | ||
* Copyright (c) 2014 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){d(a.targetScope.$id,h.$id)&&(h=a.targetScope)});var i=function(a){var b=a.parent||(/^(.+)\.[^.]+$/.exec(a.name)||[])[1];return b},j=function(c,d){for(var g,i,j=e(d),k=0,l=c.length;l>k;k+=1)if(c[k].name===j.state)return;g=b.get(j.state),g.abstract&&!a.includeAbstract||g.ncyBreadcrumb&&g.ncyBreadcrumb.skip||(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:'<ul class="breadcrumb"><li ng-repeat="step in steps" ng-switch="$last || !!step.abstract" ng-class="{active: $last}"><a ng-switch-when="false" href="{{step.ncyBreadcrumbLink}}">{{step.ncyBreadcrumbLabel}}</a> <span ng-switch-when="true">{{step.ncyBreadcrumbLabel}}</span><span class="divider" ng-hide="$last">/</span></li></ul>',bootstrap3:'<ol class="breadcrumb"><li ng-repeat="step in steps" ng-class="{active: $last}" ng-switch="$last || !!step.abstract"><a ng-switch-when="false" href="{{step.ncyBreadcrumbLink}}">{{step.ncyBreadcrumbLabel}}</a> <span ng-switch-when="true">{{step.ncyBreadcrumbLabel}}</span></li></ol>'};return{restrict:"AE",replace:!0,scope:{},template:c.getTemplate(e),templateUrl:c.getTemplateUrl(),link:{post:function(e){var f=[],g=function(){k(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),j(f,c,d,b)}else b.ncyBreadcrumbLabel=b.name})};d.$on("$viewContentLoaded",function(){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(){k(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),j(e,g,c,d)}else d.ncyBreadcrumbLabel=f.name};c.$on("$viewContentLoaded",function(){f()}),f()}}}}}var i=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},j=function(a,c,d,e){b.forEach(i(c),function(b){var f=d.$watch(b,function(){e.ncyBreadcrumbLabel=c(d)});a.push(f)})},k=function(a){b.forEach(a,function(a){a()}),a=[]};g.$inject=["$interpolate","$breadcrumb","$rootScope"],h.$inject=["$interpolate","$breadcrumb","$rootScope"],b.module("ncy-angular-breadcrumb",["ui.router.state"]).provider("$breadcrumb",f).directive("ncyBreadcrumb",g).directive("ncyBreadcrumbLast",h)}(window,window.angular); | ||
* 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){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:'<ul class="breadcrumb"><li ng-repeat="step in steps" ng-switch="$last || !!step.abstract" ng-class="{active: $last}"><a ng-switch-when="false" href="{{step.ncyBreadcrumbLink}}">{{step.ncyBreadcrumbLabel}}</a><span ng-switch-when="true">{{step.ncyBreadcrumbLabel}}</span><span class="divider" ng-hide="$last">/</span></li></ul>',bootstrap3:'<ol class="breadcrumb"><li ng-repeat="step in steps" ng-class="{active: $last}" ng-switch="$last || !!step.abstract"><a ng-switch-when="false" href="{{step.ncyBreadcrumbLink}}">{{step.ncyBreadcrumbLabel}}</a><span ng-switch-when="true">{{step.ncyBreadcrumbLabel}}</span></li></ol>'};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(){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(){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(){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); |
@@ -128,3 +128,3 @@ 'use strict'; | ||
'bower_components/angular-ui-bootstrap-bower/ui-bootstrap-tpls.js', | ||
'bower_components/bootstrap.css/css/bootstrap.css', | ||
'bower_components/bootstrap/docs/assets/css/bootstrap.css', | ||
'bower_components/underscore/underscore.js' | ||
@@ -131,0 +131,0 @@ ], |
{ | ||
"name": "angular-breadcrumb", | ||
"description": "AngularJS module that generates a breadcrumb from ui-router's states", | ||
"version": "0.3.3", | ||
"version": "0.4.0", | ||
"homepage": "http://ncuillery.github.io/angular-breadcrumb", | ||
@@ -6,0 +6,0 @@ "author": { |
@@ -1,4 +0,4 @@ | ||
/*! angular-breadcrumb - v0.3.3 | ||
/*! angular-breadcrumb - v0.4.0 | ||
* http://ncuillery.github.io/angular-breadcrumb | ||
* Copyright (c) 2014 Nicolas Cuillery; Licensed MIT */ | ||
* Copyright (c) 2015 Nicolas Cuillery; Licensed MIT */ | ||
@@ -50,5 +50,6 @@ (function (window, angular, undefined) { | ||
// Check if state has explicit parent OR we try guess parent from its name | ||
var name = state.parent || (/^(.+)\.[^.]+$/.exec(state.name) || [])[1]; | ||
// If we were able to figure out parent name then get this state | ||
return name; | ||
var parent = state.parent || (/^(.+)\.[^.]+$/.exec(state.name) || [])[1]; | ||
var isObjectParent = typeof parent === "object"; | ||
// if parent is a object reference, then extract the name | ||
return isObjectParent ? parent.name : parent; | ||
}; | ||
@@ -60,3 +61,5 @@ | ||
parentParams, | ||
ref = parseStateRef(stateRef); | ||
ref = parseStateRef(stateRef), | ||
force = false, | ||
skip = false; | ||
@@ -70,3 +73,8 @@ for(var i=0, l=chain.length; i<l; i+=1) { | ||
conf = $state.get(ref.state); | ||
if((!conf.abstract || $$options.includeAbstract) && !(conf.ncyBreadcrumb && conf.ncyBreadcrumb.skip)) { | ||
// Get breadcrumb options | ||
if(conf.ncyBreadcrumb) { | ||
if(conf.ncyBreadcrumb.force){ force = true; } | ||
if(conf.ncyBreadcrumb.skip){ skip = true; } | ||
} | ||
if((!conf.abstract || $$options.includeAbstract || force) && !skip) { | ||
if(ref.paramExpr) { | ||
@@ -175,3 +183,2 @@ parentParams = $lastViewScope.$eval(ref.paramExpr); | ||
}); | ||
labelWatcherArray = []; | ||
}; | ||
@@ -183,3 +190,3 @@ | ||
'<li ng-repeat="step in steps" ng-switch="$last || !!step.abstract" ng-class="{active: $last}">' + | ||
'<a ng-switch-when="false" href="{{step.ncyBreadcrumbLink}}">{{step.ncyBreadcrumbLabel}}</a> ' + | ||
'<a ng-switch-when="false" href="{{step.ncyBreadcrumbLink}}">{{step.ncyBreadcrumbLabel}}</a>' + | ||
'<span ng-switch-when="true">{{step.ncyBreadcrumbLabel}}</span>' + | ||
@@ -191,3 +198,3 @@ '<span class="divider" ng-hide="$last">/</span>' + | ||
'<li ng-repeat="step in steps" ng-class="{active: $last}" ng-switch="$last || !!step.abstract">' + | ||
'<a ng-switch-when="false" href="{{step.ncyBreadcrumbLink}}">{{step.ncyBreadcrumbLabel}}</a> ' + | ||
'<a ng-switch-when="false" href="{{step.ncyBreadcrumbLink}}">{{step.ncyBreadcrumbLabel}}</a>' + | ||
'<span ng-switch-when="true">{{step.ncyBreadcrumbLabel}}</span>' + | ||
@@ -210,2 +217,4 @@ '</li>' + | ||
deregisterWatchers(labelWatchers); | ||
labelWatchers = []; | ||
var viewScope = $breadcrumb.$getLastViewScope(); | ||
@@ -257,2 +266,4 @@ scope.steps = $breadcrumb.getStatesChain(); | ||
deregisterWatchers(labelWatchers); | ||
labelWatchers = []; | ||
var viewScope = $breadcrumb.$getLastViewScope(); | ||
@@ -288,6 +299,73 @@ var lastStep = $breadcrumb.getLastStep(); | ||
function BreadcrumbTextDirective($interpolate, $breadcrumb, $rootScope) { | ||
return { | ||
restrict: 'A', | ||
scope: {}, | ||
template: '{{ncyBreadcrumbChain}}', | ||
compile: function(cElement, cAttrs) { | ||
// Override the default template if ncyBreadcrumbText has a value | ||
var template = cElement.attr(cAttrs.$attr.ncyBreadcrumbText); | ||
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) { | ||
if (newValue !== oldValue) { | ||
renderLabel(); | ||
} | ||
}); | ||
labelWatcherArray.push(watcher); | ||
}); | ||
}; | ||
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); | ||
} else { | ||
combinedLabels.push(step.name); | ||
} | ||
}); | ||
scope.ncyBreadcrumbChain = combinedLabels.join(separator); | ||
}; | ||
$rootScope.$on('$viewContentLoaded', function () { | ||
renderLabel(); | ||
}); | ||
// View(s) may be already loaded while the directive's linking | ||
renderLabel(); | ||
} | ||
}; | ||
} | ||
}; | ||
} | ||
BreadcrumbTextDirective.$inject = ['$interpolate', '$breadcrumb', '$rootScope']; | ||
angular.module('ncy-angular-breadcrumb', ['ui.router.state']) | ||
.provider('$breadcrumb', $Breadcrumb) | ||
.directive('ncyBreadcrumb', BreadcrumbDirective) | ||
.directive('ncyBreadcrumbLast', BreadcrumbLastDirective); | ||
.directive('ncyBreadcrumbLast', BreadcrumbLastDirective) | ||
.directive('ncyBreadcrumbText', BreadcrumbTextDirective); | ||
})(window, window.angular); |
@@ -1,4 +0,4 @@ | ||
/*! angular-breadcrumb - v0.3.3 | ||
/*! angular-breadcrumb - v0.4.0 | ||
* http://ncuillery.github.io/angular-breadcrumb | ||
* Copyright (c) 2014 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){d(a.targetScope.$id,h.$id)&&(h=a.targetScope)});var i=function(a){var b=a.parent||(/^(.+)\.[^.]+$/.exec(a.name)||[])[1];return b},j=function(c,d){for(var g,i,j=e(d),k=0,l=c.length;l>k;k+=1)if(c[k].name===j.state)return;g=b.get(j.state),g.abstract&&!a.includeAbstract||g.ncyBreadcrumb&&g.ncyBreadcrumb.skip||(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:'<ul class="breadcrumb"><li ng-repeat="step in steps" ng-switch="$last || !!step.abstract" ng-class="{active: $last}"><a ng-switch-when="false" href="{{step.ncyBreadcrumbLink}}">{{step.ncyBreadcrumbLabel}}</a> <span ng-switch-when="true">{{step.ncyBreadcrumbLabel}}</span><span class="divider" ng-hide="$last">/</span></li></ul>',bootstrap3:'<ol class="breadcrumb"><li ng-repeat="step in steps" ng-class="{active: $last}" ng-switch="$last || !!step.abstract"><a ng-switch-when="false" href="{{step.ncyBreadcrumbLink}}">{{step.ncyBreadcrumbLabel}}</a> <span ng-switch-when="true">{{step.ncyBreadcrumbLabel}}</span></li></ol>'};return{restrict:"AE",replace:!0,scope:{},template:c.getTemplate(e),templateUrl:c.getTemplateUrl(),link:{post:function(e){var f=[],g=function(){k(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),j(f,c,d,b)}else b.ncyBreadcrumbLabel=b.name})};d.$on("$viewContentLoaded",function(){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(){k(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),j(e,g,c,d)}else d.ncyBreadcrumbLabel=f.name};c.$on("$viewContentLoaded",function(){f()}),f()}}}}}var i=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},j=function(a,c,d,e){b.forEach(i(c),function(b){var f=d.$watch(b,function(){e.ncyBreadcrumbLabel=c(d)});a.push(f)})},k=function(a){b.forEach(a,function(a){a()}),a=[]};g.$inject=["$interpolate","$breadcrumb","$rootScope"],h.$inject=["$interpolate","$breadcrumb","$rootScope"],b.module("ncy-angular-breadcrumb",["ui.router.state"]).provider("$breadcrumb",f).directive("ncyBreadcrumb",g).directive("ncyBreadcrumbLast",h)}(window,window.angular); | ||
* 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){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:'<ul class="breadcrumb"><li ng-repeat="step in steps" ng-switch="$last || !!step.abstract" ng-class="{active: $last}"><a ng-switch-when="false" href="{{step.ncyBreadcrumbLink}}">{{step.ncyBreadcrumbLabel}}</a><span ng-switch-when="true">{{step.ncyBreadcrumbLabel}}</span><span class="divider" ng-hide="$last">/</span></li></ul>',bootstrap3:'<ol class="breadcrumb"><li ng-repeat="step in steps" ng-class="{active: $last}" ng-switch="$last || !!step.abstract"><a ng-switch-when="false" href="{{step.ncyBreadcrumbLink}}">{{step.ncyBreadcrumbLabel}}</a><span ng-switch-when="true">{{step.ncyBreadcrumbLabel}}</span></li></ol>'};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(){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(){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(){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); |
61181
18.66%891
16.78%