Difference between revisions of "MediaWiki:Common.js"

From XilePK - Ragnarok Online Server
Jump to navigation Jump to search
Line 1: Line 1:
CSS
+
JS
/* CSS placed here will be applied to all skins */
+
/* Any JavaScript here will be loaded for all users on every page load. */
  
/* ========== ESTILOS GERAIS ========== */
+
$(document).ready(function() {
a {
+
  // Função única para cópia de texto
     text-underline-offset: 0px;
+
  $(document).on('click', '.warp-copy', function(e) {
}
+
    e.preventDefault();
 +
    var textToCopy = $(this).attr('data-copy');
 +
   
 +
    // Cria elemento temporário para cópia
 +
    var tempInput = document.createElement('textarea');
 +
    tempInput.value = textToCopy;
 +
    document.body.appendChild(tempInput);
 +
    tempInput.select();
 +
    document.execCommand('copy');
 +
    document.body.removeChild(tempInput);
 +
   
 +
    // Adiciona classe para feedback visual
 +
    var $element = $(this);
 +
    $element.addClass('copied');
 +
    setTimeout(function() {
 +
      $element.removeClass('copied');
 +
     }, 2000);
 +
  });
  
.external {
+
  // Adicionar funcionalidade às imagens dos NPCs
     background: none !important;
+
  function initImageCopy() {
     padding-right: 0 !important;
+
    $('.tile-top.tile-image a').each(function() {
}
+
      var $link = $(this);
 +
      if (!$link.hasClass('warp-copy')) {
 +
        var npcId = $link.attr('href').replace('#','');
 +
        $link.addClass('warp-copy')
 +
            .attr('data-copy', '@warp ' + npcId)
 +
            .css('cursor', 'pointer');
 +
      }
 +
     });
 +
      
 +
    // Aplicar tamanhos personalizados para imagens
 +
    $('.tile-top.tile-image img').each(function() {
 +
      var $img = $(this);
 +
      var width = $img.data('width') || $img.attr('width');
 +
      var height = $img.data('height') || $img.attr('height');
 +
     
 +
      if (width || height) {
 +
        $img.addClass('custom-size');
 +
        if (width) {
 +
          $img.css('--custom-width', width + 'px');
 +
        }
 +
        if (height) {
 +
          $img.css('--custom-height', height + 'px');
 +
        }
 +
      }
 +
    });
 +
  }
  
/* ========== WAR COPY (TEXTO E IMAGENS) ========== */
+
  // Inicializar ao carregar e em atualizações de conteúdo
.warp-copy {
+
  initImageCopy();
     color: #0066cc;
+
  if (typeof mw !== 'undefined' && mw.hook) {
    cursor: pointer;
+
     mw.hook('wikipage.content').add(initImageCopy);
    text-decoration: underline dotted #0066cc;
+
  }
    text-underline-offset: 2px;
 
    position: relative;
 
    display: inline-block;
 
}
 
  
/* Tooltip padrão */
+
  /* Auto-expand sections when clicking anchored links */
.warp-copy::after {
+
  console.log("Inicializando script para expandir seções com links âncora");
    content: "Copy";
+
 
    position: absolute;
+
  // Handle initial page load with hash
    left: 50%;
+
  if (window.location.hash) {
    background-color: #333;
+
     console.log("Página carregada com hash: " + window.location.hash);
    color: white;
+
     setTimeout(function() {
    padding: 2px 6px;
+
      expandSectionForAnchor(window.location.hash);
    border-radius: 3px;
+
     }, 300);
    font-size: 12px;
+
  }
    white-space: nowrap;
+
 
    z-index: 10;
+
  // Handle clicks on anchor links
    opacity: 0;
+
  $(document).on('click', 'a[href^="#"]', function(event) {
    visibility: hidden;
+
     var hash = $(this).attr('href');
    pointer-events: none;
+
     console.log("Clique em link âncora: " + hash);
    transform: translateX(-50%);
+
     event.preventDefault();
}
+
   
 
+
    if (history.pushState) {
/* Seta do tooltip */
+
      history.pushState(null, null, hash);
.warp-copy::before {
+
     } else {
     content: "";
+
      location.hash = hash;
     position: absolute;
+
     }
    left: 50%;
+
      
     border-width: 4px;
+
     expandSectionForAnchor(hash);
    border-style: solid;
+
  });
    z-index: 10;
+
 
    opacity: 0;
+
  function expandSectionForAnchor(hash) {
    visibility: hidden;
+
     console.log("Procurando e expandindo seção para âncora: " + hash);
    pointer-events: none;
+
     var targetElement = $(hash);
    transform: translateX(-50%);
+
      
}
+
     if (targetElement.length) {
 
+
      console.log("Elemento alvo encontrado");
/* Tooltip PARA TEXTO */
+
     
.warp-copy:not(img)::after {
+
      var collapsibleSections = targetElement.parents('.mw-collapsible.mw-collapsed');
     bottom: calc(100% + 5px);
+
      var directCollapsible = targetElement.closest('.mw-collapsible.mw-collapsed');
}
+
     
 
+
      if (directCollapsible.length) {
.warp-copy:not(img)::before {
+
        collapsibleSections = collapsibleSections.add(directCollapsible);
     bottom: calc(100% + 1px);
+
      }
     border-color: #333 transparent transparent transparent;
+
     
}
+
      console.log("Seções colapsáveis encontradas: " + collapsibleSections.length);
 
+
     
/* Tooltip PARA IMAGENS */
+
      if (collapsibleSections.length > 0) {
.tile-top.tile-image .warp-copy::after {
+
        collapsibleSections.each(function() {
    bottom: -25px;
+
          var section = $(this);
     top: auto !important;
+
          console.log("Expandindo seção colapsável");
}
+
         
 
+
          section.removeClass('mw-collapsed');
.tile-top.tile-image .warp-copy::before {
+
          var toggleButton = section.find('.mw-collapsible-toggle').first();
    bottom: -18px;
+
          if (toggleButton.length) {
    top: auto !important;
+
            console.log("Clicando no botão de expansão");
     border-color: #333 transparent transparent transparent !important;
+
            toggleButton.click();
}
+
          }
 
+
         
/* Estados de hover */
+
          if (section.hasClass('wikitable')) {
.warp-copy:hover::after,
+
            console.log("Expandindo tabela wikitable");
.warp-copy:hover::before {
+
            section.find('tr:not(:first-child)').show();
     opacity: 1;
+
          }
     visibility: visible;
+
         
}
+
          section.find('.mw-collapsible-content').show();
 
+
        });
/* Feedback de copiado - APLICA-SE A TODOS OS WARP-COPY */
+
       
.warp-copy.copied::after {
+
        setTimeout(function() {
     content: "Copied!" !important;
+
          scrollToTarget(targetElement);
     background-color: #4CAF50 !important;
+
        }, 400);
     opacity: 1 !important;
+
      } else {
     visibility: visible !important;
+
        scrollToTarget(targetElement);
}
+
      }
 
+
     } else {
.warp-copy.copied {
+
      console.log("Elemento alvo não encontrado para hash: " + hash);
    color: #4CAF50 !important;
+
     }
    text-decoration: underline dotted #4CAF50 !important;
+
  }
}
+
 
 
+
  function scrollToTarget(element) {
/* ========== ESTILOS ESPECÍFICOS PARA NPCs ========== */
+
     console.log("Rolando até o elemento alvo");
.tile-row {
+
    $('html, body').animate({
    display: flex;
+
      scrollTop: element.offset().top - 100
    flex-flow: row wrap;
+
     }, 200);
    margin-bottom: 1em;
+
  }
}
+
 
 
+
  if (typeof mw !== 'undefined' && mw.hook) {
.tile-halves {
+
     mw.hook('wikipage.content').add(function() {
    display: flex;
+
      console.log("Conteúdo da wiki atualizado");
    flex-flow: row wrap;
+
      if (window.location.hash) {
    border: 1px solid #e4eaee;
+
        setTimeout(function() {
    background: #ffffff;
+
          expandSectionForAnchor(window.location.hash);
    box-shadow: 0 0.25rem 0.35rem -0.25rem rgba(0, 0, 0, 0.1);
+
        }, 300);
    position: relative;
+
      }
}
+
     });
 
+
  }
.tile-halves h2 {
+
});
    font-size: 1.4em;
 
    font-weight: bold;
 
    border: none;
 
    margin: 0 0 0.4em;
 
}
 
 
 
