Diferencia entre revisiones de «MediaWiki:Common.js»

De 15Mpedia
Saltar a: navegación, buscar
(siempre colapsadas)
(cuando visitas el wiki como anónimo, las navbox no se colapsan siempre aparecen desplegadas, a ver si este nuevo código funciona)
Línea 45: Línea 45:
 
}
 
}
  
/**
+
    /**
* Collapsible tables *********************************************************
+
* Collapsible tables; reimplemented with mw-collapsible
*
+
* Styling is also in place to avoid FOUC
* Description: Allows tables to be collapsed, showing only the header. See
+
*
*              [[Wikipedia:NavFrame]].
+
* Allows tables to be collapsed, showing only the header. See [[Help:Collapsing]].
* Maintainers: [[User:R. Koot]]
+
* @version 3.0.0 (2018-05-20)
*/
+
* @source https://www.mediawiki.org/wiki/MediaWiki:Gadget-collapsibleTables.js
+
* @author [[User:R. Koot]]
var autoCollapse = 0;
+
* @author [[User:Krinkle]]
var collapseCaption = 'ocultar';
+
* @author [[User:TheDJ]]
var expandCaption = 'mostrar';
+
* @deprecated Since MediaWiki 1.20: Use class="mw-collapsible" instead which
+
* is supported in MediaWiki core. Shimmable since MediaWiki 1.32
window.collapseTable = function ( tableIndex ) {
+
*
    var Button = document.getElementById( 'collapseButton' + tableIndex );
+
* @param {jQuery} $content
    var Table = document.getElementById( 'collapsibleTable' + tableIndex );
+
*/
+
function makeCollapsibleMwCollapsible( $content ) {
    if ( !Table || !Button ) {
+
var $tables = $content
        return false;
+
.find( 'table.collapsible:not(.mw-collapsible)' )
    }
+
.addClass( 'mw-collapsible' );
+
 
    var Rows = Table.rows;
+
$.each( $tables, function ( index, table ) {
    var i;
+
// mw.log.warn( 'This page is using the deprecated class collapsible. Please replace it with mw-collapsible.');
+
if ( $( table ).hasClass( 'collapsed' ) ) {
    if ( Button.firstChild.data === collapseCaption ) {
+
$( table ).addClass( 'mw-collapsed' );
        for ( i = 1; i < Rows.length; i++ ) {
+
// mw.log.warn( 'This page is using the deprecated class collapsed. Please replace it with mw-collapsed.');
            Rows[i].style.display = 'none';
+
}
        }
+
} );
        Button.firstChild.data = expandCaption;
+
if ( $tables.length > 0 ) {
    } else {
+
mw.loader.using( 'jquery.makeCollapsible' ).then( function () {
        for ( i = 1; i < Rows.length; i++ ) {
+
$tables.makeCollapsible();
            Rows[i].style.display = Rows[0].style.display;
+
} );
        }
+
}
        Button.firstChild.data = collapseCaption;
+
}
    }
+
mw.hook( 'wikipage.content' ).add( makeCollapsibleMwCollapsible );
};
+
 
+
/**
function createCollapseButtons() {
+
* Add support to mw-collapsible for autocollapse, innercollapse and outercollapse
    var tableIndex = 0;
+
*
    var NavigationBoxes = {};
+
* Maintainers: TheDJ
    var Tables = document.getElementsByTagName( 'table' );
+
*/
    var i;
