2007-09-15 03:08:25 +02:00
|
|
|
/**
|
|
|
|
* @author Mateusz
|
2007-09-15 22:54:37 +02:00
|
|
|
*/
|
2007-09-15 03:26:36 +02:00
|
|
|
var 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-09-15 03:26:36 +02:00
|
|
|
this.reportSize = ImageToResize.reportSize.bind(this);
|
|
|
|
this.onImageLoad = ImageToResize.onImageLoad.bind(this);
|
|
|
|
this.resizeOnFirstLoad = 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) {
|
|
|
|
$('imageWidth').innerHTML = width + "px";
|
|
|
|
$('imageHeight').innerHTML = height + "px";
|
|
|
|
} else {
|
2007-09-15 22:54:37 +02:00
|
|
|
$('imageWidth').innerHTML = this.imageToResize.width + "px";
|
|
|
|
$('imageHeight').innerHTML = this.imageToResize.height + "px";
|
|
|
|
}
|
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-09-15 22:54:37 +02:00
|
|
|
imageBox.hideIndicator();
|
|
|
|
Element.show($('imageContainer'),$('image'));
|
2007-09-15 22:53:26 +02:00
|
|
|
if(resize.imageContainerResize.originalHeight == 0 && resize.imageContainerResize.originalWidth == 0) {
|
2007-09-15 22:54:37 +02:00
|
|
|
imageHistory.add('initialize',$('image').src);
|
|
|
|
this.resizeOnFirstLoad();
|
|
|
|
imageBox.center();
|
|
|
|
}
|
|
|
|
resize.imageContainerResize.originalWidth = this.imageToResize.width;
|
|
|
|
resize.imageContainerResize.originalHeight = this.imageToResize.height;
|
|
|
|
resize.imageContainerResize.placeClickBox();
|
|
|
|
crop.enable();
|
|
|
|
resize.imageContainerResize.enable();
|
|
|
|
effects.enableRotate();
|
2007-09-15 22:55:50 +02:00
|
|
|
imageHistory.enable();
|
|
|
|
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() {
|
|
|
|
var windowWidth = Element.getDimensions($('mainContainer')).width;
|
|
|
|
var windowHeight = Element.getDimensions($('mainContainer')).height - 100;
|
|
|
|
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-09-15 22:54:37 +02:00
|
|
|
imageHistory.clear();
|
|
|
|
Element.hide($('imageContainer'),$('image'));
|
|
|
|
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-09-15 22:53:26 +02:00
|
|
|
resize.imageContainerResize.setVisible(false);
|
2007-09-15 22:54:37 +02:00
|
|
|
imageTransformation.resize(imageWidth,imageHeight,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'));
|
|
|
|
resize.imageContainerResize.setVisible(true);
|
2007-09-15 22:54:37 +02:00
|
|
|
resize.imageContainerResize.placeClickBox();
|
|
|
|
imageBox.center();
|
2007-09-15 03:26:36 +02:00
|
|
|
}
|
2007-09-15 03:08:25 +02:00
|
|
|
};
|