.tile-top {
 
    width: 100%;
 
    padding: 1.3rem 1.5rem 0.6rem;
 
}
 
 
 
.tile-top.tile-image {
 
    display: flex;
 
    align-items: center;
 
    justify-content: center;
 
    background-color: #949eaa;
 
    overflow: visible;
 
    padding: 0;
 
    height: auto;
 
    width: 100%;
 
    box-sizing: border-box;
 
}
 
 
 
.tile-top.tile-image a {
 
    width: 100%;
 
    height: 100%;
 
    display: flex;
 
    justify-content: center;
 
    align-items: center;
 
}
 
 
 
.tile-top.tile-image img {
 
    display: block;
 
    max-width: 100%;
 
    width: auto;
 
    height: auto;
 
    margin: 0;
 
    transition: 0.4s ease-out;
 
    object-fit: contain;
 
}
 
 
 
/* Estilo para tamanhos personalizados */
 
.tile-top.tile-image img.custom-size {
 
    width: var(--custom-width, auto);
 
    height: var(--custom-height, auto);
 
    max-width: var(--custom-width, 100%);
 
    max-height: var(--custom-height, none);
 
}
 
 
 
.tile-bottom {
 
    background: #ffffff;
 
    border-top: 1px solid #e4eaee;
 
    width: 100%;
 
    padding: 1rem 1.5rem 0.6rem;
 
}
 
 
 
