MediaWiki:Common.js
Jump to navigation
Jump to search
Note: After publishing, you may have to bypass your browser's cache to see the changes.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
- Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
mw.loader.using('mediawiki.util', function () {
$(function () {
if ($('#handwiki-topnav').length || $('#handwiki-rightnav').length) {
return;
}
function makeMenu(buttonText, extraClass) {
var menu = $('<div>', {
class: 'handwiki-dropdown ' + extraClass
});
var button = $('<div>', {
class: 'handwiki-dropdown-button',
text: buttonText
});
var content = $('<div>', {
class: 'handwiki-dropdown-content'
});
menu.append(button);
menu.append(content);
return {
menu: menu,
content: content
};
}
function addSection(content, title) {
content.append($('<div>', {
class: 'handwiki-menu-section',
text: title
}));
}
function addBand(content, title, extraClass) {
content.append($('<div>', {
class: 'handwiki-menu-band ' + (extraClass || ''),
text: title
}));
}
function addTitle(content, title) {
content.append($('<div>', {
class: 'handwiki-menu-title',
text: title
}));
}
function addLink(content, href, text, bold) {
content.append(
$('<a>', {
href: href,
text: text,
class: bold ? 'handwiki-menu-bold' : ''
})
);
}
/* ============================================================
Left top navigation: Portal + Sources
============================================================ */
var topnav = $('<div>', {
id: 'handwiki-topnav'
});
var portal = makeMenu('Portal ▾', 'handwiki-portal-menu');
addTitle(portal.content, 'Encyclopedia of Knowledge');
addBand(portal.content, 'Portals');
addLink(portal.content, '/index.php/Main_Page', 'Main page', true);
addLink(portal.content, '/create/', 'Add a new article', true);
addLink(portal.content, '/index.php/Portal:Data_analysis', 'Data analysis', false);
addLink(portal.content, '/index.php/Portal:Mathematics', 'Mathematics', false);
addSection(portal.content, 'Natural Sciences');
addLink(portal.content, '/index.php/Portal:Astronomy_%26_Space', 'Astronomy & Space', false);
addLink(portal.content, '/index.php/Portal:Biology', 'Biology', false);
addLink(portal.content, '/index.php/Portal:Computer_concepts', 'Computer concepts', false);
addLink(portal.content, '/index.php/Portal:Chemistry', 'Chemistry', false);
addLink(portal.content, '/index.php/Portal:Physics', 'Physics', false);
addLink(portal.content, '/index.php/Portal:Earth_studies', 'Earth studies', false);
addLink(portal.content, '/index.php/Portal:Unsolved_problems', 'Unsolved problems', false);
addSection(portal.content, 'Humanities');
addLink(portal.content, '/index.php/Portal:History', 'History', false);
addLink(portal.content, '/index.php/Portal:Philosophy', 'Philosophy', false);
addLink(portal.content, '/index.php/Portal:Social_studies', 'Social studies', false);
addLink(portal.content, '/index.php/Portal:Religion', 'Religion', false);
addLink(portal.content, '/index.php/Portal:Medicine', 'Medicine', false);
addSection(portal.content, 'Technology & Finance');
addLink(portal.content, '/index.php/Portal:Engineering_%26_Tech', 'Engineering & Tech', false);
addLink(portal.content, '/index.php/Portal:Software_programs', 'Software programs', false);
addLink(portal.content, '/index.php/Portal:Business_and_economics', 'Business and economics', false);
addLink(portal.content, '/index.php/Portal:Finance', 'Finance', false);
var sources = makeMenu('Sources ▾', 'handwiki-sources-menu');
addTitle(sources.content, 'Sources');
addBand(sources.content, 'Quantum Collection', 'handwiki-menu-band-orange');
addLink(sources.content, '/index.php/Book:Quantum_Collection', 'Quantum Collection', true);
addLink(sources.content, '/index.php/Physics:Quantum basics', 'Physics:Quantum basics', false);
addLink(sources.content, '/index.php/Book:Quantum_Collection/Matter_(by_scale)', 'Matter by scale', false);
addLink(sources.content, '/index.php/Book:Quantum_Collection/Methods_and_tools', 'Methods and tools', false);
addSection(sources.content, 'Wiki sources');
addLink(sources.content, '/index.php/Special:RecentChanges', 'Recent changes', false);
addLink(sources.content, '/index.php/Special:Random', 'Random page', false);
addLink(sources.content, '/index.php/Special:SpecialPages', 'Special pages', false);
addLink(sources.content, '/index.php/Special:Upload', 'Upload file', false);
topnav.append(portal.menu);
topnav.append(sources.menu);
/* ============================================================
Right top navigation: Tools
============================================================ */
var pageName = mw.config.get('wgPageName');
var revisionId = mw.config.get('wgRevisionId');
var rightnav = $('<div>', {
id: 'handwiki-rightnav'
});
var tools = makeMenu('Tools ▾', 'handwiki-tools-menu');
addTitle(tools.content, 'Page tools');
addBand(tools.content, 'Tools', 'handwiki-menu-band-gradient');
addLink(tools.content, mw.util.getUrl(pageName, { action: 'edit' }), 'Edit', false);
addLink(tools.content, mw.util.getUrl(pageName, { action: 'history' }), 'History', false);
addLink(tools.content, mw.util.getUrl('Special:WhatLinksHere/' + pageName), 'What links here', false);
addLink(tools.content, mw.util.getUrl('Special:RecentChangesLinked/' + pageName), 'Related changes', false);
addLink(tools.content, mw.util.getUrl(pageName, { printable: 'yes' }), 'Printable version', false);
if (revisionId) {
addLink(tools.content, mw.util.getUrl(pageName, { oldid: revisionId }), 'Permanent link', false);
}
addLink(tools.content, mw.util.getUrl(pageName, { action: 'info' }), 'Page information', false);
addSection(tools.content, 'Admin');
addLink(tools.content, mw.util.getUrl(pageName, { action: 'delete' }), 'Delete', false);
addLink(tools.content, mw.util.getUrl('Special:MovePage/' + pageName), 'Move', false);
addLink(tools.content, mw.util.getUrl(pageName, { action: 'protect' }), 'Protect', false);
rightnav.append(tools.menu);
$('body').append(topnav);
$('body').append(rightnav);
});
});