MediaWiki:Common.js/file.js: Difference between revisions

From Official Kodi Wiki
Jump to navigation Jump to search
(prioritize changes.)
(condense use function, but text and sizes unchanged.)
Line 2: Line 2:
// SVG images: adds links to rendered PNG images in different resolutions
// SVG images: adds links to rendered PNG images in different resolutions
function SVGThumbs() {
function SVGThumbs() {
      if (wgAction == "view" && wgTitle.substring(wgTitle.lastIndexOf(".")).toLowerCase() == ".svg") {  
var file = document.getElementById("file"); // might fail if MediaWiki can't render the SVG
      var file = document.getElementById("file");
if (file && wgAction == "view" && wgTitle.substring(wgTitle.lastIndexOf(".")).toLowerCase() == ".svg") {
      if (!file) return;  // might happen if MediaWiki can't render the SVG
function svgAltSize( w, h, title) {
      var div = document.createElement("p");
var a = document.createElement("A");
      div.appendChild(document.createTextNode("This image rendered as PNG in some sizes"+": "));
a.setAttribute("href", wgServer + wgScriptPath + "/thumb.php?f=" + encodeURIComponent(wgTitle) + "&width="+w+"px&height="+h+"px");
      var a200 = document.createElement("a");
a.appendChild(document.createTextNode(title));
      a200.setAttribute("href", wgServer + wgScriptPath + "/thumb.php?f=" + encodeURIComponent(wgTitle) + "&width=200px&height=200px");
return a;
      a200.appendChild(document.createTextNode("200px"));
}
      var a500 = document.createElement("a");
var p = document.createElement("p");
      a500.setAttribute("href",  wgServer + wgScriptPath + "/thumb.php?f=" + encodeURIComponent(wgTitle) + "&width=500px&height=500px");
p.className = "SVGThumbs";
      a500.appendChild(document.createTextNode("500px"));
p.appendChild(document.createTextNode("This image rendered as PNG in some sizes"+": "));
      var a1000 = document.createElement("a");
p.appendChild(svgAltSize(200,200,"200px"));
      a1000.setAttribute("href", wgServer + wgScriptPath + "/thumb.php?f=" + encodeURIComponent(wgTitle) + "&width=1000px&height=1000px");
p.appendChild(document.createTextNode(", "));
      a1000.appendChild(document.createTextNode("1000px"));
p.appendChild(svgAltSize(500,500,"500px"));
      var a2000 = document.createElement("a");
p.appendChild(document.createTextNode(", "));
      a2000.setAttribute("href", wgServer + wgScriptPath + "/thumb.php?f=" + encodeURIComponent(wgTitle) + "&width=2000px&height=2000px");
p.appendChild(svgAltSize(1000,1000,"1000px"));
      a2000.appendChild(document.createTextNode("2000px"));
p.appendChild(document.createTextNode(", "));
      div.appendChild(a200);
p.appendChild(svgAltSize(2000,2000,"2000px"));
      div.appendChild(document.createTextNode(", "));
p.appendChild(document.createTextNode("."));
      div.appendChild(a500);
var info = getElementsByClassName( file.parentNode, 'div', 'fullMedia' )[0];
      div.appendChild(document.createTextNode(", "));
if( info ) info.appendChild(p);
      div.appendChild(a1000);
}
      div.appendChild(document.createTextNode(", "));
      div.appendChild(a2000);
      div.appendChild(document.createTextNode("."));
      var info = getElementsByClassName( file.parentNode, 'div', 'fullMedia' )[0];
      if( info ) info.appendChild(div);
  }
};
};
addOnloadHook( SVGThumbs )
addOnloadHook( SVGThumbs )
/* </nowiki></source> */
/* </nowiki></source> */

Revision as of 21:35, 25 November 2009

/* <source lang="javascript"><nowiki> */
// SVG images: adds links to rendered PNG images in different resolutions
function SVGThumbs() {
	var file = document.getElementById("file"); // might fail if MediaWiki can't render the SVG
	if (file && wgAction == "view" && wgTitle.substring(wgTitle.lastIndexOf(".")).toLowerCase() == ".svg") {	
		function svgAltSize( w, h, title) {
			var a = document.createElement("A");
			a.setAttribute("href", wgServer + wgScriptPath + "/thumb.php?f=" + encodeURIComponent(wgTitle) + "&width="+w+"px&height="+h+"px");
			a.appendChild(document.createTextNode(title));
			return a;
		}
		var p = document.createElement("p");
		p.className = "SVGThumbs";
		p.appendChild(document.createTextNode("This image rendered as PNG in some sizes"+": "));
		p.appendChild(svgAltSize(200,200,"200px"));
		p.appendChild(document.createTextNode(", "));
		p.appendChild(svgAltSize(500,500,"500px"));
		p.appendChild(document.createTextNode(", "));
		p.appendChild(svgAltSize(1000,1000,"1000px"));
		p.appendChild(document.createTextNode(", "));
		p.appendChild(svgAltSize(2000,2000,"2000px"));
		p.appendChild(document.createTextNode("."));
		var info = getElementsByClassName( file.parentNode, 'div', 'fullMedia' )[0];
		if( info ) info.appendChild(p);
	}
};
addOnloadHook( SVGThumbs )
/* </nowiki></source> */