var angular = require('angular');
require('../modules');

var module = angular.module('commons.directives.sinoevent');

module.directive('onEnd', function() {
  return {
    restrict: 'A',
    priority: 100,
    scope: {
      onEnd: '='
    },
    link: function(scope, element) {
      element.bind('webkitTransitionEnd transitionend', function() {
        scope.$evalAsync(function(){
          scope.onEnd();
        });
      });
    }
  };
});

module.directive('stopEvent', function(){
  return {
    restrict: 'A',
    link: function(scope, element) {
      element.bind('click', function(event) {
        event.stopPropagation();
        event.preventDefault();
      });
    }
  };
});

module.directive('stopEventDefault', function(){
  return {
    restrict: 'A',
    link: function(scope, element) {
      element.bind('click', function(event) {
        event.stopPropagation();
      });
    }
  };
});
