You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
1.7 KiB

  1. /*!
  2. * Angular Material Design
  3. * https://github.com/angular/material
  4. * @license MIT
  5. * v1.1.1
  6. */
  7. goog.provide('ngmaterial.components.showHide');
  8. goog.require('ngmaterial.core');
  9. /**
  10. * @ngdoc module
  11. * @name material.components.showHide
  12. */
  13. // Add additional handlers to ng-show and ng-hide that notify directives
  14. // contained within that they should recompute their size.
  15. // These run in addition to Angular's built-in ng-hide and ng-show directives.
  16. angular.module('material.components.showHide', [
  17. 'material.core'
  18. ])
  19. .directive('ngShow', createDirective('ngShow', true))
  20. .directive('ngHide', createDirective('ngHide', false));
  21. function createDirective(name, targetValue) {
  22. return ['$mdUtil', '$window', function($mdUtil, $window) {
  23. return {
  24. restrict: 'A',
  25. multiElement: true,
  26. link: function($scope, $element, $attr) {
  27. var unregister = $scope.$on('$md-resize-enable', function() {
  28. unregister();
  29. var node = $element[0];
  30. var cachedTransitionStyles = node.nodeType === $window.Node.ELEMENT_NODE ?
  31. $window.getComputedStyle(node) : {};
  32. $scope.$watch($attr[name], function(value) {
  33. if (!!value === targetValue) {
  34. $mdUtil.nextTick(function() {
  35. $scope.$broadcast('$md-resize');
  36. });
  37. var opts = {
  38. cachedTransitionStyles: cachedTransitionStyles
  39. };
  40. $mdUtil.dom.animator.waitTransitionEnd($element, opts).then(function() {
  41. $scope.$broadcast('$md-resize');
  42. });
  43. }
  44. });
  45. });
  46. }
  47. };
  48. }];
  49. }
  50. ngmaterial.components.showHide = angular.module("material.components.showHide");