Skip to content

Instantly share code, notes, and snippets.

@crmaxx
Last active December 22, 2015 00:09
Show Gist options
  • Select an option

  • Save crmaxx/6387408 to your computer and use it in GitHub Desktop.

Select an option

Save crmaxx/6387408 to your computer and use it in GitHub Desktop.
Rewrite to CoffeeScript
class CropApi
constructor: (@node) ->
$node = $(node)
$body = $("body")
$cropXField = $node.find('.crop_x')
$cropYField = $node.find('.crop_y')
$cropWField = $node.find('.crop_w')
$cropHField = $node.find('.crop_h')
returnKeyHandler: (event) ->
if (event.keyCode == 13)
$node.find('.crop_image').submit()
$body.unbind('keyup', @returnKeyHandler)
@
cropAreaChanged: (coords) ->
$cropXField.val(coords.x)
$cropYField.val(coords.y)
$cropWField.val(coords.w)
$cropHField.val(coords.h)
cropOptionsShown = true
attachCroppingTo: (node) ->
jCropApi = $.Jcrop(node, {
'onSelect': @cropAreaChanged,
'onChange': @cropAreaChanged,
'aspectRatio': 1,
'setSelect': [
parseInt($cropXField.val()),
parseInt($cropYField.val()),
parseInt($cropXField.val()) + parseInt($cropWField.val()),
parseInt($cropYField.val()) + parseInt($cropHField.val())
]
})
$body.keyup(self.returnKeyHandler)
$node.val('Crop')
cropOptionsShown = false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment