# all files / Core/Components/DragFile/ DragFileDirective.js

66.67% Statements 12/18
100% Branches 0/0
50% Functions 2/4
66.67% Lines 12/18

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38

    1

    1

    1
    1

    1
    1

    1
    1
    1

    1

    1

    1
     'use strict';

    // Utilities:
    var _ = require('lodash');

    // Module:
    var Core = require('../../Core');

    var DragFileDirective = function () {
        return {
            restrict: 'A',

            link: link
        };

        function link ($scope, $element) {
            var element = _.first($element);

            element.draggable = true;
            element.addEventListener('dragstart', _.partial(dragstart, $scope));
            element.addEventListener('dragend', dragend);
        }

        function dragstart ($scope, event) {
            event.dataTransfer.effectAllowed = 'move';
            event.dataTransfer.setData('file', JSON.stringify($scope.item));
            this.classList.add('drag');
            return false;
        }

        function dragend () {
            this.classList.remove('drag');
            return false;
        }
    };

    Core.directive('tractorDragFile', DragFileDirective);