+
function mwCollapsibleSetup( $collapsibleContent ) {
+
var $element,
    function handleButtonLink( index, e ) {
+
$toggle,
        window.collapseTable( index );
+
autoCollapseThreshold = 2;
        e.preventDefault();
+
$.each( $collapsibleContent, function ( index, element ) {
    }
+
$element = $( element );
+
if ( $element.hasClass( 'collapsible' ) ) {
    for ( i = 0; i < Tables.length; i++ ) {
+
$element.find( 'tr:first > th:first' ).prepend( $element.find( 'tr:first > * > .mw-collapsible-toggle' ) );
        if ( $( Tables[i] ).hasClass( 'collapsible' ) ) {
+
}
+
if ( $collapsibleContent.length >= autoCollapseThreshold && $element.hasClass( 'autocollapse' ) ) {
            /* only add button and increment count if there is a header row to work with */
+
$element.data( 'mw-collapsible' ).collapse();
            var HeaderRow = Tables[i].getElementsByTagName( 'tr' )[0];
+
} else if ( $element.hasClass( 'innercollapse' ) ) {
            if ( !HeaderRow ) continue;
+
if ( $element.parents( '.outercollapse' ).length > 0 ) {
            var Header = HeaderRow.getElementsByTagName( 'th' )[0];
+
$element.data( 'mw-collapsible' ).collapse();
            if ( !Header ) continue;
+
}
+
}
            NavigationBoxes[ tableIndex ] = Tables[i];
+
// because of colored backgrounds, style the link in the text color
            Tables[i].setAttribute( 'id', 'collapsibleTable' + tableIndex );
+
// to ensure accessible contrast
+
$toggle = $element.find( '.mw-collapsible-toggle' );
            var Button    = document.createElement( 'span' );
+
if ( $toggle.length ) {
            var ButtonLink = document.createElement( 'a' );
+
// Make the toggle inherit text color (Updated for T333357 2023-04-29)
            var ButtonText = document.createTextNode( collapseCaption );
+
if ( $toggle.parent()[ 0 ].style.color ) {
+
$toggle.css( 'color', 'inherit' );
            Button.className = 'collapseButton';  /* Styles are declared in Common.css */
+
$toggle.find( '.mw-collapsible-text' ).css( 'color', 'inherit' );
+
}
            ButtonLink.style.color = Header.style.color;
+
}
            ButtonLink.setAttribute( 'id', 'collapseButton' + tableIndex );
+
} );
            ButtonLink.setAttribute( 'href', '#' );
+
}
            $( ButtonLink ).on( 'click', $.proxy( handleButtonLink, ButtonLink, tableIndex ) );
+
 
            ButtonLink.appendChild( ButtonText );
+
mw.hook( 'wikipage.collapsibleContent' ).add( mwCollapsibleSetup );
+
            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;
+
                }
+
            }
+
        }
+
    }
+
}
+
+
$( createCollapseButtons );
+

Revisión de 18:23 25 jul 2023

/* Cualquier código JavaScript escrito aquí se cargará para todos los usuarios en cada carga de página */
 
// oculta categorías en español en páginas de otros idiomas
/*if ( mw.config.get( 'wgNamespaceNumber') === 0 && mw.config.get( 'wgPageName' ).indexOf('/') === (mw.config.get( 'wgPageName' ).length - 3) ) {
    document.getElementById('catlinks').style.display = "none";
}*/
 
//buscador
document.getElementById('p-search').style.width = '400px';
document.getElementById('searchform').style.width = '400px';
document.getElementById('simpleSearch').style.width = '400px';
document.getElementById('searchInput').style.width = '400px';
document.getElementById('searchInput').style.fontWeight = 'bold';
document.getElementById('searchInput').style.fontSize = '95%';
document.getElementById('simpleSearch').style.border = '2px solid #347BFF';
document.getElementById('searchInput').focus();
 
// negritas en pestaña [editar]
if (document.getElementById('ca-form_edit')) {
    document.getElementById('ca-form_edit').getElementsByTagName('a')[0].text = 'Modificar';
    document.getElementById('ca-form_edit').style.fontWeight = 'bold';
    document.getElementById('ca-edit').getElementsByTagName('a')[0].text = 'Código fuente';
} else {
    document.getElementById('ca-edit').getElementsByTagName('a')[0].text = 'Modificar';
    document.getElementById('ca-edit').style.fontWeight = 'bold';
}
var editsections = document.getElementsByClassName("editsection");
[].forEach.call(editsections, function (editsection) { editsection.getElementsByTagName('a')[0].text = 'modificar' });
 
// iconos de compartir en FB, TW, etc
document.getElementById('firstHeading').innerHTML = '<div><span style="float: right;"><a href="https://www.facebook.com/sharer/sharer.php?u='+document.URL+'" title="Compartir esta página en Facebook"><img alt="Facebook.png" src="/w/images/5/55/Facebook.png" width="15" height="15" /></a>&#160;<a href="https://twitter.com/intent/tweet?text=Estoy+leyendo+'+encodeURIComponent(document.URL)+'+en+%4015Mpedia" title="Compartir esta página en Twitter"><img alt="Twitter.png" src="/w/images/f/f7/Twitter.png" width="15" height="19" /></a></span></div>' + document.getElementById('firstHeading').innerHTML;
//document.getElementById('firstHeading').innerHTML = '<div><span style="float: right;"><a href="https://www.facebook.com/sharer/sharer.php?u='+document.URL+'" title="Compartir esta página en Facebook"><img alt="Facebook.png" src="/w/images/5/55/Facebook.png" width="15" height="15" /></a>&#160;<a href="https://twitter.com/home?status=Estoy+leyendo+'+encodeURIComponent(document.URL)+'+en+%4015Mpedia" title="Compartir esta página en Twitter"><img alt="Twitter.png" src="/w/images/f/f7/Twitter.png" width="15" height="19" /></a>&#160;<a href="https://identi.ca/notice/new?status_textarea=Estoy+leyendo+'+encodeURIComponent(document.URL)+'+en+15Mpedia" title="Compartir esta página en Identi.ca"><img alt="Identica.png" src="/w/images/9/9e/Identica.png" width="15" height="15" /></a></span></div>' + document.getElementById('firstHeading').innerHTML;
 
