Widget:C.Background

De Wiki Gla
Revisão de 21h35min de 31 de dezembro de 2025 por Gurren1 (discussão | contribs) (Criou página com '<!-- BACKGROUND SYSTEM --> <script> (function () { 'use strict'; const { filePathURL } = window.__CBase || {}; function buildBgURL(fileName) {...')
(dif) ← Edição anterior | Revisão atual (dif) | Versão posterior → (dif)
Ir para navegação Ir para pesquisar

<script>

   (function () {
       'use strict';
       const { filePathURL } = window.__CBase || {};
       function buildBgURL(fileName) {
           if (filePathURL) return filePathURL(fileName);
           if (!fileName) return ;
           const base = (window.mw && mw.util && typeof mw.util.wikiScript === 'function')
               ? mw.util.wikiScript()
               : (window.mw && window.mw.config ? (mw.config.get('wgScript') || '/index.php') : '/index.php');
           const path = 'Especial:FilePath/' + fileName.replace(/^Arquivo:|^File:/, );
           if (window.mw && mw.util && typeof mw.util.wikiUrlencode === 'function') {
               return base + '?title=' + mw.util.wikiUrlencode(path);
           } else {
               return base + '?title=' + encodeURIComponent(path).replace(/%2F/g, '/');
           }
       }
       function applyBg(el) {
           try {
               let url = el.getAttribute('data-bg-url');
               if (!url) {
                   const f = el.getAttribute('data-bg-file');
                   if (f) {
                       url = buildBgURL(f);
                       el.setAttribute('data-bg-url', url);
                   }
               }
               if (url) {
                   el.style.backgroundImage = 'url("' + url + '")';
               }
           } catch (e) {
               // no-op
           }
       }
       // Aplicar backgrounds imediatamente
       document.querySelectorAll('[data-bg-url], [data-bg-file]').forEach(applyBg);
       // Apply to future elements (AJAX)
       if (window.MutationObserver) {
           new MutationObserver(function (mutations) {
               mutations.forEach(function (m) {
                   if (m.type === 'childList') {
                       m.addedNodes.forEach(function (n) {
                           if (n.nodeType === 1) {
                               if (n.hasAttribute && (n.hasAttribute('data-bg-file') || n.hasAttribute('data-bg-url'))) {
                                   applyBg(n);
                               }
                               if (n.querySelectorAll) {
                                   n.querySelectorAll('[data-bg-file], [data-bg-url]').forEach(applyBg);
                               }
                           }
                       });
                   } else if (m.type === 'attributes' && m.target) {
                       applyBg(m.target);
                   }
               });
           }).observe(document.body, {
               attributes: true,
               attributeFilter: ['data-bg-file', 'data-bg-url'],
               childList: true,
               subtree: true,
           });
       }
   })();

</script>