User:Gerbrant/svg/fromImg.js

module("Gerbrant.svg.fromImg", new function {	this.svgs = [];

function resize(o) {		e = o.element; if(e.tagName == "IFRAME") {			try {				e.contentWindow.document.body.style.border = ""; }			catch(notreadyyet) {				window.setTimeout(function				{					resize(o)				}, 100); return; }			e = e.contentWindow.document.body.children[0]; }		var d = e.getSVGDocument, n;		if(d) {			try {				d = d.childNodes; if(d.length == 0) {					window.setTimeout(function					{						resize(o)					}, 100); return; }				o.svg = d;				for(j = 0; j < d.length; j++) {					n = d.item(j); if(n.tagName == "svg") {						if(!n.getAttribute("viewBox")) {							n.setAttribute("viewBox", "0 0 " +								n.getAttribute("width") + " " +								n.getAttribute("height")); n.setAttribute("width", "100%"); n.setAttribute("height", "100%"); }					}				}			}			catch(permissionDenied) {			}		}	};

this.embedFromImg = function(i) {		var m = i.src.match(/^(.*\/)thumb\/(.*\.svg)\/\d*px-(?:.*).svg.png$/); if(m != null) {			if(i.outerHTML == undefined) {				var e = document.createElement("embed"); e.width = i.width; e.height = i.height; e.src = "file:///d:/Mijn%20documenten/SVG/Kanji%20en%20kana%20-%20Nihongo%20desu.svg"; //e.src = i[1] + i[2]; var p = i.parentNode; p.insertBefore(e, i); p.removeChild(i); i = e;			} else {				i.outerHTML = ''; i = document.getElementById("gerbrant-svg-fromImg-newObj"); i.id = null; }			i = {element:i}; this.svgs.push(i); window.setTimeout(function			{				resize(i);			}, 100); }	} });