MediaWiki:Common.js: Difference between revisions

Jump to navigation Jump to search
no edit summary
No edit summary
No edit summary
Line 6: Line 6:


function formatParagraphs(text) {
function formatParagraphs(text) {
        // Split the text into paragraphs and wrap each in a <span>
    var paragraphs = text.split('\n').filter(function (p) { return p.trim() !== '' });
        var paragraphs = text.split('\n').filter(function (p) { return p.trim() !== '' });
    return paragraphs.map(function (p) { return '<p>' + p.trim() + '</p>'; }).join('');
        return paragraphs.map(function (p) { return '<p>' + p.trim() + '</p>'; }).join('');
}
    }
       
function formatCommunityCardDescriptions() {
    // Description formatting for Community Cards
    console.log("Formatting community card descriptions");
    function formatCommunityCardDescriptions() {
    $('.community-card').each(function() {
        console.log("Formatting community card descriptions");
        console.log("Processing a community card");
        $('.community-card').each(function() {
        var descriptionContainer = $(this).find('.community-description');
            console.log("Processing a community card");
        var rawDescription = descriptionContainer.text();
            var descriptionContainer = $(this).find('.community-description');
        console.log("Raw Description:", rawDescription);
            var rawDescription = descriptionContainer.text();
            console.log("Raw Description:", rawDescription);
        var formattedDescription = formatParagraphs(rawDescription);
            var formattedDescription = formatParagraphs(rawDescription);
        descriptionContainer.html(formattedDescription);
            descriptionContainer.html(formattedDescription);
            console.log("Formatted Description HTML:", descriptionContainer.html());
        // Remove empty <p> tags, including those containing only <br>
        });
        descriptionContainer.find('p').each(function() {
    }
            if ($(this).is(':empty') || $(this).html().trim() === '<br>') {
 
                $(this).remove();
    // Check if we are on a page that requires community card formatting
            }
    if ($('.community-card').length) {
        });
        formatCommunityCardDescriptions();
    }
        console.log("Formatted Description HTML:", descriptionContainer.html());
   
    });
}
// Check if we are on a page that requires community card formatting
if ($('.community-card').length) {
    formatCommunityCardDescriptions();
}
     // Delegate the mousedown event to the '.card' elements inside the '#list' container
     // Delegate the mousedown event to the '.card' elements inside the '#list' container
     $('#list').on('mousedown', '.card', function (event) {
     $('#list').on('mousedown', '.card', function (event) {

Navigation menu