.tile-bottom.link-button {
 
    align-self: center;
 
    padding: 0;
 
    width: auto;
 
    margin: 0 auto;
 
    max-width: fit-content;
 
}
 
 
 
.mainpage-contents .tile-halves {
 
    display: inline-block;
 
     flex: 0 0 auto;
 
    margin-right: 0.9rem;
 
    width: auto;
 
     max-width: max-content;
 
}
 
 
 
.mainpage-contents .tile-halves:hover .tile-top img {
 
     transform: scale(1.04);
 
}
 
 
 
.mainpage-contents .tile-halves:last-child {
 
    margin-right: 0;
 
}
 
 
 
.npc-subtitle {
 
    font-size: 0.8em;
 
    color: #666;
 
    margin-top: -5px;
 
     text-align: center;
 
    font-style: italic;
 
    line-height: 1.2;
 
}
 
 
 
.mainpage-contents.tile-row {
 
     display: flex;
 
    flex-flow: row wrap;
 
    gap: 15px;
 
    justify-content: flex-start;
 
}
 
 
 
.mainpage-contents .contents-equipment.tile-halves {
 
    margin-right: 0;
 
    flex: 0 0 auto;
 
    min-width: 150px;
 
    max-width: 200px;
 
}
 
 
 
/* Título do NPC */
 
.tile-bottom.link-button h2 .warp-copy {
 
    color: #000080;
 
    font-weight: bold;
 
    display: block;
 
    text-align: center;
 
    text-decoration: none;
 
}
 
 
 
.tile-bottom.link-button h2 {
 
    position: relative;
 
    overflow: visible;
 
}
 
 
 
/* Classes para dimensionamento manual */
 
.npc-image-small {
 
     max-width: 150px !important;
 
}
 
.npc-image-medium {
 
    max-width: 200px !important;
 
}
 
.npc-image-large {
 
    max-width: 250px !important;
 
}
 

Revision as of 16:25, 9 May 2025

JS
/* Any JavaScript here will be loaded for all users on every page load. */

