* @cfg {Number} errorTimeout default 3000
* @cfg {Number} minWidth default 300
* @cfg {Number} minHeight default 300
+ * @cfg {Number} outputMaxWidth default 1200
* @cfg {Array} buttons default ['rotateLeft', 'pictureBtn', 'rotateRight']
* @cfg {Boolean} isDocument (true|false) default false
* @cfg {String} url action url
cropData : false,
minWidth : 300,
minHeight : 300,
+ outputMaxWidth : 1200,
file : false,
exif : {},
baseRotate : 1,
setCanvasPosition : function()
{
- console.log("SET CANVAS POSITION");
if(!this.canvasEl){
return;
}
this.startScale = this.scale;
this.scale = (e.getWheelDelta() == 1) ? (this.scale + 1) : (this.scale - 1);
- console.log("START SCALE:" + this.startScale);
- console.log("TEST SCALE: " + this.scale);
if(!this.zoomable()){
this.scale = this.startScale;
return;
}
- console.log("END SCALE: " + this.scale);
this.draw();
if(this.minWidth < this.minHeight){
minScale = this.thumbEl.getHeight() / this.minHeight;
}
-
- console.log("MINSCALE: " + minScale);
var width = Math.ceil(this.imageEl.OriginWidth * this.getScaleLevel() / minScale);
var height = Math.ceil(this.imageEl.OriginHeight * this.getScaleLevel() / minScale);
- console.log("WIDTH: " + width);
- console.log("HEIGHT: " + height);
var maxWidth = this.imageEl.OriginWidth;
var maxHeight = this.imageEl.OriginHeight;
!this.isDocument &&
(this.rotate == 0 || this.rotate == 180) &&
(
- width < this.minWidth ||
- height < this.minHeight ||
+ (this.imageEl.OriginWidth >= this.minWidth) && width < this.minWidth ||
+ (this.imageEl.OriginHeight >= this.minHeight) && height < this.minHeight ||
width > maxWidth ||
height > maxHeight
)
draw : function()
{
- console.log("DRAW");
this.previewEl.dom.innerHTML = '';
var canvasEl = document.createElement("canvas");
var contextEl = canvasEl.getContext("2d");
-
- console.log(this.getScaleLevel());
canvasEl.width = this.imageEl.OriginWidth * this.getScaleLevel();
canvasEl.height = this.imageEl.OriginWidth * this.getScaleLevel();
var canvas = document.createElement("canvas");
var context = canvas.getContext("2d");
-
- canvas.width = this.minWidth;
- canvas.height = this.minHeight;
+
+ canvas.width = this.thumbEl.getWidth() / this.getScaleLevel();
+
+ canvas.height = this.thumbEl.getHeight() / this.getScaleLevel();
switch (this.rotate) {
case 0 :
var x = (this.thumbEl.getLeft(true) > this.previewEl.getLeft(true)) ? 0 : ((this.previewEl.getLeft(true) - this.thumbEl.getLeft(true)) / this.getScaleLevel());
var y = (this.thumbEl.getTop(true) > this.previewEl.getTop(true)) ? 0 : ((this.previewEl.getTop(true) - this.thumbEl.getTop(true)) / this.getScaleLevel());
- var targetWidth = this.minWidth - 2 * x;
- var targetHeight = this.minHeight - 2 * y;
-
- var scale = 1;
-
- if((x == 0 && y == 0) || (x == 0 && y > 0)){
- scale = targetWidth / width;
- }
-
- if(x > 0 && y == 0){
- scale = targetHeight / height;
- }
-
- if(x > 0 && y > 0){
- scale = targetWidth / width;
-
- if(width < height){
- scale = targetHeight / height;
- }
- }
-
- context.scale(scale, scale);
-
- var sx = Math.min(this.canvasEl.width - this.thumbEl.getWidth(), this.thumbEl.getLeft(true) - this.previewEl.getLeft(true));
- var sy = Math.min(this.canvasEl.height - this.thumbEl.getHeight(), this.thumbEl.getTop(true) - this.previewEl.getTop(true));
+ var sx = this.thumbEl.getLeft(true) - this.previewEl.getLeft(true);
+ var sy = this.thumbEl.getTop(true) - this.previewEl.getTop(true);
sx = sx < 0 ? 0 : (sx / this.getScaleLevel());
sy = sy < 0 ? 0 : (sy / this.getScaleLevel());
+ if(canvas.width > this.outputMaxWidth) {
+ var scale = this.outputMaxWidth / canvas.width;
+ canvas.width = canvas.width * scale;
+ canvas.height = canvas.height * scale;
+ context.scale(scale, scale);
+ }
+
context.drawImage(imageCanvas, sx, sy, width, height, x, y, width, height);
break;
baseScaleLevel : function()
{
- console.log("BASE SCALE LEVEL");
var width, height;
if(this.isDocument){
if(this.imageEl.OriginWidth < this.minWidth || this.imageEl.OriginHeight < this.minHeight) {
this.baseScale = width / this.minWidth;
}
- console.log(this.baseScale);
+
return;
},
var formData = new FormData();
- formData.append("onid", "43024");
- formData.append("ontable", "pressrelease_boilerplate");
-
formData.append('returnHTML', 'NO');
-
+
if(crop){
formData.append('crop', crop);
var blobBin = atob(crop.split(',')[1]);
for(var i = 0; i < blobBin.length; i++) {
array.push(blobBin.charCodeAt(i));
}
- var croppedFile =new Blob([new Uint8Array(array)], {type: 'image/png'});
+ var croppedFile =new Blob([new Uint8Array(array)], {type: this.cropType});
formData.append(this.paramName, croppedFile, file.name);
}
}
this.file = file;
- this.cropType = file.type;
+ if(typeof(file.type) != 'undefined') {
+ console.log("CROPTYPE");
+ console.log(this.cropType);
+ console.log("FILETYPE");
+ console.log(typeof(file.type));
+ console.log(this.file.type);
+ this.cropType = file.type;
+ }
var _this = this;