Skip to content
This repository

Fix `loadFromJSON` for `fabric.Image` objects without image filters #800

Merged
merged 1 commit into from 11 months ago

2 participants

Stefan Kienzle Juriy Zaytsev
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Aug 21, 2013
Stefan Kienzle Kienz Fix loadFromJSON for image objects without image filters 55d5d99
This page is out of date. Refresh to see the latest.

Showing 2 changed files with 10 additions and 5 deletions. Show diff stats Hide diff stats

  1. +5 3 src/node.js
  2. +5 2 src/shapes/image.class.js
8 src/node.js
@@ -106,7 +106,7 @@
106 106 fabric.loadSVGFromString = function(string, callback, reviver) {
107 107 var doc = new DOMParser().parseFromString(string);
108 108 fabric.parseSVGDocument(doc.documentElement, function(results, options) {
109   - callback(results, options);
  109 + callback && callback(results, options);
110 110 }, reviver);
111 111 };
112 112
@@ -122,8 +122,10 @@
122 122 var oImg = new fabric.Image(img);
123 123
124 124 oImg._initConfig(object);
125   - oImg._initFilters(object);
126   - callback(oImg);
  125 + oImg._initFilters(object, function(filters) {
  126 + oImg.filters = filters || [ ];
  127 + callback && callback(oImg);
  128 + });
127 129 });
128 130 };
129 131
7 src/shapes/image.class.js
@@ -364,9 +364,12 @@
364 364 _initFilters: function(object, callback) {
365 365 if (object.filters && object.filters.length) {
366 366 fabric.util.enlivenObjects(object.filters, function(enlivenedObjects) {
367   - callback(enlivenedObjects);
  367 + callback && callback(enlivenedObjects);
368 368 }, 'fabric.Image.filters');
369 369 }
  370 + else {
  371 + callback && callback();
  372 + }
370 373 },
371 374
372 375 /**
@@ -419,7 +422,7 @@
419 422 /** @ignore */
420 423 img.onload = function() {
421 424 fabric.Image.prototype._initFilters.call(object, object, function(filters) {
422   - object.filters = filters;
  425 + object.filters = filters || [ ];
423 426
424 427 var instance = new fabric.Image(img, object);
425 428 callback && callback(instance);

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.