v1.18.x
pichalite 8 years ago
parent 484891472e
commit 43f4d9819e

@ -4,75 +4,75 @@
define('pictureCropper', ['translator', 'cropper'], function (translator, cropper) { define('pictureCropper', ['translator', 'cropper'], function (translator, cropper) {
var module = {}; var module = {};
module.handleImageCrop = function (data, callback) { module.handleImageCrop = function (data, callback) {
$('#crop-picture-modal').remove(); $('#crop-picture-modal').remove();
templates.parse('modals/crop_picture', {url: data.url}, function (cropperHtml) { templates.parse('modals/crop_picture', {url: data.url}, function (cropperHtml) {
translator.translate(cropperHtml, function (translated) { translator.translate(cropperHtml, function (translated) {
var cropperModal = $(translated); var cropperModal = $(translated);
cropperModal.modal('show'); cropperModal.modal('show');
var img = document.getElementById('cropped-image');
var cropperTool = new cropper.default(img, {
aspectRatio: data.aspectRatio,
viewMode: 1
});
cropperModal.find('.rotate').on('click', function () {
var degrees = this.getAttribute("data-degrees");
cropperTool.rotate(degrees);
});
cropperModal.find('.flip').on('click', function () {
var option = this.getAttribute("data-option");
var method = this.getAttribute("data-method");
method === 'scaleX' ? cropperTool.scaleX(option) : cropperTool.scaleY(option);
this.setAttribute("data-option", option * -1);
});
cropperModal.find('.reset').on('click', function () {
cropperTool.reset();
});
cropperModal.find('.crop-btn').on('click', function () {
$(this).addClass('disabled');
var imageData = data.imageType ? cropperTool.getCroppedCanvas().toDataURL(data.imageType) : cropperTool.getCroppedCanvas().toDataURL();
var img = document.getElementById('cropped-image'); cropperModal.find('#upload-progress-bar').css('width', '100%');
var cropperTool = new cropper.default(img, { cropperModal.find('#upload-progress-box').show().removeClass('hide');
aspectRatio: data.aspectRatio,
viewMode: 1
});
cropperModal.find('.rotate').on('click', function () { var socketData = {};
var degrees = this.getAttribute("data-degrees"); socketData[data.paramName] = data.paramValue;
cropperTool.rotate(degrees); socketData['imageData'] = imageData;
});
cropperModal.find('.flip').on('click', function () { socket.emit(data.socketMethod, socketData, function (err, imageData) {
var option = this.getAttribute("data-option"); if (err) {
var method = this.getAttribute("data-method"); cropperModal.find('#upload-progress-box').hide();
method === 'scaleX' ? cropperTool.scaleX(option) : cropperTool.scaleY(option); cropperModal.find('.upload-btn').removeClass('disabled');
this.setAttribute("data-option", option * -1); cropperModal.find('.crop-btn').removeClass('disabled');
}); return app.alertError(err.message);
}
cropperModal.find('.reset').on('click', function () { callback(imageData.url);
cropperTool.reset(); cropperModal.modal('hide');
}); });
});
cropperModal.find('.crop-btn').on('click', function () {
$(this).addClass('disabled'); cropperModal.find('.upload-btn').on('click', function () {
var imageData = data.imageType ? cropperTool.getCroppedCanvas().toDataURL(data.imageType) : cropperTool.getCroppedCanvas().toDataURL(); $(this).addClass('disabled');
cropperTool.destroy();
cropperModal.find('#upload-progress-bar').css('width', '100%');
cropperModal.find('#upload-progress-box').show().removeClass('hide'); cropperTool = new cropper.default(img, {
viewMode: 1,
var socketData = {}; autoCropArea: 1
socketData[data.paramName] = data.paramValue;
socketData['imageData'] = imageData;
socket.emit(data.socketMethod, socketData, function (err, imageData) {
if (err) {
cropperModal.find('#upload-progress-box').hide();
cropperModal.find('.upload-btn').removeClass('disabled');
cropperModal.find('.crop-btn').removeClass('disabled');
return app.alertError(err.message);
}
callback(imageData.url);
cropperModal.modal('hide');
});
});
cropperModal.find('.upload-btn').on('click', function () {
$(this).addClass('disabled');
cropperTool.destroy();
cropperTool = new cropper.default(img, {
viewMode: 1,
autoCropArea: 1
});
cropperModal.find('.crop-btn').trigger('click');
}); });
cropperModal.find('.crop-btn').trigger('click');
}); });
}); });
} });
};
return module; return module;
}); });

Loading…
Cancel
Save