angular.module("robware").directive('dragDrop', function() {
	return {
		restrict: 'A',
		scope: {
			dragDrop:'='
		},
		link: function(scope, element) {
			function handleEvent(e){
				e.preventDefault();
				e.stopPropagation();
			}

			element.on('dragover', function(e) {
				handleEvent(e);
			});
			element.on('dragenter', function(e) {
				handleEvent(e);
				$(element).addClass("dragOver");
			});
			element.on('dragleave', function(e) {
				handleEvent(e);
				$(element).removeClass("dragOver");
			});
			element.on('drop', function(e){
				handleEvent(e);
				$(element).removeClass("dragOver");

				if (e.originalEvent.dataTransfer){
					if (e.originalEvent.dataTransfer.files.length > 0) {
						scope.dragDrop(e.originalEvent.dataTransfer.files);
						scope.$apply();
					}
				}
			});
		}
	};
});

