MediaWiki:Common.js: mudanças entre as edições

De Wiki@DCOM
Ir para navegação Ir para pesquisar
mSem resumo de edição
Etiqueta: Revertido
mSem resumo de edição
Etiquetas: Reversão manual Revertido
Linha 1: Linha 1:
$(document).ready(function() {
jQuery(function ($) {
 
 
   const $document = $(document);
   function abrirOculto(elemento) {
  const $window = $(window);
    var ocultoConteudo = elemento.parents('.oculto-conteudo');
  const $referencia_tip = $('#referencia_tip');
    if (ocultoConteudo.length) {
  const $mw_head = $('#mw-head');
      ocultoConteudo.removeClass('mw-collapsed');
  const $mw_body = $('.mw-body, #p-personal, #right-navigation');
      ocultoConteudo.css('display', 'block'); // É necessário manter o 'display: block;' por compatibilidade
  const $toc = $('.toc');
     };
  const $relacionados = $('.relacionados');
 
  function abrirOculto(element) {
     $(element).closest('.oculto-conteudo').removeClass('mw-collapsed').show();
   };
   };
 
 
  function scrollToElement(element) {
    window.scrollTo({top: $(element).offset().top, behavior: 'smooth'});
  };
 
   function abrirAba() {
   function abrirAba() {
     const hash = location.hash.slice(1).trim();
     var aba_escolhida = location.hash.slice(1).trim().split('/');
    if (!hash) return;
     abas_id = '';
   
     abas_num = '';
    const parametros = location.hash.slice(1).trim().split('/');
     aba_nome = '';
     let abas_id = '';
     $.each(aba_escolhida, function () {
     let abas_num = '';
      if (this.indexOf('abas_id=') === 0) {
     let aba_nome = '';
        abas_id = this.split('=')[1];
      
       } else if (this.indexOf('abas_num=') === 0) {
    parametros.forEach(param => {
         abas_num = this.split('=')[1];
      const [key, value] = param.split('=');
      } else if (this.indexOf('aba_nome=') === 0) {
       switch (key) {
         aba_nome = decodeURIComponent(this.split('=')[1]).replace(/_/g, ' ');
         case 'abas_id': abas_id = value; break;
        case 'abas_num': abas_num = value; break;
         case 'aba_nome': aba_nome = decodeURIComponent(value).replace(/_/g, ' '); break;
       }
       }
     });
     });
   
 
    let $aba;
     if (abas_id === '') {
     if (abas_id) {
       var aba = $('.tabs-tabbox:has(input[name=tabs-' + abas_num + ']) .tabs-label:contains(' + aba_nome + ')')
       $aba = $(`.tabs-tabbox[id="${abas_id}"] .tabs-label:contains("${aba_nome}")`);
     } else {
     } else {
       $aba = $(`.tabs-tabbox:has(input[name="tabs-${abas_num}"]) .tabs-label:contains("${aba_nome}")`);
       var aba = $('.tabs-tabbox[id=' + abas_id + '] .tabs-label:contains(' + aba_nome + ')')
     };
     };
   
 
     $aba.each(function () {
     aba.each(function () {
       abrirOculto($(this));
       abrirOculto($(this));
       this.click();  
       this.click();  
       scrollToElement(this);
       window.scrollTo({top: $(this).offset().top, behavior: 'smooth'});
     });
     });
   
 
     $(document.querySelectorAll('.oculto-conteudo :target, .tabs-content :target')).each(function () {
     $(':target').each(function () {
       const $this = $(this);
       if ($(this).parents('.oculto-conteudo')) {
      const dentroOculto = $this.closest('.oculto-conteudo').length > 0;
         abrirOculto($(this));
      const dentroAba = $this.closest('.tabs-content').length > 0;
         window.scrollTo({top: $(this).offset().top, behavior: 'smooth'});
     
       };
      if (dentroOculto) {
 
         abrirOculto(this);
       if ($(this).parents('.tabs-content')) {
         scrollToElement(this);
         var aba = $(this).parents('.tabs-content').attr('class').split('-')[3];
       }
         $(this).parents('.tabs-container').siblings('[data-tabpos=' + aba + ']').click();
     
         window.scrollTo({top: $(this).offset().top, behavior: 'smooth'});
       if (dentroAba) {
       };
         let 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() {
   // Chama a função abrirAba quando o documento estiver pronto
     const $this = $(this);
   $(document).ready(abrirAba);
    const abas_id = $this.closest('div').prop('id');
 
     const abas_num = $this.attr('for').split('-')[2];
  // Chama a função abrirAba quando o hash da URL mudar
     const aba_nome = $this.text();
  $(window).on('hashchange', abrirAba);
     const hash = abas_id ? `abas_id=${abas_id}/abas_num=${abas_num}/aba_nome=${aba_nome}` : `abas_num=${abas_num}/aba_nome=${aba_nome}`;
});
 
$(document).ready(function() {
 
  $(document).on('click', '.tabs-tabbox .tabs-label', function() {
     var abas_id = $(this).closest("div").prop("id");
     var abas_num = $(this).attr("for").split('-')[2];
     var aba_nome = $(this).text();
     if (abas_id === '') {
      var hash = 'abas_num=' + abas_num + '/aba_nome=' + aba_nome;
    } else {
      var hash = 'abas_id=' + abas_id + '/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" */
   $document.on('click', '#botao-fechar', () => {
   $(document).on('click', '#botao-fechar', function() {
     $relacionados.hide();
     $('.relacionados').hide();
     checarTOCeRelacionados();
     checarTOCeRelacionados();
   });
   });
    
    
   /* Oculta o Índice totalmente */
   /* Oculta o Índice totalmente */
   $document.on('click', 'input#toctogglecheckbox.toctogglecheckbox', () => {
   $(document).on('click', 'input#toctogglecheckbox.toctogglecheckbox', function() {
     if ($('.toc ul').is(":hidden")) {
     if ($('.toc ul').is(":hidden")) {
       $toc.hide();
       $('.toc').hide();
     };
     };
     checarTOCeRelacionados();
     checarTOCeRelacionados();
Linha 90: Linha 86:
    
    
   /* 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*/
   $document.on('mouseenter', '.reference', function() {
   $(document).on('mouseover', '.reference', function(e) {
     const $this = $(this);
     var referencia_id = $(this).children().eq(0).attr('href').substring(1);
    const referencia_id = $this.children().eq(0).attr('href').substring(1);
     var referencia_nome = $('#' + referencia_id);
     const referencia_nome = $('#' + referencia_id);
     var referencia_conteudo = referencia_nome.find('.reference-text').html();
     const referencia_conteudo = referencia_nome.find('.reference-text').html();
 
   
     var topo    = ($(this).offset().top  - 140) + "px";
     const topo    = ($this.offset().top  - 140) + "px";
     var esquerda = ($(this).offset().left - 115) + "px";  
     const esquerda = ($this.offset().left - 115) + "px";  
 
   
     $('#referencia_tip').html(referencia_conteudo);
     $referencia_tip.html(referencia_conteudo).css({
    $('#referencia_tip').css({
       top: topo,
       top: topo,
       left: esquerda   
       left: esquerda   
     }).hide().dequeue().show();
     });
    $('#referencia_tip').hide().dequeue();
    $('#referencia_tip').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', () => {
   $(document).on('mouseout', '.reference', function() {
     $referencia_tip.delay(1000).hide(1);
     $('#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', () => {
   $(document).on('mouseover', '#referencia_tip', function() {
     $referencia_tip.hide().dequeue().show();
     $('#referencia_tip').hide().dequeue();
    $('#referencia_tip').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', () =>{
   $(document).on('mouseout', '#referencia_tip', function() {
     $referencia_tip.hide();
     $('#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;
    
    
  /* Confere se o ìndice e o box Relacionados estão ocultos e muda a margem direita*/
    if (tocOculto && relacionadosOculto) {
  const checarTOCeRelacionados = () => {
      $('.mw-body, #p-personal, #right-navigation').css('margin-right', '1em');
    const tocOculto = !$toc.is(':visible') || !$toc.length;
    }
    const relacionadosOculto = !$relacionados.is(':visible') || !$relacionados.length;
    $mw_body.css('margin-right', (tocOculto && relacionadosOculto) ? '1em' : '');
   };
   };
 
 
   /* 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.estaVisivel = function() {
   $.fn.isInViewport = function() {
     var elementTop = this.offset().top;
     var elementTop = $(this).offset().top;
     var elementBottom = elementTop + this.outerHeight();
     var elementBottom = elementTop + $(this).outerHeight();
     var viewportTop = $window.scrollTop();
     var viewportTop = $(window).scrollTop();
     var viewportBottom = viewportTop + $window.height();
     var viewportBottom = viewportTop + $(window).height();
     return elementBottom > viewportTop && elementTop < viewportBottom;
     return elementBottom > viewportTop && elementTop < viewportBottom;
   };
   };
 
 
   $window.on('ready resize load scroll', function () {
   $(window).on('ready resize load scroll', function() {
     const estaVisivel = $mw_head.estaVisivel();
     if ($('#mw-head').isInViewport()) {
     $toc.css('top', estaVisivel ? '55px' : '10px');
      var topo = '55px';
     $('.mw-wiki-logo').css('opacity', estaVisivel ? 0 : 1);
      var opacidade = '0';
   });
    } else {
 
      var topo = '10px';
   $window.on('hashchange', abrirAba);
      var opacidade = '1';
 
    };
  $(abrirAba);
     $('.toc').css({'top': topo});
  $(checarTOCeRelacionados);
     $('.mw-wiki-logo').css({'opacity': opacidade});
 
   });  
 
   checarTOCeRelacionados();
});
});

Edição das 17h27min de 9 de fevereiro de 2025

jQuery(function ($) {

  function abrirOculto(elemento) {
    var ocultoConteudo = elemento.parents('.oculto-conteudo');
    if (ocultoConteudo.length) {
      ocultoConteudo.removeClass('mw-collapsed');
      ocultoConteudo.css('display', 'block'); // É necessário manter o 'display: block;' por compatibilidade
    };
  };

  function abrirAba() {
    var aba_escolhida = location.hash.slice(1).trim().split('/');
    abas_id = '';
    abas_num = '';
    aba_nome = '';
    $.each(aba_escolhida, 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 === '') {
      var aba = $('.tabs-tabbox:has(input[name=tabs-' + abas_num + ']) .tabs-label:contains(' + aba_nome + ')')
    } else {
      var aba = $('.tabs-tabbox[id=' + abas_id + '] .tabs-label:contains(' + aba_nome + ')')
    };

    aba.each(function () {
      abrirOculto($(this));
      this.click(); 
      window.scrollTo({top: $(this).offset().top, behavior: 'smooth'});
    });

    $(':target').each(function () {
      if ($(this).parents('.oculto-conteudo')) {
        abrirOculto($(this));
        window.scrollTo({top: $(this).offset().top, behavior: 'smooth'});
      };

      if ($(this).parents('.tabs-content')) {
        var aba = $(this).parents('.tabs-content').attr('class').split('-')[3];
        $(this).parents('.tabs-container').siblings('[data-tabpos=' + aba + ']').click();
        window.scrollTo({top: $(this).offset().top, behavior: 'smooth'});
      };
    });
  };

  // Chama a função abrirAba quando o documento estiver pronto
  $(document).ready(abrirAba);

  // Chama a função abrirAba quando o hash da URL mudar
  $(window).on('hashchange', abrirAba);
});

$(document).ready(function() {

  $(document).on('click', '.tabs-tabbox .tabs-label', function() {
    var abas_id = $(this).closest("div").prop("id");
    var abas_num = $(this).attr("for").split('-')[2];
    var aba_nome = $(this).text();
    if (abas_id === '') {
      var hash = 'abas_num=' + abas_num + '/aba_nome=' + aba_nome;
    } else {
      var hash = 'abas_id=' + abas_id + '/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('mouseover', '.reference', function(e) {
    var referencia_id = $(this).children().eq(0).attr('href').substring(1);
    var referencia_nome = $('#' + referencia_id);
    var referencia_conteudo = referencia_nome.find('.reference-text').html();
  
    var topo     = ($(this).offset().top  - 140) + "px";
    var esquerda = ($(this).offset().left - 115) + "px"; 
   
    $('#referencia_tip').html(referencia_conteudo);
    $('#referencia_tip').css({
      top: topo,
      left: esquerda  
    });
    $('#referencia_tip').hide().dequeue();
    $('#referencia_tip').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();
    $('#referencia_tip').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, #p-personal, #right-navigation').css('margin-right', '1em');
    }
  };

  /* Exibe texto do logo DCOM e altera posição índice ao rolar tela*/
  $.fn.isInViewport = 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() {
    if ($('#mw-head').isInViewport()) {
      var topo = '55px';
      var opacidade = '0';
    } else {
      var topo = '10px';
      var opacidade = '1';
    };
    $('.toc').css({'top': topo});
    $('.mw-wiki-logo').css({'opacity': opacidade});
  }); 

  checarTOCeRelacionados();
});