aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcash <cash.costello@gmail.com>2011-10-27 18:30:26 -0400
committercash <cash.costello@gmail.com>2011-10-27 18:30:26 -0400
commit1bd24e93d69fb940f7491d1d7a12b1b13bebcfd5 (patch)
treec65dfc3fb4f5be41edac84bfd14e93a57a26c5fc
parent2f59afd29170066cb0d8ae19aa76ef2b7cb0b7db (diff)
downloadelgg-1bd24e93d69fb940f7491d1d7a12b1b13bebcfd5.tar.gz
elgg-1bd24e93d69fb940f7491d1d7a12b1b13bebcfd5.tar.bz2
Fixes #3832 initialize avatar crop area
-rw-r--r--js/lib/avatar_cropper.js30
1 files changed, 28 insertions, 2 deletions
diff --git a/js/lib/avatar_cropper.js b/js/lib/avatar_cropper.js
index bfd76225b..df6ba7866 100644
--- a/js/lib/avatar_cropper.js
+++ b/js/lib/avatar_cropper.js
@@ -6,18 +6,40 @@ elgg.provide('elgg.avatarCropper');
/**
* Register the avatar cropper.
+ *
+ * If the hidden inputs have the coordinates from a previous cropping, begin
+ * the selection and preview with that displayed.
*/
elgg.avatarCropper.init = function() {
- $('#user-avatar-cropper').imgAreaSelect({
+ var params = {
selectionOpacity: 0,
aspectRatio: '1:1',
onSelectEnd: elgg.avatarCropper.selectChange,
onSelectChange: elgg.avatarCropper.preview
- });
+ };
+
+ if ($('input[name=x2]').val()) {
+ params.x1 = $('input[name=x1]').val();
+ params.x2 = $('input[name=x2]').val();
+ params.y1 = $('input[name=y1]').val();
+ params.y2 = $('input[name=y2]').val();
+ }
+
+ $('#user-avatar-cropper').imgAreaSelect(params);
+
+ if ($('input[name=x2]').val()) {
+ var ias = $('#user-avatar-cropper').imgAreaSelect({instance: true});
+ var selection = ias.getSelection();
+ elgg.avatarCropper.preview($('#user-avatar-cropper'), selection);
+ }
}
/**
* Handler for changing select area.
+ *
+ * @param {Object} reference to the image
+ * @param {Object} imgareaselect selection object
+ * @return void
*/
elgg.avatarCropper.preview = function(img, selection) {
// catch for the first click on the image
@@ -39,6 +61,10 @@ elgg.avatarCropper.preview = function(img, selection) {
/**
* Handler for updating the form inputs after select ends
+ *
+ * @param {Object} reference to the image
+ * @param {Object} imgareaselect selection object
+ * @return void
*/
elgg.avatarCropper.selectChange = function(img, selection) {
$('input[name=x1]').val(selection.x1);