MediaWiki:Common.js: Difference between revisions

From HandWiki Stage
Jump to navigation Jump to search
No edit summary
No edit summary
 
(3 intermediate revisions by the same user not shown)
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;
         }
         }


         var sidebarLinks = [];
         function makeMenu(buttonText, extraClass) {
            var menu = $('<div>', {
                class: 'handwiki-dropdown ' + extraClass
            });


        $('#mw-panel a').each(function () {
            var button = $('<div>', {
            var text = $(this).text().trim();
                class: 'handwiki-dropdown-button',
             var href = $(this).attr('href');
                text: buttonText
             });


             if (text && href) {
             var content = $('<div>', {
                 sidebarLinks.push({
                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,
                     text: text,
                     href: href
                     class: bold ? 'handwiki-menu-bold' : ''
                 });
                 })
            }
            );
         });
        }
 
         /* ============================================================
          Left top navigation: Portal + Sources
          ============================================================ */


         var topnav = $('<div>', {
         var topnav = $('<div>', {
Line 23: Line 67:
         });
         });


         var sidebarMenu = $('<div>', {
         var portal = makeMenu('Portal ▾', 'handwiki-portal-menu');
            class: 'handwiki-dropdown'
 
        });
        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');


         var sidebarButton = $('<div>', {
         addTitle(sources.content, 'Sources');
            class: 'handwiki-dropdown-button',
        addBand(sources.content, 'Quantum Collection', 'handwiki-menu-band-orange');
            text: 'Sidebar ▾'
        });


         var sidebarContent = $('<div>', {
         addLink(sources.content, '/index.php/Book:Quantum_Collection', 'Quantum Collection', true);
            class: 'handwiki-dropdown-content'
        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);


         sidebarLinks.forEach(function (link) {
         addSection(sources.content, 'Wiki sources');
            sidebarContent.append(
        addLink(sources.content, '/index.php/Special:RecentChanges', 'Recent changes', false);
                $('<a>', {
        addLink(sources.content, '/index.php/Special:Random', 'Random page', false);
                    href: link.href,
        addLink(sources.content, '/index.php/Special:SpecialPages', 'Special pages', false);
                    text: link.text
         addLink(sources.content, '/index.php/Special:Upload', 'Upload file', false);
                })
            );
         });


         sidebarMenu.append(sidebarButton);
         topnav.append(portal.menu);
         sidebarMenu.append(sidebarContent);
         topnav.append(sources.menu);


         var secondMenu = $('<div>', {
         /* ============================================================
            class: 'handwiki-dropdown'
          Right top navigation: Tools
        });
          ============================================================ */


         var secondButton = $('<div>', {
         var pageName = mw.config.get('wgPageName');
            class: 'handwiki-dropdown-button',
        var revisionId = mw.config.get('wgRevisionId');
            text: 'Quantum ▾'
        });


         var secondContent = $('<div>', {
         var rightnav = $('<div>', {
             class: 'handwiki-dropdown-content'
             id: 'handwiki-rightnav'
         });
         });


         secondContent.append($('<a>', {
         var tools = makeMenu('Tools ▾', 'handwiki-tools-menu');
            href: '/index.php/Book:Quantum_Collection',
            text: 'Quantum Collection'
        }));


         secondContent.append($('<a>', {
         addTitle(tools.content, 'Page tools');
            href: '/index.php/Book:Quantum_Collection/Matter_(by_scale)',
        addBand(tools.content, 'Tools', 'handwiki-menu-band-gradient');
            text: 'Matter by scale'
        }));


         secondContent.append($('<a>', {
         addLink(tools.content, mw.util.getUrl(pageName, { action: 'edit' }), 'Edit', false);
            href: '/index.php/Book:Quantum_Collection/Methods_and_tools',
        addLink(tools.content, mw.util.getUrl(pageName, { action: 'history' }), 'History', false);
            text: 'Methods and tools'
        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);


         secondContent.append($('<a>', {
         if (revisionId) {
             href: '/index.php/Special:RecentChanges',
             addLink(tools.content, mw.util.getUrl(pageName, { oldid: revisionId }), 'Permanent link', false);
            text: 'Recent changes'
         }
         }));


         secondContent.append($('<a>', {
         addLink(tools.content, mw.util.getUrl(pageName, { action: 'info' }), 'Page information', false);
            href: '/index.php/Special:SpecialPages',
            text: 'Special pages'
        }));


         secondMenu.append(secondButton);
         addSection(tools.content, 'Admin');
         secondMenu.append(secondContent);
        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);


         topnav.append(sidebarMenu);
         rightnav.append(tools.menu);
        topnav.append(secondMenu);


         $('body').append(topnav);
         $('body').append(topnav);
        $('body').append(rightnav);
     });
     });
});
});

Latest revision as of 22:16, 13 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, '/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);
    });
});