<commit_before>angular.module('foundation.common.directives', []);

angular.module('foundation.common.directives')
  .directive('faClose', ['FoundationApi', function(foundationApi) {
  return {
    restrict: 'A',
    link: function(scope, element, attrs) {
      var parentElement= false;
      var tempElement = element.parent();

      //find parent modal
      while(parentElement == false) {
        if(tempElement[0].nodeName == 'BODY') {
          parentElement = '';
        }

        if(typeof tempElement.attr('fa-closable') !== 'undefined' && tempElement.attr('fa-closable') !== false) {
          parentElement = tempElement;
        }

        tempElement = tempElement.parent();
      }

      element.on('click', function(e) {
        foundationApi.publish(parentElement.attr('id'), 'close');
        e.preventDefault();
      });
    }
  }
}]);

angular.module('foundation.common.directives')
  .directive('faOpen', ['FoundationApi', function(foundationApi) {
  return {
    restrict: 'A',
    link: function(scope, element, attrs) {
      element.on('click', function(e) {
        foundationApi.publish(attrs.faOpen, 'open');
        e.preventDefault();
      });
    }
  }
}]);

angular.module('foundation.common.directives')
  .directive('faToggle', ['FoundationApi', function(foundationApi) {
  return {
    restrict: 'A',
    link: function(scope, element, attrs) {
      element.on('click', function(e) {
        foundationApi.publish(attrs.faToggle, 'toggle');
        e.preventDefault();
      });
    }
  }
}]);

angular.module('foundation.common.directives')
  .directive('faAnimate', ['FoundationApi', function(foundationApi) {
  return {
    restrict: 'A',
    priority: 100, //set priority to override other directives
    link: function(scope, element, attrs) {
      var isActive = false;
      var animationIn = attrs.animationIn;
      var animationOut = attrs.animationOut;

      var activeClass = 'is-active';

      var reflow = function() {
        return element[0].offsetWidth;
      };

      var reset = function() {
        element[0].style.transitionDuration = 0;
        element.removeClass(activeClass + ' ' + animationIn + ' ' + animationOut);
      };

      var animate = function(animationClass, activation) {
        console.log(animationClass, activation, 'test');
        //stop animation
        reset();
        element.addClass(animationClass);

        //force a "tick"
        reflow();

        //activate
        element[0].style.transitionDuration = '';
        element.addClass(activeClass);
        isActive = activation;
      };

      //subscribe
      foundationApi.subscribe(attrs.id, function(msg) {
        console.log(msg);
        if(msg === 'show' || msg === 'open') {
          animate(animationIn, true);
        } else if (msg === 'hide' || msg === 'close') {
          animate(animationOut, false);
        } else if (msg === 'toggle') {
          var newState = !isActive;
          var newAnimation = newState ? animationIn : animationOut;

          animate(newAnimation, newState);
        }

      });
    }
  };

}]);<commit_msg>Resolve conflict with other animation systems<commit_after>angular.module('foundation.common.directives', []);

angular.module('foundation.common.directives')
  .directive('faClose', ['FoundationApi', function(foundationApi) {
  return {
    restrict: 'A',
    link: function(scope, element, attrs) {
      var parentElement= false;
      var tempElement = element.parent();

      //find parent modal
      while(parentElement == false) {
        if(tempElement[0].nodeName == 'BODY') {
          parentElement = '';
        }

        if(typeof tempElement.attr('fa-closable') !== 'undefined' && tempElement.attr('fa-closable') !== false) {
          parentElement = tempElement;
        }

        tempElement = tempElement.parent();
      }

      element.on('click', function(e) {
        foundationApi.publish(parentElement.attr('id'), 'close');
        e.preventDefault();
      });
    }
  }
}]);

angular.module('foundation.common.directives')
  .directive('faOpen', ['FoundationApi', function(foundationApi) {
  return {
    restrict: 'A',
    link: function(scope, element, attrs) {
      element.on('click', function(e) {
        foundationApi.publish(attrs.faOpen, 'open');
        e.preventDefault();
      });
    }
  }
}]);

angular.module('foundation.common.directives')
  .directive('faToggle', ['FoundationApi', function(foundationApi) {
  return {
    restrict: 'A',
    link: function(scope, element, attrs) {
      element.on('click', function(e) {
        foundationApi.publish(attrs.faToggle, 'toggle');
        e.preventDefault();
      });
    }
  }
}]);

angular.module('foundation.common.directives')
  .directive('faAnimate', ['FoundationApi', function(foundationApi) {
  return {
    restrict: 'A',
    priority: 100, //set priority to override other directives
    link: function(scope, element, attrs) {
      var isActive = false;
      var animationIn = attrs.animationIn;
      var animationOut = attrs.animationOut;

      var activeClass = 'is-active';

      var reflow = function() {
        return element[0].offsetWidth;
      };

      var reset = function() {
        element[0].style.transitionDuration = 0;
        element.removeClass(activeClass + ' ' + animationIn + ' ' + animationOut);
      };

      var animate = function(animationClass, activation) {
        //stop animation
        reset();
        element.addClass(animationClass);

        //force a "tick"
        reflow();

        //activate
        element[0].style.transitionDuration = '';
        element.addClass(activeClass);
        isActive = activation;
      };

      //subscribe
      foundationApi.subscribe(attrs.id, function(msg) {
        if(msg === 'show' || msg === 'open') {
          animate(animationIn, true);
        } else if (msg === 'hide' || msg === 'close') {
          animate(animationOut, false);
        } else if (msg === 'toggle') {
          var newState = !isActive;
          var newAnimation = newState ? animationIn : animationOut;

          //allow other elements to do their job
          setTimeout(function() {
            animate(newAnimation, newState);
          }, 1);
        }

      });
    }
  };

}]);
{'fraction_non_alphanumeric': 0.14916334661354583, 'fraction_numerical': 0.0027091633466135457, 'mean_word_length': 2.5760683760683762, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '6423957', 'n_tokens_mistral': 1793, 'n_tokens_neox': 1783, 'n_words': 346}