Commit 4a39b2b6 authored by bbaer's avatar bbaer
Browse files

fixed error with resizing and empty fabric json not displaying an image

parent 10629efb
...@@ -327,14 +327,15 @@ $(function (n) { ...@@ -327,14 +327,15 @@ $(function (n) {
console.log("prepareStaticCanvas"); console.log("prepareStaticCanvas");
this.generateStaticCanvas(width, height); this.generateStaticCanvas(width, height);
if (this.fabricJSON) { if (this.fabricJSON) {
console.log("getFabric");
this.canvas.loadFromJSON(this.fabricJSON); this.canvas.loadFromJSON(this.fabricJSON);
} else {
this.setBackground();
} }
this.resizeCanvas(); this.canvas.renderAll();
var that = this; var that = this;
setTimeout(function () { setTimeout(function () {
that.resizeCanvas();
that.canvas.renderAll(); that.canvas.renderAll();
}, 1000); }, 1000);
}; };
...@@ -348,6 +349,7 @@ $(function (n) { ...@@ -348,6 +349,7 @@ $(function (n) {
this.parentElement.append(canvas); this.parentElement.append(canvas);
this.canvas = this.__canvas = new fabric.StaticCanvas(canvas); this.canvas = this.__canvas = new fabric.StaticCanvas(canvas);
this.parentElement.on("click", function(e) { that.toggleObjects(); }); this.parentElement.on("click", function(e) { that.toggleObjects(); });
$(window).resize(function() { that.resizeCanvas(); });
}; };
n.Fabric.prototype.getMeta = function(url, callback) { n.Fabric.prototype.getMeta = function(url, callback) {
...@@ -431,11 +433,17 @@ $(function (n) { ...@@ -431,11 +433,17 @@ $(function (n) {
n.Fabric.prototype.resizeCanvas = function () { n.Fabric.prototype.resizeCanvas = function () {
console.log("resize canvas started"); console.log("resize canvas started");
var source = false;
var backgroundSizing = false; var backgroundSizing = false;
var oldWidth = this.canvas.getWidth(); var oldWidth = this.canvas.getWidth();
var backgroundImageWidth = 0; var backgroundImageWidth = 0;
if (this.canvas.backgroundImage) { if (this.canvas.backgroundImage) {
backgroundImageWidth = this.canvas.backgroundImage.width || 0; source = this.canvas;
} else {
source = this.fabricJSON;
}
if (source) {
backgroundImageWidth = source.backgroundImage.width;
} }
if (oldWidth !== backgroundImageWidth && backgroundImageWidth !== 0) { if (oldWidth !== backgroundImageWidth && backgroundImageWidth !== 0) {
oldWidth = backgroundImageWidth; oldWidth = backgroundImageWidth;
...@@ -446,13 +454,17 @@ $(function (n) { ...@@ -446,13 +454,17 @@ $(function (n) {
var scaleMultiplier = newWidth / oldWidth; var scaleMultiplier = newWidth / oldWidth;
var oldHeight; var oldHeight;
if (backgroundSizing) { if (backgroundSizing) {
oldHeight = this.canvas.backgroundImage.height || 0; if (source) {
oldHeight = source.backgroundImage.height;
}
} else { } else {
oldHeight = this.canvas.getHeight(); oldHeight = this.canvas.getHeight();
} }
this.canvas.setWidth(this.parentElement.innerWidth()); this.canvas.setWidth(newWidth);
this.canvas.setHeight(oldHeight * scaleMultiplier); this.canvas.setHeight(oldHeight * scaleMultiplier);
var objects = this.canvas.getObjects();
var objects = source.getObjects();
for (var i in objects) { for (var i in objects) {
objects[i].scaleX = objects[i].scaleX * scaleMultiplier; objects[i].scaleX = objects[i].scaleX * scaleMultiplier;
objects[i].scaleY = objects[i].scaleY * scaleMultiplier; objects[i].scaleY = objects[i].scaleY * scaleMultiplier;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment