User:TheDJ/svg.js
From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. In Internet Explorer and Firefox, hold down the Ctrl key and click the Refresh or Reload button. Opera users have to clear their caches through Tools→Preferences, see the instructions for Opera. Konqueror and Safari users can just click the Reload button.
// Clientside SVG-rendering // Works for Safari 3.1 // Based on [[:de:Benutzer:ThePeritus/monobook.js]] // Firefox and Opera only allow you to view SVGs in either a window of there own, // or in an iframe/embed/object. Unfortunately, you cannot get the SVG to draw // in a "thumbed" size with that method it seems. Some JS used to work to fix this // for FF, but this no longer seems to work. function simpleReplaceSVGs() { var potimgs = document.getElementsByTagName("img"); var imgs = Array(); document.svgs = Array(); for(var j = 0; j<potimgs.length; j++) { imgs[imgs.length] = potimgs[j]; // HTMLCollection != Array of IMGObject's } while(imgs.length > 0) { var i = imgs.shift(); var split = i.src.split("/"); if(i.src.substr(0, 28) == 'http://upload.wikimedia.org/' && split[5] == 'thumb' // assuming there are no non-thumb .svgs && split[8].split(".")[1] == 'svg' ) { var svgsrc = "http://upload.wikimedia.org/wikipedia/".concat( split[4], "/", split[6], "/", split[7], "/", split[8] ); i.src = svgsrc; globeregex = /Erioll[ _]world.svg/ if( globeregex.test( split[8]) ) { i.width = "18"; i.height = "18"; } } } } addOnloadHook( function() { if( is_khtml || is_safari ) simpleReplaceSVGs(); });

