1 /** Init for Jcrop library and page setup
4 * @author Sarven Capadisli <csarven@status.net>
5 * @author Mikael Nordfeldth <mmn@hethane.se>
6 * @copyright 2009 StatusNet, Inc.
7 * @copyright 2013 Free Software Foundation, Inc.
8 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
9 * @link http://status.net/
13 var x = ($('#avatar_crop_x').val()) ? $('#avatar_crop_x').val() : 0;
14 var y = ($('#avatar_crop_y').val()) ? $('#avatar_crop_y').val() : 0;
15 var w = ($('#avatar_crop_w').val()) ? $('#avatar_crop_w').val() : $("#avatar_original img").attr("width");
16 var h = ($('#avatar_crop_h').val()) ? $('#avatar_crop_h').val() : $("#avatar_original img").attr("height");
18 $("#avatar_original img").Jcrop({
19 onChange: showPreview,
20 setSelect: [ x, y, w, h ],
21 onSelect: updateCoords,
30 function showPreview(coords) {
31 var rx = 96 / coords.w;
32 var ry = 96 / coords.h;
34 var img_width = $("#avatar_original img").attr("width");
35 var img_height = $("#avatar_original img").attr("height");
37 $('#avatar_preview img').css({
38 width: Math.round(rx *img_width) + 'px',
39 height: Math.round(ry * img_height) + 'px',
40 marginLeft: '-' + Math.round(rx * coords.x) + 'px',
41 marginTop: '-' + Math.round(ry * coords.y) + 'px'
45 function updateCoords(c) {
46 $('#avatar_crop_x').val(c.x);
47 $('#avatar_crop_y').val(c.y);
48 $('#avatar_crop_w').val(c.w);
49 $('#avatar_crop_h').val(c.h);