Skip to content

Instantly share code, notes, and snippets.

@rickychilcott
Created June 10, 2012 20:45
Show Gist options
  • Save rickychilcott/2907258 to your computer and use it in GitHub Desktop.
Save rickychilcott/2907258 to your computer and use it in GitHub Desktop.
jQuery ->
new ImageCropper()
class ImageCropper
constructor: ->
$('#cropbox').Jcrop
aspectRatio: 1
setSelect: [0, 0, 600, 600]
onSelect: @update
onChange: @update
update: (coords) =>
$('#business_crop_x').val(coords.x)
$('#business_crop_y').val(coords.y)
$('#business_crop_w').val(coords.w)
$('#business_crop_h').val(coords.h)
@updatePreview(coords)
updatePreview: (coords) =>
$('#preview').css
width: Math.round(100/coords.w * $('#cropbox').width()) + 'px'
height: Math.round(100/coords.h * $('#cropbox').height()) + 'px'
marginLeft: '-' + Math.round(100/coords.w * coords.x) + 'px'
marginTop: '-' + Math.round(100/coords.h * coords.y) + 'px'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment