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

Module:LinkGrid: Difference between revisions

From Jules RNG Wiki
No edit summary
No edit summary
Line 2: Line 2:


function p.render(frame)
function p.render(frame)
     -- 1. DEFINE YOUR DATA
     -- Get arguments from the Template that called this module
     local cards = {
     -- If you use {{#invoke:}} directly, use frame.args
        {
    -- If you use a {{Template}}, use frame:getParent().args
            link = "Auras",
    local args = frame:getParent().args
            title = "Auras",
    local cards = {}
            image = "AurasIcon.png",
    local i = 1
            body = "Over 500+ unique auras to collect! Ranging from event auras, to biome exclusive auras. There's tons of auras to discover!"
 
        },
    -- Loop: Look for title1, title2, title3... until we run out
        {
    while args['title' .. i] do
            link = "Items",
         table.insert(cards, {
            title = "Items",
             link = args['link' .. i] or args['title' .. i], -- If link is missing, use title
            image = "ItemsIcon.png",
             title = args['title' .. i],
            body = "Increase your luck, roll speed, Gem multiplier, and more with potions, biome randomizers, night bells, and much much more."
             image = args['image' .. i] or 'Default.png',     -- Fallback image
        },
             body = args['body' .. i] or ''
        {
         })
            link = "Minigames",
         i = i + 1
            title = "Minigames",
     end
            image = "MinigamesIcon.png",
            body = "Grind for Potions and Gems in interactive games."
         },
        {
             link = "Achievements",
            title = "Achievements",
            image = "AchievementsIcon.png",
            body = "Complete Achievements to earn gems! Show off your dedication by finishing them all!"
        },
        {
            link = "Biomes",
             title = "Biomes",
             image = "BiomesIcon.png",
             body = "Discover rare and unique biomes! Collect exclusive Biome Specific Auras!"
         },
         {
            link = "Events",
            title = "Events",
            image = "EventsIcon.png",
            body = "Show your holiday spirit by collecting limited-themed auras! Collect them all before they're gone!"
        }
     }


     -- 2. DEFINE STYLES
     -- 2. DEFINE STYLES (Citizen Skin Compatible)
    -- (We keep these CSS strings the same as before)
     local containerStyle = {
     local containerStyle = {
         ['display'] = 'flex',
         ['display'] = 'flex',
Line 87: Line 64:
     }
     }


     -- 3. BUILD THE HTML CONTAINER
     -- 3. BUILD THE HTML
     local root = mw.html.create('div')
     local root = mw.html.create('div'):css(containerStyle)
        :addClass('citizen-card-grid') -- Class for our custom CSS to target
        :css(containerStyle)


     for _, card in ipairs(cards) do
     for _, card in ipairs(cards) do
Line 100: Line 75:
             :wikitext(string.format('[[File:%s|80px|link=%s]]', card.image, card.link))
             :wikitext(string.format('[[File:%s|80px|link=%s]]', card.image, card.link))
          
          
         -- Body
         -- Content
         local bodyDiv = cardDiv:tag('div'):css(bodyStyle)
         local bodyDiv = cardDiv:tag('div'):css(bodyStyle)
          
          
Line 114: Line 89:
     end
     end


    -- 4. INSERT CSS (The Correct Way)
    -- We use frame:extensionTag to safely insert the <style> block
    -- Note: 'templatestyles' is preferred if installed, but 'style' works for now.
    local css = '@media (max-width: 768px) { .citizen-card-grid > div { max-width: 100% !important; } }'
   
    -- If Extension:TemplateStyles is installed (recommended):
    -- return frame:extensionTag('templatestyles', '', { src = 'Template:CardGrid.css' }) .. tostring(root)
   
    -- Since we are doing inline styles (easier for now):
    -- We can just rely on the 'max-width: 100%' being the default behavior of flex items if we remove the hard constraint.
    -- OR, insert the raw HTML for style if permitted.
   
    -- **BEST FIX:** Use 'templatestyles' if you can. If not, return just the root and rely on 'flex-wrap' natural behavior.
    -- The previous issue was trying to inject raw HTML <style> which gets escaped.
   
    -- Let's try returning JUST the root first, because 'flex: 1 1 300px' ALREADY handles mobile perfectly!
    -- When screen < 600px, 300px items will naturally stack.
    -- The 'max-width: 32%' is the only thing fighting us.
   
     return tostring(root)
     return tostring(root)
end
end


return p
return p

Revision as of 03:45, 27 January 2026

Documentation for this module may be created at Module:LinkGrid/doc

local p = {}

function p.render(frame)
    -- Get arguments from the Template that called this module
    -- If you use {{#invoke:}} directly, use frame.args
    -- If you use a {{Template}}, use frame:getParent().args
    local args = frame:getParent().args
    local cards = {}
    local i = 1

    -- Loop: Look for title1, title2, title3... until we run out
    while args['title' .. i] do
        table.insert(cards, {
            link  = args['link' .. i] or args['title' .. i], -- If link is missing, use title
            title = args['title' .. i],
            image = args['image' .. i] or 'Default.png',      -- Fallback image
            body  = args['body' .. i] or ''
        })
        i = i + 1
    end

    -- 2. DEFINE STYLES (Citizen Skin Compatible)
    local containerStyle = {
        ['display'] = 'flex',
        ['flex-wrap'] = 'wrap',
        ['gap'] = '1rem',
        ['justify-content'] = 'center'
    }

    local cardStyle = {
        ['flex'] = '1 1 300px',
        ['max-width'] = '32%', 
        ['border'] = '1px solid var(--border-color-base)',
        ['border-radius'] = 'var(--border-radius-base, 12px)',
        ['box-shadow'] = 'var(--box-shadow-level-1)',
        ['overflow'] = 'hidden',
        ['background'] = 'var(--color-surface-1)',
        ['transition'] = 'transform 0.2s ease',
        ['box-sizing'] = 'border-box'
    }

    local imageAreaStyle = {
        ['background'] = 'var(--color-surface-2)',
        ['padding'] = '20px',
        ['text-align'] = 'center',
        ['border-bottom'] = '1px solid var(--border-color-base)'
    }

    local bodyStyle = {
        ['padding'] = '15px'
    }

    local titleStyle = {
        ['font-weight'] = 'bold',
        ['font-size'] = '1.2em',
        ['margin-bottom'] = '8px',
        ['color'] = 'var(--color-base)'
    }

    local textStyle = {
        ['color'] = 'var(--color-subtle)',
        ['font-size'] = '0.95em',
        ['line-height'] = '1.4'
    }

    -- 3. BUILD THE HTML
    local root = mw.html.create('div'):css(containerStyle)

    for _, card in ipairs(cards) do
        local cardDiv = root:tag('div'):css(cardStyle)
        
        -- Image
        cardDiv:tag('div')
            :css(imageAreaStyle)
            :wikitext(string.format('[[File:%s|80px|link=%s]]', card.image, card.link))
        
        -- Content
        local bodyDiv = cardDiv:tag('div'):css(bodyStyle)
        
        -- Title
        bodyDiv:tag('div')
            :css(titleStyle)
            :wikitext(string.format('[[%s|%s]]', card.link, card.title))
            
        -- Description
        bodyDiv:tag('div')
            :css(textStyle)
            :wikitext(card.body)
    end

    return tostring(root)
end

return p