aboutsummaryrefslogtreecommitdiffstats
path: root/src/ng/directive/ngShowHide.js
diff options
context:
space:
mode:
authorMatias Niemelä2013-06-18 13:59:57 -0400
committerMisko Hevery2013-07-26 23:49:54 -0700
commit81923f1e41560327f7de6e8fddfda0d2612658f3 (patch)
treebbf8151bddf4d026f8f5fa3196b84a45ecd9c858 /src/ng/directive/ngShowHide.js
parent11521a4cde689c2bd6aaa227b1f45cb3fb53725b (diff)
downloadangular.js-81923f1e41560327f7de6e8fddfda0d2612658f3.tar.bz2
feat(ngAnimate): complete rewrite of animations
- ngAnimate directive is gone and was replaced with class based animations/transitions - support for triggering animations on css class additions and removals - done callback was added to all animation apis - $animation and $animator where merged into a single $animate service with api: - $animate.enter(element, parent, after, done); - $animate.leave(element, done); - $animate.move(element, parent, after, done); - $animate.addClass(element, className, done); - $animate.removeClass(element, className, done); BREAKING CHANGE: too many things changed, we'll write up a separate doc with migration instructions
Diffstat (limited to 'src/ng/directive/ngShowHide.js')
-rw-r--r--src/ng/directive/ngShowHide.js64
1 files changed, 28 insertions, 36 deletions
diff --git a/src/ng/directive/ngShowHide.js b/src/ng/directive/ngShowHide.js
index 7ef7008c..bdbcf463 100644
--- a/src/ng/directive/ngShowHide.js
+++ b/src/ng/directive/ngShowHide.js
@@ -12,8 +12,6 @@
* With ngHide this is the reverse whereas true values cause the element itself to become
* hidden.
*
- * Additionally, you can also provide animations via the ngAnimate attribute to animate the **show**
- * and **hide** effects.
*
* @animations
* show - happens after the ngShow expression evaluates to a truthy value and the contents are set to visible
@@ -29,36 +27,37 @@
Click me: <input type="checkbox" ng-model="checked"><br/>
<div>
Show:
- <span class="check-element"
- ng-show="checked"
- ng-animate="{show: 'example-show', hide: 'example-hide'}">
+ <span class="check-element example-show-hide" ng-show="checked">
<span class="icon-thumbs-up"></span> I show up when your checkbox is checked.
</span>
</div>
<div>
Hide:
- <span class="check-element"
- ng-hide="checked"
- ng-animate="{show: 'example-show', hide: 'example-hide'}">
+ <span class="check-element example-show-hide" ng-hide="checked">
<span class="icon-thumbs-down"></span> I hide when your checkbox is checked.
</span>
</div>
</file>
<file name="animations.css">
- .example-show, .example-hide {
+ .example-show-hide {
-webkit-transition:all linear 0.5s;
-moz-transition:all linear 0.5s;
-ms-transition:all linear 0.5s;
-o-transition:all linear 0.5s;
transition:all linear 0.5s;
+ display:block;
+ }
+ .example-show-hide.ng-hide {
+ display:none;
}
- .example-show {
+ .example-show-hide.ng-hide-remove {
+ display:block;
line-height:0;
opacity:0;
padding:0 10px;
}
- .example-show-active.example-show-active {
+ .example-show-hide.ng-hide-remove.ng-hide-remove-active {
line-height:20px;
opacity:1;
padding:10px;
@@ -66,14 +65,14 @@
background:white;
}
- .example-hide {
+ .example-show-hide.ng-hide-add {
line-height:20px;
opacity:1;
padding:10px;
border:1px solid black;
background:white;
}
- .example-hide-active.example-hide-active {
+ .example-show-hide.ng-hide-add.ng-hide-add-active {
line-height:0;
opacity:0;
padding:0 10px;
@@ -98,12 +97,10 @@
</file>
</example>
*/
-//TODO(misko): refactor to remove element from the DOM
-var ngShowDirective = ['$animator', function($animator) {
+var ngShowDirective = ['$animate', function($animate) {
return function(scope, element, attr) {
- var animate = $animator(scope, attr);
scope.$watch(attr.ngShow, function ngShowWatchAction(value){
- animate[toBoolean(value) ? 'show' : 'hide'](element);
+ $animate[toBoolean(value) ? 'show' : 'hide'](element);
});
};
}];
@@ -121,9 +118,6 @@ var ngShowDirective = ['$animator', function($animator) {
* With ngHide this is the reverse whereas true values cause the element itself to become
* hidden.
*
- * Additionally, you can also provide animations via the ngAnimate attribute to animate the **show**
- * and **hide** effects.
- *
* @animations
* show - happens after the ngHide expression evaluates to a non truthy value and the contents are set to visible
* hide - happens after the ngHide expression evaluates to a truthy value and just before the contents are set to hidden
@@ -138,36 +132,36 @@ var ngShowDirective = ['$animator', function($animator) {
Click me: <input type="checkbox" ng-model="checked"><br/>
<div>
Show:
- <span class="check-element"
- ng-show="checked"
- ng-animate="{show: 'example-show', hide: 'example-hide'}">
+ <span class="check-element example-show-hide" ng-show="checked">
<span class="icon-thumbs-up"></span> I show up when your checkbox is checked.
</span>
</div>
<div>
Hide:
- <span class="check-element"
- ng-hide="checked"
- ng-animate="{show: 'example-show', hide: 'example-hide'}">
+ <span class="check-element example-show-hide" ng-hide="checked">
<span class="icon-thumbs-down"></span> I hide when your checkbox is checked.
</span>
</div>
</file>
<file name="animations.css">
- .example-show, .example-hide {
+ .example-show-hide {
-webkit-transition:all linear 0.5s;
-moz-transition:all linear 0.5s;
- -ms-transition:all linear 0.5s;
-o-transition:all linear 0.5s;
transition:all linear 0.5s;
+ display:block;
+ }
+ .example-show-hide.ng-hide {
+ display:none;
}
- .example-show {
+ .example-show-hide.ng-hide-remove {
+ display:block;
line-height:0;
opacity:0;
padding:0 10px;
}
- .example-show.example-show-active {
+ .example-show-hide.ng-hide-remove.ng-hide-remove-active {
line-height:20px;
opacity:1;
padding:10px;
@@ -175,14 +169,14 @@ var ngShowDirective = ['$animator', function($animator) {
background:white;
}
- .example-hide {
+ .example-show-hide.ng-hide-add {
line-height:20px;
opacity:1;
padding:10px;
border:1px solid black;
background:white;
}
- .example-hide.example-hide-active {
+ .example-show-hide.ng-hide-add.ng-hide-add-active {
line-height:0;
opacity:0;
padding:0 10px;
@@ -207,12 +201,10 @@ var ngShowDirective = ['$animator', function($animator) {
</file>
</example>
*/
-//TODO(misko): refactor to remove element from the DOM
-var ngHideDirective = ['$animator', function($animator) {
+var ngHideDirective = ['$animate', function($animate) {
return function(scope, element, attr) {
- var animate = $animator(scope, attr);
scope.$watch(attr.ngHide, function ngHideWatchAction(value){
- animate[toBoolean(value) ? 'hide' : 'show'](element);
+ $animate[toBoolean(value) ? 'hide' : 'show'](element);
});
};
}];