MediaWiki:Common.js

De la Wikiștiri

Notă: După salvare, trebuie să treceți peste cache-ul browser-ului pentru a vedea modificările. Mozilla/Safari/Konqueror: țineți apăsat Shift în timp ce apăsați Reload (sau apăsați Ctrl-Shift-R), IE: apăsați Ctrl-F5, Opera: apăsați F5.

// support for project:IRC
 $(function () {
	mw.loader.load('//yi.wiktionary.org/w/index.php?title=mediawiki:Irc.js&action=raw&ctype=text/javascript');
 });

// template:Ticker
 $(function () {if ((window.disable_ticker2 !== true) && (document.getElementById("singleTickerForPage") || document.getElementById('enableTickers'))) importScript("MediaWiki:ticker2.js");});

 //Twitter/facebook etc. See [[template:Social bookmarks]]
 //makes stuff in id="social_bookmarks" open in new window
 //and dynamically re-writes links to twitter to shorten urls
var newSmallPopup = function(url) {
return (function () {
window.open(url, "_blank", "width=640,height=480,menubar,resizable,scrollbars,status,toolbar");
return false;
});
}

/** Administrare afișare diacritice. Vedeți [[Wikiștiri:Corectarea diacriticelor]] */
 
importScript("MediaWiki:Diacritice.js");
 
/** End administrare diacritice *************/

$(function () {
var soc = document.getElementById('social_bookmarks');
if (soc) {
var links = soc.getElementsByTagName('a')
for (i=0;i<links.length;i++) {
if ( links[i].href.indexOf("http://twitter.com/?status") === 0) { /*isTwitter*/
links[i].href = "http://twitter.com/?status=" + encodeURIComponent("Uite ce am găsit pe Wikiştiri: http://enwn.net/+" + mw.config.get('wgArticleId'));
//enwn.net is owned by ShakataGaNai
}
links[i].onclick = newSmallPopup(links[i].href);
}}});

//

/** Collapsible tables *********************************************************
 *
 *  Description: Allows tables to be collapsed, showing only the header. See
 *                         http://www.mediawiki.org/wiki/Manual:Collapsible_tables.
 *  Maintainers: [[en:User:R. Koot]]
 */
 
var autoCollapse = 2;
var collapseCaption = 'ascunde';
var expandCaption = 'arată';
 
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 ( $(Tables[i]).hasClass( '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 [[MediaWiki:Common.css]]
 
                        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 ( $(NavigationBoxes[i]).hasClass( 'collapsed' ) || ( tableIndex >= autoCollapse && $(NavigationBoxes[i]).hasClass( 'autocollapse' ) ) ) {
                        collapseTable( i );
                } else if ( $(NavigationBoxes[i]).hasClass( 'innercollapse' ) ) {
                        var element = NavigationBoxes[i];
                        while ( element = element.parentNode ) {
                                if ( $(element).hasClass( 'outercollapse' ) ) {
                                        collapseTable( i );
                                        break;
                                }
                        }
                }
        }
}
 
$( createCollapseButtons );