Elgg  Version 3.0
ui.avatar_cropper.js
Go to the documentation of this file.
1 
5 elgg.provide('elgg.avatarCropper');
6 
13 elgg.avatarCropper.init = function() {
14 
15  var $img = $('#user-avatar-cropper');
16  var img = $img.get(0);
17 
18  var params = {
19  selectionOpacity: 0,
20  aspectRatio: '1:1',
21  onSelectEnd: elgg.avatarCropper.selectChange,
22  onSelectChange: elgg.avatarCropper.preview,
23  imageHeight: img.naturalHeight,
24  imageWidth: img.naturalWidth
25  };
26 
27  if ($('input[name=x2]').val()) {
28  params.x1 = $('input[name=x1]').val();
29  params.x2 = $('input[name=x2]').val();
30  params.y1 = $('input[name=y1]').val();
31  params.y2 = $('input[name=y2]').val();
32  }
33 
34  $img.imgAreaSelect(params);
35 };
36 
44 elgg.avatarCropper.selectChange = function(img, selection) {
45 
46  // Elgg expects a square, because of rounding issues this can be a difference of 1px
47  var rounding_diff = selection.width - selection.height;
48 
49  $('input[name=x1]').val(selection.x1);
50  $('input[name=x2]').val(selection.x2);
51  $('input[name=y1]').val(selection.y1);
52  $('input[name=y2]').val(selection.y2 + rounding_diff);
53 };
54 
55 elgg.register_hook_handler('init', 'system', elgg.avatarCropper.init);
if(elgg_extract('use_link', $vars, true)) if(!isset($vars['width'])) if(!isset($vars['height'])) if(!empty($class)) if(!empty($vars['width'])) if(!empty($vars['height'])) $img
Definition: default.php:62
var elgg
Definition: elgglib.js:4