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 () { | ||
// Avoid double-injection | |||
if ($('#drg-navbar').length) return; | if ($('#drg-navbar').length) return; | ||
Line 11: | Line 12: | ||
let userArea = ''; | let userArea = ''; | ||
if (userName) { | if (userName) { | ||
// | // Personal links | ||
const personalLis = []; | const personalLis = []; | ||
$('#p-personal ul li').each(function() { | $('#p-personal ul li').each(function() { | ||
personalLis.push($(this).find('a').prop('outerHTML')); | personalLis.push($(this).find('a').prop('outerHTML')); | ||
}); | }); | ||
// | // Page actions (Read/Edit/View history) | ||
const pageLis = []; | const pageLis = []; | ||
$('#p-views ul li').each(function() { | $('#p-views ul li').each(function() { | ||
Line 30: | Line 31: | ||
</div>`; | </div>`; | ||
} else { | } else { | ||
userArea = `<a class="drg-button" | userArea = `<a class="drg-button" href="${mw.util.getUrl('Special:UserLogin')}">Login</a>`; | ||
} | } | ||
Line 66: | Line 66: | ||
</nav>`; | </nav>`; | ||
// 6) Inject | // 6) Inject custom navbar | ||
$('body').prepend(` | $('body').prepend(` | ||
<div id="drg-navbar"> | <div id="drg-navbar"> | ||
Line 84: | Line 84: | ||
`); | `); | ||
// 7) | // 7) Re-insert original footer | ||
function insertFooter() { | function insertFooter() { | ||
const icons = document.getElementById('footer-icons'); | const icons = document.getElementById('footer-icons'); | ||
Line 90: | Line 90: | ||
icons.insertAdjacentHTML('beforebegin', ` | icons.insertAdjacentHTML('beforebegin', ` | ||
<div id="drg-footer"> | <div id="drg-footer"> | ||
<div class="drg-columns"> | <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?trk=public_post_feed-actor-name" target="_blank" rel="noopener">LinkedIn</a> | |||
<a href="#" target="_blank" rel="noopener">MYRIAD-EU dashboard</a> | |||
</div> | |||
</div> | </div> | ||
<div class="drg-disclaimer"> | <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> | ||
</div> | </div> |
Revision as of 15:25, 24 June 2025
mw.loader.using('mediawiki.util', function () {
$(document).ready(function () {
// Avoid double-injection
if ($('#drg-navbar').length) return;
// 1) Grab Vector’s logo icon
const logoSrc = $('.mw-logo-icon').attr('src')
|| '/images/3/3f/Myriad_logo_icon_transparent.png';
// 2) Build “Myriad-admin” dropdown (personal + page actions)
const userName = mw.config.get('wgUserName');
let userArea = '';
if (userName) {
// Personal links
const personalLis = [];
$('#p-personal ul li').each(function() {
personalLis.push($(this).find('a').prop('outerHTML'));
});
// Page actions (Read/Edit/View history)
const pageLis = [];
$('#p-views ul li').each(function() {
pageLis.push($(this).find('a').prop('outerHTML'));
});
const userItems = [...personalLis, ...pageLis]
.map(html => `<li>${html}</li>`).join('');
userArea = `<div class="drg-user">
<span>Welcome, ${userName}</span>
<ul class="drg-user-dropdown">
${userItems}
</ul>
</div>`;
} else {
userArea = `<a class="drg-button" href="${mw.util.getUrl('Special:UserLogin')}">Login</a>`;
}
// 3) Build “Tools” dropdown
const toolsLis = [];
$('#p-cactions ul li').each(function() {
toolsLis.push($(this).find('a').prop('outerHTML'));
});
const toolsItems = toolsLis.map(html => `<li>${html}</li>`).join('');
const toolsArea = `<div class="drg-tools">
<span>Tools</span>
<ul class="drg-tools-dropdown">
${toolsItems}
</ul>
</div>`;
// 4) Manual search form
const searchForm = `
<form class="drg-search"
action="${mw.util.getUrl('Special:Search')}"
method="get">
<input type="search" name="search"
placeholder="Search Disaster Risk Gateway">
<input type="submit" value="Search">
</form>`;
// 5) 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>`;
// 6) Inject custom 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}
${searchForm}
<div class="drg-navbar-actions">
${userArea}
${toolsArea}
</div>
</div>
</div>
`);
// 7) Re-insert original footer
function insertFooter() {
const icons = document.getElementById('footer-icons');
if (!icons) return setTimeout(insertFooter, 100);
icons.insertAdjacentHTML('beforebegin', `
<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?trk=public_post_feed-actor-name" 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();
});
});