Update elements_parser.js

Changed Resolvegradient function for fill and stroke
This commit is contained in:
Andrea Bogazzi 2014-08-16 08:11:50 +02:00
parent 145bf6e461
commit 77911424ce

View file

@ -43,7 +43,8 @@ fabric.ElementsParser.prototype._createObject = function(klass, el, index) {
}
else {
var obj = klass.fromElement(el, this.options);
this.resolveGradient(obj);
this.resolveGradient(obj,'fill');
this.resolveGradient(obj,'stroke');
this.reviver && this.reviver(el, obj);
this.instances[index] = obj;
this.checkIfDone();
@ -53,22 +54,23 @@ fabric.ElementsParser.prototype._createObject = function(klass, el, index) {
fabric.ElementsParser.prototype.createCallback = function(index, el) {
var _this = this;
return function(obj) {
_this.resolveGradient(obj);
_this.resolveGradient(obj,'fill');
_this.resolveGradient(obj,'stroke');
_this.reviver && _this.reviver(el, obj);
_this.instances[index] = obj;
_this.checkIfDone();
};
};
fabric.ElementsParser.prototype.resolveGradient = function(obj) {
fabric.ElementsParser.prototype.resolveGradient = function(obj,property) {
var instanceFillValue = obj.get('fill');
var instanceFillValue = obj.get(property);
if (!(/^url\(/).test(instanceFillValue)) {
return;
}
var gradientId = instanceFillValue.slice(5, instanceFillValue.length - 1);
if (fabric.gradientDefs[gradientId]) {
obj.set('fill',
obj.set(property,
fabric.Gradient.fromElement(fabric.gradientDefs[gradientId], obj));
}
};