5 elgg.provide(
'elgg.avatarCropper');
13 elgg.avatarCropper.init =
function() {
17 onSelectEnd:
elgg.avatarCropper.selectChange,
18 onSelectChange:
elgg.avatarCropper.preview
21 if ($(
'input[name=x2]').val()) {
22 params.x1 = $(
'input[name=x1]').val();
23 params.x2 = $(
'input[name=x2]').val();
24 params.y1 = $(
'input[name=y1]').val();
25 params.y2 = $(
'input[name=y2]').val();
28 $(
'#user-avatar-cropper').imgAreaSelect(params);
30 if ($(
'input[name=x2]').val()) {
31 var ias = $(
'#user-avatar-cropper').imgAreaSelect({instance:
true});
32 var selection = ias.getSelection();
33 elgg.avatarCropper.preview($(
'#user-avatar-cropper'), selection);
44 elgg.avatarCropper.preview =
function(
img, selection) {
46 if (selection.width === 0 || selection.height === 0) {
50 var origWidth = $(
"#user-avatar-cropper").
width();
51 var origHeight = $(
"#user-avatar-cropper").
height();
52 var scaleX = 100 / selection.width;
53 var scaleY = 100 / selection.height;
54 $(
'#user-avatar-preview > img').css({
55 width: Math.round(scaleX * origWidth) +
'px',
56 height: Math.round(scaleY * origHeight) +
'px',
57 marginLeft:
'-' + Math.round(scaleX * selection.x1) +
'px',
58 marginTop:
'-' + Math.round(scaleY * selection.y1) +
'px' 69 elgg.avatarCropper.selectChange =
function(
img, selection) {
70 $(
'input[name=x1]').val(selection.x1);
71 $(
'input[name=x2]').val(selection.x2);
72 $(
'input[name=y1]').val(selection.y1);
73 $(
'input[name=y2]').val(selection.y2);
76 elgg.register_hook_handler(
'init',
'system',
elgg.avatarCropper.init);