Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

MediaWiki:Common.js: Difference between revisions

MediaWiki interface page
No edit summary
Tag: Reverted
No edit summary
Tag: Reverted
Line 39: Line 39:


$(document).ready(function() {
$(document).ready(function() {
     // Create the Add Category button
     // Wait until the page actions menu is fully loaded
     var addCategoryButton = $('<li>').append(
     mw.util.addPortletLink(
         $('<a>').text('Add Category').click(function() {
        'p-cactions',          // The ID of the page action menu container
             var category = prompt('Enter the category to add:');
         '#',                    // The link URL, # is a placeholder
             if (category) {
        'Add Category',          // The text to display
                 var categoryMarkup = '[[' + category + ']]';
        'ca-add-category',      // The ID to apply to the new item
                 var editButton = $('#ca-edit a');
        'Add a category to this page',  // The tooltip text
                if (editButton.length) {
        '',                      // CSS class (optional)
                    // Redirect to the edit page with the category preloaded
        function () {
                    window.location.href = editButton.attr('href') + '&section=new&preload=' + encodeURIComponent(categoryMarkup);
            // Prompt the user to input a category
                }
             var categoryName = prompt("Enter category name:");
             if (categoryName) {
                // Add the category to the page if user provides a name
                 var categoryMarkup = "[[Category:" + categoryName + "]]";
                 mw.toolbar.insertText(categoryMarkup); // Insert the category text into the editor
             }
             }
         })
         }
     );
     );
    // Append the button to the main navigation menu
    $('').append(addCategoryButton);
});
});

Revision as of 00:08, 31 December 2024

/* Any JavaScript here will be loaded for all users on every page load. */
 $(function(){
  $('.card').on('mousenter', function(event){
    event.preventDefault();
    $(this).toggleClass('hovered');
  });
   $('.card').on('mouseleave', function(event){
    event.preventDefault();
    $(this).toggleClass('hovered');
  });
});
document.querySelectorAll('.sub-card').forEach(card => {
    card.addEventListener('click', function(event) {
        event.stopPropagation(); // Prevent event bubbling

        // Toggle the expanded state of the clicked card
        const isExpanded = card.getAttribute('data-expanded') === 'true';
        
        // Flip the current sub-card
        card.setAttribute('data-expanded', isExpanded ? 'false' : 'true');

        // Hide all other sub-cards
        document.querySelectorAll('.sub-card').forEach(otherCard => {
            if (otherCard !== card) {
                otherCard.setAttribute('data-expanded', 'false');
            }
        });
    });
});

document.querySelectorAll('.card').forEach(card => {
    card.addEventListener('mouseleave', function() {
        // Collapse all sub-cards when mouse leaves the main card
        document.querySelectorAll('.sub-card').forEach(subCard => {
            subCard.setAttribute('data-expanded', 'false');
        });
    });
});

$(document).ready(function() {
    // Wait until the page actions menu is fully loaded
    mw.util.addPortletLink(
        'p-cactions',           // The ID of the page action menu container
        '#',                     // The link URL, # is a placeholder
        'Add Category',          // The text to display
        'ca-add-category',       // The ID to apply to the new item
        'Add a category to this page',  // The tooltip text
        '',                      // CSS class (optional)
        function () {
            // Prompt the user to input a category
            var categoryName = prompt("Enter category name:");
            if (categoryName) {
                // Add the category to the page if user provides a name
                var categoryMarkup = "[[Category:" + categoryName + "]]";
                mw.toolbar.insertText(categoryMarkup);  // Insert the category text into the editor
            }
        }
    );
});
Cookies help us deliver our services. By using our services, you agree to our use of cookies.