Mudanças entre as edições de "Widget:Droflax"

De Wiki Gla
Ir para navegação Ir para pesquisar
Linha 2: Linha 2:
     'use strict';
     'use strict';
      
      
    // Configuración del widget
     var config = {
     var config = {
         modes: {
         modes: {
             styles: function() {
             styles: function() {
                 // Solo inyectar CSS crítico
                 // CSS crítico para visualización inicial
                 mw.loader.load('//tu-wiki.org/w/index.php?title=MediaWiki:PersonaStyles.css&action=raw&ctype=text/css', 'text/css');
                 var criticalCSS = `
                    .personaje-box {
                        display: block;
                        visibility: visible;
                        min-height: 200px;
                        font-family: sans-serif;
                    }
                    .personaje-header {
                        background: #f5f5f5;
                        padding: 15px;
                        border-radius: 8px 8px 0 0;
                    }
                    .personaje-nome {
                        font-size: 24px;
                        font-weight: bold;
                    }
                    .art-personaje {
                        max-width: 100%;
                        height: auto;
                        display: block;
                        margin: 0 auto;
                    }
                `;
                  
                  
                 // Precargar recursos no críticos
                var styleTag = document.createElement('style');
                styleTag.textContent = criticalCSS;
                document.head.appendChild(styleTag);
               
                 // Precargar recursos
                 var preloadLinks = [
                 var preloadLinks = [
                     '<link rel="preload" href="//tu-wiki.org/w/index.php?title=MediaWiki:PersonaAnimations.css&action=raw&ctype=text/css" as="style" onload="this.onload=null;this.rel=\'stylesheet\'">',
                     '<link rel="preload" href="https://wiki.gla.com.br/w/index.php?title=MediaWiki:Droflax.css&action=raw&ctype=text/css" as="style" onload="this.onload=null;this.rel=\'stylesheet\'">',
                     '<link rel="preload" href="//tu-wiki.org/js/PersonaInteractions.js" as="script">'
                     '<link rel="preload" href="https://wiki.gla.com.br/w/index.php?title=MediaWiki:Droflax.js&action=raw&ctype=text/javascript" as="script">'
                 ].join('');
                 ].join('');
                  
                  
Linha 18: Linha 43:
             },
             },
             scripts: function() {
             scripts: function() {
                // Esperar a que el contenido Lua esté listo
                 var checkReady = setInterval(function() {
                 var checkReady = setInterval(function() {
                     var container = document.querySelector('.personaje-box');
                     var container = document.querySelector('.personaje-box');
                     if (container && container.getAttribute('data-loaded') === 'false') {
                     if (container && container.getAttribute('data-loaded') === 'false') {
                         clearInterval(checkReady);
                         clearInterval(checkReady);
                         container.setAttribute('data-loaded', 'true');
                         initDroflax();
                        initPersonaje();
                     }
                     }
                 }, 100);
                 }, 100);
                  
                  
                 function initPersonaje() {
                 function initDroflax() {
                    // Cargar JS no crítico de forma diferida
                     var script = document.createElement('script');
                     var script = document.createElement('script');
                     script.src = '//tu-wiki.org/js/PersonaInteractions.js';
                     script.src = 'https://wiki.gla.com.br/w/index.php?title=MediaWiki:Droflax.js&action=raw&ctype=text/javascript';
                     script.defer = true;
                     script.defer = true;
                    script.async = true;
                     document.head.appendChild(script);
                     document.head.appendChild(script);
                   
                    // Activar animaciones CSS solo cuando todo esté listo
                    document.documentElement.classList.add('animations-ready');
                 }
                 }
             }
             }
         },
         },
         init: function() {
         init: function() {
             var mode = $.getUrlVar('mode') || 'scripts';
             var mode = this.getMode();
             if (this.modes[mode]) {
             if (this.modes[mode]) {
                 this.modes[mode]();
                 this.modes[mode]();
             }
             }
        },
        getMode: function() {
            var matches = location.href.match(/[?&]mode=([^&]+)/);
            return matches ? matches[1] : 'scripts';
         }
         }
     };
     };
      
      
    // Inicialización
     if (typeof module === 'object' && typeof module.exports === 'object') {
     if (typeof module === 'object' && typeof module.exports === 'object') {
         module.exports = config;
         module.exports = config;

Edição das 23h21min de 19 de julho de 2025

(function() {

   'use strict';
   
   var config = {
       modes: {
           styles: function() {
               // CSS crítico para visualización inicial
               var criticalCSS = `
                   .personaje-box {
                       display: block;
                       visibility: visible;
                       min-height: 200px;
                       font-family: sans-serif;
                   }
                   .personaje-header {
                       background: #f5f5f5;
                       padding: 15px;
                       border-radius: 8px 8px 0 0;
                   }
                   .personaje-nome {
                       font-size: 24px;
                       font-weight: bold;
                   }
                   .art-personaje {
                       max-width: 100%;
                       height: auto;
                       display: block;
                       margin: 0 auto;
                   }
               `;
               
               var styleTag = document.createElement('style');
               styleTag.textContent = criticalCSS;
               document.head.appendChild(styleTag);
               
               // Precargar recursos
               var preloadLinks = [
                   '<link rel="preload" href="https://wiki.gla.com.br/w/index.php?title=MediaWiki:Droflax.css&action=raw&ctype=text/css" as="style" onload="this.onload=null;this.rel=\'stylesheet\'">',
                   '<link rel="preload" href="https://wiki.gla.com.br/w/index.php?title=MediaWiki:Droflax.js&action=raw&ctype=text/javascript" as="script">'
               ].join();
               
               document.head.insertAdjacentHTML('beforeend', preloadLinks);
           },
           scripts: function() {
               var checkReady = setInterval(function() {
                   var container = document.querySelector('.personaje-box');
                   if (container && container.getAttribute('data-loaded') === 'false') {
                       clearInterval(checkReady);
                       initDroflax();
                   }
               }, 100);
               
               function initDroflax() {
                   var script = document.createElement('script');
                   script.src = 'https://wiki.gla.com.br/w/index.php?title=MediaWiki:Droflax.js&action=raw&ctype=text/javascript';
                   script.defer = true;
                   document.head.appendChild(script);
               }
           }
       },
       init: function() {
           var mode = this.getMode();
           if (this.modes[mode]) {
               this.modes[mode]();
           }
       },
       getMode: function() {
           var matches = location.href.match(/[?&]mode=([^&]+)/);
           return matches ? matches[1] : 'scripts';
       }
   };
   
   if (typeof module === 'object' && typeof module.exports === 'object') {
       module.exports = config;
   } else {
       config.init();
   }

})();