MediaWiki:Common.js: Difference between revisions
Jump to navigation
Jump to search
Superadmin (talk | contribs) No edit summary |
Superadmin (talk | contribs) No edit summary |
||
| Line 25: | Line 25: | ||
} | } | ||
var RO_API_JS = '/robrowser/api.js'; | var RO_API_JS = '/robrowser/api.js'; | ||
function | function ensureROBrowser() { | ||
var sprite = | return loadScriptOnce(RO_API_JS, 'robrowser-api').then(function () { | ||
var jobId = parseInt( | if (!window.ROBrowser) throw new Error('ROBrowser not available after loading api.js'); | ||
var job = | }); | ||
var robe = | } | ||
// POPUP viewer (button) | |||
function openPopupFromLink(a) { | |||
var sprite = a.getAttribute('data-sprite') || a.getAttribute('data-accessory') || ''; | |||
var jobId = parseInt(a.getAttribute('data-jobid') || '0', 10) || 0; | |||
var job = a.getAttribute('data-job') || ''; | |||
var robe = a.getAttribute('data-robe') || ''; | |||
if (!sprite) return; | |||
var ro = new window.ROBrowser({ | var ro = new window.ROBrowser({ | ||
| Line 39: | Line 46: | ||
width: 820, | width: 820, | ||
height: 520, | height: 520, | ||
development: true, | development: true, | ||
remoteClient: 'https://grf.robrowser.com/', | remoteClient: 'https://grf.robrowser.com/', | ||
skipIntro: true, | skipIntro: true, | ||
skipServerList: true, | skipServerList: true, | ||
accessory: sprite, | accessory: sprite, | ||
jobId: jobId, | jobId: jobId, | ||
| Line 56: | Line 59: | ||
} | } | ||
// EMBED viewer (div) | |||
function initEmbed(el) { | |||
if ( | if (el.getAttribute('data-ro-init') === '1') return; | ||
el.setAttribute('data-ro-init', '1'); | |||
var accessory = el.getAttribute('data-accessory') || ''; | var accessory = el.getAttribute('data-accessory') || ''; | ||
if (!accessory) return; | if (!accessory) return; | ||
| Line 96: | Line 71: | ||
target: el, | target: el, | ||
application: window.ROBrowser.APP.MODELVIEWER, | application: window.ROBrowser.APP.MODELVIEWER, | ||
development: true, | development: true, | ||
remoteClient: 'https://grf.robrowser.com/', | remoteClient: 'https://grf.robrowser.com/', | ||
skipIntro: true, | skipIntro: true, | ||
skipServerList: true, | skipServerList: true, | ||
accessory: accessory | accessory: accessory | ||
}); | }); | ||
| Line 112: | Line 81: | ||
} | } | ||
function | // Click handler for popup buttons | ||
var nodes = document.querySelectorAll('.ro-modelviewer'); | document.addEventListener('click', function (e) { | ||
var a = e.target.closest && e.target.closest('a.dp-modelviewer'); | |||
if (!a) return; | |||
// IMPORTANT: prevents navigation / recursion | |||
e.preventDefault(); | |||
e.stopPropagation(); | |||
ensureROBrowser() | |||
.then(function () { openPopupFromLink(a); }) | |||
.catch(function (err) { console.error('ModelViewer popup error:', err); }); | |||
}); | |||
// Auto-init embedded viewers on page load / ajax loads | |||
function bootEmbeds(root) { | |||
var nodes = (root || document).querySelectorAll('.ro-modelviewer'); | |||
if (!nodes.length) return; | if (!nodes.length) return; | ||
ensureROBrowser() | |||
.then(function () { | .then(function () { nodes.forEach(initEmbed); }) | ||
.catch(function (err) { console.error('ModelViewer embed error:', err); }); | |||
.catch(function (err) { | |||
} | } | ||
if (window.mw && mw.hook) { | if (window.mw && mw.hook) { | ||
mw.hook('wikipage.content').add( | mw.hook('wikipage.content').add(function ($content) { | ||
bootEmbeds($content[0]); | |||
}); | |||
} else { | } else { | ||
document.addEventListener('DOMContentLoaded', | document.addEventListener('DOMContentLoaded', function () { bootEmbeds(document); }); | ||
} | } | ||
})(); | })(); | ||
Revision as of 15:28, 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);
});
}
var RO_API_JS = '/robrowser/api.js';
function ensureROBrowser() {
return loadScriptOnce(RO_API_JS, 'robrowser-api').then(function () {
if (!window.ROBrowser) throw new Error('ROBrowser not available after loading api.js');
});
}
// POPUP viewer (button)
function openPopupFromLink(a) {
var sprite = a.getAttribute('data-sprite') || a.getAttribute('data-accessory') || '';
var jobId = parseInt(a.getAttribute('data-jobid') || '0', 10) || 0;
var job = a.getAttribute('data-job') || '';
var robe = a.getAttribute('data-robe') || '';
if (!sprite) return;
var ro = new window.ROBrowser({
application: window.ROBrowser.APP.MODELVIEWER,
type: window.ROBrowser.TYPE.POPUP,
width: 820,
height: 520,
development: true,
remoteClient: 'https://grf.robrowser.com/',
skipIntro: true,
skipServerList: true,
accessory: sprite,
jobId: jobId,
job: job,
robe: robe
});
ro.start();
}
// EMBED viewer (div)
function initEmbed(el) {
if (el.getAttribute('data-ro-init') === '1') return;
el.setAttribute('data-ro-init', '1');
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,
development: true,
remoteClient: 'https://grf.robrowser.com/',
skipIntro: true,
skipServerList: true,
accessory: accessory
});
ro.start();
}
// Click handler for popup buttons
document.addEventListener('click', function (e) {
var a = e.target.closest && e.target.closest('a.dp-modelviewer');
if (!a) return;
// IMPORTANT: prevents navigation / recursion
e.preventDefault();
e.stopPropagation();
ensureROBrowser()
.then(function () { openPopupFromLink(a); })
.catch(function (err) { console.error('ModelViewer popup error:', err); });
});
// Auto-init embedded viewers on page load / ajax loads
function bootEmbeds(root) {
var nodes = (root || document).querySelectorAll('.ro-modelviewer');
if (!nodes.length) return;
ensureROBrowser()
.then(function () { nodes.forEach(initEmbed); })
.catch(function (err) { console.error('ModelViewer embed error:', err); });
}
if (window.mw && mw.hook) {
mw.hook('wikipage.content').add(function ($content) {
bootEmbeds($content[0]);
});
} else {
document.addEventListener('DOMContentLoaded', function () { bootEmbeds(document); });
}
})();