diff options
Diffstat (limited to 'public/javascripts/profile_photo.js')
-rw-r--r-- | public/javascripts/profile_photo.js | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/public/javascripts/profile_photo.js b/public/javascripts/profile_photo.js new file mode 100644 index 000000000..9f01dc58d --- /dev/null +++ b/public/javascripts/profile_photo.js @@ -0,0 +1,30 @@ +// Remember to invoke within jQuery(window).load(...) +// If you don't, Jcrop may not initialize properly +jQuery(window).load(function(){ + + jQuery('#profile_photo_cropbox').Jcrop({ + onChange: showPreview, + onSelect: showPreview, + aspectRatio: 1 + }); + +}); + +// Our simple event handler, called from onChange and onSelect +// event handlers, as per the Jcrop invocation above +function showPreview(coords) +{ + if (parseInt(coords.w) > 0) + { + var rx = 100 / coords.w; + var ry = 100 / coords.h; + + jQuery('#profile_photo_preview').css({ + width: Math.round(rx * 500) + 'px', + height: Math.round(ry * 370) + 'px', + marginLeft: '-' + Math.round(rx * coords.x) + 'px', + marginTop: '-' + Math.round(ry * coords.y) + 'px' + }); + } +} + |