Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 8ed0d5b

Browse files
matskomhevery
authored andcommitted
chore($animate): replace show/hide with addClass/removeClass
1 parent 81923f1 commit 8ed0d5b

File tree

8 files changed

+52
-138
lines changed

8 files changed

+52
-138
lines changed

Diff for: docs/component-spec/annotationsSpec.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,10 @@ describe('Docs Annotations', function() {
7474
enter : function(element, done) {
7575
$window.setTimeout(done, 1000);
7676
},
77-
show : function(element, done) {
77+
removeClass : function(element, className, done) {
7878
$window.setTimeout(done, 500);
7979
},
80-
hide : function(element, done) {
80+
addClass : function(element, className, done) {
8181
$window.setTimeout(done, 200);
8282
}
8383
}

Diff for: docs/components/angular-bootstrap/bootstrap.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -366,12 +366,12 @@ directive.foldout = ['$http', '$animate','$window', function($http, $animate, $w
366366
//avoid showing the element if the user has already closed it
367367
if(container.css('display') == 'block') {
368368
container.css('display','none');
369-
$animate.show(container);
369+
$animate.addClass(container, 'ng-hide');
370370
}
371371
});
372372
}
373373
else {
374-
container.hasClass('ng-hide') ? $animate.show(container) : $animate.hide(container);
374+
container.hasClass('ng-hide') ? $animate.removeClass(container, 'ng-hide') : $animate.addClass(container, 'ng-hide');
375375
}
376376
});
377377
});

Diff for: src/ng/animate.js

