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

Module:Infobox: Difference between revisions

From Jules RNG Wiki
Created page with "local p = {} function p.render(frame) local args = frame:getParent().args -- 1. SETUP CONTAINER local root = mw.html.create('div') :addClass('citizen-infobox') -- Hook for CSS :css({ ['float'] = 'right', ['width'] = '300px', ['max-width'] = '100%', ['background'] = 'var(--color-surface-2)', ['border'] = '1px solid var(--border-color-base)', ['border-radius'] = 'var(-..."
 
No edit summary
 
Line 6: Line 6:
     -- 1. SETUP CONTAINER
     -- 1. SETUP CONTAINER
     local root = mw.html.create('div')
     local root = mw.html.create('div')
         :addClass('citizen-infobox') -- Hook for CSS
         :addClass('citizen-infobox')
         :css({
         :css({
             ['float'] = 'right',
             ['float'] = 'right',
Line 16: Line 16:
             ['box-shadow'] = 'var(--box-shadow-level-1)',
             ['box-shadow'] = 'var(--box-shadow-level-1)',
             ['margin'] = '0 0 1em 1em',
             ['margin'] = '0 0 1em 1em',
             ['padding'] = '0',
             ['overflow'] = 'hidden',
             ['display'] = 'flex',
             ['clear'] = 'right' -- Prevents floating weirdness
            ['flex-direction'] = 'column',
            ['overflow'] = 'hidden'
         })
         })


     -- 2. TITLE HEADER
     -- 2. HEADER / TITLE
     if args['name'] then
     if args['title'] or args['name'] then
         root:tag('div')
         root:tag('div')
             :css({
             :css({
                 ['background'] = 'var(--color-primary--hover)', -- Use theme accent color
                 ['background'] = 'var(--color-primary)',  
                 ['color'] = '#fff',
                 ['color'] = '#fff',  
                 ['padding'] = '12px',
                 ['padding'] = '12px',
                 ['text-align'] = 'center',
                 ['text-align'] = 'center',
Line 33: Line 31:
                 ['font-size'] = '1.2em'
                 ['font-size'] = '1.2em'
             })
             })
             :wikitext(args['name'])
             :wikitext(args['title'] or args['name'])
     end
     end


Line 39: Line 37:
     local images = {}
     local images = {}
     local i = 1
     local i = 1
   
    -- We loop to find image1, image2...
     while args['image' .. i] do
     while args['image' .. i] do
         table.insert(images, {
         table.insert(images, {
             file    = args['image' .. i],
             file    = args['image' .. i],
             tab    = args['tab' .. i] or ('View ' .. i),
            -- FIX: Look for 'image1tabtext' OR 'tabtext1'
             caption = args['caption' .. i] or ''
             tab    = args['image' .. i .. 'tabtext'] or args['tabtext' .. i] or ('View ' .. i),
            -- FIX: Look for 'image1undertext' OR 'undertext1'
             caption = args['image' .. i .. 'undertext'] or args['undertext' .. i] or ''
         })
         })
         i = i + 1
         i = i + 1
