Module:Infobox: Difference between revisions
From Jules RNG Wiki
More actions
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') | :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', | ||
[' | ['overflow'] = 'hidden', | ||
[' | ['clear'] = 'right' -- Prevents floating weirdness | ||
}) | }) | ||
-- 2. TITLE | -- 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 | ['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[' | -- FIX: Look for 'image1tabtext' OR 'tabtext1' | ||
caption = args[' | 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 | -- A. Render Buttons (only if > 1 image) | ||
if #images > 1 then | if #images > 1 then | ||
local | local btnRow = imageContainer:tag('div') | ||
:css({['display'] = 'flex', ['justify-content'] = 'center', ['gap'] = ' | :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 | ||
local btn = btnRow:tag('span') | |||
:addClass('infobox-tab-btn') | :addClass('infobox-tab-btn') | ||
: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 | -- 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') | ||
: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| | 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 | ||
-- | 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)', | ||
['padding'] = '8px', | ['padding'] = '8px', | ||
['text-align'] = 'center', | ['text-align'] = 'center', | ||
| Line 105: | Line 112: | ||
}) | }) | ||
:wikitext(args['header' .. j]) | :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 | 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