MediaWiki:Common.js
Opomba: Da bodo spremembe prišle do veljave, po objavi izpraznite predpomnilnik svojega brskalnika.
- Firefox/Safari: Držite Shift in kliknite Znova naloži (Reload) ali pritisnite Ctrl + Shift + R ali Ctrl + R (⌘ + R v sistemu Mac)
- Internet Explorer/Edge: Držite Ctrl + F5 in kliknite Osveži (Refresh) ali pritisnite Ctrl + F5
- Google Chrome: Pritisnite Ctrl + Shift + R (⌘ + Shift + R v sistemu Mac)
- Opera: Pritisnite Ctrl + F5.
/* Preizkus, ali ima element določen razred **************************************
*
* Opis: Uses regular expressions and caching for better performance.
* Vzdrževalci: [[:en:User:Mike Dillon|Mike Dillon]], [[:en:User:R. Koot|R. Koot]], [[:en:User:SG|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);
};
})();
/** Medjezikovne povezave na izbrane članke ***************************************
*
* Opis: Highlights interwiki links to featured articles (or
* equivalents) by changing the bullet before the interwiki link
* into a star.
* Vzdrževalci: [[:en:User:R. Koot|R. Koot]]
*/
function LinkFA()
{
if ( document.getElementById( "p-lang" ) ) {
var InterwikiLinks = document.getElementById( "p-lang" ).getElementsByTagName( "li" );
for ( var i = 0; i < InterwikiLinks.length; i++ ) {
if ( document.getElementById( InterwikiLinks[i].className + "-fa" ) ) {
InterwikiLinks[i].className += " FA"
InterwikiLinks[i].title = "V drugem jeziku ima članek položaj izbranega članka.";
}
}
}
}
$( LinkFA );
function LinkGA()
{
if ( document.getElementById( "p-lang" ) ) {
var InterwikiLinks = document.getElementById( "p-lang" ).getElementsByTagName( "li" );
for ( var i = 0; i < InterwikiLinks.length; i++ ) {
if ( document.getElementById( InterwikiLinks[i].className + "-ga" ) ) {
InterwikiLinks[i].className += " GA"
InterwikiLinks[i].title = "V drugem jeziku ima članek položaj dobrega članka.";
}
}
}
}
$( LinkGA );
/** Skrčljive razpredelnice *********************************************************
*
* Opis: Allows tables to be collapsed, showing only the header. See
* [[:en:Wikipedia:NavFrame]].
* Vzdrževalci: [[:en:User:R. Koot|R. Koot]]
*/
var autoCollapse = 2;
var collapseCaption = "zapri";
var expandCaption = "odpri";
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 );
/** Dinamični navigacijski menuji (preizkusno) *************************************
*
* Opis: See [[:en:Wikipedia:NavFrame|Wikipedia:NavFrame]].
* Vzdrževalci: NI VZDRŽEVANO
*/
// 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 );
/** Popravek postavitve Glavne strani ******************************************************* <nowiki>
*
* Opis: Various layout fixes for the main page, including an
* additional link to the complete list of languages available
* and the renaming of the 'Article' to to 'Main Page'.
* Vzdrževalci: [[:en:User:AzaToth|AzaToth]], [[:en:User:R. Koot|R. Koot]], [[User:Alex Smotrov]]
*/
//============================================================
// Gumbi za v urejevalno vrstico
//============================================================
importScript("MediaWiki:Gumbi.js");
/** Popravek za tehnične omejitve pri naslovih *****************************************
*
* Opis:
* Vzdrževalci: en:User:Interiot, en:User:Mets501, en:User:Freakofnurture
*/
//
// Pri straneh, ki bi se morale začeti z malo začetnico, zamenjaj naslov, vendar le, če se ga da izrezati in prilepiti kot veljavno wikipovezavo.
// tak je npr. naslov iPod. [[C#]] pa ni ekvivalentna
// wikipovezava, zato še naprej ostane naslov [[C Sharp]])
//
// 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.
//
var disableRealTitle = 0; // users can set disableRealTitle = 1 locally to disable.
if (mw.config.get('wgIsArticle')) { // don't display the RealTitle when editing, since it is apparently inconsistent (doesn't show when editing sections, doesn't show when not previewing)
$(function() {
try {
var realTitleBanner = document.getElementById("RealTitleBanner");
if (realTitleBanner && !document.getElementById("DisableRealTitle") && !disableRealTitle ) {
var realTitle = document.getElementById("RealTitle");
if (realTitle) {
var realTitleHTML = realTitle.innerHTML;
realTitleText = pickUpText(realTitle);
var isPasteable = 0;
//var containsHTML = /</.test(realTitleHTML); // contains ANY HTML
var containsTooMuchHTML = /</.test( realTitleHTML.replace(/<\/?(sub|sup|small|big)>/gi, "") ); // contains HTML that will be ignored when cut-n-pasted as a wikilink
// calculate whether the title is pasteable
var verifyTitle = realTitleText.replace(/^ +/, ""); // trim left spaces
verifyTitle = verifyTitle[0].toUpperCase() + verifyTitle.substring(1, verifyTitle.length); // uppercase first character
// if the namespace prefix is there, remove it on our verification copy. If it isn't there, add it to the original realValue copy.
if (mw.config.get('wgNamespaceNumber') != 0) {
if (mw.config.get('wgCanonicalNamespace') == verifyTitle.substr(0, mw.config.get('wgCanonicalNamespace').length).replace(/ /g, "_") && verifyTitle.charAt(mw.config.get('wgCanonicalNamespace').length) == ":") {
verifyTitle = verifyTitle.substr(mw.config.get('wgCanonicalNamespace').length + 1);
} else {
realTitleText = mw.config.get('wgCanonicalNamespace').replace(/_/g, " ") + ":" + realTitleText;
realTitleHTML = mw.config.get('wgCanonicalNamespace').replace(/_/g, " ") + ":" + realTitleHTML;
}
}
// verify whether wgTitle matches
verifyTitle = verifyTitle.replace(/[\s_]+/g, " "); // underscores and multiple spaces to single spaces
verifyTitle = verifyTitle.replace(/^\s+/, "").replace(/\s+$/, ""); // trim left and right spaces
verifyTitle = verifyTitle[0].toUpperCase() + verifyTitle.substring(1, verifyTitle.length); // uppercase first character
if ( (verifyTitle == mw.config.get('wgTitle')) || (verifyTitle == mw.config.get('wgTitle').replace(/^(.+)?(January|February|March|April|May|June|July|August|September|October|November|December)\s+([12]?[0-9]|3[0123])([^\d].*)?$/g, "$1$3 $2$4") )) isPasteable = 1;
var h1 = document.getElementsByTagName("h1")[0];
if (h1 && isPasteable) {
h1.innerHTML = containsTooMuchHTML ? realTitleText : realTitleHTML;
if (!containsTooMuchHTML)
realTitleBanner.style.display = "none";
}
document.title = realTitleText + " - Wikipedija, prosta enciklopedija";
}
}
} catch (e) {
/* Something went wrong. */
}
});
}
// similar to innerHTML, but only returns the text portions of the insides, excludes HTML
function pickUpText(aParentElement) {
var str = "";
function pickUpTextInternal(aElement) {
var child = aElement.firstChild;
while (child) {
if (child.nodeType == 1) // ELEMENT_NODE
pickUpTextInternal(child);
else if (child.nodeType == 3) // TEXT_NODE
str += child.nodeValue;
child = child.nextSibling;
}
}
pickUpTextInternal(aParentElement);
return str;
}
//fix edit summary prompt for undo
//this code fixes the fact that the undo function combined with the "no edit summary prompter" causes problems if leaving the
//edit summary unchanged
//this was added by [[:en:User:Deskana|Deskana]], code by [[:en:User:Tra|Tra]]
$(function () {
if (document.location.search.indexOf("undo=") != -1
&& document.getElementsByName('wpAutoSummary')[0]) {
document.getElementsByName('wpAutoSummary')[0].value='1';
}
})
/** Obvestilo o novem sporočilu doda gumb 'skrij' *************************************
*
* Opis: Hide the watchlist message for one week.
* Vzdrževalci: [[:en:User:Ruud Koot|Ruud Koot]]
*/
function addDismissButton() {
var watchlistMessage = document.getElementById("watchlist-message");
if ( watchlistMessage == null ) return;
var watchlistCookieID = watchlistMessage.className.replace(/cookie\-ID\_/ig,'');
if ( document.cookie.indexOf( "hidewatchlistmessage-" + watchlistCookieID + "=yes" ) != -1 ) {
watchlistMessage.style.display = "none";
}
var Button = document.createElement( "span" );
var ButtonLink = document.createElement( "a" );
var ButtonText = document.createTextNode( "skrij" );
ButtonLink.setAttribute( "id", "dismissButton" );
ButtonLink.setAttribute( "href", "javascript:dismissWatchlistMessage();" );
ButtonLink.setAttribute( "title", "Skrije obvestilo za en teden" );
ButtonLink.appendChild( ButtonText );
Button.appendChild( document.createTextNode( "[" ) );
Button.appendChild( ButtonLink );
Button.appendChild( document.createTextNode( "]" ) );
watchlistMessage.appendChild( Button );
}
function dismissWatchlistMessage() {
var e = new Date();
e.setTime( e.getTime() + (7*24*60*60*1000) );
var watchlistMessage = document.getElementById("watchlist-message");
var watchlistCookieID = watchlistMessage.className.replace(/cookie\-ID\_/ig,'');
document.cookie = "hidewatchlistmessage-" + watchlistCookieID + "=yes; expires=" + e.toGMTString() + "; path=/";
watchlistMessage.style.display = "none";
}
$( addDismissButton );
/** Slika ob izbrisu Glavne strani *******************************************************
*
* Opis: If the Main Page does not exist (i.e., it's been deleted) then insert an image
* instead of showing the "page does not exist" text.
* Avtor: [[:en:User:Mark]], with invaluable help from [[:en:User:Pathoschild]]
*/
function MainPageDeletedImage() {
try {
//If the article does not exist and it is the Main Page, proceed
if ( document.getElementById( "noarticletext" ) && mw.config.get('wgTitle') == 'Glavna stran' ) {
// Insert a protected commons image at the end of the document explaining it.
var contentbox = document.getElementById('content');
var newimg = document.createElement('img');
newimg.setAttribute('src','//upload.wikimedia.org/wikipedia/commons/9/99/WikipediaTechnical.png');
contentbox.appendChild(newimg);
// Hide the article-does-not-exist text
var NoArticleMessage = document.getElementById('noarticletext');
NoArticleMessage.style.display="none";
// Hide the edit button
var EditThisPageButton = document.getElementById('ca-edit');
EditThisPageButton.style.display="none";
}
} catch(e) {
// In case it does not work, do nothing
return;
}
}
$( MainPageDeletedImage );
/** K Special:Search doda spustljivi meni *******************************************************
*
* Opis: Change Special:Search to use a drop-down menu, with the default being
* the internal MediaWiki engine
* Avtor in vzdrževalec: [[:en:User:Gracenotes]]
*/
if (mw.config.get('wgCanonicalSpecialPageName') == "Search") {
var searchEngines = [];
$(SpecialSearchEnhanced);
}
function SpecialSearchEnhanced() {
var createOption = function(site, action, mainQ, addQ, addV) {
var opt = document.createElement('option');
opt.appendChild(document.createTextNode(site));
searchEngines[searchEngines.length] = [action, mainQ, addQ, addV];
return opt;
}
var searchForm = document.forms['search'];
var selectBox = document.createElement('select');
selectBox.id = 'searchEngine';
searchForm.onsubmit = function() {
var optSelected = searchEngines[document.getElementById('searchEngine').selectedIndex];
searchForm.action = optSelected[0];
searchForm.lsearchbox.name = optSelected[1];
searchForm.title.value = optSelected[3];
searchForm.title.name = optSelected[2];
}
selectBox.appendChild(createOption('Iskanje MediaWiki', wgScriptPath + '/index.php', 'search', 'title', 'Special:Search'));
selectBox.appendChild(createOption('Google', 'http://www.google.com/search', 'q', 'sitesearch', 'sl.wikipedia.org'));
selectBox.appendChild(createOption('Yahoo', 'http://search.yahoo.com/search', 'p', 'vs', 'sl.wikipedia.org'));
selectBox.appendChild(createOption('Windows Live', 'http://search.live.com/results.aspx', 'q', 'q1', 'site:http://sl.wikipedia.org'));
searchForm.lsearchbox.style.marginLeft = '0px';
var lStat = document.getElementById('loadStatus');
lStat.parentNode.insertBefore(selectBox, lStat);
lStat.parentNode.insertBefore(document.createTextNode(" "), lStat);
}
/** WikiMiniAtlas *******************************************************
*
* Description: Zemljevid sveta WikiMiniAtlas - izskokci.
* This script causes all of our coordinate links to display the WikiMiniAtlas popup button.
* The script itself is located on meta because it is used by many projects.
* See [[Meta:WikiMiniAtlas]] for more information.
* Created by: [[User:Dschwen]]
*/
mw.loader.load('//meta.wikimedia.org/w/index.php?title=MediaWiki:Wikiminiatlas.js&action=raw&ctype=text/javascript');
/**
* Remove need for CSS hacks regarding MSIE and IPA.
*/
if(navigator.userAgent.indexOf("MSIE") != -1 && document.createStyleSheet) {
document.createStyleSheet().addRule('.IPA', 'font-family: "Doulos SIL", "Charis SIL", Gentium, "DejaVu Sans", Code2000, "TITUS Cyberbit Basic", "Arial Unicode MS", "Lucida Sans Unicode", "Chrysanthi Unicode";');
}
/** Obvezni predogled za anonimne urejevalce ************************************************
*
* Opis: Force IP to preview before saving changes.
* Avtor in vzdrževalec: [[:fr:User:Marc Mongenet]]
*/
function forcePreview() {
if (mw.config.get('wgUserName') || mw.config.get('wgAction') !== 'edit') return;
saveButton = document.getElementById("wpSave");
if (!saveButton) return;
saveButton.disabled = true;
saveButton.value = "Shrani (po predogledu)";
saveButton.style.fontWeight = "normal";
document.getElementById("wpPreview").style.fontWeight = "bold";
}
$(forcePreview);
/** Onemogočeno ustvarjanje novih strani anonimnim uporabnikom (izključene so pogovorne strani)
*
* Avtor: [[User:Dbc334]], vzdržuje [[User:Smihael]]
*/
function checkNewPageUser() {
if(!mw.config.get('wgArticleId') && (mw.config.get('wgAction') == "edit") && (mw.config.get('wgUserName') == null) && (mw.config.get('wgNamespaceNumber')%2 == 0)) {
document.getElementById('newarticletext').innerHTML = "<p><b>Anonimnim uporabnikom je ustvarjanje novih strani preprečeno.</b></p><p>Če želite ustvariti novo stran, se prosimo <a href=\"/w/index.php?title=Special:UserLogin&type=signup\">registrirajte</a>.</p>";
document.getElementById('mw-anon-edit-warning').style.display = "none";
document.getElementById('editform').style.display = "none";
document.getElementById('wpTextbox1').style.display = "none";
if(document.getElementById('talkpagetext')) {document.getElementById('talkpagetext').style.display = "none";}
}
}
$(checkNewPageUser);
/* Maksimalna veljavnost preklica sporocilca na vrhu Wikija naj bo 7 dni (namesto 30)
http://sl.wikipedia.org/w/index.php?title=Wikipedija%3APod_lipo&diff=3729959&oldid=3729833 */
function dismissNotice() {
var date = new Date();
date.setTime(date.getTime() + 7*86400*1000);
document.cookie = cookieName + siteNoticeID + "; expires="+date.toGMTString() + "; path=/";
var element = document.getElementById('mw-dismissable-notice');
element.parentNode.removeChild(element);
}
// Legacy razporeditev v starem urejevalniku kode
$("#editpage-specialchars").prependTo(".editOptions");
// 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");
}