Raphael JS - Thinking of SVG on the fly

I found a neat SVG parser at http://bkp.ee/atirip/ that parses an SVG file and outputs it to javascript that uses the Raphael JS library (raphaeljs.com). You can notice in the source code http://bkp.ee/atirip/svg2rdemo.php :

<script> jQuery(document).ready( function() { $("#c1").each(function(){ var c = Raphael(this, 190, 154, 0, 0); var g1 = c.set(); ... 

it creates variables like g1, g2, etc. But he also reuses these variables. I would like to create unique variables for each group. In my .ai file, I named my groups, and I would like to use these names to create variable names.

Where in http://bkp.ee/atirip/f/svgToRaphaelParser.php.zip should I see how to change this?

+4
source share
1 answer

I made some adjustments and squeezed one error. You can download the new version.

Now you can call the parser as follows:

 svgToRaphaelParser::parse(filename, containername, canvasname, groupname, shapename) 

Without shapename, it works as if: svgToRaphaelParser::parse("f.svg", "this", "c", "g") creates code that you already know.

To avoid reusing the same names, use different canvas names and / or groups for different SVG files.

As a new feature, if you need access to various forms, use it as follows:

 svgToRaphaelParser::parse("f.svg", "this", "c", "g", "s") 

Without shapename, you get the following:

 g1.push(c.path(...)); 

With shapename you get it

 var s1 = c.path(...); g1.push(s1); 
+2
source

Source: https://habr.com/ru/post/1310055/


All Articles