मीडियाविकि:Common.js
सूचना: यह पृष्ठ सुरक्षित करने बाद, परिवर्तनों को देखने लिए ब्राउज़र का कैश ख़ाली करने की आवश्यकता हो सकती है।
- मोज़िला / फ़ायरफ़ॉक्स / सफ़ारी: shift hold करें जब आप reload क्लिक करते है, या Ctrl-Shift-R (अपल मैक में Cmd-Shift-R) दबाएँ;
- गूगल क्रोम: Ctrl-shift-R (मैक में Cmd-Shift-R) दबाएँ
- इंटरनेट एक्सप्लोरर: Ctrl hold करें जब आप refresh क्लिक करते हैं, या Ctrl-F5 क्लिक करते हैं;
- कॉङ्करर: सिर्फ़ Reload बटन पर क्लिक करें, या F5 क्लिक करें;
- ऑपरा सदस्य को Tools→Preferences में सम्पूर्ण कैश ख़ाली करने की ज़रूरत हो सकती है।
/**
* @authors: Mayur Kumar ([[user:mayur]])
* @date 2010-10-09
* License: GPLv3, CC-BY-SA 3.0
*/
/*
=== MayurEdittoolsystem ===
*/
// switches for scripts
// TODO: migrate to JSConfig
//
var load_extratabs = true;
/*HERE STARTS THE WORKING-CODE OF "METABOXES"
*/
/* Funcionament de la Plantilla:Metacaixa
Implementat per: Usuari:Peleguer.
Actualitzat per Joanjoc seguint les indicacions d'en Martorell
*/
function MetaCaixaInit(){
//S'executa al carregar-se la pàgina, si hi ha metacaixes,
// s'assignen els esdeveniments als botons
//alert("MetaCaixaInit");
var i=0 //Inicialitzem comptador de caixes
for (i=0;i<=9;i++){
var vMc = document.getElementById("mc"+i);
if (!vMc) break;
//alert("MetaCaixaInit, trobada Metacaixa mc"+i);
var j=1 //Inicialitzem comptador de botons dins de la caixa
var vPsIni = 0 //Pestanya visible inicial
for (j=1;j<=9;j++){
var vBt = document.getElementById("mc"+i+"bt"+j);
if (!vBt) break;
//alert("MetaCaixaInit, trobat botó mc"+i+"bt"+j);
vBt.onclick = MetaCaixaMostraPestanya; //A cada botó assignem l'esdeveniment onclick
//alert (vBt.className);
if (vBt.className=="mcBotoSel") vPsIni=j; //Si tenim un botó seleccionat, en guardem l'index
}
//alert ("mc="+i+", ps="+j+", psini="+vPsIni );
if (vPsIni == 0) { //Si no tenim cap botó seleccionat, n'agafem un aleatòriament
vPsIni = 1+Math.floor((j-1)*Math.random()) ;
//alert ("Activant Pestanya a l'atzar; _mc"+i+"bt"+vPsIni +"_");
document.getElementById("mc"+i+"ps"+vPsIni).style.display = "block";
document.getElementById("mc"+i+"ps"+vPsIni).style.visibility = "visible";
document.getElementById("mc"+i+"bt"+vPsIni).className="mcBotoSel";
}
}
}
function MetaCaixaMostraPestanya(){
//S'executa al clicar una pestanya,
//aquella es fa visible i les altres s'oculten
var vMcNom = this.id.substr(0,3); //A partir del nom del botó, deduïm el nom de la caixa
var vIndex = this.id.substr(5,1); //I l'index
var i=1
for (i=1;i<=9;i++){ //busquem totes les pestanyes d'aquella caixa
//alert(vMcNom+"ps"+i);
var vPsElem = document.getElementById(vMcNom+"ps"+i);
if (!vPsElem) break;
if (vIndex==i){ //Si és la pestanya bona la mostrem i canviem la classe de botó
vPsElem.style.display = "block";
vPsElem.style.visibility = "visible";
document.getElementById(vMcNom+"bt"+i).className="mcBotoSel";
} else { //Sinó, l'ocultem i canviem la classe de botó
vPsElem.style.display = "none";
vPsElem.style.visibility = "hidden";
document.getElementById(vMcNom+"bt"+i).className="mcBoto";
}
}
return false; //evitem la recàrrega de la pàgina
}
jQuery( document ).ready( function( $ ) {
MetaCaixaInit();
} );
/*HERE FINISHES THE WORKING-CODE OF "METABOXES"</pre> */
/**
* 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() {
if ( document.getElementById( 'p-lang' ) ) {
var InterwikiLinks = document.getElementById( 'p-lang' ).getElementsByTagName( 'li' );
for ( var i = 0; i < InterwikiLinks.length; i++ ) {
var className = InterwikiLinks[i].className.match(/interwiki-[-\w]+/);
if ( document.getElementById( className + '-fa' ) && InterwikiLinks[i].className.indexOf( 'badge-featuredarticle' ) === -1 ) {
InterwikiLinks[i].className += ' FA';
InterwikiLinks[i].title = 'यह इस भाषा में एक निर्वाचित लेख है।';
} else if ( document.getElementById( className + '-ga' ) && InterwikiLinks[i].className.indexOf( 'badge-goodarticle' ) === -1 ) {
InterwikiLinks[i].className += ' GA';
InterwikiLinks[i].title = 'यह इस भाषा में एक श्रेष्ठ लेख है।';
}
}
}
}
mw.hook( 'wikipage.content' ).add( LinkFA );
/**
* 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');
function mainPageAppendCompleteListLink() {
try {
var node = document.getElementById( "p-lang" )
.getElementsByTagName('div')[0]
.getElementsByTagName('ul')[0];
var aNode = document.createElement( 'a' );
var liNode = document.createElement( 'li' );
aNode.appendChild( document.createTextNode( 'Complete list' ) );
aNode.setAttribute( 'href' , '//meta.wikimedia.org/wiki/List_of_Wikipedias' );
liNode.appendChild( aNode );
liNode.className = 'interwiki-completelist';
node.appendChild( liNode );
} catch(e) {
// lets just ignore what's happened
return;
}
}
if ( mw.config.get('wgIsMainPage') ) {
jQuery( document ).ready( function( $ ) {
mainPageAppendCompleteListLink();
} );
}
/**
* Collapsible tables *********************************************************
*
* Description: Allows tables to be collapsed, showing only the header. See
* [[Wikipedia:NavFrame]].
* Maintainers: [[User:R. Koot]]
*/
var autoCollapse = 2;
var collapseCaption = 'छुपाएँ';
var expandCaption = 'दिखाएँ';
window.collapseTable = function ( tableIndex ) {
var Button = document.getElementById( 'collapseButton' + tableIndex );
var Table = document.getElementById( 'collapsibleTable' + tableIndex );
if ( !Table || !Button ) {
return false;
}
var Rows = Table.rows;
var i;
if ( Button.firstChild.data === collapseCaption ) {
for ( i = 1; i < Rows.length; i++ ) {
Rows[i].style.display = 'none';
}
Button.firstChild.data = expandCaption;
} else {
for ( 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 = {};
var Tables = document.getElementsByTagName( 'table' );
var i;
function handleButtonLink( index, e ) {
window.collapseTable( index );
e.preventDefault();
}
for ( 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 Common.css */
ButtonLink.style.color = Header.style.color;
ButtonLink.setAttribute( 'id', 'collapseButton' + tableIndex );
ButtonLink.setAttribute( 'href', '#' );
$( ButtonLink ).on( 'click', $.proxy( handleButtonLink, ButtonLink, tableIndex ) );
ButtonLink.appendChild( ButtonText );
Button.appendChild( document.createTextNode( '[' ) );
Button.appendChild( ButtonLink );
Button.appendChild( document.createTextNode( ']' ) );
Header.insertBefore( Button, Header.firstChild );
tableIndex++;
}
}
for ( i = 0; i < tableIndex; i++ ) {
if ( $( NavigationBoxes[i] ).hasClass( 'collapsed' ) || ( tableIndex >= autoCollapse && $( NavigationBoxes[i] ).hasClass( 'autocollapse' ) ) ) {
window.collapseTable( i );
}
else if ( $( NavigationBoxes[i] ).hasClass ( 'innercollapse' ) ) {
var element = NavigationBoxes[i];
while ((element = element.parentNode)) {
if ( $( element ).hasClass( 'outercollapse' ) ) {
window.collapseTable ( i );
break;
}
}
}
}
}
mw.hook( 'wikipage.content' ).add( 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
**/
window.toggleNavigationBar = function ( indexNavigationBar, event ) {
var NavToggle = document.getElementById( 'NavToggle' + indexNavigationBar );
var NavFrame = document.getElementById( 'NavFrame' + indexNavigationBar );
var NavChild;
if ( !NavFrame || !NavToggle ) {
return false;
}
/* if shown now */
if ( NavToggle.firstChild.data === NavigationBarHide ) {
for ( NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling ) {
if ( $( NavChild ).hasClass( 'NavContent' ) || $( NavChild ).hasClass( 'NavPic' ) ) {
NavChild.style.display = 'none';
}
}
NavToggle.firstChild.data = NavigationBarShow;
/* if hidden now */
} else if ( NavToggle.firstChild.data === NavigationBarShow ) {
for ( NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling ) {
if ( $( NavChild ).hasClass( 'NavContent' ) || $( NavChild ).hasClass( 'NavPic' ) ) {
NavChild.style.display = 'block';
}
}
NavToggle.firstChild.data = NavigationBarHide;
}
event.preventDefault();
};
/* adds show/hide-button to navigation bars */
function createNavigationBarToggleButton() {
var indexNavigationBar = 0;
var NavFrame;
var NavChild;
/* iterate over all < div >-elements */
var divs = document.getElementsByTagName( 'div' );
for ( var i = 0; (NavFrame = divs[i]); i++ ) {
/* if found a navigation bar */
if ( $( NavFrame ).hasClass( 'NavFrame' ) ) {
indexNavigationBar++;
var NavToggle = document.createElement( 'a' );
NavToggle.className = 'NavToggle';
NavToggle.setAttribute( 'id', 'NavToggle' + indexNavigationBar );
NavToggle.setAttribute( 'href', '#' );
$( NavToggle ).on( 'click', $.proxy( window.toggleNavigationBar, window, indexNavigationBar ) );
var isCollapsed = $( NavFrame ).hasClass( 'collapsed' );
/**
* Check if any children are already hidden. This loop is here for backwards compatibility:
* the old way of making NavFrames start out collapsed was to manually add style="display:none"
* to all the NavPic/NavContent elements. Since this was bad for accessibility (no way to make
* the content visible without JavaScript support), the new recommended way is to add the class
* "collapsed" to the NavFrame itself, just like with collapsible tables.
*/
for ( NavChild = NavFrame.firstChild; NavChild != null && !isCollapsed; NavChild = NavChild.nextSibling ) {
if ( $( NavChild ).hasClass( 'NavPic' ) || $( NavChild ).hasClass( 'NavContent' ) ) {
if ( NavChild.style.display === 'none' ) {
isCollapsed = true;
}
}
}
if ( isCollapsed ) {
for ( NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling ) {
if ( $( NavChild ).hasClass( 'NavPic' ) || $( NavChild ).hasClass( 'NavContent' ) ) {
NavChild.style.display = 'none';
}
}
}
var NavToggleText = document.createTextNode( isCollapsed ? NavigationBarShow : 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] ).hasClass( 'NavHead' ) ) {
NavToggle.style.color = NavFrame.childNodes[j].style.color;
NavFrame.childNodes[j].appendChild( NavToggle );
}
}
NavFrame.setAttribute( 'id', 'NavFrame' + indexNavigationBar );
}
}
}
mw.hook( 'wikipage.content' ).add( createNavigationBarToggleButton );