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

Module:LinkGridBanner: Difference between revisions

From Jules RNG Wiki
Created page with "local p = {} function p.render(frame) local args = frame:getParent().args local cards = {} local i = 1 -- Loop to gather data while args['title' .. i] do table.insert(cards, { link = args['link' .. i] or args['title' .. i], title = args['title' .. i], image = args['image' .. i] or 'Default.png', body = args['body' .. i] or '' }) i = i + 1 end -- 1. CONTAINER STYLE..."
 
No edit summary
 
(5 intermediate revisions by the same user not shown)
Line 6: Line 6:
     local i = 1
     local i = 1


    -- Loop to gather data
     while args['title' .. i] do
     while args['title' .. i] do
         table.insert(cards, {
         table.insert(cards, {
             link  = args['link' .. i] or args['title' .. i],
            -- CHANGE 1: We do NOT default to title anymore.
            -- If link is missing, it stays nil.
             link  = args['link' .. i],  
             title = args['title' .. i],
             title = args['title' .. i],
             image = args['image' .. i] or 'Default.png',
             image = args['image' .. i] or 'Default.png',
Line 17: Line 18:
     end
     end


     -- 1. CONTAINER STYLE
     -- CONTAINER STYLE
     local containerStyle = {
     local containerStyle = {
         ['display'] = 'flex',
         ['display'] = 'flex',
         ['flex-wrap'] = 'wrap',
         ['flex-wrap'] = 'wrap',
         ['gap'] = '1rem',
         ['gap'] = '1rem',
         ['justify-content'] = 'center'
         ['justify-content'] = 'center',
        ['margin-top'] = '1rem'
     }
     }


     -- 2. CARD STYLE
     -- CARD STYLE
     local cardStyle = {
     local cardStyle = {
         ['flex'] = '1 1 300px',
         ['flex'] = '1 1 300px',
         ['max-width'] = '32%',  
         ['max-width'] = '32%',
         ['border'] = '1px solid var(--border-color-base)',
         ['border'] = '1px solid var(--border-color-base)',
         ['border-radius'] = 'var(--border-radius-base, 12px)',
         ['border-radius'] = 'var(--border-radius-base, 12px)',
Line 34: Line 36:
         ['overflow'] = 'hidden',
         ['overflow'] = 'hidden',
         ['background'] = 'var(--color-surface-1)',
         ['background'] = 'var(--color-surface-1)',
        ['display'] = 'flex',
        ['flex-direction'] = 'column',
         ['transition'] = 'transform 0.2s ease',
         ['transition'] = 'transform 0.2s ease',
        ['box-sizing'] = 'border-box',
        ['display'] = 'flex',            -- New: Flex column layout
        ['flex-direction'] = 'column'    -- New: Ensures footer stays at bottom
     }
     }


     -- 3. IMAGE BANNER STYLE (The Major Change)
     -- BANNER WRAPPER
     local imageAreaStyle = {
     local imageWrapperStyle = {
         ['width'] = '100%',
         ['width'] = '100%',
         ['aspect-ratio'] = '16 / 9',     -- Enforce 16:9 ratio
         ['aspect-ratio'] = '16 / 9',
         ['overflow'] = 'hidden',        -- Crop excess
         ['overflow'] = 'hidden',
        ['border-bottom'] = '1px solid var(--border-color-base)',
         ['position'] = 'relative',
         ['position'] = 'relative',
         ['background'] = 'var(--color-surface-2)' -- Placeholder color
         ['background'] = 'var(--color-surface-2)',
    }
         ['border-bottom'] = '1px solid var(--border-color-base)'
 
    -- 4. TEXT STYLES
    local bodyStyle = {
        ['padding'] = '15px',
         ['flex-grow'] = '1',            -- New: Pushes content to fill space
        ['display'] = 'flex',
        ['flex-direction'] = 'column',
        ['gap'] = '8px'
     }
     }


    local titleStyle = {
        ['font-weight'] = 'bold',
        ['font-size'] = '1.2em',
        ['color'] = 'var(--color-base)'
    }
    local textStyle = {
        ['color'] = 'var(--color-subtle)',
        ['font-size'] = '0.95em',
        ['line-height'] = '1.4',
        ['text-align'] = 'left'          -- Keeps bullet points aligned nicely
    }
    -- 5. BUILD HTML
     local root = mw.html.create('div'):css(containerStyle)
     local root = mw.html.create('div'):css(containerStyle)


     for _, card in ipairs(cards) do
     for _, card in ipairs(cards) do
         local cardDiv = root:tag('div'):css(cardStyle)
         local cardDiv = root:tag('div')
            :addClass('jule-grid-card')
            :css(cardStyle)
          
          
         -- Image Area (Banner)
         -- Banner Image Area
        -- We use a slightly larger image size (400px) to ensure it looks crisp
         local imgDiv = cardDiv:tag('div'):css(imageWrapperStyle)
        -- We add a generic class to target it with CSS if needed later
         cardDiv:tag('div')
            :css(imageAreaStyle)
            :wikitext(string.format('[[File:%s|400px|center|link=%s|class=linkgrid-banner]]', card.image, card.link))
          
          
         -- Body Area
         -- CHANGE 2: Image Linking Logic
         local bodyDiv = cardDiv:tag('div'):css(bodyStyle)
        if card.link and card.link ~= '' then
            -- If link exists, link the image to it
            imgDiv:wikitext(string.format('[[File:%s|400px|center|link=%s|class=linkgrid-banner]]', card.image, card.link))
        else
            -- If no link, set link= (empty) to make it unclickable
            imgDiv:wikitext(string.format('[[File:%s|400px|center|link=|class=linkgrid-banner]]', card.image))
        end
       
        -- Text Content Area
         local textDiv = cardDiv:tag('div'):css({
            ['padding'] = '15px',
            ['flex-grow'] = '1',
            ['display'] = 'flex',
            ['flex-direction'] = 'column',
            ['gap'] = '8px'
        })
          
          
         -- Title
         -- Title
         bodyDiv:tag('div')
         local titleDiv = textDiv:tag('div')
             :css(titleStyle)
             :css({
             :wikitext(string.format('[[%s|%s]]', card.link, card.title))
                ['font-weight'] = 'bold',
                ['font-size'] = '1.3em',
                ['color'] = 'var(--color-base)',
                ['line-height'] = '1.2'
            })
 
        -- CHANGE 3: Title Linking Logic
        if card.link and card.link ~= '' then
             titleDiv:wikitext(string.format('[[%s|%s]]', card.link, card.title))
        else
            titleDiv:wikitext(card.title)
        end
              
              
         -- Description
         -- Body
         bodyDiv:tag('div')
         textDiv:tag('div')
             :css(textStyle)
             :css({
                ['color'] = 'var(--color-subtle)',
                ['font-size'] = '0.95em',
                ['line-height'] = '1.5'
            })
             :wikitext(card.body)
             :wikitext(card.body)
     end
     end


    -- 6. CSS FIX FOR IMAGES
     return tostring(root)
    -- This tiny style block forces the Wikitext image to behave like a background cover
    -- "object-fit: cover" is the magic property here.
    local cssFix = mw.html.create('style')
    cssFix:wikitext([[
        .linkgrid-banner img {
            width: 100% !important;
            height: 100% !important;
            object-fit: cover !important;
            display: block !important;
        }
        /* Mobile adjustment for card width */
        @media (max-width: 768px) { .citizen-card-grid > div { max-width: 100% !important; } }
    ]])
 
     return tostring(cssFix) .. tostring(root)
end
end


return p
return p

Latest revision as of 05:25, 27 January 2026

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

local p = {}

function p.render(frame)
    local args = frame:getParent().args
    local cards = {}
    local i = 1

    while args['title' .. i] do
        table.insert(cards, {
            -- CHANGE 1: We do NOT default to title anymore. 
            -- If link is missing, it stays nil.
            link  = args['link' .. i], 
            title = args['title' .. i],
            image = args['image' .. i] or 'Default.png',
            body  = args['body' .. i] or ''
        })
        i = i + 1
    end

    -- CONTAINER STYLE
    local containerStyle = {
        ['display'] = 'flex',
        ['flex-wrap'] = 'wrap',
        ['gap'] = '1rem',
        ['justify-content'] = 'center',
        ['margin-top'] = '1rem'
    }

    -- CARD STYLE
    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)',
        ['display'] = 'flex',
        ['flex-direction'] = 'column',
        ['transition'] = 'transform 0.2s ease',
    }

    -- BANNER WRAPPER
    local imageWrapperStyle = {
        ['width'] = '100%',
        ['aspect-ratio'] = '16 / 9',
        ['overflow'] = 'hidden',
        ['position'] = 'relative',
        ['background'] = 'var(--color-surface-2)',
        ['border-bottom'] = '1px solid var(--border-color-base)'
    }

    local root = mw.html.create('div'):css(containerStyle)

    for _, card in ipairs(cards) do
        local cardDiv = root:tag('div')
            :addClass('jule-grid-card')
            :css(cardStyle)
        
        -- Banner Image Area
        local imgDiv = cardDiv:tag('div'):css(imageWrapperStyle)
        
        -- CHANGE 2: Image Linking Logic
        if card.link and card.link ~= '' then
            -- If link exists, link the image to it
            imgDiv:wikitext(string.format('[[File:%s|400px|center|link=%s|class=linkgrid-banner]]', card.image, card.link))
        else
            -- If no link, set link= (empty) to make it unclickable
            imgDiv:wikitext(string.format('[[File:%s|400px|center|link=|class=linkgrid-banner]]', card.image))
        end
        
        -- Text Content Area
        local textDiv = cardDiv:tag('div'):css({
            ['padding'] = '15px',
            ['flex-grow'] = '1',
            ['display'] = 'flex',
            ['flex-direction'] = 'column',
            ['gap'] = '8px'
        })
        
        -- Title
        local titleDiv = textDiv:tag('div')
            :css({
                ['font-weight'] = 'bold',
                ['font-size'] = '1.3em',
                ['color'] = 'var(--color-base)',
                ['line-height'] = '1.2'
            })

        -- CHANGE 3: Title Linking Logic
        if card.link and card.link ~= '' then
            titleDiv:wikitext(string.format('[[%s|%s]]', card.link, card.title))
        else
            titleDiv:wikitext(card.title)
        end
            
        -- Body
        textDiv:tag('div')
            :css({
                ['color'] = 'var(--color-subtle)',
                ['font-size'] = '0.95em',
                ['line-height'] = '1.5'
            })
            :wikitext(card.body)
    end

    return tostring(root)
end

return p