mirror of
https://github.com/Hopiu/fabric.js.git
synced 2026-05-12 07:43:11 +00:00
Merge pull request #1595 from asturur/Load-Gradient-before-reviver
Load gradient before reviver
This commit is contained in:
commit
2cc901f2f7
2 changed files with 15 additions and 22 deletions
|
|
@ -43,6 +43,7 @@ fabric.ElementsParser.prototype._createObject = function(klass, el, index) {
|
|||
}
|
||||
else {
|
||||
var obj = klass.fromElement(el, this.options);
|
||||
this.resolveGradient(obj);
|
||||
this.reviver && this.reviver(el, obj);
|
||||
this.instances[index] = obj;
|
||||
this.checkIfDone();
|
||||
|
|
@ -52,18 +53,31 @@ 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.reviver && _this.reviver(el, obj);
|
||||
_this.instances[index] = obj;
|
||||
_this.checkIfDone();
|
||||
};
|
||||
};
|
||||
|
||||
fabric.ElementsParser.prototype.resolveGradient = function(obj) {
|
||||
|
||||
var instanceFillValue = obj.get('fill');
|
||||
if (!(/^url\(/).test(instanceFillValue)) {
|
||||
return;
|
||||
}
|
||||
var gradientId = instanceFillValue.slice(5, instanceFillValue.length - 1);
|
||||
if (fabric.gradientDefs[gradientId]) {
|
||||
obj.set('fill',
|
||||
fabric.Gradient.fromElement(fabric.gradientDefs[gradientId], obj));
|
||||
}
|
||||
};
|
||||
|
||||
fabric.ElementsParser.prototype.checkIfDone = function() {
|
||||
if (--this.numElements === 0) {
|
||||
this.instances = this.instances.filter(function(el) {
|
||||
return el != null;
|
||||
});
|
||||
fabric.resolveGradients(this.instances);
|
||||
this.callback(this.instances);
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -632,27 +632,6 @@
|
|||
|
||||
extend(fabric, {
|
||||
|
||||
/**
|
||||
* Initializes gradients on instances, according to gradients parsed from a document
|
||||
* @param {Array} instances
|
||||
*/
|
||||
resolveGradients: function(instances) {
|
||||
for (var i = instances.length; i--; ) {
|
||||
var instanceFillValue = instances[i].get('fill');
|
||||
|
||||
if (!(/^url\(/).test(instanceFillValue)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
var gradientId = instanceFillValue.slice(5, instanceFillValue.length - 1);
|
||||
|
||||
if (fabric.gradientDefs[gradientId]) {
|
||||
instances[i].set('fill',
|
||||
fabric.Gradient.fromElement(fabric.gradientDefs[gradientId], instances[i]));
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Parses an SVG document, returning all of the gradient declarations found in it
|
||||
* @static
|
||||
|
|
|
|||
Loading…
Reference in a new issue