Skip to content

Commit eb68955

Browse files
Revert "feat(ui-view): Add noanimation attribute to specify static renderer. fix(ui-view) use static renderer if animations not enabled . Closes #2485"
This reverts commit 2523bbd.
1 parent 84fd412 commit eb68955

File tree

2 files changed

+8
-76
lines changed

2 files changed

+8
-76
lines changed

src/viewDirective.js

+8-25
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
var ngMajorVer = angular.version.major;
2-
var ngMinorVer = angular.version.minor;
31
/**
42
* @ngdoc directive
53
* @name ui.router.state.directive:ui-view
@@ -24,9 +22,6 @@ var ngMinorVer = angular.version.minor;
2422
* service, {@link ui.router.state.$uiViewScroll}. This custom service let's you
2523
* scroll ui-view elements into view when they are populated during a state activation.
2624
*
27-
* @param {string=} noanimation If truthy, the non-animated renderer will be selected (no animations
28-
* will be applied to the ui-view)
29-
*
3025
* *Note: To revert back to old [`$anchorScroll`](http://docs.angularjs.org/api/ng.$anchorScroll)
3126
* functionality, call `$uiViewScrollProvider.useAnchorScroll()`.*
3227
*
@@ -138,35 +133,24 @@ function $ViewDirective( $state, $injector, $uiViewScroll, $interpolate)
138133
// Returns a set of DOM manipulation functions based on which Angular version
139134
// it should use
140135
function getRenderer(attrs, scope) {
141-
var statics = {
142-
enter: function (element, target, cb) { target.after(element); cb(); },
143-
leave: function (element, cb) { element.remove(); cb(); }
136+
var statics = function() {
137+
return {
138+
enter: function (element, target, cb) { target.after(element); cb(); },
139+
leave: function (element, cb) { element.remove(); cb(); }
140+
};
144141
};
145142

146-
if (!!attrs.noanimation) return statics;
147-
148-
function animEnabled(element) {
149-
if (ngMajorVer === 1 && ngMinorVer >= 4) return !!$animate.enabled(element);
150-
if (ngMajorVer === 1 && ngMinorVer >= 2) return !!$animate.enabled();
151-
return (!!$animator);
152-
}
153-
154-
// ng 1.2+
155143
if ($animate) {
156144
return {
157145
enter: function(element, target, cb) {
158-
if (!animEnabled(element)) {
159-
statics.enter(element, target, cb);
160-
} else if (angular.version.minor > 2) {
146+
if (angular.version.minor > 2) {
161147
$animate.enter(element, null, target).then(cb);
162148
} else {
163149
$animate.enter(element, null, target, cb);
164150
}
165151
},
166152
leave: function(element, cb) {
167-
if (!animEnabled(element)) {
168-
statics.leave(element, cb);
169-
} else if (angular.version.minor > 2) {
153+
if (angular.version.minor > 2) {
170154
$animate.leave(element).then(cb);
171155
} else {
172156
$animate.leave(element, cb);
@@ -175,7 +159,6 @@ function $ViewDirective( $state, $injector, $uiViewScroll, $interpolate)
175159
};
176160
}
177161

178-
// ng 1.1.5
179162
if ($animator) {
180163
var animate = $animator && $animator(scope, attrs);
181164

@@ -185,7 +168,7 @@ function $ViewDirective( $state, $injector, $uiViewScroll, $interpolate)
185168
};
186169
}
187170

188-
return statics;
171+
return statics();
189172
}
190173

191174
var directive = {

test/viewDirectiveSpec.js

-51
Original file line numberDiff line numberDiff line change
@@ -560,56 +560,5 @@ describe('uiView', function () {
560560
// No more animations
561561
expect($animate.queue.length).toBe(0);
562562
}));
563-
564-
it ('should disable animations if noanimation="true" is present', inject(function($state, $q, $compile, $animate) {
565-
var content = 'Initial Content', animation;
566-
elem.append($compile('<div><ui-view noanimation="true">' + content + '</ui-view></div>')(scope));
567-
568-
animation = $animate.queue.shift();
569-
expect(animation).toBeUndefined();
570-
571-
$state.transitionTo(aState);
572-
$q.flush();
573-
animation = $animate.queue.shift();
574-
expect(animation).toBeUndefined();
575-
expect(elem.text()).toBe(aState.template);
576-
577-
$state.transitionTo(bState);
578-
$q.flush();
579-
animation = $animate.queue.shift();
580-
expect(animation).toBeUndefined();
581-
expect(elem.text()).toBe(bState.template);
582-
}));
583-
584-
it('$destroy event is triggered after animation ends', inject(function($state, $q, $animate, $rootScope) {
585-
elem.append($compile('<div><ui-view></ui-view></div>')(scope));
586-
$rootScope.$on('$stateChangeSuccess', function(evt, toState) { log += 'success(' + toState.name + ');'; });
587-
588-
$state.transitionTo('m');
589-
$q.flush();
590-
expect(log).toBe('success(m);ctrl(m);');
591-
$state.transitionTo('n');
592-
$q.flush();
593-
if ($animate) {
594-
expect(log).toBe('success(m);ctrl(m);success(n);ctrl(n);');
595-
animateFlush($animate);
596-
expect(log).toBe('success(m);ctrl(m);success(n);ctrl(n);$destroy(m);');
597-
} else {
598-
expect(log).toBe('success(m);ctrl(m);$destroy(m);success(n);ctrl(n);');
599-
}
600-
}));
601-
602-
it('$destroy event is triggered before $stateChangeSuccess if noanimation is present', inject(function($state, $q, $animate, $rootScope) {
603-
elem.append($compile('<div><ui-view noanimation="true"></ui-view></div>')(scope));
604-
$rootScope.$on('$stateChangeSuccess', function(evt, toState) { log += 'success(' + toState.name + ');'; });
605-
606-
$state.transitionTo('m');
607-
$q.flush();
608-
expect(log).toBe('success(m);ctrl(m);');
609-
$state.transitionTo('n');
610-
$q.flush();
611-
expect(log).toBe('success(m);ctrl(m);success(n);$destroy(m);ctrl(n);');
612-
}));
613-
614563
});
615564
});

0 commit comments

Comments
 (0)