MediaWiki:Common.js

Izvor: Hrvatska internetska enciklopedija
Skoči na:orijentacija, traži

Napomena: nakon snimanja, trebate očistiti memoriju svog internetskog preglednika kako biste odmah vidjeli promjene: Firefox, Google Chrome i drugi preglednici temeljeni na Chromiumu, Safari i Internet Explorer: pritisnite i držite tipku ⇧ Shift i kliknite Osvježi u alatnoj traci Vašeg preglednika.

<!--'''MediaWiki:Common.js'''-->//<syntaxhighlight lang="javascript">

/* Učitavanje dodatnih skripti ako je potrebno */

if (mw.config.get('wgAction') === "edit" || mw.config.get('wgAction') === "submit" || mw.config.get('wgPageName') === "Posebno:Postavi_datoteku") // skripte za uređivanje stranica
{
    importScript("MediaWiki:Common.js/edit.js");
}
if (navigator.appName === "Microsoft Internet Explorer") // skripte za Internet Explorer
{
 importScript( 'MediaWiki:Common.js/IEfixes.js' );
}

/**
 * WikiMiniAtlas is a popup click and drag world map.
 * See [[meta:WikiMiniAtlas]] for more information.
 * Maintainers: [[w:User:Dschwen]]
 */
mw.loader.load( '//meta.wikimedia.org/w/index.php?title=MediaWiki:Wikiminiatlas.js&action=raw&ctype=text/javascript' );

/* {{mbox}}, {{ambox}}, {{ombox}}, {{fmbox}}, etc... */
mw.loader.load( '//www.mediawiki.org/w/index.php?title=MediaWiki:Gadget-enwp-boxes.css&action=raw&ctype=text/css', 'text/css' );


/** InterProjekti *******************************************************
  *
  * Opis: Poveznice na ostale wiki projekte za glavnu stranicu
  *       s de:wikt:Mediawiki:monobook.js
  *
  */
mw.loader.using('mediawiki.util', function() {
  mw.util.addCSS('#interProject {display: none; speak: none;} #p-tb .pBody {padding-right: 0;}');
});
$(function () {
	if(document.getElementById("interProject")) {
		var iProject = document.getElementById("interProject").innerHTML;
		var interProject = document.createElement("div");
		interProject.style.marginTop = "0.7em";
		interProject.innerHTML = '<h5>Drugi projekti<\/h5><div class="pBody">'+iProject+'<\/div>';
		document.getElementById("p-tb").appendChild(interProject);
	}
});

/** Main Page layout fixes *********************************************************
  *
  *  Description:        Various layout fixes for the main page, including an
  *                      additional link to the complete list of languages available
  *  Maintainers:        [[User:AzaToth]], [[User:R. Koot]]
  */

if (mw.config.get('wgIsMainPage') || mw.config.get('wgPageName') === 'Razgovor:Glavna_stranica') {
    $.when(mw.loader.using('mediawiki.util'), $.ready).then(function () {
        mw.util.addPortletLink('p-lang', '//meta.wikimedia.org/wiki/List_of_Wikipedias',
                 'Cijeli popis', 'interwiki-completelist', 'Popis svih Wikipedija');
    });
}

/* 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.
 */

function LinkFA()
{
   // iterate over all <span>-elements
   for(var i=0; a = document.getElementsByTagName("span")[i]; i++) {
      // if found a FA span
      if(a.className === "FA") {
         // iterate over all <li>-elements
         for(var j=0; b = document.getElementsByTagName("li")[j]; j++) {
            // if found a FA link
            if(b.className === "interwiki-" + a.id && b.className.indexOf("badge-featuredarticle") === -1 && b.className.indexOf("badge-goodarticle") === -1) {
               b.style.padding = "0 0 0 16px";
               b.style.backgroundImage = "url('//upload.wikimedia.org/wikipedia/en/6/60/LinkFA-star.png')";
               b.style.backgroundRepeat = "no-repeat";
               b.title = "Ovaj je članak dobio status izabranog članka";
            }
         }
      }
   }
}

$(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 = "sakrij";
var expandCaption = "otkrij";

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 j = 1; j < Rows.length; j++ ) {
            Rows[j].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.className = "collapseButton";  //Styles are declared in Common.css

            ButtonLink.style.color = Header.style.color;
            ButtonLink.setAttribute( "id", "collapseButton" + tableIndex );
            ButtonLink.setAttribute( "href", "#" );
            ButtonLink.addEventListener("click", new Function("e","e.preventDefault(); 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 );
        }
        else if ( hasClass( NavigationBoxes[i], "innercollapse" ) ) {
            var element = NavigationBoxes[i];
            while (element = element.parentNode) {
                if ( hasClass( element, "outercollapse" ) ) {
                    collapseTable ( i );
                    break;
                }
            }
        }
    }
}

