Skip to content

Instantly share code, notes, and snippets.

@qickstarter
Created September 27, 2012 08:34
Show Gist options
  • Select an option

  • Save qickstarter/3792907 to your computer and use it in GitHub Desktop.

Select an option

Save qickstarter/3792907 to your computer and use it in GitHub Desktop.
# ???よー分からん
$ ->
class Jcrop
constructor : (target, preview) ->
@target = $ target
@preview = $ preview
@appendJcrop()
getBounds : =>
console.debug @
@bounds = getBounds.call(@target)
@boundx = bounds[0]
@boundy = bounds[1]
# 座標取得してなんかやってる
updatePreview : (coords) =>
console.debug @
if parseInt(coords.w) > 0
rx = 100 / coords.w
ry = 100 / coords.h
@preview.css
width: Math.round(rx * @boundx) + 'px'
height: Math.round(ry * @boundy) + 'px'
marginLeft: '-' + Math.round(rx * coords.x) + 'px'
marginTop: '-' + Math.round(ry * coords.y) + 'px'
# Jcrop plugin
# lean more [ http://deepliquid.com/projects/Jcrop/demos.php ]
appendJcrop : ->
console.debug @
self = @
@target?.Jcrop {
onChange: self.updatePreview.call(@)
onSelect: self.updatePreview.call(@)
aspectRatio: 1
}, -># callback
jcrop_api = @
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment