Module:Navbox: Difference between revisions
Appearance
trim list items |
fix white border on dark mode |
||
Line 56: | Line 56: | ||
local function renderListRow(tbl, group, isOdd) | local function renderListRow(tbl, group, isOdd) | ||
local listClass = | local listClass = "navbox-list1 navbox-list" | ||
listClass = listClass..(isOdd and "navbox-odd" or "navbox-even") | |||
local row = tbl:tag('tr') | local row = tbl:tag('tr') | ||
row:tag('th') | row:tag('th') | ||
:attr('scope', 'row') | :attr('scope', 'row') | ||
: | :addClass('navbox-group') | ||
:wikitext(group.title) | :wikitext(group.title) | ||
Line 69: | Line 70: | ||
row:tag('td') | row:tag('td') | ||
: | :addClass(listClass) | ||
: | :cssText('width:100%; padding:0 0 0 0.3rem; margin:0px; border-left-width:0;') | ||
:tag('div') | :tag('div') | ||
:wikitext(listContent) | :wikitext(listContent) |
Latest revision as of 11:20, 8 September 2025
Documentation for this module may be created at Module:Navbox/doc
local p = {}
local args, groups
local function parseGroups()
local groups = {}
local currentGroup = nil
local i = 1
while args[i] ~= nil do
local arg = args[i]
i = i + 1
if arg:sub(1, 2) == "+ " then
table.insert(currentGroup.items, mw.text.trim(arg:sub(3)))
else
currentGroup = { title = arg, items = {} }
table.insert(groups, currentGroup)
end
end
return groups
end
local function renderTitleRow(tbl)
tbl:tag('tr')
:tag('th')
:attr('class', 'navbox-title')
:attr('scope', 'col')
:attr('colspan', '3')
:tag('div')
:wikitext(args.title)
end
local function renderAboveRow(tbl)
if args.above and args.above ~= "" then
tbl:tag('tr')
:tag('td')
:attr('class', 'navbox-abovebelow')
:attr('colspan', '3')
:tag('div')
:wikitext(args.above)
end
end
local function renderBelowRow(tbl)
if args.below and args.below ~= "" then
tbl:tag('tr')
:tag('td')
:attr('class', 'navbox-abovebelow')
:attr('colspan', '3')
:tag('div')
:wikitext(args.below)
end
end
local function renderListRow(tbl, group, isOdd)
local listClass = "navbox-list1 navbox-list"
listClass = listClass..(isOdd and "navbox-odd" or "navbox-even")
local row = tbl:tag('tr')
row:tag('th')
:attr('scope', 'row')
:addClass('navbox-group')
:wikitext(group.title)
local listContent = table.concat(group.items, " ")
mw.log(listContent)
row:tag('td')
:addClass(listClass)
:cssText('width:100%; padding:0 0 0 0.3rem; margin:0px; border-left-width:0;')
:tag('div')
:wikitext(listContent)
end
p.navbox = function(frame)
args = frame:getParent().args
groups = parseGroups()
local navbox = mw.html.create('div')
:addClass('navbox')
local tbl = navbox:tag('table')
:addClass('nowraplinks')
:addClass("navbox-inner")
:addClass(args.bodyclass)
renderTitleRow(tbl)
renderAboveRow(tbl)
for i, group in ipairs(groups) do
renderListRow(tbl, group, i % 2 == 1)
end
renderBelowRow(tbl)
return tostring(navbox)
end
return p