Skip to content

Commit 2984a2e

Browse files
committed
1.4.0
1 parent 904b724 commit 2984a2e

File tree

6 files changed

+86
-72
lines changed

6 files changed

+86
-72
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
# 1.4.0 (2015-03-13)
2+
3+
- Refactored render directive using modern `$transclude` cloning mechanism instead of manual cloning ([32dea](https://github.com/artch/angular-route-segment/commit/904b72477e322a7ab647d8b6c96165c7d4332dea)).
4+
**ATTENTION:** AngularJS 1.1.x is no longer supported due to this fix!
5+
- Fixed a bug with a segment placed inside ng-if ([32dea](https://github.com/artch/angular-route-segment/commit/904b72477e322a7ab647d8b6c96165c7d4332dea)).
6+
- Fixed a bug with camelCasing default segment names ([74b64](https://github.com/artch/angular-route-segment/commit/60bf2eca0ed554809c14f4556776a92eb2574b64)).
7+
18
# 1.3.3 (2014-09-30)
29

310
- Due to [angular.js@fca6be71](https://github.com/angular/angular.js/commit/fca6be71), filters are now flagged as `$stateful=true` for compatibility reasons ([03f8425](https://github.com/artch/angular-route-segment/commit/03f8425)).

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ bower install angular-route-segment
1818
```
1919
Or use this CDN link (thanks to [cdnjs.com](http://cdnjs.com)):
2020
```html
21-
<script src="//cdnjs.cloudflare.com/ajax/libs/angular-route-segment/1.3.0/angular-route-segment.min.js"></script>
21+
<script src="//cdnjs.cloudflare.com/ajax/libs/angular-route-segment/1.4.0/angular-route-segment.min.js"></script>
2222
```
2323

24-
Tested with AngularJS 1.1.5, 1.2.21, 1.3.14, and 1.4.0-beta.5.
24+
Tested with AngularJS 1.2.21, 1.3.14, and 1.4.0-beta.5.
2525

2626
Overview
2727
--------

bower.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular-route-segment",
3-
"version": "1.3.3",
3+
"version": "1.4.0",
44
"main": "build/angular-route-segment.js",
55
"ignore": [
66
"**/.*",
@@ -10,9 +10,9 @@
1010
"tests",
1111
"example",
1212
"Gruntfile.js",
13-
"karma-angular-1.1.conf.js",
1413
"karma-angular-1.2.conf.js",
1514
"karma-angular-1.3.conf.js",
15+
"karma-angular-1.4.conf.js",
1616
"package.json",
1717
"src",
1818
"**/*.min.js"

build/angular-route-segment.js

Lines changed: 72 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* angular-route-segment 1.3.3
2+
* angular-route-segment 1.4.0
33
* https://angular-route-segment.com
44
* @author Artem Chivchalov
55
* @license MIT License http://opensource.org/licenses/MIT
@@ -74,7 +74,7 @@ mod.provider( '$routeSegment',
7474
* @returns {Object} The same level pointer.
7575
*/
7676
segment: function(name, params) {
77-
segment[camelCase(name)] = {params: params};
77+
segment[camelCase(name)] = {name: name, params: params};
7878
lastAddedName = name;
7979
return this;
8080
},
@@ -302,7 +302,7 @@ mod.provider( '$routeSegment',
302302
(function(i, children, index) {
303303
if (children[i].params['default']) {
304304
defaultChildUpdatePromise = defaultChildUpdatePromise.then(function () {
305-
return updateSegment(index, {name: i, params: children[i].params})
305+
return updateSegment(index, {name: children[i].name, params: children[i].params})
306306
.then(function (result) {
307307
if (result.success) broadcast(result.success);
308308
});
@@ -566,111 +566,118 @@ mod.filter('routeSegmentParam', ['$routeSegment', function($routeSegment) {
566566
(function(angular) {
567567

568568
angular.module( 'view-segment', [ 'route-segment' ] ).directive( 'appViewSegment',
569-
['$route', '$compile', '$controller', '$routeParams', '$routeSegment', '$q', '$injector', '$timeout',
570-
function($route, $compile, $controller, $routeParams, $routeSegment, $q, $injector, $timeout) {
569+
['$route', '$compile', '$controller', '$routeParams', '$routeSegment', '$q', '$injector', '$timeout', '$animate',
570+
function($route, $compile, $controller, $routeParams, $routeSegment, $q, $injector, $timeout, $animate) {
571571

572572
return {
573573
restrict : 'ECA',
574-
priority: 500,
575-
compile : function(tElement, tAttrs) {
576-
577-
var defaultContent = tElement.html(), isDefault = true,
578-
anchor = angular.element(document.createComment(' view-segment '));
574+
priority: 400,
575+
transclude: 'element',
579576

580-
tElement.prepend(anchor);
577+
compile : function(tElement, tAttrs) {
581578

582-
return function($scope) {
579+
return function($scope, element, attrs, ctrl, $transclude) {
583580

584-
var currentScope, currentElement, currentSegment, onloadExp = tAttrs.onload || '', animate,
585-
viewSegmentIndex = parseInt(tAttrs.appViewSegment), updatePromise;
581+
var currentScope, currentElement, currentSegment = {}, onloadExp = tAttrs.onload || '',
582+
viewSegmentIndex = parseInt(tAttrs.appViewSegment), updatePromise, previousLeaveAnimation;
586583

587-
try {
588-
// angular 1.1.x
589-
var $animator = $injector.get('$animator')
590-
animate = $animator($scope, tAttrs);
591-
}
592-
catch(e) {}
593-
try {
594-
// angular 1.2.x
595-
animate = $injector.get('$animate');
596-
}
597-
catch(e) {}
598-
599-
if($routeSegment.chain[viewSegmentIndex])
600-
updatePromise = $timeout(function() {
584+
if($routeSegment.chain[viewSegmentIndex]) {
585+
updatePromise = $timeout(function () {
601586
update($routeSegment.chain[viewSegmentIndex]);
602587
}, 0);
588+
}
589+
else {
590+
update();
591+
}
603592

604593
// Watching for the specified route segment and updating contents
605594
$scope.$on('routeSegmentChange', function(event, args) {
606595

607596
if(updatePromise)
608597
$timeout.cancel(updatePromise);
609598

610-
if(args.index == viewSegmentIndex && currentSegment != args.segment)
599+
if(args.index == viewSegmentIndex && currentSegment != args.segment) {
611600
update(args.segment);
601+
}
612602
});
613603

614604
function clearContent() {
615-
616-
if(currentElement) {
617-
animate.leave(currentElement);
618-
currentElement = null;
605+
if (previousLeaveAnimation) {
606+
$animate.cancel(previousLeaveAnimation);
607+
previousLeaveAnimation = null;
619608
}
620609

621610
if (currentScope) {
622611
currentScope.$destroy();
623612
currentScope = null;
624613
}
614+
if (currentElement) {
615+
previousLeaveAnimation = $animate.leave(currentElement);
616+
if(previousLeaveAnimation) {
617+
previousLeaveAnimation.then(function () {
618+
previousLeaveAnimation = null;
619+
});
620+
}
621+
currentElement = null;
622+
}
625623
}
626624

627-
628625
function update(segment) {
629626

630627
currentSegment = segment;
631628

632-
if(isDefault) {
633-
isDefault = false;
634-
tElement.replaceWith(anchor);
635-
}
629+
var newScope = $scope.$new();
636630

637-
if(!segment) {
631+
var clone = $transclude(newScope, function(clone) {
632+
if(segment) {
633+
clone.data('viewSegment', segment);
634+
}
635+
$animate.enter(clone, null, currentElement || element);
638636
clearContent();
639-
currentElement = tElement.clone();
640-
currentElement.html(defaultContent);
641-
animate.enter( currentElement, null, anchor );
642-
$compile(currentElement, false, 499)($scope);
643-
return;
644-
}
637+
});
638+
639+
currentElement = clone;
640+
currentScope = newScope;
641+
currentScope.$emit('$viewContentLoaded');
642+
currentScope.$eval(onloadExp);
643+
}
644+
}
645+
}
646+
}
647+
}]);
645648

646-
var locals = angular.extend({}, segment.locals),
647-
template = locals && locals.$template;
649+
angular.module( 'view-segment').directive( 'appViewSegment',
650+
['$route', '$compile', '$controller', function($route, $compile, $controller) {
648651

649-
clearContent();
652+
return {
653+
restrict: 'ECA',
654+
priority: -400,
655+
link: function ($scope, element) {
650656

651-
currentElement = tElement.clone();
652-
currentElement.html(template ? template : defaultContent);
653-
animate.enter( currentElement, null, anchor );
657+
var segment = element.data('viewSegment') || {};
654658

655-
var link = $compile(currentElement, false, 499), controller;
659+
var locals = angular.extend({}, segment.locals),
660+
template = locals && locals.$template;
656661

657-
currentScope = $scope.$new();
658-
if (segment.params.controller) {
659-
locals.$scope = currentScope;
660-
controller = $controller(segment.params.controller, locals);
662+
if(template) {
663+
element.html(template);
664+
}
665+
666+
var link = $compile(element.contents());
667+
668+
if (segment.params && segment.params.controller) {
669+
locals.$scope = $scope;
670+
var controller = $controller(segment.params.controller, locals);
661671
if(segment.params.controllerAs)
662-
currentScope[segment.params.controllerAs] = controller;
663-
currentElement.data('$ngControllerController', controller);
664-
currentElement.children().data('$ngControllerController', controller);
672+
$scope[segment.params.controllerAs] = controller;
673+
element.data('$ngControllerController', controller);
674+
element.children().data('$ngControllerController', controller);
665675
}
666676

667-
link(currentScope);
668-
currentScope.$emit('$viewContentLoaded');
669-
currentScope.$eval(onloadExp);
670-
}
677+
link($scope);
671678
}
672679
}
673-
}
674-
}]);
680+
681+
}]);
675682

676683
})(angular);

0 commit comments

Comments
 (0)