silverstripe-reports/javascript/ImageEditor/Image.js
Ingo Schommer 030b55d750 mujma: ENHANCEMENTS: Added new design for ImageEditor?.
(merged from branches/gsoc)


git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@42046 467b73ca-7a2a-4603-9d3b-597d59a354a9
2007-09-16 02:23:10 +00:00

79 lines
3.0 KiB
JavaScript

/**
* @author Mateusz
*/
var ImageToResize = {
initialize: function(imageFile) {
Element.hide($('image'));
this.imageToResize = $('image');
this.imageToResize.src = imageFile;
this.reportSize = ImageToResize.reportSize.bind(this);
this.onImageLoad = ImageToResize.onImageLoad.bind(this);
this.resizeOnFirstLoad = ImageToResize.resizeOnFirstLoad.bind(this);
Event.observe(this.imageToResize,'load',this.onImageLoad);
},
reportSize: function(width,height) {
if(width != null && height != null) {
$('ImageWidth').innerHTML = width + "px";
$('ImageHeight').innerHTML = height + "px";
} else {
$('ImageWidth').innerHTML = this.imageToResize.width + "px";
$('ImageHeight').innerHTML = this.imageToResize.height + "px";
}
},
onImageLoad: function(event) {
if(this.imageToResize.width != 0 && this.imageToResize.height != 0) {
$('imageContainer').style.backgroundImage = 'url("' + $('image').src + '")';
imageBox.hideIndicator();
Element.show($('imageContainer'),$('image'));
crop.enable();
resize.imageContainerResize.enable();
effects.enableRotate();
imageHistory.enable();
if(resize.imageContainerResize.originalHeight == 0 && resize.imageContainerResize.originalWidth == 0) {
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.onImageLoadCallback();
}
this.reportSize();
},
resizeOnFirstLoad: function() {
var windowWidth = Element.getDimensions($('Main')).width;
var windowHeight = Element.getDimensions($('Main')).height - 100;
var imageWidth = Element.getDimensions($('image')).width;
var imageHeight = Element.getDimensions($('image')).height;
if(imageWidth > windowWidth - 40 || imageHeight > windowHeight - 40) {
imageHistory.clear();
Element.hide($('imageContainer'),$('image'));
ratio = imageWidth / imageHeight;
$('loadingIndicatorContainer2').style.left = windowWidth/2 + 'px';
$('loadingIndicatorContainer2').style.top = windowHeight/2 + 100 + 'px';
while(imageWidth > windowWidth - 40 || imageHeight > windowHeight - 40) {
imageWidth--;
imageHeight = imageWidth * (1/ratio);
}
this.reportSize(0,0);
resize.imageContainerResize.setVisible(false);
crop.disable();
resize.imageContainerResize.disable();
effects.disableRotate();
imageHistory.disable();
imageTransformation.resize(imageWidth,imageHeight,ImageToResize.resizeOnFirstLoadCallBack.bind(this),false);
}
},
resizeOnFirstLoadCallBack: function() {
Element.hide($('loadingIndicatorContainer2'));
resize.imageContainerResize.setVisible(true);
resize.imageContainerResize.placeClickBox();
imageBox.center();
}
};