also replace svg images with png when the server doesn't send the correct mimetype for svg images

(which breaks svg images for most browsers)
This commit is contained in:
Robin Appelman 2011-08-22 14:53:52 +02:00
parent af3080402b
commit 13b7cb59eb
1 changed files with 45 additions and 20 deletions

View File

@ -183,6 +183,31 @@ function SVGSupport() {
return !!document.createElementNS && !!document.createElementNS('http://www.w3.org/2000/svg', "svg").createSVGRect; return !!document.createElementNS && !!document.createElementNS('http://www.w3.org/2000/svg', "svg").createSVGRect;
} }
//replace all svg images with png for browser compatibility
function replaceSVG(){
$('img.svg').each(function(index,element){
element=$(element);
var src=element.attr('src');
element.attr('src',src.substr(0,src.length-3)+'png');
});
$('.svg').each(function(index,element){
element=$(element);
var background=element.css('background-image');
if(background && background!='none'){
background=background.substr(0,background.length-4)+'png)';
element.css('background-image',background);
}
element.find('*').each(function(index,element) {
element=$(element);
var background=element.css('background-image');
if(background && background!='none'){
background=background.substr(0,background.length-4)+'png)';
element.css('background-image',background);
}
});
});
}
/** /**
* prototypal inharitence functions * prototypal inharitence functions
* *
@ -197,28 +222,28 @@ function object(o) {
$(document).ready(function(){ $(document).ready(function(){
if(!SVGSupport()){//replace all svg images with png images for browser that dont support svg if(!SVGSupport()){//replace all svg images with png images for browser that dont support svg
$('img.svg').each(function(index,element){ replaceSVG();
element=$(element); };
var src=element.attr('src'); $.ajax({
element.attr('src',src.substr(0,src.length-3)+'png'); url: OC.imagePath('core','breadcrumb.svg'),
}); success:function(data,text,xhr){
$('.svg').each(function(index,element){ var headerParts=xhr.getAllResponseHeaders().split("\n");
element=$(element); var headers={};
var background=element.css('background-image'); $.each(headerParts,function(i,text){
if(background && background!='none'){ if(text){
background=background.substr(0,background.length-4)+'png)'; var parts=text.split(':',2);
element.css('background-image',background); var value=parts[1].trim();
} if(value[0]=='"'){
element.find('*').each(function(index,element) { value=value.substr(1,value.length-2);
element=$(element); }
var background=element.css('background-image'); headers[parts[0]]=value;
if(background && background!='none'){
background=background.substr(0,background.length-4)+'png)';
element.css('background-image',background);
} }
}); });
}); if(headers["Content-Type"]!='image/svg+xml'){
}; replaceSVG();
}
}
});
$('form.searchbox').submit(function(event){ $('form.searchbox').submit(function(event){
event.preventDefault(); event.preventDefault();
}) })