MediaWiki:Common.js/file.js: Difference between revisions
Jump to navigation
Jump to search
m redundant syntaxhighlight |
|||
| Line 1: | Line 1: | ||
/ | /** | ||
* 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() { | ||
var file = document.getElementById( | var file = document.getElementById( 'file' ), // might fail if MediaWiki can't render the SVG | ||
if (file && wgIsArticle && wgTitle.match(/\.svg$/i)) { | 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 ) ) { | |||
function | // Define language fallbacks | ||
var path = thumbu.replace(/\/\d+(px-[^\/]+$)/, | i18n['en-gb'] = i18n.en; | ||
var a = document.createElement( | i18n['pt-br'] = i18n.pt; | ||
a.setAttribute( | //i18n['zh-hant'] = i18n.zh; | ||
a.appendChild(document.createTextNode(title)); | |||
// Define interface message | |||
mw.messages.set( { | |||
'svg-thumbs-desc': i18n[ mw.config.get( 'wgUserLanguage' ) ] || i18n.en | |||
} ); | |||
var thumbu = file.getElementsByTagName( 'IMG' )[0].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; | return a; | ||
} | }; | ||
var p = document.createElement( | var p = document.createElement( 'p' ); | ||
p.className = | p.className = 'SVGThumbs'; | ||
p.appendChild(document.createTextNode( | p.appendChild( document.createTextNode( mw.msg( 'svg-thumbs-desc' ) ) ); | ||
var l = | var l = [ 200, 500, 1000, 2000 ]; | ||
for( var i = 0; i < l.length; i++ ) { | for( var i = 0; i < l.length; i++ ) { | ||
p.appendChild(svgAltSize( l[i], l[i] + | p.appendChild( svgAltSize( l[i], l[i] + 'px') ); | ||
if( i < l.length-1 ) p.appendChild(document.createTextNode( | if( i < l.length-1 ) { | ||
p.appendChild( document.createTextNode( ', ' ) ); | |||
} | |||
} | } | ||
p.appendChild(document.createTextNode( | p.appendChild( document.createTextNode( '.' ) ); | ||
var info = getElementsByClassName( file.parentNode, 'div', 'fullMedia' )[0]; | var info = getElementsByClassName( file.parentNode, 'div', 'fullMedia' )[0]; | ||
if( info ) info.appendChild(p); | if( info ) { | ||
info.appendChild( p ); | |||
} | |||
} | } | ||
} | } | ||
$( SVGThumbs ); | |||
Revision as of 19:43, 26 October 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].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 );