-10
Original file line numberDiff line numberDiff line change
@@ -80,16 +80,6 @@ var $AnimateProvider = ['$provide', function($provide) {
8080
this.enter(element, parent, after, done);
8181
},
8282

83-
show : function(element, done) {
84-
element.removeClass('ng-hide');
85-
(done || noop)();
86-
},
87-
88-
hide : function(element, done) {
89-
element.addClass('ng-hide');
90-
(done || noop)();
91-
},
92-
9383
addClass : function(element, className, done) {
9484
className = isString(className) ?
9585
className :

Diff for: src/ng/directive/ngShowHide.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@
100100
var ngShowDirective = ['$animate', function($animate) {
101101
return function(scope, element, attr) {
102102
scope.$watch(attr.ngShow, function ngShowWatchAction(value){
103-
$animate[toBoolean(value) ? 'show' : 'hide'](element);
103+
$animate[toBoolean(value) ? 'removeClass' : 'addClass'](element, 'ng-hide');
104104
});
105105
};
106106
}];
@@ -204,7 +204,7 @@ var ngShowDirective = ['$animate', function($animate) {
204204
var ngHideDirective = ['$animate', function($animate) {
205205
return function(scope, element, attr) {
206206
scope.$watch(attr.ngHide, function ngHideWatchAction(value){
207-
$animate[toBoolean(value) ? 'hide' : 'show'](element);
207+
$animate[toBoolean(value) ? 'addClass' : 'removeClass'](element, 'ng-hide');
208208
});
209209
};
210210
}];

Diff for: src/ngAnimate/animate.js

+1-61
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030
* | {@link ng.directive:ngInclude#animations ngInclude} | enter and leave |
3131
* | {@link ng.directive:ngSwitch#animations ngSwitch} | enter and leave |
3232
* | {@link ng.directive:ngIf#animations ngIf} | enter and leave |
33-
* | {@link ng.directive:ngShow#animations ngShow & ngHide} | show and hide |
3433
* | {@link ng.directive:ngShow#animations ngClass} | add and remove |
34+
* | {@link ng.directive:ngShow#animations ngShow & ngHide} | add and remove (the ng-hide class value) |
3535
*
3636
* You can find out more information about animations upon visiting each directive page.
3737
*
@@ -335,60 +335,6 @@ angular.module('ngAnimate', ['ng'])
335335
performAnimation('move', 'ng-move', element, null, null, done);
336336
},
337337

338-
/**
339-
* @ngdoc function
340-
* @name ngAnimate.$animate#show
341-
* @methodOf ngAnimate.$animate
342-
* @function
343-
*
344-
* @description
345-
* Reveals the element by removing the `ng-hide` class thus performing an animation in the process. During
346-
* this animation the CSS classes present on the element will be:
347-
*
348-
* <pre>
349-
* .ng-hide //already on the element if hidden
350-
* .ng-hide-remove
351-
* .ng-hide-remove-active
352-
* </pre>
353-
*
354-
* Once the animation is complete then all three CSS classes will be removed from the element.
355-
* The done callback, if provided, will be also fired once the animation is complete.
356-
*
357-
* @param {jQuery/jqLite element} element the element that will be rendered visible or hidden
358-
* @param {function()=} done callback function that will be called once the animation is complete
359-
*/
360-
show : function(element, done) {
361-
performAnimation('show', 'ng-hide-remove', element, null, null, function() {
362-
$delegate.show(element, done);
363-
});
364-
},
365-
366-
/**
367-
* @ngdoc function
368-
* @name ngAnimate.$animate#hide
369-
* @methodOf ngAnimate.$animate
370-
*
371-
* @description
372-
* Sets the element to hidden by adding the `ng-hide` class it. However, before the class is applied
373-
* the following CSS classes will be added temporarily to trigger any animation code:
374-
*
375-
* <pre>
376-
* .ng-hide-add
377-
* .ng-hide-add-active
378-
* </pre>
379-
*
380-
* Once the animation is complete then both CSS classes will be removed and `ng-hide` will be added to the element.
381-
* The done callback, if provided, will be also fired once the animation is complete.
382-
*
383-
* @param {jQuery/jqLite element} element the element that will be rendered visible or hidden
384-
* @param {function()=} done callback function that will be called once the animation is complete
385-
*/
386-
hide : function(element, done) {
387-
performAnimation('hide', 'ng-hide-add', element, null, null, function() {
388-
$delegate.hide(element, done);
389-
});
390-
},
391-
392338
/**
393339
* @ngdoc function
394340
* @name ngAnimate.$animate#addClass
@@ -617,12 +563,6 @@ angular.module('ngAnimate', ['ng'])
617563
move : function(element, done) {
618564
return animate(element, 'ng-move', done);
619565
},
620-
show : function(element, done) {
621-
return animate(element, 'ng-hide-remove', done);
622-
},
623-
hide : function(element, done) {
624-
return animate(element, 'ng-hide-add', done);
625-
},
626566
addClass : function(element, className, done) {
627567
return animate(element, className, done);
628568
},

Diff for: test/ng/animateSpec.js

+1-13
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,10 @@ describe("$animate", function() {
3131
expect(element.text()).toBe('21');
3232
}));
3333

34-
it("should animate the show animation event", inject(function($animate) {
35-
element.addClass('ng-hide');
36-
$animate.show(element);
37-
expect(element).toBeShown();
38-
}));
39-
40-
it("should animate the hide animation event", inject(function($animate) {
41-
expect(element).toBeShown();
42-
$animate.hide(element);
43-
expect(element).toBeHidden();
44-
}));
45-
4634
it("should still perform DOM operations even if animations are disabled", inject(function($animate) {
4735
$animate.enabled(false);
4836
expect(element).toBeShown();
49-
$animate.hide(element);
37+
$animate.addClass(element, 'ng-hide');
5038
expect(element).toBeHidden();
5139
}));
5240
});

Diff for: test/ng/directive/ngShowHideSpec.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,14 @@ describe('ngShow / ngHide animations', function() {
8181
))($scope);
8282
$scope.$digest();
8383

84-
item = $animate.process('show').element;
84+
item = $animate.process('removeClass').element;
8585
expect(item.text()).toBe('data');
8686
expect(item).toBeShown();
8787

8888
$scope.on = false;
8989
$scope.$digest();
9090

91-
item = $animate.process('hide').element;
91+
item = $animate.process('addClass').element;
9292
expect(item.text()).toBe('data');
9393
expect(item).toBeHidden();
9494
}));
@@ -104,14 +104,14 @@ describe('ngShow / ngHide animations', function() {
104104
))($scope);
105105
$scope.$digest();
106106

107-
item = $animate.process('hide').element;
107+
item = $animate.process('addClass').element;
108108
expect(item.text()).toBe('datum');
109109
expect(item).toBeHidden();
110110

111111
$scope.off = false;
112112
$scope.$digest();
113113

114-
item = $animate.process('show').element;
114+
item = $animate.process('removeClass').element;
115115
expect(item.text()).toBe('datum');
116116
expect(item).toBeShown();
117117
}));

0 commit comments

Comments
 (0)