crccheck / raphael-svg-import-classic

Import SVG files to Raphael
MIT License
98 stars 40 forks source link

No Style Attribute Parsing + Callback #14

Closed Liziel closed 10 years ago

Liziel commented 10 years ago

There's two modification i could suggest:

First: the style attribute isn't parsed as is has to be and the "xlink:href" (equal to src) attribute of an image is not added

Second: It could be good to add Callback in the goal of helping the user to set his own...set:) this is the generated diff':

9c9
< Raphael.fn.importSVG = function (svgXML) {

---
> Raphael.fn.importSVG = function (svgXML, ImportCallback) {
26c26,38
<         attr[elShape.attributes[i].name] = elShape.attributes[i].value;

---
>         switch (elShape.attributes[i].name) {
>           case "xlink:href" :
>             attr["src"] = elShape.attributes[i].value;
>             break;
>           case "style" :
>           for (var k = 0; k < elShape.attributes[i].value.split(';').length; k++) {
>             if (elShape.attributes[i].value.split(';')[k] !== "")
>               attr[elShape.attributes[i].value.split(';')[k].split(':')[0]] = elShape.attributes[i].value.split(';')[k].split(':')[1];
>             };
>             break;
>           default :
>           attr[elShape.attributes[i].name] = elShape.attributes[i].value;
>         }
154a167,173
> /**
> * CollioTV modif':
> *the callback can be called in the goal of making our own set
> **/
>     if (ImportCallback) shape = ImportCallback(shape, nodeID, attr)
> 
>     if (shape)          myNewSet.push(shape);
156d174
<     myNewSet.push(shape);
crccheck commented 10 years ago

thanks, good catch, and this is javascript... so callbacks everywherrrrreeeee.

Liziel commented 10 years ago

thanks^^ i'm pleased to be usefulll (and sorry for my english..i'm a french student!)