diff --git a/src/gradient.class.js b/src/gradient.class.js index d601fe02..1f7c8a8a 100644 --- a/src/gradient.class.js +++ b/src/gradient.class.js @@ -3,7 +3,7 @@ /* _FROM_SVG_START_ */ function getColorStop(el) { var style = el.getAttribute('style'), - offset = el.getAttribute('offset'), + offset = el.getAttribute('offset') || 0, color, colorAlpha, opacity; // convert percents to absolute values diff --git a/test/unit/gradient.js b/test/unit/gradient.js index bbf525d7..cdf4cf9c 100644 --- a/test/unit/gradient.js +++ b/test/unit/gradient.js @@ -177,6 +177,31 @@ equal(gradient.colorStops[0].opacity, 0); }); + test('fromElement without stop', function() { + ok(typeof fabric.Gradient.fromElement == 'function'); + + var element = fabric.document.createElement('linearGradient'); + var stop1 = fabric.document.createElement('stop'); + var stop2 = fabric.document.createElement('stop'); + + stop1.setAttribute('stop-color', 'white'); + + stop2.setAttribute('offset', '100%'); + stop2.setAttribute('stop-color', 'black'); + stop2.setAttribute('stop-opacity', '0'); + + element.appendChild(stop1); + element.appendChild(stop2); + + var object = new fabric.Object({ width: 100, height: 100 }); + var gradient = fabric.Gradient.fromElement(element, object); + + ok(gradient instanceof fabric.Gradient); + + equal(gradient.colorStops[0].offset, 1); + equal(gradient.colorStops[1].offset, 0); + }); + test('fromElement radialGradient', function() { ok(typeof fabric.Gradient.fromElement == 'function');