From d5ba4ec825c0c0c207b40546a3c545ce95e46235 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 22 Aug 2011 15:20:24 +0200 Subject: [PATCH] some improvements in automatic svg replacement --- core/js/js.js | 50 +++++++++++++++++++++++------------------ files/js/fileactions.js | 9 +++++--- 2 files changed, 34 insertions(+), 25 deletions(-) diff --git a/core/js/js.js b/core/js/js.js index ee84122769..770ce4ea69 100644 --- a/core/js/js.js +++ b/core/js/js.js @@ -180,8 +180,32 @@ if (!Array.prototype.indexOf){ * check if the browser support svg images */ function SVGSupport() { - return !!document.createElementNS && !!document.createElementNS('http://www.w3.org/2000/svg', "svg").createSVGRect; + return SVGSupport.checkMimeType.correct && !!document.createElementNS && !!document.createElementNS('http://www.w3.org/2000/svg', "svg").createSVGRect; } +SVGSupport.checkMimeType=function(){ + $.ajax({ + url: OC.imagePath('core','breadcrumb.svg'), + success:function(data,text,xhr){ + var headerParts=xhr.getAllResponseHeaders().split("\n"); + var headers={}; + $.each(headerParts,function(i,text){ + if(text){ + var parts=text.split(':',2); + var value=parts[1].trim(); + if(value[0]=='"'){ + value=value.substr(1,value.length-2); + } + headers[parts[0]]=value; + } + }); + if(headers["Content-Type"]!='image/svg+xml'){ + replaceSVG(); + SVGSupport.checkMimeType.correct=false + } + } + }); +} +SVGSupport.checkMimeType.correct=true; //replace all svg images with png for browser compatibility function replaceSVG(){ @@ -223,27 +247,9 @@ function object(o) { $(document).ready(function(){ if(!SVGSupport()){//replace all svg images with png images for browser that dont support svg replaceSVG(); - }; - $.ajax({ - url: OC.imagePath('core','breadcrumb.svg'), - success:function(data,text,xhr){ - var headerParts=xhr.getAllResponseHeaders().split("\n"); - var headers={}; - $.each(headerParts,function(i,text){ - if(text){ - var parts=text.split(':',2); - var value=parts[1].trim(); - if(value[0]=='"'){ - value=value.substr(1,value.length-2); - } - headers[parts[0]]=value; - } - }); - if(headers["Content-Type"]!='image/svg+xml'){ - replaceSVG(); - } - } - }); + }else{ + SVGSupport.checkMimeType(); + } $('form.searchbox').submit(function(event){ event.preventDefault(); }) diff --git a/files/js/fileactions.js b/files/js/fileactions.js index a0a04ff166..04943abf74 100644 --- a/files/js/fileactions.js +++ b/files/js/fileactions.js @@ -85,6 +85,9 @@ FileActions={ } if(actions['Delete']){ var img=FileActions.icons['Delete']; + if(img.call){ + img=img(file); + } var html=''; var element=$(html); if(img){ @@ -121,15 +124,15 @@ FileActions={ } } -FileActions.register('all','Download',OC.imagePath('core','actions/download'),function(filename){ +FileActions.register('all','Download',function(){return OC.imagePath('core','actions/download')},function(filename){ window.location='ajax/download.php?files='+filename+'&dir='+$('#dir').val(); }); -FileActions.register('all','Delete',OC.imagePath('core','actions/delete'),function(filename){ +FileActions.register('all','Delete',function(){return OC.imagePath('core','actions/delete')},function(filename){ FileList.delete(filename); }); -FileActions.register('all','Rename',OC.imagePath('core','actions/rename'),function(filename){ +FileActions.register('all','Rename',function(){return OC.imagePath('core','actions/rename')},function(filename){ FileList.rename(filename); });