$(document).ready(function() {
  // Função única para cópia de texto
  $(document).on('click', '.warp-copy', function(e) {
    e.preventDefault();
    var textToCopy = $(this).attr('data-copy');
    
    // Cria elemento temporário para cópia
    var tempInput = document.createElement('textarea');
    tempInput.value = textToCopy;
    document.body.appendChild(tempInput);
    tempInput.select();
    document.execCommand('copy');
    document.body.removeChild(tempInput);
    
    // Adiciona classe para feedback visual
    var $element = $(this);
    $element.addClass('copied');
    setTimeout(function() {
      $element.removeClass('copied');
    }, 2000);
  });

  // Adicionar funcionalidade às imagens dos NPCs
  function initImageCopy() {
    $('.tile-top.tile-image a').each(function() {
      var $link = $(this);
      if (!$link.hasClass('warp-copy')) {
        var npcId = $link.attr('href').replace('#','');
        $link.addClass('warp-copy')
             .attr('data-copy', '@warp ' + npcId)
             .css('cursor', 'pointer');
      }
    });
    
    // Aplicar tamanhos personalizados para imagens
    $('.tile-top.tile-image img').each(function() {
      var $img = $(this);
      var width = $img.data('width') || $img.attr('width');
      var height = $img.data('height') || $img.attr('height');
      
      if (width || height) {
        $img.addClass('custom-size');
        if (width) {
          $img.css('--custom-width', width + 'px');
        }
        if (height) {
          $img.css('--custom-height', height + 'px');
        }
      }
    });
  }

  // Inicializar ao carregar e em atualizações de conteúdo
  initImageCopy();
  if (typeof mw !== 'undefined' && mw.hook) {
    mw.hook('wikipage.content').add(initImageCopy);
  }

  /* Auto-expand sections when clicking anchored links */
  console.log("Inicializando script para expandir seções com links âncora");
  
  // Handle initial page load with hash
  if (window.location.hash) {
    console.log("Página carregada com hash: " + window.location.hash);
    setTimeout(function() {
      expandSectionForAnchor(window.location.hash);
    }, 300);
  }
  
  // Handle clicks on anchor links
  $(document).on('click', 'a[href^="#"]', function(event) {
    var hash = $(this).attr('href');
    console.log("Clique em link âncora: " + hash);
    event.preventDefault();
    
    if (history.pushState) {
      history.pushState(null, null, hash);
    } else {
      location.hash = hash;
    }
    
    expandSectionForAnchor(hash);
  });
  
  function expandSectionForAnchor(hash) {
    console.log("Procurando e expandindo seção para âncora: " + hash);
    var targetElement = $(hash);
    
    if (targetElement.length) {
      console.log("Elemento alvo encontrado");
      
      var collapsibleSections = targetElement.parents('.mw-collapsible.mw-collapsed');
      var directCollapsible = targetElement.closest('.mw-collapsible.mw-collapsed');
      
      if (directCollapsible.length) {
        collapsibleSections = collapsibleSections.add(directCollapsible);
      }
      
      console.log("Seções colapsáveis encontradas: " + collapsibleSections.length);
      
      if (collapsibleSections.length > 0) {
        collapsibleSections.each(function() {
          var section = $(this);
          console.log("Expandindo seção colapsável");
          
          section.removeClass('mw-collapsed');
          var toggleButton = section.find('.mw-collapsible-toggle').first();
          if (toggleButton.length) {
            console.log("Clicando no botão de expansão");
            toggleButton.click();
          }
          
          if (section.hasClass('wikitable')) {
            console.log("Expandindo tabela wikitable");
            section.find('tr:not(:first-child)').show();
          }
          
          section.find('.mw-collapsible-content').show();
        });
        
        setTimeout(function() {
          scrollToTarget(targetElement);
        }, 400);
      } else {
        scrollToTarget(targetElement);
      }
    } else {
      console.log("Elemento alvo não encontrado para hash: " + hash);
    }
  }
  
  function scrollToTarget(element) {
    console.log("Rolando até o elemento alvo");
    $('html, body').animate({
      scrollTop: element.offset().top - 100
    }, 200);
  }
  
  if (typeof mw !== 'undefined' && mw.hook) {
    mw.hook('wikipage.content').add(function() {
      console.log("Conteúdo da wiki atualizado");
      if (window.location.hash) {
        setTimeout(function() {
          expandSectionForAnchor(window.location.hash);
        }, 300);
      }
    });
  }
});