Last active
December 10, 2015 21:28
-
-
Save kangax/4494811 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
loadFromJSON: function (json, callback) { | |
if (!json) return; | |
// serialize if it wasn't already | |
var serialized = (typeof json === 'string') | |
? JSON.parse(json) | |
: json; | |
if (!serialized || (serialized && !serialized.objects)) return; | |
this.clear(); | |
var _this = this; | |
this._enlivenObjects(serialized.objects, function () { | |
_this.backgroundColor = serialized.background; | |
var backgroundImageLoaded, overlayImageLoaded; | |
if (serialized.backgroundImage) { | |
_this.setBackgroundImage(serialized.backgroundImage, function() { | |
_this.backgroundImageOpacity = serialized.backgroundImageOpacity; | |
_this.backgroundImageStretch = serialized.backgroundImageStretch; | |
_this.renderAll(); | |
backgroundImageLoaded = true; | |
callback && overlayImageLoaded && callback(); | |
}); | |
} | |
else { | |
backgroundImageLoaded = true; | |
} | |
if (serialized.overlayImage) { | |
_this.setOverlayImage(serialized.overlayImage, function() { | |
_this.overlayImageLeft = serialized.overlayImageLeft || 0; | |
_this.overlayImageTop = serialized.overlayImageTop || 0; | |
_this.renderAll(); | |
overlayImageLoaded = true; | |
callback && backgroundImageLoaded && callback(); | |
}); | |
} | |
else { | |
overlayImageLoaded = true; | |
} | |
if (!serialized.backgroundImage && !serialized.overlayImage) { | |
callback && callback(); | |
} | |
}); | |
return this; | |
}, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment