MediaWiki:Common.js: Difference between revisions

From HandWiki Stage
Jump to navigation Jump to search
No edit summary
No edit summary
Line 5: Line 5:
         }
         }


         var sidebarLinks = [];
         var topnav = $('<div>', {
            id: 'handwiki-topnav'
        });


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


             if (text && href) {
             var button = $('<div>', {
                 sidebarLinks.push({
                 class: 'handwiki-dropdown-button',
                    text: text,
                text: buttonText
                    href: href
             });
                });
             }
        });


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


        var sidebarMenu = $('<div>', {
            menu.append(button);
             class: 'handwiki-dropdown'
             menu.append(content);
        });


        var sidebarButton = $('<div>', {
            return {
            class: 'handwiki-dropdown-button',
                menu: menu,
             text: 'Sidebar ▾'
                content: content
         });
             };
         }


         var sidebarContent = $('<div>', {
         function addSection(content, title) {
            class: 'handwiki-dropdown-content'
            content.append($('<div>', {
        });
                class: 'handwiki-menu-section',
                text: title
            }));
        }


         sidebarLinks.forEach(function (link) {
         function addLink(content, href, text, bold) {
             sidebarContent.append(
             content.append(
                 $('<a>', {
                 $('<a>', {
                     href: link.href,
                     href: href,
                     text: link.text
                     text: text,
                    class: bold ? 'handwiki-menu-bold' : ''
                 })
                 })
             );
             );
         });
         }
 
        var portal = makeMenu('Portal ▾', 'handwiki-portal-menu');
 
        portal.content.append($('<div>', {
            class: 'handwiki-menu-title',
            text: 'Encyclopedia of Knowledge'
        }));


         sidebarMenu.append(sidebarButton);
         portal.content.append($('<div>', {
         sidebarMenu.append(sidebarContent);
            class: 'handwiki-menu-band',
            text: 'Portals'
         }));


         var secondMenu = $('<div>', {
         addLink(portal.content, '/index.php/Main_Page', 'Main page', true);
            class: 'handwiki-dropdown'
        addLink(portal.content, '/index.php/Portal:Data_analysis', 'Data analysis', false);
         });
         addLink(portal.content, '/index.php/Portal:Mathematics', 'Mathematics', false);


         var secondButton = $('<div>', {
         addSection(portal.content, 'Natural Sciences');
            class: 'handwiki-dropdown-button',
        addLink(portal.content, '/index.php/Portal:Astronomy_%26_Space', 'Astronomy & Space', false);
            text: 'Quantum ▾'
        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);


         var secondContent = $('<div>', {
         addSection(portal.content, 'Humanities');
            class: 'handwiki-dropdown-content'
        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);


         secondContent.append($('<a>', {
         addSection(portal.content, 'Technology & Finance');
            href: '/index.php/Book:Quantum_Collection',
        addLink(portal.content, '/index.php/Portal:Engineering_%26_Tech', 'Engineering & Tech', false);
            text: 'Quantum Collection'
        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);


         secondContent.append($('<a>', {
         var sources = makeMenu('Sources ▾', 'handwiki-sources-menu');
            href: '/index.php/Book:Quantum_Collection/Matter_(by_scale)',
            text: 'Matter by scale'
        }));


         secondContent.append($('<a>', {
         sources.content.append($('<div>', {
             href: '/index.php/Book:Quantum_Collection/Methods_and_tools',
             class: 'handwiki-menu-title',
             text: 'Methods and tools'
             text: 'Sources'
         }));
         }));


         secondContent.append($('<a>', {
         sources.content.append($('<div>', {
             href: '/index.php/Special:RecentChanges',
             class: 'handwiki-menu-band handwiki-menu-band-orange',
             text: 'Recent changes'
             text: 'Quantum Collection'
         }));
         }));


         secondContent.append($('<a>', {
         addLink(sources.content, '/index.php/Book:Quantum_Collection', 'Quantum Collection', true);
            href: '/index.php/Special:SpecialPages',
        addLink(sources.content, '/index.php/Book:Quantum_Collection/Matter_(by_scale)', 'Matter by scale', false);
            text: 'Special pages'
        addLink(sources.content, '/index.php/Book:Quantum_Collection/Methods_and_tools', 'Methods and tools', false);
        }));


         secondMenu.append(secondButton);
         addSection(sources.content, 'Wiki sources');
         secondMenu.append(secondContent);
        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(sidebarMenu);
         topnav.append(portal.menu);
         topnav.append(secondMenu);
         topnav.append(sources.menu);


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

Revision as of 17:30, 9 May 2026

mw.loader.using('mediawiki.util', function () {
    $(function () {
        if ($('#handwiki-topnav').length) {
            return;
        }

        var topnav = $('<div>', {
            id: 'handwiki-topnav'
        });

        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 addLink(content, href, text, bold) {
            content.append(
                $('<a>', {
                    href: href,
                    text: text,
                    class: bold ? 'handwiki-menu-bold' : ''
                })
            );
        }

        var portal = makeMenu('Portal ▾', 'handwiki-portal-menu');

        portal.content.append($('<div>', {
            class: 'handwiki-menu-title',
            text: 'Encyclopedia of Knowledge'
        }));

        portal.content.append($('<div>', {
            class: 'handwiki-menu-band',
            text: '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');

        sources.content.append($('<div>', {
            class: 'handwiki-menu-title',
            text: 'Sources'
        }));

        sources.content.append($('<div>', {
            class: 'handwiki-menu-band handwiki-menu-band-orange',
            text: 'Quantum Collection'
        }));

        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);

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