Line 52: Line 54:
             :css({['background'] = 'var(--color-surface-1)', ['text-align'] = 'center', ['border-bottom'] = '1px solid var(--border-color-base)'})
             :css({['background'] = 'var(--color-surface-1)', ['text-align'] = 'center', ['border-bottom'] = '1px solid var(--border-color-base)'})


         -- A. Render the Tabs (only if > 1 image)
         -- A. Render Buttons (only if > 1 image)
         if #images > 1 then
         if #images > 1 then
             local tabRow = imageContainer:tag('div'):addClass('infobox-tabs')
             local btnRow = imageContainer:tag('div')
                 :css({['display'] = 'flex', ['justify-content'] = 'center', ['gap'] = '5px', ['padding'] = '10px 10px 0 10px'})
                 :css({['display'] = 'flex', ['justify-content'] = 'center', ['gap'] = '8px', ['padding'] = '10px 10px 0 10px'})
              
              
             for idx, imgData in ipairs(images) do
             for idx, imgData in ipairs(images) do
                 tabRow:tag('span')
                 local btn = btnRow:tag('span')
                     :addClass('infobox-tab-btn')
                     :addClass('infobox-tab-btn')
                    :addClass(idx == 1 and 'active' or '') -- First one is active
                     :attr('data-target', 'infobox-img-' .. idx)
                     :attr('data-target', 'infobox-img-' .. idx)
                     :wikitext(imgData.tab)
                     :wikitext(imgData.tab)
               
                -- Force first button active by default
                if idx == 1 then btn:addClass('active') end
             end
             end
         end
         end


         -- B. Render the Images
         -- B. Render Images
         for idx, imgData in ipairs(images) do
         for idx, imgData in ipairs(images) do
             local imgWrapper = imageContainer:tag('div')
             local imgWrapper = imageContainer:tag('div')
                 :addClass('infobox-img-content')
                 :addClass('infobox-img-content')
                :addClass(idx == 1 and 'active' or '')
                 :attr('id', 'infobox-img-' .. idx)
                 :attr('id', 'infobox-img-' .. idx)
                 :css({['padding'] = '15px'})
                 :css({['padding'] = '15px'})
           
            -- Force first image visible by default
            if idx == 1 then imgWrapper:addClass('active') end


             -- Image
             -- The Image
             imgWrapper:tag('div'):wikitext(string.format('[[File:%s|250px]]', imgData.file))
             imgWrapper:tag('div'):wikitext(string.format('[[File:%s|260px]]', imgData.file))
              
              
             -- Caption
             -- The Caption
             if imgData.caption ~= '' then
             if imgData.caption ~= '' then
                 imgWrapper:tag('div')
                 imgWrapper:tag('div')
                     :css({['font-size'] = '0.9em', ['color'] = 'var(--color-subtle)', ['margin-top'] = '8px'})
                     :css({['font-size'] = '0.9em', ['color'] = 'var(--color-subtle)', ['margin-top'] = '8px', ['font-style'] = 'italic'})
                     :wikitext(imgData.caption)
                     :wikitext(imgData.caption)
             end
             end
Line 91: Line 97:
      
      
     local j = 1
     local j = 1
     while args['label' .. j] or args['header' .. j] do
    -- Loop to find data1name/data1body OR label1/value1
         -- A. Section Header (Optional)
     while args['label' .. j] or args['data' .. j .. 'name'] or args['header' .. j] do
       
         -- Header Row
         if args['header' .. j] then
         if args['header' .. j] then
             contentTable:tag('tr'):tag('th')
             contentTable:tag('tr'):tag('th')
Line 99: Line 107:
                     ['background'] = 'var(--color-surface-2)',
                     ['background'] = 'var(--color-surface-2)',
                     ['border-top'] = '1px solid var(--border-color-base)',
                     ['border-top'] = '1px solid var(--border-color-base)',
                    ['border-bottom'] = '1px solid var(--border-color-base)',
                     ['padding'] = '8px',
                     ['padding'] = '8px',
                     ['text-align'] = 'center',
                     ['text-align'] = 'center',
Line 105: Line 112:
                 })
                 })
                 :wikitext(args['header' .. j])
                 :wikitext(args['header' .. j])
         end
          
        -- Data Row
        else
            local label = args['label' .. j] or args['data' .. j .. 'name']
            local value = args['value' .. j] or args['data' .. j .. 'body']


        -- B. Data Row (Label + Value)
            if label and value then
        if args['label' .. j] and args['value' .. j] then
                local row = contentTable:tag('tr')
            local row = contentTable:tag('tr')
                    :css({['border-bottom'] = '1px solid var(--border-color-subtle)'})
                :css({['border-bottom'] = '1px solid var(--border-color-subtle)'})
               
           
                -- Label Cell
            -- Label
                row:tag('th')
            row:tag('th')
                    :css({['text-align'] = 'left', ['padding'] = '10px', ['width'] = '40%', ['color'] = 'var(--color-subtle)'})
                :css({['text-align'] = 'left', ['padding'] = '10px', ['width'] = '40%', ['color'] = 'var(--color-subtle)'})
                    :wikitext(label)
                :wikitext(args['label' .. j])
               
           
                -- Value Cell
            -- Value
                row:tag('td')
            row:tag('td')
                    :css({['text-align'] = 'right', ['padding'] = '10px', ['font-weight'] = '500'})
                :css({['text-align'] = 'right', ['padding'] = '10px', ['font-weight'] = '500'})
                    :wikitext(value)
                :wikitext(args['value' .. j])
            end
         end
         end
         j = j + 1
         j = j + 1

Latest revision as of 19:29, 27 January 2026

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

local p = {}

