MediaWiki:Common.js: mudanças entre as edições
Ir para navegação
Ir para pesquisar
mSem resumo de edição |
mSem resumo de edição |
||
| (33 revisões intermediárias pelo mesmo usuário não estão sendo mostradas) | |||
| Linha 1: | Linha 1: | ||
$(document).ready(function() { | |||
const $document = $(document); | |||
const $window = $(window); | |||
const $referencia_tip = $('#referencia_tip'); | |||
const $mw_head = $('#mw-head'); | |||
const $mw_body = $('.mw-body, #p-personal, #right-navigation'); | |||
const $toc = $('.toc'); | |||
const $relacionados = $('.relacionados'); | |||
function abrirOculto(element) { | |||
$(element).closest('.oculto-conteudo').removeClass('mw-collapsed').show(); | |||
}; | |||
function scrollToElement(element) { | |||
setTimeout(function(){ | |||
$(element)[0].scrollIntoView({behavior: 'smooth', block: 'start'}); | |||
}, 500); | |||
}; | |||
function abrirAba() { | function abrirAba() { | ||
var | var hash = location.hash.slice(1).trim(); | ||
if (!hash) return; | |||
if ( | var parametros = hash.split('/'); | ||
if (parametros != hash) { | |||
abas_id = ''; | |||
this. | abas_num = ''; | ||
aba_nome = ''; | |||
$.each(parametros, function () { | |||
if (this.indexOf('abas_id=') === 0) { | |||
abas_id = this.split('=')[1]; | |||
} else if (this.indexOf('abas_num=') === 0) { | |||
abas_num = this.split('=')[1]; | |||
} else if (this.indexOf('aba_nome=') === 0) { | |||
aba_nome = decodeURIComponent(this.split('=')[1]).replace(/_/g, ' '); | |||
}; | |||
}); | }); | ||
if (abas_id !== '') { | |||
$( | aba = $('.tabs-tabbox[id=' + abas_id + '] .tabs-label:contains(' + aba_nome + ')'); | ||
$(this). | } else { | ||
aba = $('.tabs-tabbox:has(input[name=tabs-' + abas_num + ']) .tabs-label:contains(' + aba_nome + ')'); | |||
}; | |||
$.each(aba, function () { | |||
if ($(this).text() !== aba_nome) { | |||
return true; | |||
}; | |||
abrirOculto(this); | |||
this.click(); | this.click(); | ||
scrollToElement(this); | |||
return false; | |||
}); | }); | ||
}; | }; | ||
if (parametros == hash) { | |||
$(document.querySelectorAll('.oculto-conteudo :target, .tabs-content :target')).each(function () { | |||
const $this = $(this); | |||
const dentroOculto = $this.closest('.oculto-conteudo').length > 0; | |||
const dentroAba = $this.closest('.tabs-content').length > 0; | |||
if (dentroOculto) { | |||
abrirOculto(this); | |||
}; | |||
if (dentroAba) { | |||
var aba = $this.closest('.tabs-content').attr('class').split('-')[3]; | |||
$this.closest('.tabs-container').siblings('[data-tabpos="'+ aba + '"]').click(); | |||
}; | |||
scrollToElement(this); | |||
}); | |||
}; | |||
} | |||
} | |||
}; | }; | ||
$document.on('click', '.tabs-tabbox .tabs-label', function() { | |||
$ | const $this = $(this); | ||
const abas_id = $this.closest('div').prop('id'); | |||
const abas_num = $this.attr('for').split('-')[2]; | |||
const aba_nome = $this.text(); | |||
const hash = abas_id ? 'abas_id=' + abas_id +'/abas_num=' + abas_num + '/aba_nome=' + aba_nome : 'abas_num=' + abas_num + '/aba_nome=' + aba_nome; | |||
history.replaceState(null, null, document.location.pathname + '#' + hash); | |||
history.replaceState(null, null, document.location.pathname + '#' + hash) | |||
}); | }); | ||
/* Fecha o box "Relacionados" */ | /* Fecha o box "Relacionados" */ | ||
$('#botao-fechar | $document.on('click', '#botao-fechar', function() { | ||
$ | $relacionados.hide(); | ||
checarTOCeRelacionados(); | checarTOCeRelacionados(); | ||
}); | }); | ||
/* Oculta o Índice totalmente */ | /* Oculta o Índice totalmente */ | ||
$('input#toctogglecheckbox.toctogglecheckbox | $document.on('click', 'input#toctogglecheckbox.toctogglecheckbox', function() { | ||
if ($('.toc ul').is( | if ($('.toc ul').is(':hidden')) { | ||
$ | $toc.hide(); | ||
}; | }; | ||
checarTOCeRelacionados(); | checarTOCeRelacionados(); | ||
} ); | }); | ||
/* Obtém os dados da referência no fim da página e exibe como pop-up ao passar o mouse sobre o seu número*/ | /* Obtém os dados da referência no fim da página e exibe como pop-up ao passar o mouse sobre o seu número*/ | ||
$('.reference | $document.on('mouseenter', '.reference', function() { | ||
const $this = $(this); | |||
const referencia_id = $this.children().eq(0).attr('href').substring(1); | |||
const referencia_nome = $('#' + referencia_id); | |||
const referencia_conteudo = referencia_nome.find('.reference-text').html(); | |||
const topo = ($this.offset().top - 140) + "px"; | |||
const esquerda = ($this.offset().left - 115) + "px"; | |||
$ | |||
$referencia_tip.html(referencia_conteudo).css({ | |||
top: topo, | top: topo, | ||
left: esquerda | left: esquerda | ||
} | }).hide().dequeue().show(); | ||
}); | }); | ||
/* Oculta o pop-up da referência ao tirar o mouse do número*/ | /* Oculta o pop-up da referência ao tirar o mouse do número*/ | ||
$ | $document.on('mouseout', '.reference', function() { | ||
$ | $referencia_tip.delay(1000).hide(1); | ||
}); | }); | ||
/* Mantém o pop-up aberto enquanto estiver com o mouse*/ | /* Mantém o pop-up aberto enquanto estiver com o mouse*/ | ||
$ | $document.on('mouseover', '#referencia_tip', function() { | ||
$ | $referencia_tip.hide().dequeue().show(); | ||
}); | }); | ||
/* Oculta o pop-up da referência ao tirar o mouse do pop-up*/ | /* Oculta o pop-up da referência ao tirar o mouse do pop-up*/ | ||
$ | $document.on('mouseout', '#referencia_tip', function() { | ||
$ | $referencia_tip.hide(); | ||
}); | }); | ||
/* Confere se o ìndice e o box Relacionados estão ocultos e muda a margem direita*/ | /* Confere se o ìndice e o box Relacionados estão ocultos e muda a margem direita*/ | ||
function checarTOCeRelacionados() { | function checarTOCeRelacionados() { | ||
var tocOculto = !$toc.is(':visible') || $toc.length === 0; | |||
var relacionadosOculto = !$relacionados.is(':visible') || $relacionados.length === 0; | |||
if (tocOculto && relacionadosOculto) { | |||
$mw_body.css('margin-right', '1em'); | |||
} | |||
if ( | |||
$ | |||
} | |||
}; | }; | ||
/* Exibe texto do logo DCOM e altera posição índice ao rolar tela*/ | /* Exibe texto do logo DCOM e altera posição índice ao rolar tela*/ | ||
$.fn. | $.fn.estaVisivel = function() { | ||
var elementTop = | var elementTop = this.offset().top; | ||
var elementBottom = elementTop + | var elementBottom = elementTop + this.outerHeight(); | ||
var viewportTop = $ | var viewportTop = $window.scrollTop(); | ||
var viewportBottom = viewportTop + $ | var viewportBottom = viewportTop + $window.height(); | ||
return elementBottom > viewportTop && elementTop < viewportBottom; | return elementBottom > viewportTop && elementTop < viewportBottom; | ||
}; | }; | ||
$ | $window.on('ready resize load scroll', function () { | ||
const estaVisivel = $mw_head.estaVisivel(); | |||
$toc.css('top', estaVisivel ? '55px' : '10px'); | |||
$('.mw-wiki-logo').css('opacity', estaVisivel ? 0 : 1); | |||
}); | |||
$window.on('hashchange', abrirAba); | |||
$(abrirAba); | |||
$(checarTOCeRelacionados); | |||
checarTOCeRelacionados | |||
}); | }); | ||
Edição atual tal como às 23h52min de 18 de fevereiro de 2025
$(document).ready(function() {
const $document = $(document);
const $window = $(window);
const $referencia_tip = $('#referencia_tip');
const $mw_head = $('#mw-head');
const $mw_body = $('.mw-body, #p-personal, #right-navigation');
const $toc = $('.toc');
const $relacionados = $('.relacionados');
function abrirOculto(element) {
$(element).closest('.oculto-conteudo').removeClass('mw-collapsed').show();
};
function scrollToElement(element) {
setTimeout(function(){
$(element)[0].scrollIntoView({behavior: 'smooth', block: 'start'});
}, 500);
};
function abrirAba() {
var hash = location.hash.slice(1).trim();
if (!hash) return;
var parametros = hash.split('/');
if (parametros != hash) {
abas_id = '';
abas_num = '';
aba_nome = '';
$.each(parametros, function () {
if (this.indexOf('abas_id=') === 0) {
abas_id = this.split('=')[1];
} else if (this.indexOf('abas_num=') === 0) {
abas_num = this.split('=')[1];
} else if (this.indexOf('aba_nome=') === 0) {
aba_nome = decodeURIComponent(this.split('=')[1]).replace(/_/g, ' ');
};
});
if (abas_id !== '') {
aba = $('.tabs-tabbox[id=' + abas_id + '] .tabs-label:contains(' + aba_nome + ')');
} else {
aba = $('.tabs-tabbox:has(input[name=tabs-' + abas_num + ']) .tabs-label:contains(' + aba_nome + ')');
};
$.each(aba, function () {
if ($(this).text() !== aba_nome) {
return true;
};
abrirOculto(this);
this.click();
scrollToElement(this);
return false;
});
};
if (parametros == hash) {
$(document.querySelectorAll('.oculto-conteudo :target, .tabs-content :target')).each(function () {
const $this = $(this);
const dentroOculto = $this.closest('.oculto-conteudo').length > 0;
const dentroAba = $this.closest('.tabs-content').length > 0;
if (dentroOculto) {
abrirOculto(this);
};
if (dentroAba) {
var aba = $this.closest('.tabs-content').attr('class').split('-')[3];
$this.closest('.tabs-container').siblings('[data-tabpos="'+ aba + '"]').click();
};
scrollToElement(this);
});
};
};
$document.on('click', '.tabs-tabbox .tabs-label', function() {
const $this = $(this);
const abas_id = $this.closest('div').prop('id');
const abas_num = $this.attr('for').split('-')[2];
const aba_nome = $this.text();
const hash = abas_id ? 'abas_id=' + abas_id +'/abas_num=' + abas_num + '/aba_nome=' + aba_nome : 'abas_num=' + abas_num + '/aba_nome=' + aba_nome;
history.replaceState(null, null, document.location.pathname + '#' + hash);
});
/* Fecha o box "Relacionados" */
$document.on('click', '#botao-fechar', function() {
$relacionados.hide();
checarTOCeRelacionados();
});
/* Oculta o Índice totalmente */
$document.on('click', 'input#toctogglecheckbox.toctogglecheckbox', function() {
if ($('.toc ul').is(':hidden')) {
$toc.hide();
};
checarTOCeRelacionados();
});
/* Obtém os dados da referência no fim da página e exibe como pop-up ao passar o mouse sobre o seu número*/
$document.on('mouseenter', '.reference', function() {
const $this = $(this);
const referencia_id = $this.children().eq(0).attr('href').substring(1);
const referencia_nome = $('#' + referencia_id);
const referencia_conteudo = referencia_nome.find('.reference-text').html();
const topo = ($this.offset().top - 140) + "px";
const esquerda = ($this.offset().left - 115) + "px";
$referencia_tip.html(referencia_conteudo).css({
top: topo,
left: esquerda
}).hide().dequeue().show();
});
/* Oculta o pop-up da referência ao tirar o mouse do número*/
$document.on('mouseout', '.reference', function() {
$referencia_tip.delay(1000).hide(1);
});
/* Mantém o pop-up aberto enquanto estiver com o mouse*/
$document.on('mouseover', '#referencia_tip', function() {
$referencia_tip.hide().dequeue().show();
});
/* Oculta o pop-up da referência ao tirar o mouse do pop-up*/
$document.on('mouseout', '#referencia_tip', function() {
$referencia_tip.hide();
});
/* Confere se o ìndice e o box Relacionados estão ocultos e muda a margem direita*/
function checarTOCeRelacionados() {
var tocOculto = !$toc.is(':visible') || $toc.length === 0;
var relacionadosOculto = !$relacionados.is(':visible') || $relacionados.length === 0;
if (tocOculto && relacionadosOculto) {
$mw_body.css('margin-right', '1em');
}
};
/* Exibe texto do logo DCOM e altera posição índice ao rolar tela*/
$.fn.estaVisivel = function() {
var elementTop = this.offset().top;
var elementBottom = elementTop + this.outerHeight();
var viewportTop = $window.scrollTop();
var viewportBottom = viewportTop + $window.height();
return elementBottom > viewportTop && elementTop < viewportBottom;
};
$window.on('ready resize load scroll', function () {
const estaVisivel = $mw_head.estaVisivel();
$toc.css('top', estaVisivel ? '55px' : '10px');
$('.mw-wiki-logo').css('opacity', estaVisivel ? 0 : 1);
});
$window.on('hashchange', abrirAba);
$(abrirAba);
$(checarTOCeRelacionados);
});