MediaWiki:Common.js
Vzhľad
Poznámka: Aby sa zmeny prejavili, po uložení musíte vymazať vyrovnávaciu pamäť vášho prehliadača. Mozilla / Firefox / Safari: držte stlačený Shift a kliknite na Reload alebo stlačte buď Ctrl-F5 alebo Ctrl-R (Command-R na Macintosh); Konqueror:: kliknite na tlačidlo Reload alebo stlačte F5; Opera vymazať vyrovnávaciu pamäť prehliadača v ponuke Tools→Preferences; Internet Explorer: držte Ctrl a kliknite na Refresh alebo stlačte Ctrl-F5;
//<source lang="javascript">
/* Import more specific scripts if necessary */
if (mw.config.get('wgAction') == "edit" || mw.config.get('wgAction') == "submit") {
//scripts specific to editing pages
importScript("MediaWiki:Common.js/edit.js")
}
/**
* Load scripts specific to Internet Explorer
*/
if ($.client) {
console.log('$.client defined');
if ( $.client.profile().name === 'msie' ) {
importScript( 'MediaWiki:Common.js/IEFixes.js' );
}
} else {
console.log('$.client undefined');
}
/* Test if an element has a certain class **************************************
*
* Description: Uses regular expressions and caching for better performance.
* Maintainers: [[User:Mike Dillon]], [[User:R. Koot]], [[User:SG]]
*/
var hasClass = (function () {
var reCache = {};
return function (element, className) {
return (reCache[className] ? reCache[className] : (reCache[className] = new RegExp("(?:\\s|^)" + className + "(?:\\s|$)"))).test(element.className);
};
})();
/** Interwiki links to featured articles ***************************************
*
* Description: Highlights interwiki links to featured articles (or
* equivalents) by changing the bullet before the interwiki link
* into a star.
* Maintainers: [[User:R. Koot]]
*/
function LinkFA()
{
var langbox = document.getElementById("p-lang");
if (!langbox) return;
var interwiki = langbox.getElementsByTagName("li");
// iterace přes všechny mezijazykové odkazy
for (var i = 0; i < interwiki.length; ++i)
{
var link = interwiki[i];
var language = link.className.substring(10); // smazat "interwiki-"
// zkusit najít odpovídající FA nebo GA element
var falink = document.getElementById("fa-link-" + language) && link.className.indexOf("badge-featuredarticle") === -1;
if (falink)
{
link.className += " featured";
link.title = "Tento článok je ohodnotený ako perfektný v inej jazykovej verzii.";
} else {
var galink = document.getElementById("ga-link-" + language) && link.className.indexOf("badge-goodarticle") === -1;
if (galink)
{
link.className += " good";
link.title = "Tento článok je ohodnotený ako dobrý v inej jazykovej verzii.";
}
}
}
}
$( LinkFA );
/** Collapsible tables *********************************************************
*
* Description: Allows tables to be collapsed, showing only the header. See
* [[Wikipedia:NavFrame]].
* Maintainers: [[User:R. Koot]]
*/
var autoCollapse = 2;
var collapseCaption = "skry";
var expandCaption = "rozbaľ";
function collapseTable( tableIndex )
{
var Button = document.getElementById( "collapseButton" + tableIndex );
var Table = document.getElementById( "collapsibleTable" + tableIndex );
if ( !Table || !Button ) {
return false;
}
var Rows = Table.rows;
if ( Button.firstChild.data == collapseCaption ) {
for ( var i = 1; i < Rows.length; i++ ) {
Rows[i].style.display = "none";
}
Button.firstChild.data = expandCaption;
} else {
for ( var i = 1; i < Rows.length; i++ ) {
Rows[i].style.display = Rows[0].style.display;
}
Button.firstChild.data = collapseCaption;
}
}
function createCollapseButtons()
{
var tableIndex = 0;
var NavigationBoxes = new Object();
var Tables = document.getElementsByTagName( "table" );
for ( var i = 0; i < Tables.length; i++ ) {
if ( hasClass( Tables[i], "collapsible" ) ) {
/* only add button and increment count if there is a header row to work with */
var HeaderRow = Tables[i].getElementsByTagName( "tr" )[0];
if (!HeaderRow) continue;
var Header = HeaderRow.getElementsByTagName( "th" )[0];
if (!Header) continue;
NavigationBoxes[ tableIndex ] = Tables[i];
Tables[i].setAttribute( "id", "collapsibleTable" + tableIndex );
var Button = document.createElement( "span" );
var ButtonLink = document.createElement( "a" );
var ButtonText = document.createTextNode( collapseCaption );
Button.style.styleFloat = "right";
Button.style.cssFloat = "right";
Button.style.fontWeight = "normal";
Button.style.textAlign = "right";
Button.style.width = "6em";
ButtonLink.style.color = Header.style.color;
ButtonLink.setAttribute( "id", "collapseButton" + tableIndex );
ButtonLink.setAttribute( "href", "javascript:collapseTable(" + tableIndex + ");" );
ButtonLink.appendChild( ButtonText );
Button.appendChild( document.createTextNode( "[" ) );
Button.appendChild( ButtonLink );
Button.appendChild( document.createTextNode( "]" ) );
Header.insertBefore( Button, Header.childNodes[0] );
tableIndex++;
}
}
for ( var i = 0; i < tableIndex; i++ ) {
if ( hasClass( NavigationBoxes[i], "collapsed" ) || ( tableIndex >= autoCollapse && hasClass( NavigationBoxes[i], "autocollapse" ) ) ) {
collapseTable( i );
}
}
}
$( createCollapseButtons );
/** Dynamic Navigation Bars (experimental) *************************************
*
* Description: See [[Wikipedia:NavFrame]].
* Maintainers: UNMAINTAINED
*/
// set up the words in your language
var NavigationBarHide = '[' + collapseCaption + ']';
var NavigationBarShow = '[' + expandCaption + ']';
// shows and hides content and picture (if available) of navigation bars
// Parameters:
// indexNavigationBar: the index of navigation bar to be toggled
function toggleNavigationBar(indexNavigationBar)
{
var NavToggle = document.getElementById("NavToggle" + indexNavigationBar);
var NavFrame = document.getElementById("NavFrame" + indexNavigationBar);
if (!NavFrame || !NavToggle) {
return false;
}
// if shown now
if (NavToggle.firstChild.data == NavigationBarHide) {
for (var NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling) {
if ( hasClass( NavChild, 'NavPic' ) ) {
NavChild.style.display = 'none';
}
if ( hasClass( NavChild, 'NavContent') ) {
NavChild.style.display = 'none';
}
}
NavToggle.firstChild.data = NavigationBarShow;
// if hidden now
} else if (NavToggle.firstChild.data == NavigationBarShow) {
for (var NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling) {
if (hasClass(NavChild, 'NavPic')) {
NavChild.style.display = 'block';
}
if (hasClass(NavChild, 'NavContent')) {
NavChild.style.display = 'block';
}
}
NavToggle.firstChild.data = NavigationBarHide;
}
}
// adds show/hide-button to navigation bars
function createNavigationBarToggleButton()
{
var indexNavigationBar = 0;
// iterate over all < div >-elements
var divs = document.getElementsByTagName("div");
for (var i = 0; NavFrame = divs[i]; i++) {
// if found a navigation bar
if (hasClass(NavFrame, "NavFrame")) {
indexNavigationBar++;
var NavToggle = document.createElement("a");
NavToggle.className = 'NavToggle';
NavToggle.setAttribute('id', 'NavToggle' + indexNavigationBar);
NavToggle.setAttribute('href', 'javascript:toggleNavigationBar(' + indexNavigationBar + ');');
var NavToggleText = document.createTextNode(NavigationBarHide);
for (var NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling) {
if ( hasClass( NavChild, 'NavPic' ) || hasClass( NavChild, 'NavContent' ) ) {
if (NavChild.style.display == 'none') {
NavToggleText = document.createTextNode(NavigationBarShow);
break;
}
}
}
NavToggle.appendChild(NavToggleText);
// Find the NavHead and attach the toggle link (Must be this complicated because Moz's firstChild handling is borked)
for(var j=0; j < NavFrame.childNodes.length; j++) {
if (hasClass(NavFrame.childNodes[j], "NavHead")) {
NavFrame.childNodes[j].appendChild(NavToggle);
}
}
NavFrame.setAttribute('id', 'NavFrame' + indexNavigationBar);
}
}
}
$( createNavigationBarToggleButton );
/** "Technical restrictions" title fix *****************************************
*
* Description: For pages that have something like Template:Wrongtitle, replace
* the title, but only if it is cut-and-pasteable as a valid
* wikilink. For instance, "NZR WB class" can be changed to
* "NZR W<sup>B</sup> class", but [[C#]] is not an equivalent wikilink,
* so [[C Sharp]] doesn't have its main title changed.
*
* The function looks for a banner like this:
* <div id="RealTitleBanner"> ... <span id="RealTitle">title</span> ... </div>
* An element with id=DisableRealTitle disables the function.
* Maintainers: Remember_the_dot
*/
if (mw.config.get('wgIsArticle')) //prevents the "Editing " prefix from disappearing during preview
{
$(function()
{
var realTitle = document.getElementById("RealTitle")
if (realTitle)
{
//normalizes a title or a namespace name (but not both)
//trims leading and trailing underscores and converts (possibly multiple) spaces and underscores to single underscores
function normalizeTitle(title)
{
return title.replace(/^_+/, "").replace(/_+$/, "").replace(/[\s_]+/g, "_")
}
if (realTitle.textContent) //everyone but IE
{
var realTitleText = realTitle.textContent
}
else //IE
{
var realTitleText = realTitle.innerText
}
var normalizedRealTitle
var normalizedPageTitle
var indexOfColon = realTitleText.indexOf(":")
var normalizedNamespaceName = normalizeTitle(realTitleText.substring(0, indexOfColon)).toLowerCase()
//make namespace prefix lowercase and uppercase the first letter of the title
if (indexOfColon == -1 || mw.config.get('wgCanonicalNamespace').toLowerCase() != normalizedNamespaceName) //no namespace prefix - either no colon or a nonsensical namespace prefix (for example, "Foo" in "Foo: The Story of My Life")
{
normalizedRealTitle = normalizeTitle(realTitleText)
normalizedRealTitle = normalizedRealTitle.charAt(0).toUpperCase() + normalizedRealTitle.substring(1)
normalizedPageTitle = mw.config.get('wgPageName').charAt(0).toUpperCase() + mw.config.get('wgPageName').substring(1)
}
else //using a namespace prefix
{
var normalizedRealPageTitle = normalizeTitle(realTitleText.substring(indexOfColon + 1))
normalizedRealTitle = normalizedNamespaceName
if (normalizedNamespaceName != "") //namespace 0 is a special case where the leading colon should never be shown
{
normalizedRealTitle += ":"
}
normalizedRealTitle += normalizedRealPageTitle.charAt(0).toUpperCase() + normalizedRealPageTitle.substring(1)
normalizedPageTitle = mw.config.get('wgPageName').substring(0, mw.config.get('wgPageName').indexOf(":") + 1).toLowerCase() + mw.config.get('wgPageName').substring(mw.config.get('wgPageName').indexOf(":") + 1)
}
if (normalizedRealTitle == normalizedPageTitle) //normalized titles match, so we can do full replacement
{
var h1 = document.getElementsByTagName("h1")[0]
//remove all child nodes, including text
while (h1.firstChild)
{
h1.removeChild(h1.firstChild)
}
//populate with nodes of real title
while (realTitle.firstChild) //the children are moved to a new parent element
{
h1.appendChild(realTitle.firstChild)
}
//delete the real title banner since the problem is solved
var realTitleBanner = document.getElementById("RealTitleBanner")
realTitleBanner.parentNode.removeChild(realTitleBanner)
}
//no matter what, correct the page title
document.title = realTitleText + " - Wikipedia, the free encyclopedia"
}
})
}
//////////////////////////////////////////////////////////////////////////////////
////////// Funkcie neinportovane z anglickej wikipedie ///////////////////////////
//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
/*
* Položka "Nahrať na Commons" v ponuke nástroje
* zdroj: //cs.wikipedia.org/wiki/MediaWiki:Common.js
*/
function addCommonsUpload ()
{
nodUpload = document.getElementById ("t-upload");
if (nodUpload)
{
var nodToolsList = nodUpload.parentNode;
var nodUploadCommons_li = document.createElement ("li");
var nodUploadCommons_a = document.createElement ("a");
nodUploadCommons_li.id = "t-upload-commons";
nodUploadCommons_a.href = "//commons.wikimedia.org/wiki/Special:UploadWizard?uselang=sk";
nodUploadCommons_a.appendChild (document.createTextNode ("Nahrať na Commons"));
nodUploadCommons_li.appendChild (nodUploadCommons_a);
nodToolsList.insertBefore (nodUploadCommons_li, nodUpload.nextSibling);
}
}
$( addCommonsUpload );
/*
* Nový nahrávací formulár
* zdroj: //cs.wikipedia.org/wiki/MediaWiki:Common.js
*/
function EasyUpload()
{
uploadLink = document.getElementById("t-upload");
if (!uploadLink) return;
a = uploadLink.firstChild;
if(a) {
a.setAttribute('href', '/wiki/Pomoc:Nahrať_súbor');
}
}
$( EasyUpload );
/*
* Predvyplnenie popisu súboru
* zdroj: //cs.wikipedia.org/wiki/MediaWiki:Common.js
*/
function PrefillUploadDescription ()
{
if (mw.config.get('wgPageName') == "Špeciálne:Upload")
document.getElementById ("wpUploadDescription").value="{{Informácia o súbore\n | Popis =\n | Zdroj =\n | Dátum =\n | Autor =\n | Povolenie =\n | Iné verzie =\n}}";
}
$( PrefillUploadDescription );
/**
* Šablóna:Album obrázkov
*/
function toggleImage(group, remindex, shwindex) {
document.getElementById("ImageGroupsGr"+group+"Im"+remindex).style.display="none";
document.getElementById("ImageGroupsGr"+group+"Im"+shwindex).style.display="inline";
}
function imageGroup(){
if (document.URL.match(/printable/g)) return;
var bc=document.getElementById("bodyContent");
if( !bc ) bc = document.getElementById("mw_contentholder");
if( !bc ) return;
var divs=bc.getElementsByTagName("div");
var i = 0, j = 0;
var units, search;
var currentimage;
var UnitNode;
for (i = 0; i < divs.length ; i++) {
if (divs[i].className != "ImageGroup") continue;
UnitNode=undefined;
search=divs[i].getElementsByTagName("div");
for (j = 0; j < search.length ; j++) {
if (search[j].className != "ImageGroupUnits") continue;
UnitNode=search[j];
break;
}
if (UnitNode==undefined) continue;
units=Array();
for (j = 0 ; j < UnitNode.childNodes.length ; j++ ) {
var temp = UnitNode.childNodes[j];
if (['center', 'mw-halign-center'].some(function(className) { return temp.classList.contains(className); })) { units.push(temp); }
}
var wrap;
for (j = 0 ; j < units.length ; j++) {
currentimage=units[j];
wrap = document.createElement('div');
wrap.id = "ImageGroupsGr" + i + "Im" + j;
currentimage.parentNode.insertBefore(wrap, currentimage);
wrap.appendChild(currentimage);
var imghead = document.createElement("div");
var leftlink;
var rightlink;
if (j != 0) {
leftlink = document.createElement("a");
leftlink.href = "javascript:toggleImage("+i+","+j+","+(j-1)+");";
leftlink.innerHTML="◀";
} else {
leftlink = document.createElement("span");
leftlink.innerHTML=" ";
}
if (j != units.length - 1) {
rightlink = document.createElement("a");
rightlink.href = "javascript:toggleImage("+i+","+j+","+(j+1)+");";
rightlink.innerHTML="▶";
} else {
rightlink = document.createElement("span");
rightlink.innerHTML=" ";
}
var comment = document.createElement("tt");
comment.innerHTML = "("+ (j+1) + "/" + units.length + ")";
with(imghead) {
style.fontSize="110%";
style.fontweight="bold";
appendChild(leftlink);
appendChild(comment);
appendChild(rightlink);
}
wrap.insertBefore(imghead,wrap.childNodes[0]);
if (j != 0) wrap.style.display="none";
}
}
}
$(imageGroup);
//</source>
/* OSM gadget */
mw.config.set( 'osm_proj_map', 'Mapa...' ); // "map" link caption in project language
mw.config.set( 'osm_proj_lang', 'sk' ); // project language
mw.loader.load('//meta.wikimedia.org/w/index.php?title=MediaWiki:OSM.js&action=raw&ctype=text/javascript');
// Results from Wikidata
// [[File:Wdsearch_script_screenshot.png]]
if ( mw.config.get( 'wgCanonicalSpecialPageName' ) === 'Search' || ( mw.config.get( 'wgArticleId' ) === 0 && mw.config.get( 'wgCanonicalSpecialPageName' ) === false ) ) {
mw.loader.load("//en.wikipedia.org/w/index.php?title=MediaWiki:Wdsearch.js&action=raw&ctype=text/javascript");
}
/* Wikimenu */
var arrowimages={down:["downarrowclass","//upload.wikimedia.org/wikipedia/commons/f/f1/MediaWiki_Vector_skin_action_arrow.svg",10],right:["rightarrowclass","//upload.wikimedia.org/wikipedia/commons/0/03/MediaWiki_Vector_skin_right_arrow.svg"]};var jqueryslidemenu={animateduration:{over:600,out:600},buildmenu:function(menuid,arrowsvar){jQuery(document).ready(function($){var $mainmenu=$("#"+menuid+">ul");var $headers=$mainmenu.find("ul").parent();$headers.each(function(i){var $curobj=$(this);var $subul=$(this).find("ul:eq(0)");this._dimensions={w:this.offsetWidth,h:this.offsetHeight,subulw:$subul.outerWidth(),subulh:$subul.outerHeight()};this.istopheader=$curobj.parents("ul").length==1?true:false;$subul.css({top:this.istopheader?this._dimensions.h+"px":0});$curobj.children("a:eq(0)").css(this.istopheader?{paddingRight:arrowsvar.down[2]}:{}).append('<img src="'+(this.istopheader?arrowsvar.down[1]:arrowsvar.right[1])+'" class="'+(this.istopheader?arrowsvar.down[0]:arrowsvar.right[0])+'" style="border:0;" />');$curobj.hover(function(e){var $targetul=$(this).children("ul:eq(0)");this._offsets={left:$(this).offset().left,top:$(this).offset().top};var menuleft=this.istopheader?0:this._dimensions.w;menuleft=(this._offsets.left+menuleft+this._dimensions.subulw>$(window).width())?(this.istopheader?-this._dimensions.subulw+this._dimensions.w:-this._dimensions.w):menuleft;if($targetul.queue().length<=1){$targetul.css({left:menuleft+"px",width:this._dimensions.subulw+"px"}).slideDown(jqueryslidemenu.animateduration.over)}},function(e){var $targetul=$(this).children("ul:eq(0)");$targetul.slideUp(jqueryslidemenu.animateduration.out)});$curobj.click(function(){$(this).children("ul:eq(0)").hide()})});$mainmenu.find("ul").css({display:"none",visibility:"visible"})})}};jqueryslidemenu.buildmenu("myslidemenu",arrowimages);
/**
* Dopĺňanie odkazu na úplný zoznam jazykových mutácii do interwiki slotu na Hlavnej stránke
*
* 2015-02-13 [[Redaktor:Teslaton]]
*/
if (mw.config.get('wgIsMainPage')) {
mw.loader.using('mediawiki.util', function() {
mw.util.addPortletLink('p-lang', '//meta.wikimedia.org/wiki/List_of_Wikipedias',
'Všetky jazyky...', 'interwiki-completelist', 'Úplný zoznam Wikipédií');
});
}
/**
* Sortable tabuľky: Aproximácia korektného zoraďovania substovaním sk (+ cs, pl) znakov s diakritikou.
*
* 2017-01-08 [[Redaktor:Teslaton]]
*/
mw.config.set('tableSorterCollation', {
'á' :'azz', 'Á' :'AZZ',
'ä' :'azzz', 'Ä' :'AZZZ',
'ą' :'azzzz', 'Ą' :'AZZZZ', // pl
'č' :'czz', 'Č' :'CZZ',
'ć' :'czzz', 'Ć' :'CZZZ', // pl
'ď' :'dzz', 'Ď' :'DZZ',
'dz':'dzzz', 'Dz':'DZZZ', 'DZ':'DZZZ',
'dž':'dzzzz', 'Dž':'DZZZZ', 'DŽ':'DZZZZ',
'é' :'ezz', 'É' :'EZZ',
'ě' :'ezzz', 'Ě' :'EZZZ', // cs
'ę' :'ezzzz', 'Ę' :'EZZZZ', // pl
'ch':'hzz', 'Ch':'HZZ', 'CH':'HZZ',
'í' :'izz', 'Í' :'IZZ',
'ĺ' :'lzz', 'Ĺ' :'LZZ',
'ľ' :'lzzz', 'Ľ' :'LZZZ',
'ł' :'lzzzz', 'Ł' :'LZZZZ', // pl
'ň' :'nzz', 'Ň' :'NZZ',
'ń' :'nzzz', 'Ń' :'NZZZ', // pl
'ó' :'ozz', 'Ó' :'OZZ',
'ô' :'ozzz', 'Ô' :'OZZZ',
'ŕ' :'rzz', 'Ŕ' :'RZZ',
'ř' :'rzzz', 'Ř' :'RZZZ', // cs
'š' :'szz', 'Š' :'SZZ',
'ś' :'szzz', 'Ś' :'SZZZ', // pl
'ť' :'tzz', 'Ť' :'TZZ',
'ú' :'uzz', 'Ú' :'UZZ',
'ů' :'uzzz', 'Ů' :'UZZZ', // cs
'ý' :'yzz', 'Ý' :'YZZ',
'ž' :'zzz', 'Ž' :'ZZZ',
'ź' :'zzzz', 'Ź' :'ZZZZ', // pl
'ż' :'zzzzz', 'Ż' :'ZZZZZ' // pl
});
/**
* Fix šablony klikatelného tlačítka
* 2019-03-22 [[Redaktor:OJJ]]+[[Redaktor:Dvorapa]]
*/
mw.hook('wikipage.content').add(function() {
if ((mw.loader.getState('oojs-ui') === 'registered') && ($('.oo-ui-widget').length)) {
mw.loader.using(['oojs-ui']);
}
});
// Please remove when all user scripts have been updated.
window.mwCustomEditButtons = [];