aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--engine/lib/elgglib.php1
-rw-r--r--js/lib/avatar_cropper.js50
-rw-r--r--js/lib/ui.js37
-rw-r--r--views/default/forms/avatar/crop.php1
4 files changed, 52 insertions, 37 deletions
diff --git a/engine/lib/elgglib.php b/engine/lib/elgglib.php
index 53a15ba7a..66268cc96 100644
--- a/engine/lib/elgglib.php
+++ b/engine/lib/elgglib.php
@@ -2046,6 +2046,7 @@ function elgg_init() {
elgg_register_js('elgg.userpicker', 'js/lib/userpicker.js');
elgg_register_js('elgg.friendspicker', 'js/lib/friends_picker.js');
elgg_register_js('jquery.easing', 'vendors/jquery/jquery.easing.1.3.packed.js');
+ elgg_register_js('elgg.avatar_cropper', 'js/lib/avatar_cropper.js');
elgg_register_js('jquery.imgareaselect', 'vendors/jquery/jquery.imgareaselect-0.9.8/scripts/jquery.imgareaselect.min.js');
elgg_register_css('jquery.imgareaselect', 'vendors/jquery/jquery.imgareaselect-0.9.8/css/imgareaselect-deprecated.css');
diff --git a/js/lib/avatar_cropper.js b/js/lib/avatar_cropper.js
new file mode 100644
index 000000000..bfd76225b
--- /dev/null
+++ b/js/lib/avatar_cropper.js
@@ -0,0 +1,50 @@
+/**
+ * Avatar cropping
+ */
+
+elgg.provide('elgg.avatarCropper');
+
+/**
+ * Register the avatar cropper.
+ */
+elgg.avatarCropper.init = function() {
+ $('#user-avatar-cropper').imgAreaSelect({
+ selectionOpacity: 0,
+ aspectRatio: '1:1',
+ onSelectEnd: elgg.avatarCropper.selectChange,
+ onSelectChange: elgg.avatarCropper.preview
+ });
+}
+
+/**
+ * Handler for changing select area.
+ */
+elgg.avatarCropper.preview = function(img, selection) {
+ // catch for the first click on the image
+ if (selection.width == 0 || selection.height == 0) {
+ return;
+ }
+
+ var origWidth = $("#user-avatar-cropper").width();
+ var origHeight = $("#user-avatar-cropper").height();
+ var scaleX = 100 / selection.width;
+ var scaleY = 100 / selection.height;
+ $('#user-avatar-preview > img').css({
+ width: Math.round(scaleX * origWidth) + 'px',
+ height: Math.round(scaleY * origHeight) + 'px',
+ marginLeft: '-' + Math.round(scaleX * selection.x1) + 'px',
+ marginTop: '-' + Math.round(scaleY * selection.y1) + 'px'
+ });
+}
+
+/**
+ * Handler for updating the form inputs after select ends
+ */
+elgg.avatarCropper.selectChange = function(img, selection) {
+ $('input[name=x1]').val(selection.x1);
+ $('input[name=x2]').val(selection.x2);
+ $('input[name=y1]').val(selection.y1);
+ $('input[name=y2]').val(selection.y2);
+}
+
+elgg.register_hook_handler('init', 'system', elgg.avatarCropper.init); \ No newline at end of file
diff --git a/js/lib/ui.js b/js/lib/ui.js
index 8cee500d0..166ca16bc 100644
--- a/js/lib/ui.js
+++ b/js/lib/ui.js
@@ -25,14 +25,6 @@ elgg.ui.init = function () {
if ($('.elgg-input-date').length) {
elgg.ui.initDatePicker();
}
-
- // avatar cropper
- $('#user-avatar-cropper').imgAreaSelect({
- selectionOpacity: 0,
- aspectRatio: '1:1',
- onSelectEnd: elgg.ui.avatarSelectChange,
- onSelectChange: elgg.ui.avatarPreview
- });
}
/**
@@ -286,34 +278,5 @@ elgg.ui.initDatePicker = function() {
});
}
-// Avatar cropping
-
-// display a preview of the users cropped section
-elgg.ui.avatarPreview = function(img, selection) {
- // catch for the first click on the image
- if (selection.width == 0 || selection.height == 0) {
- return;
- }
-
- var origWidth = $("#user-avatar-cropper").width();
- var origHeight = $("#user-avatar-cropper").height();
- var scaleX = 100 / selection.width;
- var scaleY = 100 / selection.height;
- $('#user-avatar-preview > img').css({
- width: Math.round(scaleX * origWidth) + 'px',
- height: Math.round(scaleY * origHeight) + 'px',
- marginLeft: '-' + Math.round(scaleX * selection.x1) + 'px',
- marginTop: '-' + Math.round(scaleY * selection.y1) + 'px'
- });
-}
-
-// populate the form with the correct coordinates once a user has cropped their image
-elgg.ui.avatarSelectChange = function(img, selection) {
- $('input[name=x1]').val(selection.x1);
- $('input[name=x2]').val(selection.x2);
- $('input[name=y1]').val(selection.y1);
- $('input[name=y2]').val(selection.y2);
-}
-
elgg.register_hook_handler('init', 'system', elgg.ui.init);
elgg.register_hook_handler('getOptions', 'ui.popup', elgg.ui.LoginHandler); \ No newline at end of file
diff --git a/views/default/forms/avatar/crop.php b/views/default/forms/avatar/crop.php
index dd1640b1f..f622fd60f 100644
--- a/views/default/forms/avatar/crop.php
+++ b/views/default/forms/avatar/crop.php
@@ -6,6 +6,7 @@
*/
elgg_load_js('jquery.imgareaselect');
+elgg_load_js('elgg.avatar_cropper');
elgg_load_css('jquery.imgareaselect');
$master_image = $vars['entity']->getIconUrl('master');