I found the solution. I edited part of code above:
if(Raphael.vml) { // SVG not supported (IE7 & IE8) and it doesn't work :/
var html = $(path.node).html();
html = html.replace(/rvml:/g, ''); // remove prefix
html = html.replace(/ = /g, '=');
html = html.substr(html.indexOf('/>') + 2); // remove xml element
var src = '';
$(html).each(function() {
if($(this).prop("tagName") == 'FILL') {
src = $(this).attr('src');
}
});
if(src != '') {
var html = $(path.node).html();
html = html.replace(src, src + '" size="50,50');
$(path.node).html(html);
}
}
else { // SVG supported and it prints correct URL
console.log($(pattern).find('image').attr('href'));
}
First of all $(path.node).html()
returns XML... So you need to parse it.
Another problem is that $.parseXML
doesn't work for this XML... (IE7 and IE8) So I had to somehow parse it for myself (it's just quick solution - I'm sure you can parse it much better for production).
Last thing is that $(html)
returns array of 6 elements (not 3!) because for some reason it treats closing tags separately. That's why I'm looping through $(html)
set of elements and I'm searching for fill tag.
Biggest problem of this approach is that my solution is read only. You can't change source of the image and easily save it back... You cant easily change its size as well. You will have to change it in XML and save it back to path element, as it's on the end of example.