diff --git a/dist/angular-breadcrumb.js b/dist/angular-breadcrumb.js index f2b868e..f554a68 100644 --- a/dist/angular-breadcrumb.js +++ b/dist/angular-breadcrumb.js @@ -1,4 +1,4 @@ -/*! angular-breadcrumb - v0.3.3-dev-2015-05-02 +/*! angular-breadcrumb - v0.4.0-dev-2015-08-06 * http://ncuillery.github.io/angular-breadcrumb * Copyright (c) 2015 Nicolas Cuillery; Licensed MIT */ @@ -39,7 +39,8 @@ function $Breadcrumb() { // Early catch of $viewContentLoaded event $rootScope.$on('$viewContentLoaded', function (event) { // With nested views, the event occur several times, in "wrong" order - if(isAOlderThanB(event.targetScope.$id, $lastViewScope.$id)) { + if(!event.targetScope.ncyBreadcrumbIgnore && + isAOlderThanB(event.targetScope.$id, $lastViewScope.$id)) { $lastViewScope = event.targetScope; } }); @@ -224,8 +225,10 @@ function BreadcrumbDirective($interpolate, $breadcrumb, $rootScope) { }); }; - $rootScope.$on('$viewContentLoaded', function () { - renderBreadcrumb(); + $rootScope.$on('$viewContentLoaded', function (event) { + if(!event.targetScope.ncyBreadcrumbIgnore) { + renderBreadcrumb(); + } }); // View(s) may be already loaded while the directive's linking @@ -274,8 +277,10 @@ function BreadcrumbLastDirective($interpolate, $breadcrumb, $rootScope) { } }; - $rootScope.$on('$viewContentLoaded', function () { - renderLabel(); + $rootScope.$on('$viewContentLoaded', function (event) { + if(!event.targetScope.ncyBreadcrumbIgnore) { + renderLabel(); + } }); // View(s) may be already loaded while the directive's linking @@ -340,8 +345,10 @@ function BreadcrumbTextDirective($interpolate, $breadcrumb, $rootScope) { scope.ncyBreadcrumbChain = combinedLabels.join(separator); }; - $rootScope.$on('$viewContentLoaded', function () { - renderLabel(); + $rootScope.$on('$viewContentLoaded', function (event) { + if(!event.targetScope.ncyBreadcrumbIgnore) { + renderLabel(); + } }); // View(s) may be already loaded while the directive's linking diff --git a/dist/angular-breadcrumb.min.js b/dist/angular-breadcrumb.min.js index a69b247..e5e8da3 100644 --- a/dist/angular-breadcrumb.min.js +++ b/dist/angular-breadcrumb.min.js @@ -1,4 +1,4 @@ -/*! angular-breadcrumb - v0.3.3-dev-2015-05-02 +/*! angular-breadcrumb - v0.4.0-dev-2015-08-06 * 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){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:' '};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); \ 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){var e={bootstrap2:' ',bootstrap3:' '};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 diff --git a/src/angular-breadcrumb.js b/src/angular-breadcrumb.js index a5d1ea9..a8f1415 100644 --- a/src/angular-breadcrumb.js +++ b/src/angular-breadcrumb.js @@ -34,7 +34,8 @@ function $Breadcrumb() { // Early catch of $viewContentLoaded event $rootScope.$on('$viewContentLoaded', function (event) { // With nested views, the event occur several times, in "wrong" order - if(isAOlderThanB(event.targetScope.$id, $lastViewScope.$id)) { + if(!event.targetScope.ncyBreadcrumbIgnore && + isAOlderThanB(event.targetScope.$id, $lastViewScope.$id)) { $lastViewScope = event.targetScope; } }); @@ -219,8 +220,10 @@ function BreadcrumbDirective($interpolate, $breadcrumb, $rootScope) { }); }; - $rootScope.$on('$viewContentLoaded', function () { - renderBreadcrumb(); + $rootScope.$on('$viewContentLoaded', function (event) { + if(!event.targetScope.ncyBreadcrumbIgnore) { + renderBreadcrumb(); + } }); // View(s) may be already loaded while the directive's linking @@ -269,8 +272,10 @@ function BreadcrumbLastDirective($interpolate, $breadcrumb, $rootScope) { } }; - $rootScope.$on('$viewContentLoaded', function () { - renderLabel(); + $rootScope.$on('$viewContentLoaded', function (event) { + if(!event.targetScope.ncyBreadcrumbIgnore) { + renderLabel(); + } }); // View(s) may be already loaded while the directive's linking @@ -335,8 +340,10 @@ function BreadcrumbTextDirective($interpolate, $breadcrumb, $rootScope) { scope.ncyBreadcrumbChain = combinedLabels.join(separator); }; - $rootScope.$on('$viewContentLoaded', function () { - renderLabel(); + $rootScope.$on('$viewContentLoaded', function (event) { + if(!event.targetScope.ncyBreadcrumbIgnore) { + renderLabel(); + } }); // View(s) may be already loaded while the directive's linking diff --git a/test/mock/test-modules.js b/test/mock/test-modules.js index 3b44881..a9876a0 100644 --- a/test/mock/test-modules.js +++ b/test/mock/test-modules.js @@ -117,3 +117,35 @@ angular.module('ncy-sample-conf', ['ncy-sample', 'ngMock']).config(function($url $httpBackend.when('GET', 'views/room_detail.html').respond('dummy room_detail view'); $httpBackend.when('GET', 'views/room_form.html').respond('dummy room_form view'); }); + +/** + * Module with abstract state with footer view + */ +angular.module('ncy-abstract-interpolation-conf', []).config(function($stateProvider) { + $stateProvider + .state('A', { + abstract: true, + url: '/a', + views: { + 'a@': { + template: '