MediaWiki:Common.js: diferenças entre revisões
Conteúdo apagado Conteúdo adicionado
Linha 106: | Linha 106: | ||
//scripts específicos para Internet Explorer |
//scripts específicos para Internet Explorer |
||
importScript( 'MediaWiki:Common.js/IEFixes.js' ); |
importScript( 'MediaWiki:Common.js/IEFixes.js' ); |
||
} |
|||
/** Para administradores |
|||
* Permite a inclusão de CSS específico para administradores e eliminadores |
|||
* por meio das páginas [[MediaWiki:Sysop.css]] e [[MediaWiki:Eliminator.css]] |
|||
* @source: [[w:en:MediaWiki:Common.js]] |
|||
*/ |
|||
if ( $.inArray( 'sysop', mw.config.get('wgUserGroups') ) > -1 ) { |
|||
importStylesheet('MediaWiki:Sysop.css'); |
|||
} |
|||
if ( $.inArray( 'eliminator', mw.config.get('wgUserGroups') ) > -1 ) { |
|||
importStylesheet('MediaWiki:Eliminator.css'); |
|||
} |
} |
||
Linha 256: | Linha 268: | ||
* @return {boolean} Caso não encontre a tabela ou o botão com o índice informado retorna false |
* @return {boolean} Caso não encontre a tabela ou o botão com o índice informado retorna false |
||
*/ |
*/ |
||
function collapseTable( |
function collapseTable(tableIndex) { |
||
var |
var i, |
||
Button = document.getElementById('collapseButton' + tableIndex), |
|||
Table = document.getElementById('collapsibleTable' + tableIndex); |
|||
if ( !Table || !Button ) { |
if ( !Table || !Button ) { |
||
Linha 281: | Linha 293: | ||
function createCollapseButtons() { |
function createCollapseButtons() { |
||
var |
var i, tableIndex = 0, |
||
⚫ | |||
var tableIndex = 0; |
|||
⚫ | |||
⚫ | |||
⚫ | |||
for (i = 0; i < Tables.length; i++) { |
for (i = 0; i < Tables.length; i++) { |
||
Linha 290: | Linha 301: | ||
/* only add button and increment count if there is a header row to work with */ |
/* only add button and increment count if there is a header row to work with */ |
||
var HeaderRow = Tables[i].getElementsByTagName( |
var HeaderRow = Tables[i].getElementsByTagName('tr')[0]; |
||
if (!HeaderRow) {continue; |
if (!HeaderRow) { |
||
continue; |
|||
} |
|||
var Header = HeaderRow.getElementsByTagName( |
var Header = HeaderRow.getElementsByTagName('th')[0]; |
||
if (!Header) { |
if (!Header) { |
||
continue; |
|||
} |
|||
NavigationBoxes[tableIndex] = Tables[i]; |
NavigationBoxes[tableIndex] = Tables[i]; |
||
Tables[i].setAttribute( 'id', 'collapsibleTable' + tableIndex); |
Tables[i].setAttribute( 'id', 'collapsibleTable' + tableIndex); |
||
var |
var Button = document.createElement( 'span' ), |
||
ButtonLink = document.createElement( 'a' ), |
|||
ButtonText = document.createTextNode( collapseCaption ); |
|||
Button.style.styleFloat = 'right'; |
|||
Button.style.cssFloat = 'right'; |
|||
Button.style.fontWeight = 'normal'; |
|||
Button.style.textAlign = 'right'; |
|||
⚫ | |||
Button.className = 'collapseButton'; //Styles are declared in Common.css |
|||
ButtonLink.style.color = Header.style.color; |
ButtonLink.style.color = Header.style.color; |
||
ButtonLink.setAttribute( |
ButtonLink.setAttribute('id', 'collapseButton' + tableIndex); |
||
ButtonLink.setAttribute( |
ButtonLink.setAttribute('href', '#'); |
||
addHandler(ButtonLink, 'click', new Function('evt', 'collapseTable(' + tableIndex + ' ); return killEvt( evt );')); |
|||
ButtonLink.appendChild(ButtonText); |
ButtonLink.appendChild(ButtonText); |
||
Linha 325: | Linha 336: | ||
if (hasClass(NavigationBoxes[i], 'collapsed' ) || (tableIndex >= autoCollapse && hasClass(NavigationBoxes[i], 'autocollapse' ))) { |
if (hasClass(NavigationBoxes[i], 'collapsed' ) || (tableIndex >= autoCollapse && hasClass(NavigationBoxes[i], 'autocollapse' ))) { |
||
collapseTable(i); |
collapseTable(i); |
||
} else if (hasClass(NavigationBoxes[i], 'innercollapse')) { |
|||
var element = NavigationBoxes[i]; |
|||
element = element.parentNode; |
|||
while (element) { |
|||
⚫ | |||
collapseTable(i); |
|||
⚫ | |||
} |
|||
element = element.parentNode; |
|||
} |
|||
} |
} |
||
} |
} |
||
Linha 349: | Linha 370: | ||
*/ |
*/ |
||
function toggleNavigationBar(indexNavigationBar) { |
function toggleNavigationBar(indexNavigationBar) { |
||
var |
var NavChild, |
||
NavToggle = document.getElementById('NavToggle' + indexNavigationBar), |
|||
NavFrame = document.getElementById('NavFrame' + indexNavigationBar); |
|||
if (!NavFrame || !NavToggle) { |
if (!NavFrame || !NavToggle) { |
||
Linha 359: | Linha 380: | ||
// if shown now |
// if shown now |
||
if (NavToggle.firstChild.data == NavigationBarHide) { |
if (NavToggle.firstChild.data == NavigationBarHide) { |
||
for (NavChild = NavFrame.firstChild; NavChild !== null; NavChild = NavChild.nextSibling) { |
|||
for ( |
|||
⚫ | |||
NavChild = NavFrame.firstChild; |
|||
NavChild !== null; |
|||
NavChild = NavChild.nextSibling) { |
|||
⚫ | |||
NavChild.style.display = 'none'; |
NavChild.style.display = 'none'; |
||
} |
} |
||
Linha 371: | Linha 389: | ||
// if hidden now |
// if hidden now |
||
} else if (NavToggle.firstChild.data == NavigationBarShow) { |
} else if (NavToggle.firstChild.data == NavigationBarShow) { |
||
for (NavChild = NavFrame.firstChild; NavChild !== null; NavChild = NavChild.nextSibling) { |
|||
for ( |
|||
⚫ | |||
NavChild = NavFrame.firstChild; |
|||
NavChild !== null; |
|||
NavChild = NavChild.nextSibling) { |
|||
⚫ | |||
NavChild.style.display = 'block'; |
NavChild.style.display = 'block'; |
||
} |
} |
||
Linha 385: | Linha 400: | ||
// adds show/hide-button to navigation bars |
// adds show/hide-button to navigation bars |
||
function createNavigationBarToggleButton() { |
function createNavigationBarToggleButton() { |
||
var |
var NavChild, |
||
indexNavigationBar = 0, |
|||
// iterate over all < div >-elements |
|||
divs = document.getElementsByTagName('div'); |
|||
NavFrame = divs[0]; |
NavFrame = divs[0]; |
||
for ( var i = 0; NavFrame; i++ ) { |
for ( var i = 0; NavFrame; i++ ) { |
||
Linha 399: | Linha 415: | ||
NavToggle.setAttribute( 'href', 'javascript:toggleNavigationBar(' + indexNavigationBar + ');' ); |
NavToggle.setAttribute( 'href', 'javascript:toggleNavigationBar(' + indexNavigationBar + ');' ); |
||
var isCollapsed = hasClass(NavFrame, 'collapsed'); |
|||
⚫ | |||
/* |
|||
* Check if any children are already hidden. This loop is here for backwards compatibility: |
|||
var NavChild = NavFrame.firstChild; |
|||
* the old way of making NavFrames start out collapsed was to manually add style="display:none" |
|||
NavChild !== null; |
|||
* to all the NavPic/NavContent elements. Since this was bad for accessibility (no way to make |
|||
NavChild = NavChild.nextSibling) { |
|||
* 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. |
|||
⚫ | |||
⚫ | |||
NavToggleText = document.createTextNode(NavigationBarShow); |
|||
for (NavChild = NavFrame.firstChild; NavChild !== null && !isCollapsed; NavChild = NavChild.nextSibling) { |
|||
⚫ | |||
⚫ | |||
⚫ | |||
isCollapsed = true; |
|||
} |
} |
||
} |
} |
||
} |
} |
||
if (isCollapsed) { |
|||
for (NavChild = NavFrame.firstChild; NavChild !== null; NavChild = NavChild.nextSibling) { |
|||
if (hasClass(NavChild, 'NavPic') || hasClass(NavChild, 'NavContent')) { |
|||
⚫ | |||
} |
|||
} |
|||
} |
|||
⚫ | |||
NavToggle.appendChild(NavToggleText); |
NavToggle.appendChild(NavToggleText); |
||
// Find the NavHead and attach the toggle link (Must be this complicated because Moz's firstChild handling is borked) |
// 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 (hasClass(NavFrame.childNodes[j], 'NavHead')) { |
|||
var j = 0; |
|||
NavToggle.style.color = NavFrame.childNodes[j].style.color; |
|||
j++) { |
|||
⚫ | |||
NavFrame.childNodes[j].appendChild(NavToggle); |
NavFrame.childNodes[j].appendChild(NavToggle); |
||
} |
} |
Revisão das 16h35min de 12 de agosto de 2011
/* Todo código JavaScript presente aqui será carregado por todos os usuários em cada página carregada. */
/**
* Extração de um parâmetro da URL atual ou da URL fornecida
* @deprecated: Use mw.util.getParamValue(paramName, [optional: url]) em vez desta função.
*/
function getURLParamValue( paramName, url ) {
return mw.util.getParamValue( paramName, url );
}
// Remover quando a [[rev:87208]] e a [[rev:91500]] forem aplicadas à cópia do MW em uso nas wikis da WMF
mw.util.wikiGetlink = function( str ) {
return mw.config.get( 'wgArticlePath' ).replace( '$1',
mw.util.wikiUrlencode( str || mw.config.get( 'wgPageName' ) ) );
};
/* Test if an element has a certain class
* Maintainers: [[User:Mike Dillon]], [[User:R. Koot]], [[User:SG]]
*
* @deprecated: Use $(element).hasClass() instead.
*/
var hasClass = (function () {
var reCache = {};
return function (element, className) {
return (reCache[className] ? reCache[className] : (reCache[className] = new RegExp( '(?:\\s|^)' + className + '(?:\\s|$)' ))).test(element.className);
};
})();
// makeCollapsible (remover assim que estiver disponível por padrão no MediaWiki)
importStylesheet('MediaWiki:JQuery-makeCollapsible.css');
importScript('MediaWiki:JQuery-makeCollapsible.js');
//Scripts para páginas e/ou domínios específicos
switch( mw.config.get( 'wgCanonicalNamespace' ) ) {
case 'Special':
switch( mw.config.get( 'wgTitle' ) ) {
case 'Pesquisar':
// Scripts específicos para a página de pesquisas
//TAREFA: Corrigir o script da página de pesquisa para que funcione com o servidor seguro
if ( mw.config.get( 'wgServer' ) !== 'https://secure.wikimedia.org' ) {
importScript( 'MediaWiki:Common.js/search.js' );
}
break;
case 'Carregar imagem':
importScript( 'MediaWiki:UploadForm.js' );
break;
case 'Páginas vigiadas':
importScript( 'MediaWiki:Common.js/watchlist.js');
break;
}
break;
case 'Project':
case 'Project_talk':
switch( mw.config.get( 'wgTitle' ) ) {
case 'Página principal':
/**
* Melhorias na página principal
* Adiciona um link a lista completa de wikipédias em outras línguas e altera o texto exibido na aba
*
* @author: [[User:AzaToth]], [[User:R. Koot]], [[User:Alex Smotrov]]
* @source: [[en:MediaWiki:Common.js]]
*/
$(function () {
mw.util.addPortletLink( 'p-lang', mw.util.wikiGetlink( 'Wikipédia:Wikipédia em outras línguas' ),
'Lista completa', 'interwiki-completelist', 'Lista completa de Wikipédias' );
if ( mw.config.get( 'wgUserLanguage' ).substr( 0, 2 ) === 'pt' ) {
$( '#ca-nstab-project a' ).text( 'Página principal' );
}
});
break;
case 'Esplanada/propostas':
case 'Esplanada/geral':
/*
* Oculta botão editar da [[Wikipédia:Esplanada/propostas]] e da [[Wikipédia:Esplanada/geral]]
*/
$(function () {
var href = mw.util.wikiGetlink( mw.config.get( 'wgPageName' ) )
+ '?action=edit§ion=new&preload=Template:Esplanada2/Preload';
if ( mw.config.get( 'wgUserLanguage' ).substr( 0, 2 ) !== 'pt' ) {
href += '/en';
}
$( '#ca-addsection a' ).attr( 'href', href );
if ( 'vector' === mw.config.get( 'skin' ) ) {
// Move o botão "editar" para o menu de ações
$('#ca-edit').appendTo('#p-cactions ul');
}
});
break;
}
break;
case 'File':
// Adiciona links para versões PNG em imagens SVG
importScript( 'MediaWiki:Common.js/SVGPNG.js' );
break;
case 'MediaWiki':
break;
default:
// Todos os demais domínios
importScript( 'MediaWiki:Wikibugs.js' );
}
if ( $.inArray( mw.config.get( 'wgAction' ), ['edit', 'submit'] ) > -1 ) {
//scripts específicos para editar páginas
importScript( 'MediaWiki:Common.js/edit.js' );
}
if ( $.client.profile().name === 'msie' ) {
//scripts específicos para Internet Explorer
importScript( 'MediaWiki:Common.js/IEFixes.js' );
}
/** Para administradores
* Permite a inclusão de CSS específico para administradores e eliminadores
* por meio das páginas [[MediaWiki:Sysop.css]] e [[MediaWiki:Eliminator.css]]
* @source: [[w:en:MediaWiki:Common.js]]
*/
if ( $.inArray( 'sysop', mw.config.get('wgUserGroups') ) > -1 ) {
importStylesheet('MediaWiki:Sysop.css');
}
if ( $.inArray( 'eliminator', mw.config.get('wgUserGroups') ) > -1 ) {
importStylesheet('MediaWiki:Eliminator.css');
}
/**
* Adiciona as predefinições {protegido} e {protegido-ip} às páginas protegidas
* @author: [[:pt:User:Rei-artur]]
*/
if ( mw.config.get( 'wgAction' ) === 'view'
&& !mw.config.get( 'wgCanonicalSpecialPageName' )
&& !$.isEmpty( mw.config.get( 'wgRestrictionEdit' ) )
&& $.inArray( mw.config.get( 'wgRestrictionEdit' )[0], ['autoconfirmed', 'sysop'] ) > -1
&& mw.config.get( 'wgPageName' ) !== 'Wikipédia:Página_principal' )
{
importScript( 'MediaWiki:Topicon.js' );
}
/**
* Banners para dicas e doações vista apenas por anônimos
* Frases aleatórias que podem ser vistas por anônimos
*
* @author: [[:en:User:Gmaxwell]], [[:en:User:MZMcBride]]
*/
if ( mw.config.get( 'wgUserName' ) === null ) {
importScript( 'MediaWiki:WikiBanners.js' );
}
/**
* Manter no servidor seguro quem se loga pelo servidor seguro quando muda para outro projeto
* Sem este código, o usuário logado por https quando segue um interwiki, usa http e será deslogado (os logins são independentes).
*/
if ( mw.config.get( 'wgServer' ) === 'https://secure.wikimedia.org' ) {
importScript( 'MediaWiki:Common.js/secure.js' );
}
/** Parâmetro &withJS= para a URL
* Permite que sejam testados scripts do domínio MediaWiki
* sem precisar editar [[Especial:Minha página/common.js]]
*/
var extraJS = mw.util.getParamValue( 'withJS' );
if (extraJS && extraJS.match( /^MediaWiki:[^&<>=%]*\.js$/ )) {
importScript(extraJS);
}
/**
* Link destaque
*
* Adiciona uma das classes 'FA', 'FL' ou 'BOM' às ligações dos artigos destacados/bons das outras Wikipédias
*/
function formatInterwikiLinks() {
if (document.getElementById( 'p-lang' )) {
var InterwikiLinks = document.getElementById( 'p-lang' ).getElementsByTagName( 'li' );
for (var i = 0; i < InterwikiLinks.length; i++) {
if (document.getElementById(InterwikiLinks[i].className + '-fa' )) {
InterwikiLinks[i].className += ' FA';
InterwikiLinks[i].title = 'Este artigo foi classificado como destacado.';
} else if (document.getElementById(InterwikiLinks[i].className + '-fl' )) {
InterwikiLinks[i].className += ' FL';
InterwikiLinks[i].title = 'Este anexo foi classificado como destacado.';
} else if (document.getElementById(InterwikiLinks[i].className + '-bom' )) {
InterwikiLinks[i].className += ' BOM';
InterwikiLinks[i].title = 'Este artigo foi classificado como bom.';
}
}
}
}
$( formatInterwikiLinks );
/** Correlatos
* Adiciona links para os projetos correlatos no menu lateral, a partir da [[Predefinição:Correlatos]].
* TODO: Remover quando o [[bugzilla:708]] for resolvido
*/
function adicionaCorrelatos() {
iProjectHTML = document.getElementById( 'interProject' );
if (iProjectHTML) {
iProjectHTML = iProjectHTML.innerHTML;
var iProject = document.createElement( 'div' );
if (self.skin === 'vector' ) {
iProject.className = 'portal';
cl = 'body';
} else {
iProject.className = 'portlet';
cl = 'pBody';
}
iProject.innerHTML = '<h5>Correlatos<\/h5><div class="' + cl + '">' + iProjectHTML;
iProject.setAttribute( 'id', 'p-correlatos' );
iProject.id = 'p-correlatos';
var ptb = document.getElementById( 'p-tb' );
ptb.parentNode.insertBefore(iProject, ptb.nextSibling);
}
}
$( adicionaCorrelatos );
/**
* Altera o título da página
*
* A função procura por um banner como:
* <nowiki><div id="RealTitleBanner">Div que está oculto</nowiki>
* <nowiki><span id="RealTitle">título</span></nowiki>
* <nowiki></div></nowiki>
* Um elemento com id=DisableRealTitle desabilita a função
* @source: [[w:en:MediaWiki:Common.js]]
*/
rewritePageH1 = function () {
try {
var realTitleBanner = document.getElementById( 'RealTitleBanner' );
if (realTitleBanner) {
if ( !document.getElementById( 'DisableRealTitle' ) ) {
var realTitle = document.getElementById( 'RealTitle' );
var h1 = document.getElementsByTagName( 'h1' )[0];
if ( realTitle && h1 ) {
h1.innerHTML = realTitle.innerHTML;
realTitleBanner.style.display = 'none';
}
}
}
} catch (e) {
mw.log( 'Algo deu errado ao tentar reescrever o título da página.' );
}
};
$( rewritePageH1 );
/**
* WikiMiniAtlas é uma popup com um mapa do mundo para clicar e arrastar disponível nos artigos com geocoordenadas
* Ver [[meta:WikiMiniAtlas]] para maiores informações
* @author: [[w:User:Dschwen]]
*/
var metaBase = 'http://meta.wikimedia.org';
if ( mw.config.get( 'wgServer' ) === 'https://secure.wikimedia.org' ) {
metaBase = 'https://secure.wikimedia.org/wikipedia/meta';
}
mw.loader.load( metaBase + '/w/index.php?title=MediaWiki:Wikiminiatlas.js&action=raw&ctype=text/javascript&smaxage=21600&maxage=86400' );
/**
* Permite criar tabelas para esconder/expandir
* Ver [[:en:Wikipédia:NavFrame]].
* @author: [[User:R. Koot]]
* TODO: Remover quando [[mw:ResourceLoader/Default_modules#jQuery.makeCollapsible]] estiver em uso e
* as predefinições forem adaptadas para usar o novo plugin
*/
var autoCollapse = 2,
collapseCaption = 'Esconder',
expandCaption = 'Expandir';
/**
* @param {number} tableIndex Índice da tabela a ser alterada
* @return {boolean} Caso não encontre a tabela ou o botão com o índice informado retorna false
*/
function collapseTable(tableIndex) {
var i,
Button = document.getElementById('collapseButton' + tableIndex),
Table = document.getElementById('collapsibleTable' + tableIndex);
if ( !Table || !Button ) {
return false;
}
var Rows = Table.rows;
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 i, tableIndex = 0,
NavigationBoxes = {},
Tables = document.getElementsByTagName('table');
for (i = 0; i < Tables.length; i++) {
if (hasClass(Tables[i], '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' ),
ButtonLink = document.createElement( 'a' ),
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', '#');
addHandler(ButtonLink, 'click', new Function('evt', 'collapseTable(' + tableIndex + ' ); return killEvt( evt );'));
ButtonLink.appendChild(ButtonText);
Button.appendChild(document.createTextNode( '[' ));
Button.appendChild(ButtonLink);
Button.appendChild(document.createTextNode( ']' ));
Header.insertBefore(Button, Header.childNodes[0]);
tableIndex++;
}
}
for (i = 0; i < tableIndex; i++) {
if (hasClass(NavigationBoxes[i], 'collapsed' ) || (tableIndex >= autoCollapse && hasClass(NavigationBoxes[i], 'autocollapse' ))) {
collapseTable(i);
} else if (hasClass(NavigationBoxes[i], 'innercollapse')) {
var element = NavigationBoxes[i];
element = element.parentNode;
while (element) {
if (hasClass(element, 'outercollapse')) {
collapseTable(i);
break;
}
element = element.parentNode;
}
}
}
}
$( createCollapseButtons );
/**
* Barras de navegação dinâmicas (experimental)
* Ver [[Wikipédia:NavFrame]].
* @author: UNMAINTAINED
* TODO: Remover quando [[mw:ResourceLoader/Default_modules#jQuery.makeCollapsible]] estiver em uso e
* as predefinições forem adaptadas para usar o novo plugin
*/
// set up the words in your language
var NavigationBarHide = '[' + collapseCaption + ']',
NavigationBarShow = '[' + expandCaption + ']';
/**
* Shows and hides content and picture (if available) of navigation bars
* @param {number} indexNavigationBar: the index of navigation bar to be toggled
* @return {boolean} Caso não encontre a tabela ou o botão com o índice informado retorna false
*/
function toggleNavigationBar(indexNavigationBar) {
var NavChild,
NavToggle = document.getElementById('NavToggle' + indexNavigationBar),
NavFrame = document.getElementById('NavFrame' + indexNavigationBar);
if (!NavFrame || !NavToggle) {
return false;
}
// if shown now
if (NavToggle.firstChild.data == NavigationBarHide) {
for (NavChild = NavFrame.firstChild; NavChild !== null; NavChild = NavChild.nextSibling) {
if (hasClass(NavChild, 'NavContent') || hasClass(NavChild, '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 (hasClass(NavChild, 'NavContent') || hasClass(NavChild, 'NavPic')) {
NavChild.style.display = 'block';
}
}
NavToggle.firstChild.data = NavigationBarHide;
}
}
// adds show/hide-button to navigation bars
function createNavigationBarToggleButton() {
var NavChild,
indexNavigationBar = 0,
// iterate over all < div >-elements
divs = document.getElementsByTagName('div');
NavFrame = divs[0];
for ( var i = 0; NavFrame; i++ ) {
// if found a navigation bar
if (hasClass(NavFrame, 'NavFrame' )) {
indexNavigationBar++;
var NavToggle = document.createElement( 'a' );
NavToggle.className = 'NavToggle';
NavToggle.setAttribute( 'id', 'NavToggle' + indexNavigationBar);
NavToggle.setAttribute( 'href', 'javascript:toggleNavigationBar(' + indexNavigationBar + ');' );
var isCollapsed = hasClass(NavFrame, '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 (hasClass(NavChild, 'NavPic') || hasClass(NavChild, 'NavContent')) {
if (NavChild.style.display == 'none') {
isCollapsed = true;
}
}
}
if (isCollapsed) {
for (NavChild = NavFrame.firstChild; NavChild !== null; NavChild = NavChild.nextSibling) {
if (hasClass(NavChild, 'NavPic') || hasClass(NavChild, '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 (hasClass(NavFrame.childNodes[j], 'NavHead')) {
NavToggle.style.color = NavFrame.childNodes[j].style.color;
NavFrame.childNodes[j].appendChild(NavToggle);
}
}
NavFrame.setAttribute( 'id', 'NavFrame' + indexNavigationBar);
}
NavFrame = divs[i];
}
}
$( createNavigationBarToggleButton );
/**
* Caixa com abas, feitas com a [[Predefinição:Metacaixa]]
* @source: [[:w:fr:MediaWiki:Common.js]] (traduzido de [[:w:ca:MediaWiki:Common.js]])
* @author: [[:w:ca:User:Peleguer]], [[:w:ca:User:Joanjoc]], [[:w:fr:User:Antaya]] (adaptação), [[:w:pt:Rei-artur]] (adaptação)
*/
function CadreOngletInit() {
var i = 0;
for (i = 0; i <= 9; i++) {
var vMb,
vBt,
j,
vOgIni = 0;
vMb = document.getElementById( 'mb' + i);
if ( !vMb ) {
break;
}
for ( j = 1; j <= 9; j++ ) {
vBt = document.getElementById( 'mb' + i + 'bt' + j );
if ( !vBt ) {
break;
}
vBt.onclick = CadreOngletVoirOnglet;
if (vBt.className === 'mbBoutonSel' ) {
vOgIni = j;
}
}
if (vOgIni === 0) {
vOgIni = 1 + Math.floor((j - 1) * Math.random());
document.getElementById( 'mb' + i + 'og' + vOgIni).style.display = 'block';
document.getElementById( 'mb' + i + 'og' + vOgIni).style.visibility = 'visible';
document.getElementById( 'mb' + i + 'bt' + vOgIni).className = 'mbBoutonSel';
}
}
}
/*
* @return {boolean} Retorna false ao terminar a execução
*/
function CadreOngletVoirOnglet() {
var vMbNom = this.id.substr( 0, 3 ),
vIndex = this.id.substr( 5, 1 ),
i;
for ( i = 1; i <= 9; i++ ) {
var vOgElem = document.getElementById( vMbNom + 'og' + i );
if ( !vOgElem ) {
break;
}
if ( vIndex == i ) {
vOgElem.style.display = 'block';
vOgElem.style.visibility = 'visible';
document.getElementById(vMbNom + 'bt' + i).className = 'mbBoutonSel';
} else {
vOgElem.style.display = 'none';
vOgElem.style.visibility = 'hidden';
document.getElementById(vMbNom + 'bt' + i).className = 'mbBouton';
}
}
return false;
}
/**
* retour si ailleurs que sur l'espace utilisateur,
* sachant que c'est une horreur au niveau de l'accessibilité
* et qu'il est impossible de 'récupérer' ou de recycler ce script
* (celui-ci fonctionnant par inclusion de sous pages)
*/
if ( $.inArray( mw.config.get( 'wgNamespaceNumber' ), [ 0, 102 ] ) === -1 ) {
$( CadreOngletInit );
}