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

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

module.directive('onTouchmove', function($parse) {
  return {
    restrict: 'A',
    link: function(scope, element, attrs) {
      var onTouchmoveHandler = $parse(attrs.onTouchmove),
        preventDefault = attrs.preventDefault === '1' || attrs.preventDefault === 'true' || attrs.preventDefault === ''? true : false;
      function onTouchmove($event) {
        scope.$evalAsync(function() {
          onTouchmoveHandler(scope, {$event: $event});
        });

        if (preventDefault) {
          $event.preventDefault();
          $event.stopPropagation();
        }
      }
      element.on('touchmove', onTouchmove);
    }
  };
});