function p.render(frame)
    local args = frame:getParent().args
    
    -- 1. SETUP CONTAINER
    local root = mw.html.create('div')
        :addClass('citizen-infobox')
        :css({
            ['float'] = 'right',
            ['width'] = '300px',
            ['max-width'] = '100%',
            ['background'] = 'var(--color-surface-2)',
            ['border'] = '1px solid var(--border-color-base)',
            ['border-radius'] = 'var(--border-radius-base, 8px)',
            ['box-shadow'] = 'var(--box-shadow-level-1)',
            ['margin'] = '0 0 1em 1em',
            ['overflow'] = 'hidden',
            ['clear'] = 'right' -- Prevents floating weirdness
        })

    -- 2. HEADER / TITLE
    if args['title'] or args['name'] then
        root:tag('div')
            :css({
                ['background'] = 'var(--color-primary)', 
                ['color'] = '#fff', 
                ['padding'] = '12px',
                ['text-align'] = 'center',
                ['font-weight'] = 'bold',
                ['font-size'] = '1.2em'
            })
            :wikitext(args['title'] or args['name'])
    end

    -- 3. IMAGES & TABS LOGIC
    local images = {}
    local i = 1
    
    -- We loop to find image1, image2...
    while args['image' .. i] do
        table.insert(images, {
            file    = args['image' .. i],
            -- FIX: Look for 'image1tabtext' OR 'tabtext1'
            tab     = args['image' .. i .. 'tabtext'] or args['tabtext' .. i] or ('View ' .. i),
            -- FIX: Look for 'image1undertext' OR 'undertext1'
            caption = args['image' .. i .. 'undertext'] or args['undertext' .. i] or ''
        })
        i = i + 1
    end

    if #images > 0 then
        local imageContainer = root:tag('div'):addClass('infobox-image-area')
            :css({['background'] = 'var(--color-surface-1)', ['text-align'] = 'center', ['border-bottom'] = '1px solid var(--border-color-base)'})

        -- A. Render Buttons (only if > 1 image)
        if #images > 1 then
            local btnRow = imageContainer:tag('div')
                :css({['display'] = 'flex', ['justify-content'] = 'center', ['gap'] = '8px', ['padding'] = '10px 10px 0 10px'})
            
            for idx, imgData in ipairs(images) do
                local btn = btnRow:tag('span')
                    :addClass('infobox-tab-btn')
                    :attr('data-target', 'infobox-img-' .. idx)
                    :wikitext(imgData.tab)
                
                -- Force first button active by default
                if idx == 1 then btn:addClass('active') end
            end
        end

        -- B. Render Images
        for idx, imgData in ipairs(images) do
            local imgWrapper = imageContainer:tag('div')
                :addClass('infobox-img-content')
                :attr('id', 'infobox-img-' .. idx)
                :css({['padding'] = '15px'})
            
            -- Force first image visible by default
            if idx == 1 then imgWrapper:addClass('active') end

            -- The Image
            imgWrapper:tag('div'):wikitext(string.format('[[File:%s|260px]]', imgData.file))
            
            -- The Caption
            if imgData.caption ~= '' then
                imgWrapper:tag('div')
                    :css({['font-size'] = '0.9em', ['color'] = 'var(--color-subtle)', ['margin-top'] = '8px', ['font-style'] = 'italic'})
                    :wikitext(imgData.caption)
            end
        end
    end

    -- 4. DATA ROWS
    local contentTable = root:tag('table')
        :css({['width'] = '100%', ['border-collapse'] = 'collapse', ['font-size'] = '0.95em'})
    
    local j = 1
    -- Loop to find data1name/data1body OR label1/value1
    while args['label' .. j] or args['data' .. j .. 'name'] or args['header' .. j] do
        
        -- Header Row
        if args['header' .. j] then
            contentTable:tag('tr'):tag('th')
                :attr('colspan', '2')
                :css({
                    ['background'] = 'var(--color-surface-2)',
                    ['border-top'] = '1px solid var(--border-color-base)',
                    ['padding'] = '8px',
                    ['text-align'] = 'center',
                    ['color'] = 'var(--color-base)'
                })
                :wikitext(args['header' .. j])
        
        -- Data Row
        else
            local label = args['label' .. j] or args['data' .. j .. 'name']
            local value = args['value' .. j] or args['data' .. j .. 'body']

            if label and value then
                local row = contentTable:tag('tr')
                    :css({['border-bottom'] = '1px solid var(--border-color-subtle)'})
                
                -- Label Cell
                row:tag('th')
                    :css({['text-align'] = 'left', ['padding'] = '10px', ['width'] = '40%', ['color'] = 'var(--color-subtle)'})
                    :wikitext(label)
                
                -- Value Cell
                row:tag('td')
                    :css({['text-align'] = 'right', ['padding'] = '10px', ['font-weight'] = '500'})
                    :wikitext(value)
            end
        end
        j = j + 1
    end

    return tostring(root)
end

return p