<commit_before>(function() {
  'use strict';

  angular.module('foundation.dynamicRouting.animations', ['foundation.dynamicRouting'])
    .directive('uiView', uiView)
  ;

  uiView.$inject = ['$rootScope', '$state'];

  function uiView($rootScope, $state) {
    var directive = {
      restrict : 'ECA',
      priority : -400,
      link     : link
    };

    return directive;

    function link(scope, element) {
      var animation = {};
      var presetHeight;

      var cleanup = [
        $rootScope.$on('$stateChangeStart', onStateChangeStart),
        $rootScope.$on('$stateChangeError', onStateChangeError),
        scope.$on('$stateChangeSuccess', onStateChangeSuccess),
        scope.$on('$viewContentAnimationEnded', onViewContentAnimationEnded)
      ];

      var destroyed = scope.$on('$destroy', function onDestroy() {
        angular.forEach(cleanup, function (cb) {
          if (angular.isFunction(cb)) {
            cb();
          }
        });

        destroyed();
      });

      function onStateChangeStart() {
        if ($state.includes(getState()) && animation.leave) {
          element.addClass(animation.leave);
          prepareParent();
        }
      }

      function onStateChangeError() {
        if (animation.leave) {
          element.removeClass(animation.leave);
        }

        resetParent();
      }

      function onStateChangeSuccess() {
        if ($state.includes(getState()) && animation.enter) {
          element.addClass(animation.enter);
        }

      }

      function onViewContentAnimationEnded(ev) {
        if (ev.targetScope === scope && animation.enter) {
          element.removeClass(animation.enter);
          resetParent();
        }

      }

      function getState() {
        var view  = element.data('$uiView');
        var state = view && view.state && view.state.self;

        if (state) {
          angular.extend(animation, state.animation);
        }

        return state;
      }


      function resetParent() {
        element.parent().removeClass('position-absolute');
        if(presetHeight > 0 == false) {
          element.parent()[0].style.height = null;
        }
      }

      function prepareParent() {
        var parentHeight = parseInt(element.parent()[0].style.height);
        var elHeight = parseInt(window.getComputedStyle(element[0], null).getPropertyValue('height'));
        var tempHeight = parentHeight > 0 ? parentHeight : elHeight > 0 ? elHeight : '';

        presetHeight = parentHeight;

        element.parent()[0].style.height = tempHeight + 'px';
        element.parent().addClass('position-absolute');
      }
    }
  }


})();
<commit_msg>Initiator takes charge of animation<commit_after>(function() {
  'use strict';

  angular.module('foundation.dynamicRouting.animations', ['foundation.dynamicRouting'])
    .directive('uiView', uiView)
  ;

  uiView.$inject = ['$rootScope', '$state'];

  function uiView($rootScope, $state) {
    var directive = {
      restrict : 'ECA',
      priority : -400,
      link     : link
    };

    return directive;

    function link(scope, element) {
      var animation = {};
      var presetHeight;
      var initiator = false;

      var cleanup = [
        $rootScope.$on('$stateChangeStart', onStateChangeStart),
        $rootScope.$on('$stateChangeError', onStateChangeError),
        scope.$on('$stateChangeSuccess', onStateChangeSuccess),
        scope.$on('$viewContentAnimationEnded', onViewContentAnimationEnded)
      ];

      var destroyed = scope.$on('$destroy', function onDestroy() {
        angular.forEach(cleanup, function (cb) {
          if (angular.isFunction(cb)) {
            cb();
          }
        });

        destroyed();
      });

      function onStateChangeStart() {
        if ($state.includes(getState()) && animation.leave) {
          element.addClass(animation.leave);
          prepareParent();
        }
      }

      function onStateChangeError() {
        if (animation.leave) {
          element.removeClass(animation.leave);
        }

        resetParent();
      }

      function onStateChangeSuccess() {
        if ($state.includes(getState()) && animation.enter) {
          element.addClass(animation.enter);
        }

        resetParent();
      }

      function onViewContentAnimationEnded(ev) {
        if (ev.targetScope === scope && animation.enter) {
          element.removeClass(animation.enter);
        }

        resetParent();
      }

      function getState() {
        var view  = element.data('$uiView');
        var state = view && view.state && view.state.self;

        if (state) {
          angular.extend(animation, state.animation);
        }

        return state;
      }


      function resetParent() {
        if(initiator === true) {
          element.parent().removeClass('position-absolute');
          if(presetHeight !== true) {
            element.parent()[0].style.height = null;
          }
        }


      }

      function prepareParent() {
        if(!element.parent().hasClass('position-absolute')) {
          var parentHeight = parseInt(element.parent()[0].style.height);
          var elHeight = parseInt(window.getComputedStyle(element[0], null).getPropertyValue('height'));
          var tempHeight = parentHeight > 0 ? parentHeight : elHeight > 0 ? elHeight : '';

          if(parentHeight > 0) {
            presetHeight = true;
          }

          element.parent()[0].style.height = tempHeight + 'px';
          element.parent().addClass('position-absolute');
          initiator = true;
        }
      }
    }
  }


})();

{'fraction_non_alphanumeric': 0.13741958541815583, 'fraction_numerical': 0.0035739814152966403, 'mean_word_length': 2.2074498567335246, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3520166', 'n_tokens_mistral': 1544, 'n_tokens_neox': 1497, 'n_words': 266}