$( createCollapseButtons );

// ============================================================
// BEGIN Dynamic Navigation Bars (experimantal)

// set up the words in your language
var NavigationBarHide = ' Sakrij ';
var NavigationBarShow = ' Otkrij ';

// set up max count of Navigation Bars on page,
// if there are more, all will be hidden
// NavigationBarShowDefault = 0; // all bars will be hidden
// NavigationBarShowDefault = 1; // on pages with more than 1 bar all bars will be hidden
var NavigationBarShowDefault = 1;


 // 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 (NavChild.className == 'NavPic') {
               NavChild.style.display = 'none';
           }
           if (NavChild.className == '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 (NavChild.className == 'NavPic') {
               NavChild.style.display = 'block';
           }
           if (NavChild.className == '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
   for(
           var i=0;
           NavFrame = document.getElementsByTagName("div")[i];
           i++
       ) {
       // if found a navigation bar
       if (NavFrame.className == "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);
           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 (NavFrame.childNodes[j].className == "NavHead") {
               NavFrame.childNodes[j].appendChild(NavToggle);
             }
           }
           NavFrame.setAttribute('id', 'NavFrame' + indexNavigationBar);
       }
   }
   // if more Navigation Bars found than Default: hide all
   if (NavigationBarShowDefault < indexNavigationBar) {
       for(
               var i=1;
               i<=indexNavigationBar;
               i++
        ) {
            toggleNavigationBar(i);
        }
    }

 }

 $(createNavigationBarToggleButton);

 // END Dynamic Navigation Bars
 // ============================================================

// The function looks for <span class="editsection">, and move them
// at the end of their parent and display them inline in small font.
// var oldEditsectionLinks=true disables the function.

function setModifySectionStyle() {
	try {
		if (!(typeof oldEditsectionLinks === 'undefined' || oldEditsectionLinks == false)) return;
		var spans = document.getElementsByTagName("span");
		for (var s = 0; s < spans.length; ++s) {
			var span = spans[s];
			if (span.className === "editsection") {
				span.style.fontSize = "xx-small";
				span.style.fontWeight = "normal";
				span.style.cssFloat = span.style.styleFloat = "none";
				span.className = "editsectionmoved";
				span.parentNode.appendChild(document.createTextNode(" "));
				span.parentNode.appendChild(span);
			}
		}
	} catch (e) { /* something went wrong */ }
}
$(setModifySectionStyle);

/* */

if(mw.config.get('wgAction') == 'submit' || mw.config.get('wgAction') == 'view') {
	mw.loader.using('mediawiki.util', function() {
		var cnote = document.getElementById('centralNotice');
		if( !document.getElementById('mw-dismissible-notice') && !(cnote && hasClass(cnote, 'expanded'))) return;
		mw.util.addCSS('#bodyContent { position:relative; } \n.topicon { position:absolute; top:-2em !important;}\n#coordinates{ position:absolute; top:1px !important; }');
	});
}

// Ispravno sortiranje u tablicama (koje koriste class="sortable").
mw.config.set('tableSorterCollation', {
    'č':'czz', 'Č':'CZZ',
    'ć':'czzz','Ć':'CZZZ',
    'dž':'dzz', 'Dž':'Dzz', 'dŽ':'dZZ', 'DŽ':'DZZ',
    'đ':'dzzz', 'Đ':'DZZZ',
    'lj':'lzz', 'Lj':'Lzz', 'lJ':'lZZ', 'LJ':'LZZ',
    'nj':'nzz', 'Nj':'Nzz', 'nJ':'nZZ', 'NJ':'NZZ',
    'š':'szz', 'Š':'SZZ',
    'ž':'zzz', 'Ž':'ZZZ'
});

//</syntaxhighlight>

function altRows() {
    var table = document.getElementById("kockastatablica");
    var tRows = table.getElementsByTagName("tr");
    var cssClassName;

    for(var i = 0; i < tRows.length; i++) {
        (i % 2 == 0) ? cssClassName = "odd" : cssClassName = "even";
        tRows[i].className = cssClassName;
    }
}

window.onload = altRows;