From 8998b8402744c094543796bcb40a2e4cc0763649 Mon Sep 17 00:00:00 2001 From: nilsding Date: Mon, 29 Dec 2014 17:22:43 +0100 Subject: [PATCH] updateVars is now called when the image finished loading --- app/assets/javascripts/settings.coffee | 29 ++++++++++++++------------ 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/app/assets/javascripts/settings.coffee b/app/assets/javascripts/settings.coffee index 3d50f262..5742e5b9 100644 --- a/app/assets/javascripts/settings.coffee +++ b/app/assets/javascripts/settings.coffee @@ -16,6 +16,19 @@ cropper = ($ '#profile-picture-cropper') preview = ($ '#profile-picture-preview') + updateVars = (data, action) -> + ($ '#crop_x').val Math.floor(data.x / data.scale) + ($ '#crop_y').val Math.floor(data.y / data.scale) + ($ '#crop_w').val Math.floor(data.w / data.scale) + ($ '#crop_h').val Math.floor(data.h / data.scale) +# rx = 100 / data.w +# ry = 100 / data.h +# ($ '#profile-picture-preview').css +# width: Math.round(rx * preview[0].naturalWidth) + 'px' +# height: Math.round(ry * preview[0].naturalHeight) + 'px' +# marginLeft: '-' + Math.round(rx * data.x) + 'px' +# marginTop: '-' + Math.round(ry * data.y) + 'px' + cropper.on 'load', -> side = if cropper[0].naturalWidth > cropper[0].naturalHeight cropper[0].naturalHeight @@ -25,19 +38,9 @@ cropper.guillotine width: side height: side - onChange: (data, action) -> - console.log data - ($ '#crop_x').val Math.floor(data.x / data.scale) - ($ '#crop_y').val Math.floor(data.y / data.scale) - ($ '#crop_w').val Math.floor(data.w / data.scale) - ($ '#crop_h').val Math.floor(data.h / data.scale) - # rx = 100 / data.w - # ry = 100 / data.h - # ($ '#profile-picture-preview').css - # width: Math.round(rx * preview[0].naturalWidth) + 'px' - # height: Math.round(ry * preview[0].naturalHeight) + 'px' - # marginLeft: '-' + Math.round(rx * data.x) + 'px' - # marginTop: '-' + Math.round(ry * data.y) + 'px' + onChange: updateVars + + updateVars cropper.guillotine('getData'), 'drag' # just because ($ '#cropper-zoom-out').click -> cropper.guillotine 'zoomOut' ($ '#cropper-zoom-in').click -> cropper.guillotine 'zoomIn'