diff options
Diffstat (limited to 'src/ng/directive/ngShowHide.js')
| -rw-r--r-- | src/ng/directive/ngShowHide.js | 54 | 
1 files changed, 41 insertions, 13 deletions
diff --git a/src/ng/directive/ngShowHide.js b/src/ng/directive/ngShowHide.js index 74195468..418a43ff 100644 --- a/src/ng/directive/ngShowHide.js +++ b/src/ng/directive/ngShowHide.js @@ -6,7 +6,18 @@   *   * @description   * The `ngShow` and `ngHide` directives show or hide a portion of the DOM tree (HTML) - * conditionally. + * conditionally based on **"truthy"** values evaluated within an {expression}. In other + * words, if the expression assigned to **ngShow evaluates to a true value** then **the element is set to visible** + * (via `display:block` in css) and **if false** then **the element is set to hidden** (so display:none). + * 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 + * hide - happens before the ngShow expression evaluates to a non truthy value and just before the contents are set to hidden   *   * @element ANY   * @param {expression} ngShow If the {@link guide/expression expression} is truthy @@ -33,11 +44,14 @@     </doc:example>   */  //TODO(misko): refactor to remove element from the DOM -var ngShowDirective = ngDirective(function(scope, element, attr){ -  scope.$watch(attr.ngShow, function ngShowWatchAction(value){ -    element.css('display', toBoolean(value) ? '' : 'none'); -  }); -}); +var ngShowDirective = ['$animator', function($animator) { +  return function(scope, element, attr) { +    var animate = $animator(scope, attr); +    scope.$watch(attr.ngShow, function ngShowWatchAction(value){ +      animate[toBoolean(value) ? 'show' : 'hide'](element); +    }); +  }; +}];  /** @@ -45,8 +59,19 @@ var ngShowDirective = ngDirective(function(scope, element, attr){   * @name ng.directive:ngHide   *   * @description - * The `ngHide` and `ngShow` directives hide or show a portion of the DOM tree (HTML) - * conditionally. + * The `ngShow` and `ngHide` directives show or hide a portion of the DOM tree (HTML) + * conditionally based on **"truthy"** values evaluated within an {expression}. In other + * words, if the expression assigned to **ngShow evaluates to a true value** then **the element is set to visible** + * (via `display:block` in css) and **if false** then **the element is set to hidden** (so display:none). + * 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   *   * @element ANY   * @param {expression} ngHide If the {@link guide/expression expression} is truthy then @@ -73,8 +98,11 @@ var ngShowDirective = ngDirective(function(scope, element, attr){     </doc:example>   */  //TODO(misko): refactor to remove element from the DOM -var ngHideDirective = ngDirective(function(scope, element, attr){ -  scope.$watch(attr.ngHide, function ngHideWatchAction(value){ -    element.css('display', toBoolean(value) ? 'none' : ''); -  }); -}); +var ngHideDirective = ['$animator', function($animator) { +  return function(scope, element, attr) { +    var animate = $animator(scope, attr); +    scope.$watch(attr.ngHide, function ngHideWatchAction(value){ +      animate[toBoolean(value) ? 'hide' : 'show'](element); +    }); +  }; +}];  | 
