Diferencia entre revisiones de «MediaWiki:Common.js»
De 15Mpedia
(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 ********************************************************* | |
− | + | * | |
− | + | * 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 ); |
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> <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> <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> <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 );