Elgg  Version 2.3
ui.avatar_cropper.js
Go to the documentation of this file.
1 
5 elgg.provide('elgg.avatarCropper');
6 
13 elgg.avatarCropper.init = function() {
14  var params = {
15  selectionOpacity: 0,
16  aspectRatio: '1:1',
17  onSelectEnd: elgg.avatarCropper.selectChange,
18  onSelectChange: elgg.avatarCropper.preview
19  };
20 
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();
26  }
27 
28  $('#user-avatar-cropper').imgAreaSelect(params);
29 
30  if ($('input[name=x2]').val()) {
31 
32  // TODO figure out why this is necessary
33  $(window).on('load', function () {
34  var ias = $('#user-avatar-cropper').imgAreaSelect({instance: true});
35  var selection = ias.getSelection();
36  elgg.avatarCropper.preview($('#user-avatar-cropper'), selection);
37  });
38  }
39 };
40 
48 elgg.avatarCropper.preview = function(img, selection) {
49  // catch for the first click on the image
50  if (selection.width === 0 || selection.height === 0) {
51  return;
52  }
53 
54  var origWidth = $("#user-avatar-cropper").width();
55  var origHeight = $("#user-avatar-cropper").height();
56  var scaleX = 100 / selection.width;
57  var scaleY = 100 / selection.height;
58  $('#user-avatar-preview > img').css({
59  width: Math.round(scaleX * origWidth) + 'px',
60  height: Math.round(scaleY * origHeight) + 'px',
61  marginLeft: '-' + Math.round(scaleX * selection.x1) + 'px',
62  marginTop: '-' + Math.round(scaleY * selection.y1) + 'px'
63  });
64 };
65 
73 elgg.avatarCropper.selectChange = function(img, selection) {
74  $('input[name=x1]').val(selection.x1);
75  $('input[name=x2]').val(selection.x2);
76  $('input[name=y1]').val(selection.y1);
77  $('input[name=y2]').val(selection.y2);
78 };
79 
80 elgg.register_hook_handler('init', 'system', elgg.avatarCropper.init);
elgg
Definition: install.js:23
line height
Definition: admin.css.php:82
imgAreaSelect
imgAreaSelect initialization
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two distribute and or modify the software for each author s protection and we want to make certain that everyone understands that there is no warranty for this free software If the software is modified by someone else and passed on
Definition: GPL-LICENSE.txt:43
img
Definition: admin.css.php:40
min width
Definition: admin.css.php:166