Last active
December 22, 2015 00:09
-
-
Save crmaxx/6387408 to your computer and use it in GitHub Desktop.
Rewrite to CoffeeScript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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