aboutsummaryrefslogtreecommitdiffstats
path: root/public/javascripts
diff options
context:
space:
mode:
Diffstat (limited to 'public/javascripts')
-rw-r--r--public/javascripts/profile_photo.js20
1 files changed, 17 insertions, 3 deletions
diff --git a/public/javascripts/profile_photo.js b/public/javascripts/profile_photo.js
index 9f01dc58d..82a34caa3 100644
--- a/public/javascripts/profile_photo.js
+++ b/public/javascripts/profile_photo.js
@@ -1,11 +1,25 @@
// Remember to invoke within jQuery(window).load(...)
// If you don't, Jcrop may not initialize properly
jQuery(window).load(function(){
+ // The size of the initial selection (largest, centreted rectangle)
+ var w = jQuery('#profile_photo_cropbox').width();
+ var h = jQuery('#profile_photo_cropbox').height();
+ var t = 0;
+ var l = 0;
+ var initial;
+ if (h < w) {
+ initial = h;
+ l = (w - initial) / 2;
+ } else {
+ initial = w;
+ t = (h - initial) / 2;
+ }
jQuery('#profile_photo_cropbox').Jcrop({
onChange: showPreview,
onSelect: showPreview,
- aspectRatio: 1
+ aspectRatio: 1,
+ setSelect: [ l, t, initial, initial ]
});
});
@@ -20,8 +34,8 @@ function showPreview(coords)
var ry = 100 / coords.h;
jQuery('#profile_photo_preview').css({
- width: Math.round(rx * 500) + 'px',
- height: Math.round(ry * 370) + 'px',
+ width: Math.round(rx * jQuery('#profile_photo_cropbox').width()) + 'px',
+ height: Math.round(ry * jQuery('#profile_photo_cropbox').height()) + 'px',
marginLeft: '-' + Math.round(rx * coords.x) + 'px',
marginTop: '-' + Math.round(ry * coords.y) + 'px'
});