2007-09-15 03:08:25 +02:00
|
|
|
/**
|
|
|
|
* @author Mateusz
|
2007-09-16 03:30:43 +02:00
|
|
|
*/
|
2007-10-03 01:26:35 +02:00
|
|
|
ImageEditor.Resize = {
|
2007-09-15 03:08:25 +02:00
|
|
|
|
|
|
|
initialize: function(element) {
|
|
|
|
this.element = element;
|
2007-09-16 04:24:11 +02:00
|
|
|
this.leftBoxConstraint = 1;
|
2007-09-16 04:23:10 +02:00
|
|
|
this.topBoxConstraint = 0;
|
2007-10-03 01:26:35 +02:00
|
|
|
this.getRelativeMousePos = ImageEditor.Resize.getRelativeMousePos.bind(this);
|
|
|
|
var options = {
|
|
|
|
resizeStop: ImageEditor.Resize.resizeStop.bind(this),
|
|
|
|
onDrag: ImageEditor.Resize.onDrag.bind(this),
|
|
|
|
onResize: ImageEditor.Resize.onResize.bind(this),
|
|
|
|
getMousePos: ImageEditor.Resize.getMousePos.bind(this)
|
2007-09-15 03:08:25 +02:00
|
|
|
};
|
2007-10-03 01:26:35 +02:00
|
|
|
new ImageEditor.Positioning.addBehaviour(this.element);
|
|
|
|
this.imageContainerResize = new ImageEditor.Resizeable.initialize(element,options);
|
2007-09-15 03:26:36 +02:00
|
|
|
this.imageContainerResize.setVisible(false);
|
2007-09-15 03:08:25 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
resizeStop: function(event) {
|
2007-10-03 01:26:35 +02:00
|
|
|
if(ImageEditor.EventStack.getLastEventElement() != null) {
|
|
|
|
var imageElement = $('image');
|
|
|
|
ImageEditor.EventStack.clearStack();
|
2007-09-15 22:54:37 +02:00
|
|
|
if(this.imageContainerResize.isEnabled) {
|
|
|
|
if(this.imageContainerResize.originalWidth != imageElement.width || this.imageContainerResize.originalHeight != imageElement.height) {
|
2007-09-16 02:49:34 +02:00
|
|
|
$('imageContainer').style.backgroundImage = 'url("")';
|
2007-10-03 01:26:35 +02:00
|
|
|
ImageEditor.imageTransformation.resize(imageElement.width,imageElement.height,ImageEditor.Resize.resizeCallback.bind(this));
|
|
|
|
ImageEditor.effects.disableRotate();
|
|
|
|
ImageEditor.crop.disable();
|
2007-09-15 22:54:37 +02:00
|
|
|
this.imageContainerResize.disable();
|
2007-10-03 01:26:35 +02:00
|
|
|
ImageEditor.imageHistory.disable();
|
2007-09-15 22:54:37 +02:00
|
|
|
}
|
|
|
|
}
|
2007-09-15 03:31:31 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
resizeCallback: function() {
|
2007-09-16 02:49:34 +02:00
|
|
|
$('imageContainer').style.backgroundImage = 'url("' + $('image').src + '")';
|
2007-09-15 03:08:25 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
onDrag: function()
|
|
|
|
{
|
|
|
|
if(this.element.getTop() < this.topBoxConstraint) this.element.style.top = this.topBoxConstraint + "px";
|
|
|
|
if(this.element.getLeft() < this.leftBoxConstraint) this.element.style.left = this.leftBoxConstraint + "px";
|
2007-10-03 01:26:35 +02:00
|
|
|
ImageEditor.imageBox.reCenterIndicator();
|
2007-09-15 03:08:25 +02:00
|
|
|
},
|
|
|
|
|
2007-09-15 03:19:43 +02:00
|
|
|
onResize: function(width,height) {
|
|
|
|
$('image').style.width = width + "px";
|
|
|
|
$('image').style.height = height + "px";
|
2007-09-15 03:08:25 +02:00
|
|
|
},
|
|
|
|
getMousePos: function(event) {
|
2007-10-03 01:26:35 +02:00
|
|
|
var relativeMouseX = this.getRelativeMousePos(event).x;
|
|
|
|
var relativeMouseY = this.getRelativeMousePos(event).y;
|
2007-09-15 03:08:25 +02:00
|
|
|
if(relativeMouseX <= this.leftBoxConstraint) x = this.leftBoxConstraint + this.element.getParentLeft(); else x = relativeMouseX + this.element.getParentLeft();
|
|
|
|
if(relativeMouseY <= this.topBoxConstraint) y = this.topBoxConstraint + this.element.getParentTop(); else y = relativeMouseY + this.element.getParentTop();
|
|
|
|
return {x: x,y: y};
|
|
|
|
},
|
|
|
|
|
|
|
|
getRelativeMousePos: function(event) {
|
2007-10-03 01:26:35 +02:00
|
|
|
var relativeMouseX = Event.pointerX(event) + $('imageEditorContainer').scrollLeft - this.element.getParentLeft();
|
|
|
|
var relativeMouseY = Event.pointerY(event) + $('imageEditorContainer').scrollTop - this.element.getParentTop();
|
2007-09-16 03:30:43 +02:00
|
|
|
return {x: relativeMouseX,y: relativeMouseY};
|
2007-09-15 03:08:25 +02:00
|
|
|
}
|
|
|
|
}
|