MediaWiki:Common.js: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
| Line 1: | Line 1: | ||
mw.loader.using('mediawiki.util', function () { | mw.loader.using('mediawiki.util', function () { | ||
$(function () { | $(function () { | ||
if ($('#handwiki-topnav').length) { | if ($('#handwiki-topnav').length || $('#handwiki-rightnav').length) { | ||
return; | return; | ||
} | } | ||
function makeMenu(buttonText, extraClass) { | function makeMenu(buttonText, extraClass) { | ||
| Line 35: | Line 31: | ||
content.append($('<div>', { | content.append($('<div>', { | ||
class: 'handwiki-menu-section', | 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 | text: title | ||
})); | })); | ||
| Line 48: | Line 58: | ||
); | ); | ||
} | } | ||
/* ============================================================ | |||
Left top navigation: Portal + Sources | |||
============================================================ */ | |||
var topnav = $('<div>', { | |||
id: 'handwiki-topnav' | |||
}); | |||
var portal = makeMenu('Portal ▾', 'handwiki-portal-menu'); | var portal = makeMenu('Portal ▾', 'handwiki-portal-menu'); | ||
portal.content | addTitle(portal.content, 'Encyclopedia of Knowledge'); | ||
addBand(portal.content, 'Portals'); | |||
portal.content | |||
addLink(portal.content, '/index.php/Main_Page', 'Main page', true); | addLink(portal.content, '/index.php/Main_Page', 'Main page', true); | ||
| Line 89: | Line 100: | ||
var sources = makeMenu('Sources ▾', 'handwiki-sources-menu'); | var sources = makeMenu('Sources ▾', 'handwiki-sources-menu'); | ||
sources.content | addTitle(sources.content, 'Sources'); | ||
addBand(sources.content, 'Quantum Collection', 'handwiki-menu-band-orange'); | |||
sources.content | |||
addLink(sources.content, '/index.php/Book:Quantum_Collection', 'Quantum Collection', true); | addLink(sources.content, '/index.php/Book:Quantum_Collection', 'Quantum Collection', true); | ||
| Line 111: | Line 115: | ||
topnav.append(portal.menu); | topnav.append(portal.menu); | ||
topnav.append(sources.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(topnav); | ||
$('body').append(rightnav); | |||
}); | }); | ||
}); | }); | ||
Revision as of 17:40, 9 May 2026
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, '/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/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);
});
});