jquery selectors and svgns

154 visualizações
Pular para a primeira mensagem não lida

AK

não lida,
12 de abr. de 2012, 20:25:2012/04/2012
para SVG Web
I'm creating svg which is downloaded via cross domain request.

Here is a snippet

//parse svg dom from string
var svg_dom = $.xmlDOM(response.data).children();

//create svg element
var s = document.createElementNS(svgns, 'svg');
s.setAttribute('width', svg_dom.attr('width'));
s.setAttribute('height', svg_dom.attr('height'));

//copy parsed dom to svg element
function copyTree(jt, st){
jt.children().each(function(){
var tag_name = this.tagName;
var e = document.createElementNS(svgns, tag_name);
$.each(this.attributes, function(k, a) {
if (a.nodeName == 'class') {
...
} else e.setAttribute(a.nodeName, a.nodeValue);
});
copyTree($(this), e);
st.appendChild(e);
if ($(this).text() !== undefined && $(this).text().length > 0 &&
$(this).children().length === 0) {
var text = document.createTextNode($(this).text(), true);
e.appendChild(text);
}
});
}
copyTree(svg_dom, s);

//init onload
window.addEventListener('SVGLoad', function() {
init();
}, false)
//append svg element
svgweb.appendChild(s, document.getElementById(svg_id));



But on IE8 (probably IE7 as well) jquery selectors do not work on s.
I understand that the reason is that jQuery uses getElementsByTagName
instead of getElementsByTagNameNS

Do anybody knows the workaround for the issue.
Probably someone has redefined $.find to work with namespaces, and
could share his experience?

Thanks
Responder a todos
Responder ao autor
Encaminhar
0 nova mensagem