diff --git a/build/angular-route-segment.js b/build/angular-route-segment.js index 74ee3a0..726f348 100644 --- a/build/angular-route-segment.js +++ b/build/angular-route-segment.js @@ -20,7 +20,7 @@ angular.module( 'route-segment', [] ).provider( '$routeSegment', * contents into `template`. * @type {boolean} */ - autoLoadTemplates: false, + autoLoadTemplates: true, /** * When true, all attempts to call `within` method on non-existing segments will throw an error (you would @@ -474,7 +474,7 @@ angular.module( 'route-segment', [] ).provider( '$routeSegment', // Watching for the specified route segment and updating contents $scope.$on('routeSegmentChange', function(event, args) { - console.log('event',args); + if(args.index == viewSegmentIndex && currentSegment != args.segment) update(args.segment); }); @@ -502,8 +502,6 @@ angular.module( 'route-segment', [] ).provider( '$routeSegment', tElement.replaceWith(anchor); } - console.log('update',segment); - if(!segment) { clearContent(); currentElement = tElement.clone(); diff --git a/build/angular-route-segment.min.js b/build/angular-route-segment.min.js index 67ec44b..fea64b6 100644 --- a/build/angular-route-segment.min.js +++ b/build/angular-route-segment.min.js @@ -4,4 +4,4 @@ * @author Artem Chivchalov * @license MIT License http://opensource.org/licenses/MIT */ -"use strict";!function(a){a.module("route-segment",[]).provider("$routeSegment",["$routeProvider",function(b){function c(a){return a.replace(/([\:\-\_]+(.))/g,function(a,b,c,d){return d?c.toUpperCase():c})}function d(a,b){if(!a)throw new Error("Invalid pointer segment");var e;return{segment:function(b,d){return a[c(b)]={params:d},e=b,this},within:function(b){var g;if(b=b||e,g=a[c(b)])void 0==g.children&&(g.children={});else{if(f.strictMode)throw new Error("Cannot get into unknown `"+b+"` segment");g=a[c(b)]={params:{},children:{}}}return d(g.children,this)},up:function(){return b},root:function(){return h}}}var e=this,f=e.options={autoLoadTemplates:!1,strictMode:!1},g=this.segments={},h=d(g,null);e.when=function(a,c){return b.when(a,{segment:c}),this},a.extend(e,h),this.$get=["$rootScope","$q","$http","$templateCache","$route","$routeParams","$injector",function(b,d,e,h,i,j,k){function l(b){var c=!1;return b.params.dependencies&&a.forEach(b.params.dependencies,function(b){a.equals(q.$routeParams[b],j[b])||(c=!0)}),c}function m(a,b){return q.chain[a]&&q.chain[a].clearWatcher&&q.chain[a].clearWatcher(),b?(r[a]=b.name,b.params.untilResolved?n(a,b.name,b.params.untilResolved).then(function(c){return void 0!=c.success&&o(a),n(a,b.name,b.params)}):n(a,b.name,b.params)):(r[a]=null,o(a),void 0)}function n(c,g,i){var j=a.extend({},i.resolve);return a.forEach(j,function(b,c){j[c]=a.isString(b)?k.get(b):k.invoke(b)}),i.template&&(j.$template=i.template),f.autoLoadTemplates&&i.templateUrl&&(j.$template=e.get(i.templateUrl,{cache:h}).then(function(a){return a.data})),d.all(j).then(function(e){if(r[c]!=g)return d.reject();if(q.chain[c]={name:g,params:i,locals:e,reload:function(){m(c,this).then(function(a){void 0!=a.success&&o(c)})}},i.watcher){var f=function(){if(!a.isFunction(i.watcher))throw new Error("Watcher is not a function in segment `"+g+"`");return k.invoke(i.watcher,{},{segment:q.chain[c]})},h=f();q.chain[c].clearWatcher=b.$watch(f,function(a){a!=h&&(h=a,q.chain[c].reload())})}return{success:c}},function(b){if(i.resolveFailed){var e={error:function(){return d.when(b)}};return n(c,g,a.extend({resolve:e},i.resolveFailed))}throw new Error("Resolving failed with a reason `"+b+"`, but no `resolveFailed` "+"provided for segment `"+g+"`")})}function o(c){q.$routeParams=a.copy(j),q.name="";for(var d=0;d=b.length)return null;for(var d,e=g,f=0;a>=f;f++)d=b[f],void 0!=e[c(d)]&&(e=e[c(d)]),a>f&&(e=e.children);return{name:d,params:e.params}}var q={name:"",$routeParams:a.copy(j),chain:[],startsWith:function(a){var b=new RegExp("^"+a);return b.test(q.name)},contains:function(a){for(var b=0;b0||l(i))&&(q.chain[h]&&q.chain[h].name==i.name&&0==g.length&&!l(i)?r[h]=i.name:g.push({index:h,newSegment:i}))}var j=d.when();if(g.length>0)for(var h=0;hf.length){var a=q.chain.length,b=q.chain.length-f.length;q.chain.splice(-b,b);for(var c=f.length;a>c;c++)m(c,null)}})}}),q}]}])}(angular),function(a){a.module("view-segment",["route-segment"]).directive("appViewSegment",["$route","$compile","$controller","$routeParams","$routeSegment","$q","$injector","$timeout",function(b,c,d,e,f,g,h,i){return{restrict:"ECA",priority:500,compile:function(b,e){var g=b.html(),j=!0,k=a.element(document.createComment(" view-segment "));return b.prepend(k),function(l){function m(){p&&(r.leave(p),p=null),o&&(o.$destroy(),o=null)}function n(e){if(q=e,j&&(j=!1,b.replaceWith(k)),console.log("update",e),!e)return m(),p=b.clone(),p.html(g),r.enter(p,null,k),c(p,!1,499)(l),void 0;var f=a.extend({},e.locals),h=f&&f.$template;m(),p=b.clone(),p.html(h?h:g),r.enter(p,null,k);var i,n=c(p,!1,499);o=l.$new(),e.params.controller&&(f.$scope=o,i=d(e.params.controller,f),e.params.controllerAs&&(o[e.params.controllerAs]=i),p.data("$ngControllerController",i),p.children().data("$ngControllerController",i)),n(o),o.$emit("$viewContentLoaded"),o.$eval(s)}var o,p,q,r,s=e.onload||"",t=parseInt(e.appViewSegment);try{var u=h.get("$animator");r=u(l,e)}catch(v){}try{r=h.get("$animate")}catch(v){}f.chain[t]&&i(function(){n(f.chain[t])},0),l.$on("routeSegmentChange",function(a,b){console.log("event",b),b.index==t&&q!=b.segment&&n(b.segment)})}}}}])}(angular); \ No newline at end of file +"use strict";!function(a){a.module("route-segment",[]).provider("$routeSegment",["$routeProvider",function(b){function c(a){return a.replace(/([\:\-\_]+(.))/g,function(a,b,c,d){return d?c.toUpperCase():c})}function d(a,b){if(!a)throw new Error("Invalid pointer segment");var e;return{segment:function(b,d){return a[c(b)]={params:d},e=b,this},within:function(b){var g;if(b=b||e,g=a[c(b)])void 0==g.children&&(g.children={});else{if(f.strictMode)throw new Error("Cannot get into unknown `"+b+"` segment");g=a[c(b)]={params:{},children:{}}}return d(g.children,this)},up:function(){return b},root:function(){return h}}}var e=this,f=e.options={autoLoadTemplates:!0,strictMode:!1},g=this.segments={},h=d(g,null);e.when=function(a,c){return b.when(a,{segment:c}),this},a.extend(e,h),this.$get=["$rootScope","$q","$http","$templateCache","$route","$routeParams","$injector",function(b,d,e,h,i,j,k){function l(b){var c=!1;return b.params.dependencies&&a.forEach(b.params.dependencies,function(b){a.equals(q.$routeParams[b],j[b])||(c=!0)}),c}function m(a,b){return q.chain[a]&&q.chain[a].clearWatcher&&q.chain[a].clearWatcher(),b?(r[a]=b.name,b.params.untilResolved?n(a,b.name,b.params.untilResolved).then(function(c){return void 0!=c.success&&o(a),n(a,b.name,b.params)}):n(a,b.name,b.params)):(r[a]=null,o(a),void 0)}function n(c,g,i){var j=a.extend({},i.resolve);return a.forEach(j,function(b,c){j[c]=a.isString(b)?k.get(b):k.invoke(b)}),i.template&&(j.$template=i.template),f.autoLoadTemplates&&i.templateUrl&&(j.$template=e.get(i.templateUrl,{cache:h}).then(function(a){return a.data})),d.all(j).then(function(e){if(r[c]!=g)return d.reject();if(q.chain[c]={name:g,params:i,locals:e,reload:function(){m(c,this).then(function(a){void 0!=a.success&&o(c)})}},i.watcher){var f=function(){if(!a.isFunction(i.watcher))throw new Error("Watcher is not a function in segment `"+g+"`");return k.invoke(i.watcher,{},{segment:q.chain[c]})},h=f();q.chain[c].clearWatcher=b.$watch(f,function(a){a!=h&&(h=a,q.chain[c].reload())})}return{success:c}},function(b){if(i.resolveFailed){var e={error:function(){return d.when(b)}};return n(c,g,a.extend({resolve:e},i.resolveFailed))}throw new Error("Resolving failed with a reason `"+b+"`, but no `resolveFailed` "+"provided for segment `"+g+"`")})}function o(c){q.$routeParams=a.copy(j),q.name="";for(var d=0;d=b.length)return null;for(var d,e=g,f=0;a>=f;f++)d=b[f],void 0!=e[c(d)]&&(e=e[c(d)]),a>f&&(e=e.children);return{name:d,params:e.params}}var q={name:"",$routeParams:a.copy(j),chain:[],startsWith:function(a){var b=new RegExp("^"+a);return b.test(q.name)},contains:function(a){for(var b=0;b0||l(i))&&(q.chain[h]&&q.chain[h].name==i.name&&0==g.length&&!l(i)?r[h]=i.name:g.push({index:h,newSegment:i}))}var j=d.when();if(g.length>0)for(var h=0;hf.length){var a=q.chain.length,b=q.chain.length-f.length;q.chain.splice(-b,b);for(var c=f.length;a>c;c++)m(c,null)}})}}),q}]}])}(angular),function(a){a.module("view-segment",["route-segment"]).directive("appViewSegment",["$route","$compile","$controller","$routeParams","$routeSegment","$q","$injector","$timeout",function(b,c,d,e,f,g,h,i){return{restrict:"ECA",priority:500,compile:function(b,e){var g=b.html(),j=!0,k=a.element(document.createComment(" view-segment "));return b.prepend(k),function(l){function m(){p&&(r.leave(p),p=null),o&&(o.$destroy(),o=null)}function n(e){if(q=e,j&&(j=!1,b.replaceWith(k)),!e)return m(),p=b.clone(),p.html(g),r.enter(p,null,k),c(p,!1,499)(l),void 0;var f=a.extend({},e.locals),h=f&&f.$template;m(),p=b.clone(),p.html(h?h:g),r.enter(p,null,k);var i,n=c(p,!1,499);o=l.$new(),e.params.controller&&(f.$scope=o,i=d(e.params.controller,f),e.params.controllerAs&&(o[e.params.controllerAs]=i),p.data("$ngControllerController",i),p.children().data("$ngControllerController",i)),n(o),o.$emit("$viewContentLoaded"),o.$eval(s)}var o,p,q,r,s=e.onload||"",t=parseInt(e.appViewSegment);try{var u=h.get("$animator");r=u(l,e)}catch(v){}try{r=h.get("$animate")}catch(v){}f.chain[t]&&i(function(){n(f.chain[t])},0),l.$on("routeSegmentChange",function(a,b){b.index==t&&q!=b.segment&&n(b.segment)})}}}}])}(angular); \ No newline at end of file diff --git a/src/route-segment.js b/src/route-segment.js index 8f2c42d..61854db 100644 --- a/src/route-segment.js +++ b/src/route-segment.js @@ -14,7 +14,7 @@ angular.module( 'route-segment', [] ).provider( '$routeSegment', * contents into `template`. * @type {boolean} */ - autoLoadTemplates: false, + autoLoadTemplates: true, /** * When true, all attempts to call `within` method on non-existing segments will throw an error (you would