<commit_before>/**
 * created by mekhonoshyn on 10/31/14.
 */

// tTarget - transformation target - translatable element (f.e. panel)
// dSTarget - drag-start target - draggable element (f.e. header of target panel)
// dETarget - drag-end target - container within which is possible to perform dragging
// xShift - initial shift by x-Axis (relatively to rendered place)
// yShift - initial shift by y-Axis (relatively to rendered place)

//add class 'no-dragging' to any child element to forbid child element to be draggable

/*jslint browser:true */
function _DnDMagic(config) {
    var xShift,
        yShift,
        savedXShift,
        savedYShift,
        savedXOffsetForDnD,
        savedYOffsetForDnD,
        matrix = ['translate(', 0, 'px, ', 0, 'px)'],
        dETarget = config.dETarget || document,
        tTarget = config.tTarget,
        onDragEndCallback = config.callback;

    function _applyTransformation(newXShift, newYShift) {
        matrix[1] = xShift = newXShift;

        matrix[3] = yShift = newYShift;

        tTarget.style.transform = matrix.join('');
    }

    function _onStartDrag(event) {
        if (event.button || event.target.classList.contains('no-dragging')) {
            return;
        }

        savedXShift = xShift;
        savedYShift = yShift;

        savedXOffsetForDnD = event.pageX;
        savedYOffsetForDnD = event.pageY;

        dETarget.addEventListener('mousemove', _onDoDrag);

        dETarget.addEventListener('mouseup', _onEndDrag);
    }

    function _onDoDrag(event) {
        _applyTransformation(savedXShift + event.pageX - savedXOffsetForDnD, savedYShift + event.pageY - savedYOffsetForDnD);
    }

    function _onEndDrag() {
        if (onDragEndCallback) {
            onDragEndCallback(xShift, yShift);
        }

        dETarget.removeEventListener('mousemove', _onDoDrag);

        dETarget.removeEventListener('mouseup', _onEndDrag);
    }

    config.dSTarget.addEventListener('mousedown', _onStartDrag);

    _applyTransformation(config.xShift || 0, config.yShift || 0);
}

/*module.exports = */function _DnDFactory(config) {
    return new _DnDMagic(config);
}<commit_msg>minor non-functional updates<commit_after>/**
 * created by mekhonoshyn on 10/31/14.
 */

// tTarget - transformation target - translatable element (f.e. panel)
// dSTarget - drag-start target - draggable element (f.e. header of target panel)
// dETarget - drag-end target - container within which is possible to perform dragging
// initialX - initial shift by x-Axis (relatively to rendered place)
// initialY - initial shift by y-Axis (relatively to rendered place)

//add class 'no-dragging' (by default) to any child element to forbid child element to be draggable

/*jslint browser:true */

_DnDFactory = (function () {
    var mouseMoveEvent = 'mousemove',
        mouseUpEvent = 'mouseup',
        mouseDownEvent = 'mousedown',
        noDraggingClass = 'no-dragging',
        transformationMatrixTemplate = ['translate(', 0, 'px, ', 0, 'px)'];

    function _DnDMagic(config) {
        var x,
            y,
            savedX,
            savedY,
            savedPageX,
            savedPageY,
            transformationMatrix = transformationMatrixTemplate.slice(),
            dETarget = config.dETarget || document,
            tTarget = config.tTarget,
            onDragEndCallback = config.callback;

        function _applyTransformation(newX, newY) {
            transformationMatrix[1] = x = newX;

            transformationMatrix[3] = y = newY;

            tTarget.style.transform = transformationMatrix.join('');
        }

        function _onStartDrag(event) {
            if (event.button || event.target.classList.contains(noDraggingClass)) {
                return;
            }

            savedX = x;
            savedY = y;

            savedPageX = event.pageX;
            savedPageY = event.pageY;

            dETarget.addEventListener(mouseMoveEvent, _onDoDrag);

            dETarget.addEventListener(mouseUpEvent, _onEndDrag);
        }

        function _onDoDrag(event) {
            _applyTransformation(savedX + event.pageX - savedPageX, savedY + event.pageY - savedPageY);
        }

        function _onEndDrag() {
            if (onDragEndCallback) {
                onDragEndCallback(x, y);
            }

            dETarget.removeEventListener(mouseMoveEvent, _onDoDrag);

            dETarget.removeEventListener(mouseUpEvent, _onEndDrag);
        }

        config.dSTarget.addEventListener(mouseDownEvent, _onStartDrag);

        _applyTransformation(config.initialX || 0, config.initialY || 0);
    }

    return function _DnDFactory(config) {
        return new _DnDMagic(config);
    }
})();
{'fraction_non_alphanumeric': 0.10250957039557634, 'fraction_numerical': 0.005104210974053594, 'mean_word_length': 2.475979305247598, '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': '7075898', 'n_tokens_mistral': 1415, 'n_tokens_neox': 1359, 'n_words': 315}