MediaWiki:Common.js: Difference between revisions
Myriad-admin (talk | contribs) No edit summary |
Myriad-admin (talk | contribs) No edit summary |
||
| Line 3: | Line 3: | ||
if ($('#drg-navbar').length) return; | if ($('#drg-navbar').length) return; | ||
// | // Logo | ||
const logoSrc = $('.mw-logo-icon').attr('src') | const logoSrc = $('.mw-logo-icon').attr('src') || '/images/3/3f/Myriad_logo_icon_transparent.png'; | ||
const logoHtml = ` | const logoHtml = ` | ||
<a href="${mw.util.getUrl('Main_Page')}" class="drg-navbar-logo"> | <a href="${mw.util.getUrl('Main_Page')}" class="drg-navbar-logo"> | ||
| Line 12: | Line 11: | ||
</a>`; | </a>`; | ||
// | // Navigation | ||
const navItems = [ | const navItems = [ | ||
{ title: 'Catalogue', url: mw.util.getUrl('Catalogue') | { title: 'Catalogue', url: mw.util.getUrl('Catalogue') }, | ||
{ title: 'Definitions', url: mw.util.getUrl('Definitions') }, | { title: 'Definitions', url: mw.util.getUrl('Definitions') }, | ||
{ title: 'Resources', url: mw.util.getUrl('Resources') | { title: 'Resources', url: mw.util.getUrl('Resources') } | ||
]; | ]; | ||
const navHtml = ` | const navHtml = ` | ||
| Line 26: | Line 25: | ||
</div>`; | </div>`; | ||
// | // Flat links | ||
const flatHtml = ` | const flatHtml = ` | ||
<a href="${mw.util.getUrl('Contribute')}" class="flat-link">Contribute</a> | <a href="${mw.util.getUrl('Contribute')}" class="flat-link">Contribute</a> | ||
<a href="${mw.util.getUrl('Disaster_Risk_Gateway')}" class="flat-link">About</a>`; | <a href="${mw.util.getUrl('Disaster_Risk_Gateway')}" class="flat-link">About</a>`; | ||
// | // Search | ||
const searchHtml = ` | const searchHtml = ` | ||
<form class="drg-search" action="${mw.util.getUrl('Special:Search')}" method="get"> | <form class="drg-search" action="${mw.util.getUrl('Special:Search')}" method="get"> | ||
| Line 38: | Line 37: | ||
</form>`; | </form>`; | ||
// | // User dropdown | ||
let userHtml; | let userHtml; | ||
if (mw.config.get('wgUserName')) { | if (mw.config.get('wgUserName')) { | ||
const items = []; | const items = []; | ||
$('#p-personal ul li').each(function() { | $('#p-personal ul li').each(function () { | ||
const a = $(this).find('a'); | const a = $(this).find('a'); | ||
if (a.attr('href').includes('Watchlist')) return; | if (a.attr('href').includes('Watchlist')) return; | ||
items.push(`<li>${a.prop('outerHTML')}</li>`); | items.push(`<li>${a.prop('outerHTML')}</li>`); | ||
}); | }); | ||
| Line 57: | Line 56: | ||
} | } | ||
// | // Tools dropdown | ||
const toolsItems = $('#p-cactions ul li').map(function() { | const toolsItems = $('#p-cactions ul li').map(function () { | ||
return `<li>${$(this).find('a').prop('outerHTML')}</li>`; | return `<li>${$(this).find('a').prop('outerHTML')}</li>`; | ||
}).get().join(''); | }).get().join(''); | ||
| Line 67: | Line 66: | ||
</div>`; | </div>`; | ||
// | // Navbar inject | ||
$('body').prepend(` | $('body').prepend(` | ||
<div id="drg-navbar"> | <div id="drg-navbar"> | ||
| Line 83: | Line 82: | ||
`); | `); | ||
// | // Footer | ||
function insertFooter() { | function insertFooter() { | ||
const icons = document.getElementById('footer-icons'); | const icons = document.getElementById('footer-icons'); | ||
| Line 89: | Line 88: | ||
icons.insertAdjacentHTML('beforebegin', ` | icons.insertAdjacentHTML('beforebegin', ` | ||
< | <footer id="drg-footer"> | ||
<div class="drg-footer-inner"> | <div class="drg-footer-inner"> | ||
<div class="drg-columns"> | <div class="drg-columns"> | ||
| Line 109: | Line 108: | ||
<div class="drg-divider"></div> | <div class="drg-divider"></div> | ||
<div class="drg-column drg-column-right"> | <div class="drg-column drg-column-right"> | ||
<a href="https://www.myriadproject.eu" target="_blank | <a href="https://www.myriadproject.eu" target="_blank">MYRIAD-EU</a> | ||
<a href="https://be.linkedin.com/company/myriad-eu-project" target="_blank | <a href="https://be.linkedin.com/company/myriad-eu-project" target="_blank">LinkedIn</a> | ||
<a href="#" target="_blank | <a href="#" target="_blank">MYRIAD-EU dashboard</a> | ||
</div> | </div> | ||
</div> | </div> | ||
| Line 117: | Line 116: | ||
<div class="drg-disclaimer-wrapper"> | <div class="drg-disclaimer-wrapper"> | ||
<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 | 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 should be directed to | |||
<a href="mailto:DisasterRiskGateway@bgs.ac.uk">DisasterRiskGateway@bgs.ac.uk</a>. | <a href="mailto:DisasterRiskGateway@bgs.ac.uk">DisasterRiskGateway@bgs.ac.uk</a>. | ||
</div> | </div> | ||
</div> | </div> | ||
</ | </footer> | ||
`); | `); | ||
} | } | ||
Revision as of 15:04, 5 August 2025
mw.loader.using('mediawiki.util', function () {
$(document).ready(function () {
if ($('#drg-navbar').length) return;
// Logo
const logoSrc = $('.mw-logo-icon').attr('src') || '/images/3/3f/Myriad_logo_icon_transparent.png';
const logoHtml = `
<a href="${mw.util.getUrl('Main_Page')}" class="drg-navbar-logo">
<img src="${logoSrc}" alt="MYRIAD Logo">
<span class="drg-logo-text">DRG</span>
</a>`;
// Navigation
const navItems = [
{ title: 'Catalogue', url: mw.util.getUrl('Catalogue') },
{ title: 'Definitions', url: mw.util.getUrl('Definitions') },
{ title: 'Resources', url: mw.util.getUrl('Resources') }
];
const navHtml = `
<div class="drg-nav">
<span>Navigation</span>
<ul class="drg-nav-dropdown">
${navItems.map(i => `<li><a href="${i.url}">${i.title}</a></li>`).join('')}
</ul>
</div>`;
// Flat links
const flatHtml = `
<a href="${mw.util.getUrl('Contribute')}" class="flat-link">Contribute</a>
<a href="${mw.util.getUrl('Disaster_Risk_Gateway')}" class="flat-link">About</a>`;
// Search
const searchHtml = `
<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>`;
// User dropdown
let userHtml;
if (mw.config.get('wgUserName')) {
const items = [];
$('#p-personal ul li').each(function () {
const a = $(this).find('a');
if (a.attr('href').includes('Watchlist')) return;
items.push(`<li>${a.prop('outerHTML')}</li>`);
});
items.push(`<li><a href="${mw.util.getUrl('Special:UserLogout')}">Logout</a></li>`);
userHtml = `
<div class="drg-user">
<span>Welcome, ${mw.config.get('wgUserName')}</span>
<ul class="drg-user-dropdown">${items.join('')}</ul>
</div>`;
} else {
userHtml = `<a class="drg-button" href="${mw.util.getUrl('Special:UserLogin')}">Login</a>`;
}
// Tools dropdown
const toolsItems = $('#p-cactions ul li').map(function () {
return `<li>${$(this).find('a').prop('outerHTML')}</li>`;
}).get().join('');
const toolsHtml = `
<div class="drg-tools">
<span>Tools</span>
<ul class="drg-tools-dropdown">${toolsItems}</ul>
</div>`;
// Navbar inject
$('body').prepend(`
<div id="drg-navbar">
<div class="drg-navbar-container">
${logoHtml}
${navHtml}
${flatHtml}
${searchHtml}
<div class="drg-navbar-actions">
${userHtml}
${toolsHtml}
</div>
</div>
</div>
`);
// Footer
function insertFooter() {
const icons = document.getElementById('footer-icons');
if (!icons) return setTimeout(insertFooter, 100);
icons.insertAdjacentHTML('beforebegin', `
<footer id="drg-footer">
<div class="drg-footer-inner">
<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">MYRIAD-EU</a>
<a href="https://be.linkedin.com/company/myriad-eu-project" target="_blank">LinkedIn</a>
<a href="#" target="_blank">MYRIAD-EU dashboard</a>
</div>
</div>
</div>
<div class="drg-disclaimer-wrapper">
<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 should be directed to
<a href="mailto:DisasterRiskGateway@bgs.ac.uk">DisasterRiskGateway@bgs.ac.uk</a>.
</div>
</div>
</footer>
`);
}
insertFooter();
});
});