jonathantneal/svg4everybody — pull request #8 by jkphl (2014-05-29 15:59:12+00:00)
Title: Added support for internal SVG references & non-alphanumeric fragment identifiers / IDs

Hi Jonathan,

I found (and patched) two issues:

1. The current usage of `x.querySelector()` will possibly fail when you have SVG fragment identifiers (IDs) containing non-alphanumeric characters (which is perfectly legal, e.g. `my~weird~id`). I implemented RegExp based escaping to enable these identifiers.

2. The script utterly failed with a "Syntax Error" when used inside a document that contains **internal SVG references** (e.g. in conjunction with an embedded inline SVG sprite):

```html

```

In these cases, the `url_root` is empty, which leads to an invalid XHR request. I implemented an alternative branch for internal references (using `getElementById()`) and created a common replacement method for both internal and external references (the `embed()` function).

I could test my modifications on Win 7 / IE 11 only, but I'm pretty sure they should work elsewhere as well. Also, the modifications would have to be applied to the IE6-8 and minified script versions, but I'd rather leave this up to you.

Cheers,
Joschi