1 /** Init for Jcrop library and page setup
4 * @author Sarven Capadisli <csarven@status.net>
5 * @copyright 2009 StatusNet, Inc.
6 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
7 * @link http://status.net/
11 var x = ($('#avatar_crop_x').val()) ? $('#avatar_crop_x').val() : 0;
12 var y = ($('#avatar_crop_y').val()) ? $('#avatar_crop_y').val() : 0;
13 var w = ($('#avatar_crop_w').val()) ? $('#avatar_crop_w').val() : $("#avatar_original img").attr("width");
14 var h = ($('#avatar_crop_h').val()) ? $('#avatar_crop_h').val() : $("#avatar_original img").attr("height");
16 jQuery("#avatar_original img").Jcrop({
17 onChange: showPreview,
18 setSelect: [ x, y, w, h ],
19 onSelect: updateCoords,
28 function showPreview(coords) {
29 var rx = 96 / coords.w;
30 var ry = 96 / coords.h;
32 var img_width = $("#avatar_original img").attr("width");
33 var img_height = $("#avatar_original img").attr("height");
35 $('#avatar_preview img').css({
36 width: Math.round(rx *img_width) + 'px',
37 height: Math.round(ry * img_height) + 'px',
38 marginLeft: '-' + Math.round(rx * coords.x) + 'px',
39 marginTop: '-' + Math.round(ry * coords.y) + 'px'
43 function updateCoords(c) {
44 $('#avatar_crop_x').val(c.x);
45 $('#avatar_crop_y').val(c.y);
46 $('#avatar_crop_w').val(c.w);
47 $('#avatar_crop_h').val(c.h);