- this question is not duplicated
- this question have nothing to do with ajax
I have developing a SCADA using fabric.js. When I load a serialized canvas from BD, I need to set two variables to false, to work with undo/redo in the canvas. There is an issue, and I don't know if is an unusual problem, or its problem of my code.
My code follows:
var canvas = this.__canvas = new fabric.Canvas('lienzo', {perPixelTargetFind:true});
//cargaBD is a flag to know when the canvas is loading objects
var cargaBD = true;
//Deshaciendo is a flag to know when i am doing undo/redo
var Deshaciendo = true;
//These vars are used to control object:added event for fabricjs
function finalizarCarga(){
canvas.renderAll.bind(canvas);
cargaBD = false;
Deshaciendo = false;
}
var json = '{"objects":[{"type":"rect","originX":"center","originY":"center","left":300,"top":150,"width":150,"height":150,"fill":"#29477F","overlayFill":null,"stroke":null,"strokeWidth":1,"strokeDashArray":null,"strokeLineCap":"butt","strokeLineJoin":"miter","strokeMiterLimit":10,"scaleX":1,"scaleY":1,"angle":0,"flipX":false,"flipY":false,"opacity":1,"shadow":{"color":"rgba(94, 128, 191, 0.5)","blur":5,"offsetX":10,"offsetY":10},"visible":true,"clipTo":null,"rx":0,"ry":0,"x":0,"y":0},{"type":"circle","originX":"center","originY":"center","left":300,"top":400,"width":200,"height":200,"fill":"rgb(166,111,213)","overlayFill":null,"stroke":null,"strokeWidth":1,"strokeDashArray":null,"strokeLineCap":"butt","strokeLineJoin":"miter","strokeMiterLimit":10,"scaleX":1,"scaleY":1,"angle":0,"flipX":false,"flipY":false,"opacity":1,"shadow":{"color":"#5b238A","blur":20,"offsetX":-20,"offsetY":-10},"visible":true,"clipTo":null,"radius":100}],"background":""}'
canvas.loadFromJSON(json, finalizarCarga);
console.log(cargaBD);
console.log(DeshaciendoBD);
<script src="http://cdnjs.cloudflare.com/ajax/libs/fabric.js/1.6.4/fabric.min.js"></script>
<canvas id="lienzo"></canvas>
The normal behavior is that a rectangle appears on screen because the function finalizarCarga
runs when the canvas is loaded from JSON.
But this does not occur. Is it problem of my code, or its problem of fabric.js?