2007-09-15 03:08:25 +02:00
|
|
|
/**
|
|
|
|
* @author Mateusz
|
2007-09-15 22:54:37 +02:00
|
|
|
*/
|
2007-10-03 01:26:35 +02:00
|
|
|
ImageEditor.ImageToResize = {
|
2007-09-15 03:08:25 +02:00
|
|
|
initialize: function(imageFile) {
|
2007-09-15 03:26:36 +02:00
|
|
|
Element.hide($('image'));
|
2007-09-15 22:54:37 +02:00
|
|
|
this.imageToResize = $('image');
|
|
|
|
this.imageToResize.src = imageFile;
|
2007-10-03 01:26:35 +02:00
|
|
|
this.reportSize = ImageEditor.ImageToResize.reportSize.bind(this);
|
|
|
|
this.onImageLoad = ImageEditor.ImageToResize.onImageLoad.bind(this);
|
|
|
|
this.resizeOnFirstLoad = ImageEditor.ImageToResize.resizeOnFirstLoad.bind(this);
|
2007-09-15 22:54:37 +02:00
|
|
|
Event.observe(this.imageToResize,'load',this.onImageLoad);
|
2007-09-15 03:08:25 +02:00
|
|
|
},
|
2007-09-15 22:54:37 +02:00
|
|
|
|
2007-09-15 03:26:36 +02:00
|
|
|
reportSize: function(width,height) {
|
|
|
|
if(width != null && height != null) {
|
2007-09-16 04:23:10 +02:00
|
|
|
$('ImageWidth').innerHTML = width + "px";
|
|
|
|
$('ImageHeight').innerHTML = height + "px";
|
2007-09-15 03:26:36 +02:00
|
|
|
} else {
|
2007-09-16 04:23:10 +02:00
|
|
|
$('ImageWidth').innerHTML = this.imageToResize.width + "px";
|
|
|
|
$('ImageHeight').innerHTML = this.imageToResize.height + "px";
|
2007-09-15 22:54:37 +02:00
|
|
|
}
|
2007-09-15 03:08:25 +02:00
|
|
|
},
|
|
|
|
|
2007-09-15 03:19:43 +02:00
|
|
|
onImageLoad: function(event) {
|
2007-09-15 22:54:37 +02:00
|
|
|
if(this.imageToResize.width != 0 && this.imageToResize.height != 0) {
|
2007-09-15 23:54:51 +02:00
|
|
|
$('imageContainer').style.backgroundImage = 'url("' + $('image').src + '")';
|
2007-10-03 01:26:35 +02:00
|
|
|
ImageEditor.imageBox.hideIndicator();
|
2007-09-15 22:54:37 +02:00
|
|
|
Element.show($('imageContainer'),$('image'));
|
2007-10-03 01:26:35 +02:00
|
|
|
ImageEditor.crop.enable();
|
|
|
|
ImageEditor.resize.imageContainerResize.enable();
|
|
|
|
ImageEditor.effects.enableRotate();
|
|
|
|
ImageEditor.imageHistory.enable();
|
|
|
|
if(ImageEditor.resize.imageContainerResize.originalHeight == 0 && ImageEditor.resize.imageContainerResize.originalWidth == 0) {
|
|
|
|
ImageEditor.imageHistory.add('initialize',$('image').src);
|
2007-09-15 22:54:37 +02:00
|
|
|
this.resizeOnFirstLoad();
|
2007-10-03 01:26:35 +02:00
|
|
|
ImageEditor.imageBox.center();
|
2007-09-15 22:54:37 +02:00
|
|
|
}
|
2007-10-03 01:26:35 +02:00
|
|
|
ImageEditor.resize.imageContainerResize.originalWidth = this.imageToResize.width;
|
|
|
|
ImageEditor.resize.imageContainerResize.originalHeight = this.imageToResize.height;
|
|
|
|
ImageEditor.resize.imageContainerResize.placeClickBox();
|
|
|
|
ImageEditor.crop.onImageLoadCallback();
|
2007-09-15 03:19:43 +02:00
|
|
|
}
|
2007-09-15 22:54:37 +02:00
|
|
|
this.reportSize();
|
2007-09-15 03:26:36 +02:00
|
|
|
},
|
|
|
|
|
2007-09-15 22:54:37 +02:00
|
|
|
resizeOnFirstLoad: function() {
|
2007-09-16 04:23:10 +02:00
|
|
|
var windowWidth = Element.getDimensions($('Main')).width;
|
|
|
|
var windowHeight = Element.getDimensions($('Main')).height - 100;
|
2007-09-15 22:54:37 +02:00
|
|
|
var imageWidth = Element.getDimensions($('image')).width;
|
|
|
|
var imageHeight = Element.getDimensions($('image')).height;
|
2007-09-16 03:30:43 +02:00
|
|
|
if(imageWidth > windowWidth - 40 || imageHeight > windowHeight - 40) {
|
2007-10-03 01:26:35 +02:00
|
|
|
ImageEditor.imageHistory.clear();
|
2007-09-15 22:54:37 +02:00
|
|
|
Element.hide($('imageContainer'),$('image'));
|
2007-10-03 01:26:35 +02:00
|
|
|
var ratio = imageWidth / imageHeight;
|
2007-09-16 03:30:43 +02:00
|
|
|
$('loadingIndicatorContainer2').style.left = windowWidth/2 + 'px';
|
|
|
|
$('loadingIndicatorContainer2').style.top = windowHeight/2 + 100 + 'px';
|
|
|
|
while(imageWidth > windowWidth - 40 || imageHeight > windowHeight - 40) {
|
2007-09-15 03:28:50 +02:00
|
|
|
imageWidth--;
|
|
|
|
imageHeight = imageWidth * (1/ratio);
|
2007-09-15 03:26:36 +02:00
|
|
|
}
|
|
|
|
this.reportSize(0,0);
|
2007-10-03 01:26:35 +02:00
|
|
|
ImageEditor.resize.imageContainerResize.setVisible(false);
|
|
|
|
ImageEditor.crop.disable();
|
|
|
|
ImageEditor.resize.imageContainerResize.disable();
|
|
|
|
ImageEditor.effects.disableRotate();
|
|
|
|
ImageEditor.imageHistory.disable();
|
|
|
|
ImageEditor.imageTransformation.resize(imageWidth,imageHeight,ImageEditor.ImageToResize.resizeOnFirstLoadCallBack.bind(this),false);
|
2007-09-15 03:26:36 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
resizeOnFirstLoadCallBack: function() {
|
2007-09-16 03:30:43 +02:00
|
|
|
Element.hide($('loadingIndicatorContainer2'));
|
2007-10-03 01:26:35 +02:00
|
|
|
ImageEditor.resize.imageContainerResize.setVisible(true);
|
|
|
|
ImageEditor.resize.imageContainerResize.placeClickBox();
|
|
|
|
ImageEditor.imageBox.center();
|
2007-09-15 03:26:36 +02:00
|
|
|
}
|
2007-09-15 03:08:25 +02:00
|
|
|
};
|