Usuario:Edmenb/mod gadget
Apariencia
/**
* Sidebar
*
*/
// Protege contra doble inclusión
if ( window.gadgetSidebar === undefined ) {
//Global
var gadgetSidebar = {
'habilitado': true
};
//Enlaza con window
window.gadgetSidebar = gadgetSidebar;
//Scope local para no contaminar espacio global
(function ( $, mw ) {
'use strict';
gadgetSidebar.agregarSeccion = function ( section, name ) {
var $node;
if ( mw.config.get ( 'skin' ) == "vector" ) {
$node = $( '<div class="portal collapsed"><h5>' + name +
'</h5><div class="body"><ul></ul></div></div>' );
} else {
$node = $( '<div class="portlet"><h5>' + name +
'</h5><div class="pBody"><ul></ul></div></div>' );
}
$node.prop( 'id', 'p-' + section );
$( '#p-tb' ).after( $node );
};
gadgetSidebar.modificarEnlace = function ( action, section, name, link ) {
var target;
try {
switch ( section ) {
case "navegación":
case "navigation":
target = "#p-navigation";
break;
case "toolbox":
case "herramientas":
target = "#p-tb";
break;
case "languages":
case "idiomas":
target = "#p-lang";
break;
default:
target = "#p-" + section;
break;
}
if ( action == "add" ) {
var $node = $( target ).find( 'ul' ),
aNode = document.createElement( 'a' ),
liNode = document.createElement( 'li' );
aNode.appendChild( document.createTextNode( name ) );
aNode.setAttribute( 'href', link );
liNode.appendChild( aNode );
liNode.className = 'plainlinks';
$node.append( liNode );
} else if ( action == "remove" ) {
var list = $( target ).find( 'ul' ),
listA = list.find( 'a' ),
listALargo = listA.length,
i;
for ( i = 0; i < listALargo; i++ ) {
if ( listA[i].innerHTML == name || listA[i].href == link ) {
list[0].removeChild( listA[i].parentNode );
break;
}
}
}
} catch (e) {
// lets just ignore what's happened
return;
}
};
function ejecutar() {
if ( gadgetSidebar.habilitado ) {
var articlePath = mw.config.get( 'wgArticlePath' );
gadgetSidebar.agregarSeccion( 'enlaceswiki', 'Enlaces Wikilibros' );
gadgetSidebar.modificarEnlace( 'add', 'enlaceswiki',
'common.js',
articlePath.replace( '$1', 'User:' +
mw.config.get( 'wgUserName' ) + '/' +
'common.js' )
);
gadgetSidebar.modificarEnlace( 'add', 'enlaceswiki',
'common.css',
articlePath.replace( '$1', 'User:' +
mw.config.get( 'wgUserName' ) + '/' +
'common.css' )
);
gadgetSidebar.modificarEnlace( 'add', 'enlaceswiki',
'Tablón de bibliotecarios',
articlePath.replace( '$1',
'Wikilibros:Tablón_de_anuncios_de_los_bibliotecarios' )
);
gadgetSidebar.modificarEnlace( 'add', 'enlaceswiki',
'Vandalismo en curso',
articlePath.replace( '$1',
'Wikilibros:Vandalismo_en_curso' )
);
gadgetSidebar.modificarEnlace( 'add', 'enlaceswiki',
'Zona de pruebas',
articlePath.replace( '$1',
'Wikilibros:Zona_de_pruebas' )
);
gadgetSidebar.modificarEnlace( 'add', 'enlaceswiki',
'El Café',
articlePath.replace( '$1',
'Wikilibros:Café' )
);
gadgetSidebar.modificarEnlace( 'add', 'enlaceswiki',
'Solicitud bot',
articlePath.replace( '$1',
'Wikilibros:Votaciones' )
);
gadgetSidebar.modificarEnlace( 'add', 'enlaceswiki',
'Mantenimiento',
articlePath.replace( '$1',
'Categoría:Wikilibros:Mantenimiento' )
);
gadgetSidebar.modificarEnlace( 'add', 'enlaceswiki',
'Vandalismo en curso',
articlePath.replace( '$1',
'Wikilibros:Vandalismo_en_curso' )
);
gadgetSidebar.modificarEnlace( 'add', 'enlaceswiki',
'Libros por mejorar',
articlePath.replace( '$1',
'Categoría:Wikilibros:Libros por mejorar' )
);
}
}
$(document).ready( ejecutar );
})( jQuery, mediaWiki ); // Fin de función anónima
} //fin de chequeo
//