<commit_before>/**
 * Created by <NAME> from Ubrainians for imCode
 * 07.09.17
 */
Imcms.define("imcms-image-cropper", [], function () {

    var $croppingArea, $imageEditor, $cropImg, croppingAreaParams, angleBorderSize, imageCoords, angleParams,
        $originImg, angles;

    function moveCropImage(newTop, newLeft) {
        var cropImgTop = -newTop + angleBorderSize,
            cropImgLeft = -newLeft + angleBorderSize
        ;

        setElementTopLeft($cropImg, cropImgTop, cropImgLeft);
    }

    function setElementTopLeft($element, newTop, newLeft) {
        $element.css({
            top: newTop,
            left: newLeft
        });
    }

    function setElementWidthHeight($element, newWidth, newHeight) {
        $element.css({
            width: newWidth,
            height: newHeight
        });
    }

    function Limit(min, max) {
        return {
            forValue: function (value) {
                return Math.min(Math.max(value, min), max);
            }
        }
    }

    function getValidCoordX(coordX) {
        return Limit(imageCoords.left, $originImg.width() + imageCoords.left + angleBorderSize).forValue(coordX);
    }

    function getValidCoordY(coordY) {
        return Limit(imageCoords.top, $originImg.height() + imageCoords.top + angleBorderSize).forValue(coordY);
    }

    function getValidLeftOnMove(left) {
        return Limit(angleBorderSize, $originImg.width() - croppingAreaParams.width + angleBorderSize).forValue(left);
    }

    function getValidTopOnMove(top) {
        return Limit(angleBorderSize, $originImg.height() - croppingAreaParams.height + angleBorderSize).forValue(top);
    }

    function getValidLeftOnResize(left) {
        return Limit(angleBorderSize, parseInt(angles.$topRight.css("left")) - angleParams.width).forValue(left);
    }

    function getValidTopOnResize(top) {
        return Limit(angleBorderSize, parseInt($croppingArea.css("top")) + $croppingArea.height() - angleParams.height * 2).forValue(top);
    }

    function getValidTopAngleY(top) {
        return Limit(0, parseInt($croppingArea.css("top")) + $croppingArea.height() - angleParams.height * 2 - angleBorderSize).forValue(top);
    }

    function getValidBottomAngleY(top) {
        return Limit(parseInt($croppingArea.css("top")) + angleParams.height, $originImg.height() - angleParams.height + angleBorderSize).forValue(top);
    }

    function getValidLeftAngleX(left) {
        return Limit(0, parseInt($croppingArea.css("left")) + $croppingArea.width() - angleBorderSize - angleParams.width * 2).forValue(left);
    }

    function getValidRightAngleX(left) {
        return Limit(parseInt($croppingArea.css("left")) + angleParams.width, $originImg.width() - angleParams.width + angleBorderSize).forValue(left);
    }

    function getValidLeftCropWidth(width) {
        return Limit(2 * angleParams.width, parseInt($croppingArea.css("left")) + $croppingArea.width() - angleBorderSize).forValue(width);
    }

    function getValidRightCropWidth(width) {
        return Limit(2 * angleParams.width, $originImg.width() - parseInt($croppingArea.css("left")) + angleBorderSize).forValue(width);
    }

    function getValidCropHeightTop(height) {
        return Limit(2 * angleParams.height, parseInt($croppingArea.css("top")) + $croppingArea.height() - angleBorderSize).forValue(height);
    }

    function getValidCropHeightBottom(height) {
        return Limit(2 * angleParams.height, $originImg.height() - parseInt($croppingArea.css("top")) + angleBorderSize).forValue(height);
    }

    function moveCropArea(top, left) {<commit_msg>IMCMS-258 - Upgrade image functionality to work with new image editor API on client side: - Image cropper refactoring.<commit_after>/**
 * Created by <NAME> from Ubrainians for imCode
 * 07.09.17
 */
Imcms.define("imcms-image-cropper", [], function () {

    var $croppingArea, $imageEditor, $cropImg, croppingAreaParams, angleBorderSize, imageCoords, angleParams,
        $originImg, angles;

    function moveCropImage(newTop, newLeft) {
        var cropImgTop = -newTop + angleBorderSize,
            cropImgLeft = -newLeft + angleBorderSize
        ;

        setElementTopLeft($cropImg, cropImgTop, cropImgLeft);
    }

    function setElementTopLeft($element, newTop, newLeft) {
        $element.css({
            top: newTop,
            left: newLeft
        });
    }

    function setElementWidthHeight($element, newWidth, newHeight) {
        $element.css({
            width: newWidth,
            height: newHeight
        });
    }

    var Limit = function () {
    };

    Limit.prototype = {
        setMin: function (min) {
            this.min = min;
            return this;
        },
        setMax: function (max) {
            this.max = max;
            return this;
        },
        forValue: function (value) {
            return Math.min(Math.max(value, this.min), this.max);
        }
    };

    function getValidCoordX(coordX) {
        return new Limit().setMin(imageCoords.left)
            .setMax($originImg.width() + imageCoords.left + angleBorderSize)
            .forValue(coordX);
    }

    function getValidCoordY(coordY) {
        return new Limit().setMin(imageCoords.top)
            .setMax($originImg.height() + imageCoords.top + angleBorderSize)
            .forValue(coordY);
    }

    function getValidLeftOnMove(left) {
        return new Limit().setMin(angleBorderSize)
            .setMax($originImg.width() - croppingAreaParams.width + angleBorderSize)
            .forValue(left);
    }

    function getValidTopOnMove(top) {
        return new Limit().setMin(angleBorderSize)
            .setMax($originImg.height() - croppingAreaParams.height + angleBorderSize)
            .forValue(top);
    }

    function getValidLeftOnResize(left) {
        return new Limit().setMin(angleBorderSize)
            .setMax(parseInt(angles.$topRight.css("left")) - angleParams.width)
            .forValue(left);
    }

    function getValidTopOnResize(top) {
        return new Limit().setMin(angleBorderSize)
            .setMax(parseInt($croppingArea.css("top")) + $croppingArea.height() - angleParams.height * 2)
            .forValue(top);
    }

    function getValidTopAngleY(top) {
        return new Limit().setMin(0)
            .setMax(parseInt($croppingArea.css("top")) + $croppingArea.height() - angleParams.height * 2 - angleBorderSize)
            .forValue(top);
    }

    function getValidBottomAngleY(top) {
        return new Limit().setMin(parseInt($croppingArea.css("top")) + angleParams.height)
            .setMax($originImg.height() - angleParams.height + angleBorderSize)
            .forValue(top);
    }

    function getValidLeftAngleX(left) {
        return new Limit().setMin(0)
            .setMax(parseInt($croppingArea.css("left")) + $croppingArea.width() - angleBorderSize - angleParams.width * 2)
            .forValue(left);
    }

    function getValidRightAngleX(left) {
        return new Limit().setMin(parseInt($croppingArea.css("left")) + angleParams.width)
            .setMax($originImg.width() - angleParams.width + angleBorderSize)
            .forValue(left);
    }

    function getValidLeftCropWidth(width) {
        return new Limit().setMin(2 * angleParams.width)
            .setMax(parseInt($croppingArea.css("left")) + $croppingArea.width() - angleBorderSize)
            .forValue(width);
    }

    function getValidRightCropWidth(width) {
        return new Limit().setMin(2 * angleParams.width)
            .setMax($originImg.width() - parseInt($croppingArea.css("left")) + angleBorderSize)
            .forValue(width);
    }

    function getValidCropHeightTop(height) {
        return new Limit().setMin(2 * angleParams.height)
            .setMax(parseInt($croppingArea.css("top")) + $croppingArea.height() - angleBorderSize)
            .forValue(height);
    }

    function getValidCropHeightBottom(height) {
        return new Limit().setMin(2 * angleParams.height)
            .setMax($originImg.height() - parseInt($croppingArea.css("top")) + angleBorderSize)
            .forValue(height);
    }

    function moveCropArea(top, left) {
{'fraction_non_alphanumeric': 0.1254598969830758, 'fraction_numerical': 0.004047093451066961, 'mean_word_length': 2.8178838951310863, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '5216309', 'n_tokens_mistral': 2460, 'n_tokens_neox': 2385, 'n_words': 406}