Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ignore svg namespace #3081

Merged
merged 3 commits into from
Jul 3, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 28 additions & 18 deletions dist/fabric.js
Original file line number Diff line number Diff line change
Expand Up @@ -3086,6 +3086,19 @@ if (typeof console !== 'undefined') {
return attributes;
}

/**
* @private
*/
function _getMultipleNodes(doc, nodeNames) {
var nodeName, nodeArray = [ ], nodeList;
for (var i = 0; i < nodeNames.length; i++) {
nodeName = nodeNames[i];
nodeList = doc.getElementsByTagName(nodeName);
nodeArray = nodeArray.concat(Array.prototype.slice.call(nodeList));
}
return nodeArray;
}

/**
* Parses "transform" attribute, returning an array of values
* @static
Expand Down Expand Up @@ -3365,7 +3378,8 @@ if (typeof console !== 'undefined') {
* @private
*/
function parseUseDirectives(doc) {
var nodelist = doc.getElementsByTagName('use'), i = 0;
var nodelist = _getMultipleNodes(doc, ['use', 'svg:use']), i = 0;

while (nodelist.length && i < nodelist.length) {
var el = nodelist[i],
xlink = el.getAttribute('xlink:href').substr(1),
Expand Down Expand Up @@ -3441,7 +3455,7 @@ if (typeof console !== 'undefined') {
x = element.getAttribute('x') || 0,
y = element.getAttribute('y') || 0,
preserveAspectRatio = element.getAttribute('preserveAspectRatio') || '',
missingViewBox = (!viewBoxAttr || !reViewBoxTagNames.test(element.tagName)
missingViewBox = (!viewBoxAttr || !reViewBoxTagNames.test(element.nodeName)
|| !(viewBoxAttr = viewBoxAttr.match(reViewBoxAttrValue))),
missingDimAttr = (!widthAttr || !heightAttr || widthAttr === '100%' || heightAttr === '100%'),
toBeParsed = missingViewBox && missingDimAttr,
Expand Down Expand Up @@ -3499,7 +3513,7 @@ if (typeof console !== 'undefined') {
(minX * scaleX) + ' ' +
(minY * scaleY) + ') ';

if (element.tagName === 'svg') {
if (element.nodeName === 'svg') {
el = element.ownerDocument.createElement('g');
while (element.firstChild != null) {
el.appendChild(element.firstChild);
Expand Down Expand Up @@ -3528,7 +3542,7 @@ if (typeof console !== 'undefined') {

function hasAncestorWithNodeName(element, nodeName) {
while (element && (element = element.parentNode)) {
if (nodeName.test(element.nodeName) && !element.getAttribute('instantiated_by_use')) {
if (element.nodeName && nodeName.test(element.nodeName.replace('svg:', '')) && !element.getAttribute('instantiated_by_use')) {
return true;
}
}
Expand Down Expand Up @@ -3562,7 +3576,7 @@ if (typeof console !== 'undefined') {

var elements = descendants.filter(function(el) {
applyViewboxTransform(el);
return reAllowedSVGTagNames.test(el.tagName) &&
return reAllowedSVGTagNames.test(el.nodeName.replace('svg:', '')) &&
!hasAncestorWithNodeName(el, reNotAllowedAncestors); // http://www.w3.org/TR/SVG/struct.html#DefsElement
});

Expand Down Expand Up @@ -3695,20 +3709,16 @@ if (typeof console !== 'undefined') {
* @return {Object} Gradient definitions; key corresponds to element id, value -- to gradient definition element
*/
getGradientDefs: function(doc) {
var linearGradientEls = doc.getElementsByTagName('linearGradient'),
radialGradientEls = doc.getElementsByTagName('radialGradient'),
el, i, j = 0, id, xlink, elList = [ ],
var tagArray = [
'linearGradient',
'radialGradient',
'svg:linearGradient',
'svg:radialGradient'],
elList = _getMultipleNodes(doc, tagArray),
el, j = 0, id, xlink,
gradientDefs = { }, idsToXlinkMap = { };

elList.length = linearGradientEls.length + radialGradientEls.length;
i = linearGradientEls.length;
while (i--) {
elList[j++] = linearGradientEls[i];
}
i = radialGradientEls.length;
while (i--) {
elList[j++] = radialGradientEls[i];
}
j = elList.length;

while (j--) {
el = elList[j];
Expand Down Expand Up @@ -4087,7 +4097,7 @@ fabric.ElementsParser.prototype.createObjects = function() {
};

fabric.ElementsParser.prototype.createObject = function(el, index) {
var klass = fabric[fabric.util.string.capitalize(el.tagName)];
var klass = fabric[fabric.util.string.capitalize(el.tagName.replace('svg:', ''))];
if (klass && klass.fromElement) {
try {
this._createObject(klass, el, index);
Expand Down
20 changes: 8 additions & 12 deletions dist/fabric.min.js

Large diffs are not rendered by default.

Binary file modified dist/fabric.min.js.gz
Binary file not shown.
Loading