- function onEndCrop( coords, dimensions ) {
- $PR( 'x1' ).value = coords.x1;
- $PR( 'y1' ).value = coords.y1;
- $PR( 'x2' ).value = coords.x2;
- $PR( 'y2' ).value = coords.y2;
- $PR( 'width' ).value = dimensions.width;
- $PR( 'height' ).value = dimensions.height;
- }
-
- Event.observe( window, 'load', function() {
- new Cropper.ImgWithPreview(
- 'croppa',
- {
- previewWrap: 'previewWrap',
- minWidth: 175,
- minHeight: 175,
- maxWidth: 640,
- maxHeight: 640,
- ratioDim: { x: 100, y:100 },
- displayOnInit: true,
- onEndCrop: onEndCrop
+ var image = document.getElementById('croppa');
+ var cropper = new Cropper(image, {
+ aspectRatio: 1 / 1,
+ viewMode: 1,
+ preview: '#profile-photo-wrapper, .crop-preview',
+ crop: function(e) {
+ $( '#x1' ).val(e.detail.x);
+ $( '#y1' ).val(e.detail.y);
+ $( '#x2' ).val(e.detail.x + e.detail.width);
+ $( '#y2' ).val(e.detail.y + e.detail.height);
+ $( '#width' ).val(e.detail.scaleX);
+ $( '#height' ).val(e.detail.scaleY);
+ },
+ ready: function() {
+ // Add the "crop-preview" class to the preview element ("profile-photo-wrapper").
+ var cwrapper = document.getElementById("profile-photo-wrapper");
+ cwrapper.classList.add("crop-preview");