updateVars is now called when the image finished loading

This commit is contained in:
nilsding 2014-12-29 17:22:43 +01:00
parent 338fa5bdb2
commit 8998b84027
1 changed files with 16 additions and 13 deletions

View File

@ -16,17 +16,7 @@
cropper = ($ '#profile-picture-cropper')
preview = ($ '#profile-picture-preview')
cropper.on 'load', ->
side = if cropper[0].naturalWidth > cropper[0].naturalHeight
cropper[0].naturalHeight
else
cropper[0].naturalWidth
cropper.guillotine
width: side
height: side
onChange: (data, action) ->
console.log data
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)
@ -39,6 +29,19 @@
# 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
else
cropper[0].naturalWidth
cropper.guillotine
width: side
height: side
onChange: updateVars
updateVars cropper.guillotine('getData'), 'drag' # just because
($ '#cropper-zoom-out').click -> cropper.guillotine 'zoomOut'
($ '#cropper-zoom-in').click -> cropper.guillotine 'zoomIn'
($ '#profile-picture-crop-controls').slideDown()