'use strict'; /* globals $ */ function ImageDataHandler(img) { var _cropData; /** * Gets information about how the cropped image is dragged * @return {Object} */ this.getCropData = function () { return _cropData; }; this.setCropData = function() { var viewportBounds = img.canvas.getViewport().getBounds(); if (!viewportBounds) { return; } var dragAxis = img.canvas.getViewport().getData().axis; _cropData = { x: dragAxis === 'x' ? (viewportBounds.left - img.left) / (img.width * img.scaleX) : 0, y: dragAxis === 'y' ? (viewportBounds.top - img.top) / (img.height * img.scaleY) : 0, viewportWidth: viewportBounds.width, viewportHeight: viewportBounds.height, }; }; this.removeCropData = function() { _cropData = null; }; /** * Gets an object containing applied transformations for the Image and also * how it is cropped and dragged. * @return {Object} */ this.getData = function () { var viewportData = img.canvas.getViewport().getData(); var returnValue = $.extend( {}, { mirrored: img.canvas.getMirror().getStatus(), width: viewportData.dim.width, height: viewportData.dim.height, }, this.getCropData() ); if (img.canvas.__type === 'canvas') { var frameHandler = img.canvas.getViewport().getFrameHandler(); returnValue.edge = frameHandler.getFrameType(); returnValue.framed = returnValue.edge !== 'none'; } return returnValue; }; } module.exports = ImageDataHandler;