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
No edit summary
No edit summary
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, {
Line 17: Line 16:
     end
     end


     -- 1. CONTAINER STYLE
     -- CONTAINER STYLE
     local containerStyle = {
     local containerStyle = {
         ['display'] = 'flex',
         ['display'] = 'flex',
Line 26: Line 25:
     }
     }


     -- 2. CARD STYLE
     -- CARD STYLE
     -- Added 'jule-grid-card' class for mobile targeting
     -- Note: 'max-width' here is for Desktop. Mobile is handled by Common.css class .jule-grid-card
     local cardStyle = {
     local cardStyle = {
         ['flex'] = '1 1 300px',
         ['flex'] = '1 1 300px',
         ['max-width'] = '32%',  -- Desktop default
         ['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 41: Line 40:
     }
     }


    -- BANNER WRAPPER (Forces 16:9)
     local imageWrapperStyle = {
     local imageWrapperStyle = {
         ['width'] = '100%',
         ['width'] = '100%',
Line 48: Line 48:
         ['background'] = 'var(--color-surface-2)',
         ['background'] = 'var(--color-surface-2)',
         ['border-bottom'] = '1px solid var(--border-color-base)'
         ['border-bottom'] = '1px solid var(--border-color-base)'
    }
    local contentStyle = {
        ['padding'] = '15px',
        ['flex-grow'] = '1',
        ['display'] = 'flex',
        ['flex-direction'] = 'column',
        ['gap'] = '8px'
     }
     }


Line 62: Line 54:
     for _, card in ipairs(cards) do
     for _, card in ipairs(cards) do
         local cardDiv = root:tag('div')
         local cardDiv = root:tag('div')
             :addClass('jule-grid-card') -- Important for CSS
             :addClass('jule-grid-card') -- CRITICAL: Uses Common.css for mobile width
             :css(cardStyle)
             :css(cardStyle)
          
          
         -- Banner Image
         -- Banner Image Area
         local imgDiv = cardDiv:tag('div'):css(imageWrapperStyle)
         local imgDiv = cardDiv:tag('div'):css(imageWrapperStyle)
       
        -- We add 'linkgrid-banner' class here so Common.css can force object-fit: cover
         imgDiv:wikitext(string.format('[[File:%s|400px|center|link=%s|class=linkgrid-banner]]', card.image, card.link))
         imgDiv:wikitext(string.format('[[File:%s|400px|center|link=%s|class=linkgrid-banner]]', card.image, card.link))
          
          
         -- Text Content
         -- Text Content Area
         local textDiv = cardDiv:tag('div'):css(contentStyle)
         local textDiv = cardDiv:tag('div'):css({
            ['padding'] = '15px',
            ['flex-grow'] = '1',
            ['display'] = 'flex',
            ['flex-direction'] = 'column',
            ['gap'] = '8px'
        })
          
          
         -- Title
         -- Title
         textDiv:tag('div')
         textDiv:tag('div')
             :css({['font-weight']='bold', ['font-size']='1.3em', ['color']='var(--color-base)', ['line-height']='1.2'})
             :css({
                ['font-weight'] = 'bold',
                ['font-size'] = '1.3em',
                ['color'] = 'var(--color-base)',
                ['line-height'] = '1.2'
            })
             :wikitext(string.format('[[%s|%s]]', card.link, card.title))
             :wikitext(string.format('[[%s|%s]]', card.link, card.title))
              
              
         -- Body
         -- Body
         textDiv:tag('div')
         textDiv:tag('div')
             :css({['color']='var(--color-subtle)', ['font-size']='0.95em', ['line-height']='1.5'})
             :css({
                ['color'] = 'var(--color-subtle)',
                ['font-size'] = '0.95em',
                ['line-height'] = '1.5'
            })
             :wikitext(card.body)
             :wikitext(card.body)
     end
     end


    -- CSS Injection for Mobile
     return tostring(root)
    local css = [[
        .linkgrid-banner img { width: 100% !important; height: 100% !important; object-fit: cover !important; }
        @media screen and (max-width: 768px) {
            .jule-grid-card { max-width: 100% !important; flex-basis: 100% !important; }
        }
    ]]
     return frame:extensionTag('style', css) .. tostring(root)
end
end


return p
return p

Revision as of 05:14, 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, {
            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

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

    -- CARD STYLE
    -- Note: 'max-width' here is for Desktop. Mobile is handled by Common.css class .jule-grid-card
    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 (Forces 16:9)
    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') -- CRITICAL: Uses Common.css for mobile width
            :css(cardStyle)
        
        -- Banner Image Area
        local imgDiv = cardDiv:tag('div'):css(imageWrapperStyle)
        
        -- We add 'linkgrid-banner' class here so Common.css can force object-fit: cover
        imgDiv:wikitext(string.format('[[File:%s|400px|center|link=%s|class=linkgrid-banner]]', card.image, card.link))
        
        -- Text Content Area
        local textDiv = cardDiv:tag('div'):css({
            ['padding'] = '15px',
            ['flex-grow'] = '1',
            ['display'] = 'flex',
            ['flex-direction'] = 'column',
            ['gap'] = '8px'
        })
        
        -- Title
        textDiv:tag('div')
            :css({
                ['font-weight'] = 'bold',
                ['font-size'] = '1.3em',
                ['color'] = 'var(--color-base)',
                ['line-height'] = '1.2'
            })
            :wikitext(string.format('[[%s|%s]]', card.link, card.title))
            
        -- 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