I have created a page that draws various SVG elements using the raphaeljs library, but I\'m having some issues in Safari.
I am drawing images and using a clipping p
The following works for me in Safari 5.0.5, MacOSX 10.5 and mobile Safari on iPad. I'm using JQuery to parse the SVG XML out of a string and raphaelJS to do the heavy lifting on the SVG side of things. Clicks can be handled with the click() function from jQuery, or the mouse event handling in RaphaelJS.
// svg is a string that contains an SVG path for clipping
SVG_NS = "http://www.w3.org/2000/svg";
pth = $.parseXML(svg)
doc = $(pth)
// Find the actual element, this may not be the most efficient method
pthelm = null;
doc.children().each(function() {pthelm = this;});
// Duplicate into the document's DOM for webkit
npth = document.createElementNS(SVG_NS, pthelm.nodeName)
for (a in pthelm.attributes) {
attr = pthelm.attributes[a];
npth.setAttribute(attr.nodeName, attr.nodeValue);
}
pthelm = npth;
cpe = document.createElementNS(SVG_NS, 'clipPath')
cpe.setAttribute('id', 'svgclippath');
cpe.appendChild(pthelm);
paper.canvas.appendChild(cpe);
img = "http://example.org/path/to/your/image.jpg";
iw = 100; // Image Width
ih = 200; // Image Height
x = svgcanvas.image(img, 0, 0, iw, ih)
x.node.setAttribute('preserveAspectRatio', 'none')
x.node.setAttribute('clip-path', 'url(#svgclippath)')