Mudanças entre as edições de "Widget:Character.Background"

De Wiki Gla
Ir para navegação Ir para pesquisar
m
m
 
Linha 3: Linha 3:
     =========================== -->
     =========================== -->
<script>
<script>
    /**
    * @typedef {Object} MediaWiki
    * @property {Object} util
    * @property {Function} util.wikiScript
    * @property {Function} util.wikiUrlencode
    * @property {Object} config
    * @property {Function} config.get
    */
    // @ts-ignore - MediaWiki global
    var mw = window.mw || {};
     (function () {
     (function () {
        /**
        * Builds a MediaWiki file URL from a filename
        * @param {string} fileName - The filename (with or without "Arquivo:" prefix)
        * @returns {string} The full URL to the file
        */
         function buildBgURL(fileName) {
         function buildBgURL(fileName) {
             if (!fileName) return '';
             if (!fileName) return '';
Linha 17: Linha 33:
         }
         }


        /**
        * Applies background image to an element
        * @param {HTMLElement} el - The element to apply background to
        */
         function applyBg(el) {
         function applyBg(el) {
             try {
             try {
Linha 30: Linha 50:
                     el.style.backgroundImage = 'url("' + url + '")';
                     el.style.backgroundImage = 'url("' + url + '")';
                 }
                 }
             } catch (e) { /* no-op */ }
             } catch (e) {
                /* no-op */
            }
         }
         }



Edição atual tal como às 11h56min de 4 de dezembro de 2025

<script>

   /**
    * @typedef {Object} MediaWiki
    * @property {Object} util
    * @property {Function} util.wikiScript
    * @property {Function} util.wikiUrlencode
    * @property {Object} config
    * @property {Function} config.get
    */
   // @ts-ignore - MediaWiki global
   var mw = window.mw || {};
   (function () {
       /**
        * Builds a MediaWiki file URL from a filename
        * @param {string} fileName - The filename (with or without "Arquivo:" prefix)
        * @returns {string} The full URL to the file
        */
       function buildBgURL(fileName) {
           if (!fileName) return ;
           var base = (window.mw && mw.util && typeof mw.util.wikiScript === 'function')
               ? mw.util.wikiScript()
               : (window.mw && mw.config ? (mw.config.get('wgScript') || '/index.php') : '/index.php');
           var 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, '/');
           }
       }
       /**
        * Applies background image to an element
        * @param {HTMLElement} el - The element to apply background to
        */
       function applyBg(el) {
           try {
               var url = el.getAttribute('data-bg-url');
               if (!url) {
                   var 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)
       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>