2007-09-15 03:08:25 +02:00
|
|
|
/**
|
|
|
|
* @author Mateusz
|
|
|
|
*/
|
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 03:08:25 +02:00
|
|
|
this.image = $('image');
|
|
|
|
this.image.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 03:19:43 +02:00
|
|
|
Event.observe(this.image,'load',this.onImageLoad);
|
2007-09-15 03:08:25 +02:00
|
|
|
imageHistory.add('initialize',this.image.src);
|
2007-09-15 03:26:36 +02:00
|
|
|
|
2007-09-15 03:08:25 +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 {
|
|
|
|
$('imageWidth').innerHTML = this.image.width + "px";
|
|
|
|
$('imageHeight').innerHTML = this.image.height + "px";
|
|
|
|
}
|
2007-09-15 03:08:25 +02:00
|
|
|
},
|
|
|
|
|
2007-09-15 03:19:43 +02:00
|
|
|
onImageLoad: function(event) {
|
2007-09-15 03:08:25 +02:00
|
|
|
this.reportSize();
|
|
|
|
$('imageContainer').style.width = this.image.width + 'px';
|
|
|
|
$('imageContainer').style.height = this.image.height + 'px';
|
2007-09-15 03:19:43 +02:00
|
|
|
if(resize.imageContainerResize.originalHeight == 0 && resize.imageContainerResize.originalWidth == 0) {
|
|
|
|
imageBox.center();
|
2007-09-15 03:26:36 +02:00
|
|
|
this.resizeOnFirstLoad();
|
2007-09-15 03:19:43 +02:00
|
|
|
}
|
2007-09-15 03:08:25 +02:00
|
|
|
resize.imageContainerResize.originalWidth = this.image.width;
|
|
|
|
resize.imageContainerResize.originalHeight = this.image.height;
|
2007-09-15 03:19:43 +02:00
|
|
|
imageBox.checkOutOfDrawingArea($('imageContainer').getWidth(),$('imageContainer').getHeight());
|
2007-09-15 03:26:36 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
resizeOnFirstLoad: function() {
|
|
|
|
windowWidth = Element.getDimensions($('mainContainer')).width;
|
2007-09-15 03:27:01 +02:00
|
|
|
windowHeight = Element.getDimensions($('mainContainer')).height - 100;
|
2007-09-15 03:26:36 +02:00
|
|
|
imageWidth = Element.getDimensions(this.image).width;
|
|
|
|
imageHeight= Element.getDimensions(this.image).height;
|
2007-09-15 03:27:01 +02:00
|
|
|
if(imageWidth > windowWidth - 120 || imageHeight > windowHeight - 120) {
|
2007-09-15 03:26:36 +02:00
|
|
|
ratio = imageWidth / imageHeight;
|
|
|
|
if(imageWidth > imageHeight) {
|
2007-09-15 03:27:01 +02:00
|
|
|
newWidth = windowWidth - 120;
|
2007-09-15 03:26:36 +02:00
|
|
|
newHeight = newWidth * (1/ratio);
|
|
|
|
} else {
|
2007-09-15 03:27:01 +02:00
|
|
|
newHeight = windowHeight - 120;
|
2007-09-15 03:26:36 +02:00
|
|
|
newWidth = newHeight * ratio;
|
|
|
|
}
|
|
|
|
this.reportSize(0,0);
|
|
|
|
imageHistory.clear();
|
|
|
|
imageTransformation.resize(newWidth,newHeight,ImageToResize.resizeOnFirstLoadCallBack.bind(this));
|
|
|
|
} else {
|
|
|
|
if(imageWidth != 0 && imageHeight != 0) Element.show($('image'));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
resizeOnFirstLoadCallBack: function() {
|
|
|
|
imageBox.center();
|
|
|
|
Element.show($('image'));
|
|
|
|
resize.imageContainerResize.setVisible(true);
|
|
|
|
}
|
2007-09-15 03:08:25 +02:00
|
|
|
};
|