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

From Official Kodi Wiki
Jump to navigation Jump to search
(prioritize changes.)
m (25 revisions)
 
(14 intermediate revisions by 3 users not shown)
Line 1: Line 1:
/* <source lang="javascript"><nowiki> */
/**
// SVG images: adds links to rendered PNG images in different resolutions
* SVG images: adds links to rendered PNG images in different resolutions
* @author: [[w:en:User:TheDJ]]
* @source: [[w:en:MediaWiki:Common.js/file.js]]
*/
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");
i18n = {
      if (!file) return;  // might happen if MediaWiki can't render the SVG
'en': 'This image rendered as PNG in other sizes: ',
      var div = document.createElement("p");
'pt': 'Esta imagem pode ser renderizada em PNG em outros tamanhos: '
      div.appendChild(document.createTextNode("This image rendered as PNG in some sizes"+": "));
};
      var a200 = document.createElement("a");
if ( file && mw.config.get( 'wgIsArticle' ) && mw.config.get( 'wgTitle' ).match( /\.svg$/i ) ) {
      a200.setAttribute("href", wgServer + wgScriptPath + "/thumb.php?f=" + encodeURIComponent(wgTitle) + "&width=200px&height=200px");
 
      a200.appendChild(document.createTextNode("200px"));
// Define language fallbacks
      var a500 = document.createElement("a");
i18n['en-gb'] = i18n.en;
      a500.setAttribute("href",  wgServer + wgScriptPath + "/thumb.php?f=" + encodeURIComponent(wgTitle) + "&width=500px&height=500px");
i18n['pt-br'] = i18n.pt;
      a500.appendChild(document.createTextNode("500px"));
//i18n['zh-hant'] = i18n.zh;
      var a1000 = document.createElement("a");
 
      a1000.setAttribute("href", wgServer + wgScriptPath + "/thumb.php?f=" + encodeURIComponent(wgTitle) + "&width=1000px&height=1000px");
// Define interface message
      a1000.appendChild(document.createTextNode("1000px"));
mw.messages.set( {
      var a2000 = document.createElement("a");
'svg-thumbs-desc': i18n[ mw.config.get( 'wgUserLanguage' ) ] || i18n.en
      a2000.setAttribute("href",  wgServer + wgScriptPath + "/thumb.php?f=" + encodeURIComponent(wgTitle) + "&width=2000px&height=2000px");
} );
      a2000.appendChild(document.createTextNode("2000px"));
 
      div.appendChild(a200);
var thumbu = file.getElementsByTagName( 'IMG' )[0].getAttribute( 'src' );
      div.appendChild(document.createTextNode(", "));
if( !thumbu ) {
      div.appendChild(a500);
return;
      div.appendChild(document.createTextNode(", "));
}
      div.appendChild(a1000);
var svgAltSize = function( w, title ) {
      div.appendChild(document.createTextNode(", "));
var path = thumbu.replace( /\/\d+(px-[^\/]+$)/, '/' + w + '$1' );
      div.appendChild(a2000);
var a = document.createElement( 'A' );
      div.appendChild(document.createTextNode("."));
a.setAttribute( 'href', path );
      var info = getElementsByClassName( file.parentNode, 'div', 'fullMedia' )[0];
a.appendChild( document.createTextNode( title ) );
      if( info ) info.appendChild(div);
return a;
  }
};
};
 
addOnloadHook( SVGThumbs )
var p = document.createElement( 'p' );
/* </nowiki></source> */
p.className = 'SVGThumbs';
p.appendChild( document.createTextNode( mw.msg( 'svg-thumbs-desc' ) ) );
var l = [ 200, 500, 1000, 2000 ];
                for( var i = 0; i < l.length; i++ ) {
p.appendChild( svgAltSize( l[i], l[i] + 'px' ) );
if( i < l.length-1 ) {
p.appendChild( document.createTextNode( ', ' ) );
}
                }
p.appendChild( document.createTextNode( '.' ) );
var info = getElementsByClassName( file.parentNode, 'div', 'fullMedia' )[0];
if( info ) {
info.appendChild( p );
}
}
}
$( SVGThumbs );

Latest revision as of 14:27, 20 November 2011

/**
 * SVG images: adds links to rendered PNG images in different resolutions
 * @author: [[w:en:User:TheDJ]]
 * @source: [[w:en:MediaWiki:Common.js/file.js]]
 */
function SVGThumbs() {
	var	file = document.getElementById( 'file' ), // might fail if MediaWiki can't render the SVG
		i18n = {
			'en': 'This image rendered as PNG in other sizes: ',
			'pt': 'Esta imagem pode ser renderizada em PNG em outros tamanhos: '
		};
	if ( file && mw.config.get( 'wgIsArticle' ) && mw.config.get( 'wgTitle' ).match( /\.svg$/i ) ) {

		// Define language fallbacks
		i18n['en-gb'] = i18n.en;
		i18n['pt-br'] = i18n.pt;
		//i18n['zh-hant'] = i18n.zh;

		// Define interface message
		mw.messages.set( {
			'svg-thumbs-desc': i18n[ mw.config.get( 'wgUserLanguage' ) ] || i18n.en
		} );

		var thumbu = file.getElementsByTagName( 'IMG' )[0].getAttribute( 'src' );
		if( !thumbu ) {
			return;
		}
		var svgAltSize = function( w, title ) {
			var path = thumbu.replace( /\/\d+(px-[^\/]+$)/, '/' + w + '$1' );
			var a = document.createElement( 'A' );
			a.setAttribute( 'href', path );
			a.appendChild( document.createTextNode( title ) );
			return a;
		};

		var p = document.createElement( 'p' );
		p.className = 'SVGThumbs';
		p.appendChild( document.createTextNode( mw.msg( 'svg-thumbs-desc' ) ) );
		var l = [ 200, 500, 1000, 2000 ];
                for( var i = 0; i < l.length; i++ ) {
			p.appendChild( svgAltSize( l[i], l[i] + 'px' ) );
			if( i < l.length-1 ) {
				p.appendChild( document.createTextNode( ', ' ) );
			}
                }
		p.appendChild( document.createTextNode( '.' ) );
		var info = getElementsByClassName( file.parentNode, 'div', 'fullMedia' )[0];
		if( info ) {
			info.appendChild( p );
		}
	}
}
$( SVGThumbs );