kbwood / svg

jQuery SVG plugin
http://keith-wood.name/svg.html
168 stars 65 forks source link

Rewritting links within included svg files that are not in current directory. #4

Closed twitwi closed 11 years ago

twitwi commented 12 years ago

Hi Keith,

(I'm Rémi, and sent you a mail recently, about the download button on your page, but this is unrelated)

Here is the motivation of the pull request.

When I have an html page and use jquery to load an svg in a subfolder, the svg is loaded as expected. However, if the svg file contained relative links inside (link to images or hyperlinks), these become wrong. More exactly, they change meaning: the paths were expressed relative to the SVG file but they are now within the html page and thus represent things relative to the html page.

I made a patch to jquery svg to rewrite these relative links. The pull request contains this, together with adding some information to the onLoad callbacks: the width and the height of the svg element (before it gets lost by the embedding into html).

I have also a branch "test-patches"¹ that provides some html and svg files to illustrate the patches.

Cheers, Rémi

¹: https://github.com/twitwi/svg/tree/test-patches

twitwi commented 12 years ago

quick note: I updated just the non minified version

kbwood commented 11 years ago

I'll add the changes for the relative links in the next release.

I'll expose the existing width and height functions to retrieve the SVG dimensions.