roojs-core.js
[roojs1] / Roo / dialog / UploadCropbox.js
index e44a20f..7bc78e3 100644 (file)
@@ -13,6 +13,7 @@
  * @cfg {Number} minWidth default 300
  * @cfg {Number} minHeight default 300
  * @cfg {Number} outputMaxWidth default 1200
+ * @cfg {Number} windowSize default 300
  * @cfg {Array} buttons default ['rotateLeft', 'pictureBtn', 'rotateRight']
  * @cfg {Boolean} isDocument (true|false) default false
  * @cfg {String} url action url
@@ -151,6 +152,7 @@ Roo.extend(Roo.dialog.UploadCropbox, Roo.Component,  {
     minWidth : 300,
     minHeight : 300,
     outputMaxWidth : 1200,
+    windowSize : 300,
     file : false,
     exif : {},
     baseRotate : 1,
@@ -558,7 +560,7 @@ Roo.extend(Roo.dialog.UploadCropbox, Roo.Component,  {
         e.stopEvent();
         
         this.startScale = this.scale;
-        this.scale = (e.getWheelDelta() == 1) ? (this.scale + 1) : (this.scale - 1);
+        this.scale = (e.getWheelDelta() > 0) ? (this.scale + 1) : (this.scale - 1);
         
         if(!this.zoomable()){
             this.scale = this.startScale;
@@ -581,8 +583,7 @@ Roo.extend(Roo.dialog.UploadCropbox, Roo.Component,  {
         
         var width = Math.ceil(this.imageEl.OriginWidth * this.getScaleLevel() / minScale);
         var height = Math.ceil(this.imageEl.OriginHeight * this.getScaleLevel() / minScale);
-
-
         var maxWidth = this.imageEl.OriginWidth;
         var maxHeight = this.imageEl.OriginHeight;
         
@@ -614,8 +615,8 @@ Roo.extend(Roo.dialog.UploadCropbox, Roo.Component,  {
                 !this.isDocument &&
                 (this.rotate == 0 || this.rotate == 180) && 
                 (
-                    (this.imageEl.OriginWidth >= this.minWidth) && width < this.minWidth ||
-                    (this.imageEl.OriginHeight >= this.minHeight) && height < this.minHeight ||
+                    (this.imageEl.OriginWidth / this.imageEl.OriginHeight >= this.minWidth / this.minHeight) && width < this.minWidth ||
+                    (this.imageEl.OriginWidth / this.imageEl.OriginHeight <= this.minWidth / this.minHeight) && height < this.minHeight ||
                     width > maxWidth ||
                     height > maxHeight
                 )
@@ -893,6 +894,10 @@ Roo.extend(Roo.dialog.UploadCropbox, Roo.Component,  {
                     context.scale(scale, scale);
                 }
 
+                context.fillStyle = 'white';
+                context.fillRect(0, 0, this.thumbEl.getWidth() / this.getScaleLevel(), this.thumbEl.getHeight() / this.getScaleLevel());
+
+
                 context.drawImage(imageCanvas, sx, sy, width, height, x, y, width, height);
                 
                 break;
@@ -1053,11 +1058,11 @@ Roo.extend(Roo.dialog.UploadCropbox, Roo.Component,  {
             }
         }
         
-        height = 300;
+        height = this.windowSize;
         width = Math.ceil(this.minWidth * height / this.minHeight);
         
         if(this.minWidth > this.minHeight){
-            width = 300;
+            width = this.windowSize;
             height = Math.ceil(this.minHeight * width / this.minWidth);
         }
         
@@ -1307,13 +1312,6 @@ Roo.extend(Roo.dialog.UploadCropbox, Roo.Component,  {
         var formData = new FormData();
 
         formData.append('returnHTML', 'NO');
-        
-        var outputFileType = 'image/jpeg';
-
-        if(typeof(file.type) != 'undefined') {
-            console.log(file.type);
-            outputFileType = file.type;
-        }
 
         if(crop){
             formData.append('crop', crop);
@@ -1322,7 +1320,7 @@ Roo.extend(Roo.dialog.UploadCropbox, Roo.Component,  {
             for(var i = 0; i < blobBin.length; i++) {
                 array.push(blobBin.charCodeAt(i));
             }
-            var croppedFile =new Blob([new Uint8Array(array)], {type: outputFileType});
+            var croppedFile =new Blob([new Uint8Array(array)], {type: this.cropType});
             formData.append(this.paramName, croppedFile, file.name);
         }
         
@@ -1396,7 +1394,9 @@ Roo.extend(Roo.dialog.UploadCropbox, Roo.Component,  {
         }
         
         this.file = file;
-        this.cropType = file.type;
+        if(typeof(file.type) != 'undefined' && file.type.length != 0) {
+            this.cropType = file.type;
+        }
         
         var _this = this;