MediaWiki:Common.js: Difference between revisions
Myriad-admin (talk | contribs) No edit summary |
Myriad-admin (talk | contribs) No edit summary |
||
Line 1: | Line 1: | ||
mw.loader.using('mediawiki.util', function () { | mw.loader.using('mediawiki.util', function () { | ||
$(document).ready(function () { | $(document).ready(function () { | ||
// | // 1) Prevent double injection | ||
if ($('#drg-navbar').length) return; | if ($('#drg-navbar').length) return; | ||
// | // 2) Grab the real logo before hiding it | ||
const logoSrc = $('#p-logo img').attr('src') | const logoSrc = $('#p-logo img').attr('src') | ||
|| '/images/3/3f/Myriad_logo_icon_transparent.png'; | || '/images/3/3f/Myriad_logo_icon_transparent.png'; | ||
// | // 3) Hide all Vector/MF headers via CSS, so no need to remove in JS | ||
// 4) Build user-area (dropdown if logged in, else Login) | |||
const userName = mw.config.get('wgUserName'); | const userName = mw.config.get('wgUserName'); | ||
let userArea; | let userArea; | ||
Line 20: | Line 22: | ||
</div>`; | </div>`; | ||
} else { | } else { | ||
userArea = `<a class="drg-button" href="${mw.util.getUrl('Special:UserLogin')}">Login</a>`; | userArea = `<a class="drg-button" href="${ | ||
mw.util.getUrl('Special:UserLogin') | |||
}">Login</a>`; | |||
} | } | ||
// | // 5) Clone MediaWiki's search | ||
const searchClone = $('#p-search form').clone() | const searchClone = $('#p-search form').clone() | ||
.wrap('<div class="drg-search"></div>') | .wrap('<div class="drg-search"></div>') | ||
.parent()[0].outerHTML; | .parent()[0].outerHTML; | ||
// | // 6) Define nav links | ||
const links = ` | const links = ` | ||
<nav class="drg-navbar-links"> | <nav class="drg-navbar-links"> | ||
Line 37: | Line 41: | ||
</nav>`; | </nav>`; | ||
// | // 7) Prepend the navbar | ||
$('body').prepend(` | $('body').prepend(` | ||
<div id="drg-navbar"> | <div id="drg-navbar"> | ||
<div class="drg-navbar-container"> | <div class="drg-navbar-container"> | ||
<a href="${mw.util.getUrl('Main_Page')}" class="drg-navbar-logo"> | <a href="${mw.util.getUrl('Main_Page')}" | ||
class="drg-navbar-logo"> | |||
<img src="${logoSrc}" alt="MYRIAD Logo"> | <img src="${logoSrc}" alt="MYRIAD Logo"> | ||
</a> | </a> | ||
Line 53: | Line 58: | ||
`); | `); | ||
// | // 8) Insert your original footer | ||
function insertFooter() { | function insertFooter() { | ||
const icons = $('#footer-icons'); | const icons = $('#footer-icons'); | ||
Line 88: | Line 93: | ||
`); | `); | ||
} | } | ||
insertFooter(); | insertFooter(); | ||
}); | }); | ||
}); | }); |
Revision as of 14:24, 24 June 2025
mw.loader.using('mediawiki.util', function () {
$(document).ready(function () {
// 1) Prevent double injection
if ($('#drg-navbar').length) return;
// 2) Grab the real logo before hiding it
const logoSrc = $('#p-logo img').attr('src')
|| '/images/3/3f/Myriad_logo_icon_transparent.png';
// 3) Hide all Vector/MF headers via CSS, so no need to remove in JS
// 4) Build user-area (dropdown if logged in, else Login)
const userName = mw.config.get('wgUserName');
let userArea;
if (userName) {
const personalMenu = $('#p-personal ul').clone()
.addClass('drg-user-dropdown')
.find('li').css('border','none').end();
userArea = `<div class="drg-user">
<span>Welcome, ${userName}</span>
${personalMenu.prop('outerHTML')}
</div>`;
} else {
userArea = `<a class="drg-button" href="${
mw.util.getUrl('Special:UserLogin')
}">Login</a>`;
}
// 5) Clone MediaWiki's search
const searchClone = $('#p-search form').clone()
.wrap('<div class="drg-search"></div>')
.parent()[0].outerHTML;
// 6) Define nav links
const links = `
<nav class="drg-navbar-links">
<a href="${mw.util.getUrl('Catalogue')}">Catalogue</a>
<a href="${mw.util.getUrl('Definitions')}">Definitions</a>
<a href="${mw.util.getUrl('Resources')}">Resources</a>
<a href="${mw.util.getUrl('Contribute')}">Contribute</a>
</nav>`;
// 7) Prepend the navbar
$('body').prepend(`
<div id="drg-navbar">
<div class="drg-navbar-container">
<a href="${mw.util.getUrl('Main_Page')}"
class="drg-navbar-logo">
<img src="${logoSrc}" alt="MYRIAD Logo">
</a>
${links}
${searchClone}
<div class="drg-navbar-actions">
${userArea}
</div>
</div>
</div>
`);
// 8) Insert your original footer
function insertFooter() {
const icons = $('#footer-icons');
if (!icons.length) return setTimeout(insertFooter, 100);
icons.before(`
<div id="drg-footer">
<div class="drg-columns">
<div class="drg-column drg-column-left">
<a href="/index.php/Disaster_Risk_Gateway">About</a>
<a href="/index.php/Disaster_Risk_Gateway:Privacy_Notice">Privacy Notice</a>
<a href="/index.php/Disaster_Risk_Gateway:Terms_of_Use">Terms of Use</a>
<a href="mailto:DisasterRiskGateway@bgs.ac.uk"><strong>Contact Us</strong></a>
</div>
<div class="drg-divider"></div>
<div class="drg-column drg-column-center">
<div class="drg-eu-flag">
<img src="/images/e/e3/Normal-reproduction-high-resolution_2.jpg" alt="EU logo">
</div>
<div class="drg-eu-text">
MYRIAD-EU project has received funding from the European Union’s Horizon 2020 Research and Innovation Programme under Grant Agreement No. 101003276.
</div>
</div>
<div class="drg-divider"></div>
<div class="drg-column drg-column-right">
<a href="https://www.myriadproject.eu" target="_blank" rel="noopener">MYRIAD-EU</a>
<a href="https://be.linkedin.com/company/myriad-eu-project" target="_blank" rel="noopener">LinkedIn</a>
<a href="#" target="_blank" rel="noopener">MYRIAD-EU dashboard</a>
</div>
</div>
<div class="drg-disclaimer">
This site is hosted by the British Geological Survey but responsibility for the content of the site lies with the MYRIAD-EU project, not with the British Geological Survey. Questions, suggestions, or comments regarding the contents of this site should be directed to <a href="mailto:DisasterRiskGateway@bgs.ac.uk">DisasterRiskGateway@bgs.ac.uk</a>.
</div>
</div>
`);
}
insertFooter();
});
});