MediaWiki:Common.js: Difference between revisions

From Fatesend Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 73: Line 73:
       });
       });
   });
   });
})();
(function () {
  function loadScriptOnce(src, id) {
    return new Promise(function (resolve, reject) {
      if (document.getElementById(id)) return resolve();
      var s = document.createElement('script');
      s.id = id;
      s.src = src;
      s.async = true;
      s.onload = resolve;
      s.onerror = reject;
      document.head.appendChild(s);
    });
  }
  function initViewer(el) {
    var accessory = el.getAttribute('data-accessory') || '';
    if (!accessory) return;
    var ro = new window.ROBrowser({
      type: window.ROBrowser.TYPE.FRAME,
      target: el,
      application: window.ROBrowser.APP.MODELVIEWER,
      // ważne, bo nie masz zbuildowanych ModelViewer.js w root:
      development: true,
      // asset source (na razie zostaw jak w teście):
      remoteClient: 'https://grf.robrowser.com/',
      skipIntro: true,
      skipServerList: true,
      accessory: accessory
    });
    ro.start();
  }
  function boot() {
    var nodes = document.querySelectorAll('.ro-modelviewer');
    if (!nodes.length) return;
    loadScriptOnce('/robrowser/api.js', 'robrowser-api')
      .then(function () {
        nodes.forEach(initViewer);
      })
      .catch(function (err) {
        console.error('Failed to load /robrowser/api.js', err);
      });
  }
  // MediaWiki hook (bezpieczne dla dynamicznych stron)
  if (window.mw && mw.hook) {
    mw.hook('wikipage.content').add(boot);
  } else {
    document.addEventListener('DOMContentLoaded', boot);
  }
})();
})();

Revision as of 15:24, 27 January 2026

/* Any JavaScript here will be loaded for all users on every page load. */
(function () {
  // If there are no DP links on the page, don't load anything.
  if (!document.querySelector('a[href*="divine-pride.net/database/item/"]')) return;

  var s = document.createElement('script');
  s.src = 'https://www.divine-pride.net/scripts/tooltip.js';
  s.async = true;
  document.head.appendChild(s);
})();


(function () {
  function loadScriptOnce(src, id) {
    return new Promise(function (resolve, reject) {
      if (document.getElementById(id)) return resolve();
      var s = document.createElement('script');
      s.id = id;
      s.src = src;
      s.async = true;
      s.onload = resolve;
      s.onerror = reject;
      document.head.appendChild(s);
    });
  }

  // Your hosted ROBrowser API
  var RO_API_JS = '/robrowser/api.js';

  function openViewer(el) {
    var sprite = el.getAttribute('data-sprite') || '';
    var jobId = parseInt(el.getAttribute('data-jobid') || '0', 10) || 0;
    var job = el.getAttribute('data-job') || '';
    var robe = el.getAttribute('data-robe') || '';

    var ro = new window.ROBrowser({
      application: window.ROBrowser.APP.MODELVIEWER,
      type: window.ROBrowser.TYPE.POPUP,
      width: 820,
      height: 520,
      development: true, 

      // Start with this. If assets don't load, we’ll switch to your own hosted client assets.
      remoteClient: 'https://grf.robrowser.com/',

      skipIntro: true,
      skipServerList: true,

      accessory: sprite,
      jobId: jobId,
      job: job,
      robe: robe
    });

    ro.start();
  }

  document.addEventListener('click', function (e) {
    var a = e.target.closest && e.target.closest('.dp-modelviewer');
    if (!a) return;
    e.preventDefault();

    loadScriptOnce(RO_API_JS, 'robrowser-api')
      .then(function () {
        if (!window.ROBrowser) {
          console.error('ROBrowser not loaded. Check /robrowser/api.js');
          return;
        }
        openViewer(a);
      })
      .catch(function (err) {
        console.error('Failed to load ROBrowser API JS:', err);
      });
  });
})();
(function () {
  function loadScriptOnce(src, id) {
    return new Promise(function (resolve, reject) {
      if (document.getElementById(id)) return resolve();
      var s = document.createElement('script');
      s.id = id;
      s.src = src;
      s.async = true;
      s.onload = resolve;
      s.onerror = reject;
      document.head.appendChild(s);
    });
  }

  function initViewer(el) {
    var accessory = el.getAttribute('data-accessory') || '';
    if (!accessory) return;

    var ro = new window.ROBrowser({
      type: window.ROBrowser.TYPE.FRAME,
      target: el,
      application: window.ROBrowser.APP.MODELVIEWER,

      // ważne, bo nie masz zbuildowanych ModelViewer.js w root:
      development: true,

      // asset source (na razie zostaw jak w teście):
      remoteClient: 'https://grf.robrowser.com/',

      skipIntro: true,
      skipServerList: true,

      accessory: accessory
    });

    ro.start();
  }

  function boot() {
    var nodes = document.querySelectorAll('.ro-modelviewer');
    if (!nodes.length) return;

    loadScriptOnce('/robrowser/api.js', 'robrowser-api')
      .then(function () {
        nodes.forEach(initViewer);
      })
      .catch(function (err) {
        console.error('Failed to load /robrowser/api.js', err);
      });
  }

  // MediaWiki hook (bezpieczne dla dynamicznych stron)
  if (window.mw && mw.hook) {
    mw.hook('wikipage.content').add(boot);
  } else {
    document.addEventListener('DOMContentLoaded', boot);
  }
})();