Diferencia entre revisiones de «MediaWiki:Common.js»

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

Revisión de 19:16 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 *********************************************************
 *
 * Description: Allows tables to be collapsed, showing only the header. See
 *              [[Wikipedia:NavFrame]].
 * Maintainers: [[User:R. Koot]]
 */
 
var autoCollapse = 0;
var collapseCaption = 'ocultar';
var expandCaption = 'mostrar';
 
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;
                }
            }
        }
    }
}
 
$( createCollapseButtons );