// ocultar h1 de headertabs en TOC
var liobjs = document.getElementsByTagName('li');
for (var i = 0; i < liobjs.length; i++)
{
   if (liobjs.item(i).className == 'toclevel-1' && liobjs.item(i).innerHTML.indexOf('<span></span>') != -1) { liobjs.item(i).style.display = 'none'; }
}
 
// ocultar thumb en archivos embebidos
if ( mw.config.get( 'wgNamespaceNumber' ) == 6 && mw.config.get( 'wgCategories' ).indexOf('Archivos embebidos') > -1 ) {
  document.getElementById('file').style.display = 'none';
  //no funciona //document.getElementsByTagName('fullMedia').style.display = 'none';
}
 
    /**
	 * Collapsible tables; reimplemented with mw-collapsible
	 * Styling is also in place to avoid FOUC
	 *
	 * Allows tables to be collapsed, showing only the header. See [[Help:Collapsing]].
	 * @version 3.0.0 (2018-05-20)
	 * @source https://www.mediawiki.org/wiki/MediaWiki:Gadget-collapsibleTables.js
	 * @author [[User:R. Koot]]
	 * @author [[User:Krinkle]]
	 * @author [[User:TheDJ]]
	 * @deprecated Since MediaWiki 1.20: Use class="mw-collapsible" instead which
	 * is supported in MediaWiki core. Shimmable since MediaWiki 1.32
	 *
	 * @param {jQuery} $content
	 */
	function makeCollapsibleMwCollapsible( $content ) {
		var $tables = $content
			.find( 'table.collapsible:not(.mw-collapsible)' )
			.addClass( 'mw-collapsible' );
 
		$.each( $tables, function ( index, table ) {
			// mw.log.warn( 'This page is using the deprecated class collapsible. Please replace it with mw-collapsible.');
			if ( $( table ).hasClass( 'collapsed' ) ) {
				$( table ).addClass( 'mw-collapsed' );
				// mw.log.warn( 'This page is using the deprecated class collapsed. Please replace it with mw-collapsed.');
			}
		} );
		if ( $tables.length > 0 ) {
			mw.loader.using( 'jquery.makeCollapsible' ).then( function () {
				$tables.makeCollapsible();
			} );
		}
	}
	mw.hook( 'wikipage.content' ).add( makeCollapsibleMwCollapsible );
 
	/**
	 * Add support to mw-collapsible for autocollapse, innercollapse and outercollapse
	 *
	 * Maintainers: TheDJ
	 */
	function mwCollapsibleSetup( $collapsibleContent ) {
		var $element,
			$toggle,
			autoCollapseThreshold = 2;
		$.each( $collapsibleContent, function ( index, element ) {
			$element = $( element );
			if ( $element.hasClass( 'collapsible' ) ) {
				$element.find( 'tr:first > th:first' ).prepend( $element.find( 'tr:first > * > .mw-collapsible-toggle' ) );
			}
			if ( $collapsibleContent.length >= autoCollapseThreshold && $element.hasClass( 'autocollapse' ) ) {
				$element.data( 'mw-collapsible' ).collapse();
			} else if ( $element.hasClass( 'innercollapse' ) ) {
				if ( $element.parents( '.outercollapse' ).length > 0 ) {
					$element.data( 'mw-collapsible' ).collapse();
				}
			}
			// because of colored backgrounds, style the link in the text color
			// to ensure accessible contrast
			$toggle = $element.find( '.mw-collapsible-toggle' );
			if ( $toggle.length ) {
				// Make the toggle inherit text color (Updated for T333357 2023-04-29)
				if ( $toggle.parent()[ 0 ].style.color ) {
					$toggle.css( 'color', 'inherit' );
					$toggle.find( '.mw-collapsible-text' ).css( 'color', 'inherit' );
				}
			}
		} );
	}
 
	mw.hook( 'wikipage.collapsibleContent' ).add( mwCollapsibleSetup );