MediaWiki:Common.js/file.js

From Official Kodi Wiki
< MediaWiki:Common.js
Revision as of 21:49, 25 November 2009 by >[email protected] (try to detect commons images, and take a stab at it.)
Jump to navigation Jump to search

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
/* <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 path = wgServer + wgScriptPath;
			if( document.getElementById( 'commons-icon' ) )
				path = 'http://commons.wikimedia.org/w'
			var a = document.createElement("A");
			a.setAttribute("href", path + "/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> */