Module:Navbox: Difference between revisions
From 2D Tower Wiki
This page was last edited on 24 September 2026, at 20:16.
Size and space room category icons |
Mark nested navboxes as subgroups |
||
| Line 56: | Line 56: | ||
:attr("aria-label", title or "Navigation") | :attr("aria-label", title or "Navigation") | ||
applyStyle(root, bodyStyle) | applyStyle(root, bodyStyle) | ||
if border == "subgroup" then | |||
root:addClass("navbox-subgroup") | |||
end | |||
if name then | if name then | ||
Revision as of 20:16, 24 September 2026
Documentation for this module may be created at Module:Navbox/doc
local p = {}
local function getArg(args, key, default)
local value = args[key]
if value == nil then
return default
end
value = mw.text.trim(tostring(value))
if value == "" then
return default
end
return value
end
local function addWikitext(node, value)
if value and value ~= "" then
node:wikitext(value)
end
end
local function applyStyle(node, style)
if style and style ~= "" then
node:cssText(style)
end
end
local function makeCell(tag, className, value, style)
local cell = mw.html.create(tag):addClass(className)
applyStyle(cell, style)
addWikitext(cell, value)
return cell
end
function p.navbox(frame)
local args = frame:getParent().args
local state = string.lower(getArg(args, "state", "autocollapse"))
local border = string.lower(getArg(args, "border", ""))
local title = getArg(args, "title")
local name = getArg(args, "name")
local above = getArg(args, "above")
local below = getArg(args, "below")
local image = getArg(args, "image")
local imageleft = getArg(args, "imageleft")
local bodyStyle = getArg(args, "bodystyle")
local titleStyle = getArg(args, "titlestyle")
local titleClass = getArg(args, "titleclass")
local groupStyle = getArg(args, "groupstyle")
local listStyle = getArg(args, "liststyle")
local oddStyle = getArg(args, "oddstyle")
local evenStyle = getArg(args, "evenstyle")
local rowClass = getArg(args, "listclass", "navbox-list")
local root = mw.html.create("div")
:addClass("navbox")
:attr("role", "navigation")
:attr("aria-label", title or "Navigation")
applyStyle(root, bodyStyle)
if border == "subgroup" then
root:addClass("navbox-subgroup")
end
if name then
root:attr("data-name", name)
end
if title then
local titleRow = mw.html.create("div"):addClass("navbox-title")
if titleClass then
titleRow:addClass(titleClass)
end
applyStyle(titleRow, titleStyle)
addWikitext(titleRow, title)
root:node(titleRow)
end
if above then
root:node(makeCell("div", "navbox-above", above, getArg(args, "abovestyle")))
end
local inner = mw.html.create("div"):addClass("navbox-inner")
local rowNumber = 0
for i = 1, 100 do
local group = getArg(args, "group" .. i)
local list = getArg(args, "list" .. i)
local header = getArg(args, "header" .. i)
local groupIcon = getArg(args, "groupicon" .. i)
local groupLink = getArg(args, "grouplink" .. i)
if group or list or header then
rowNumber = rowNumber + 1
local row = mw.html.create("div"):addClass("navbox-row")
if rowNumber % 2 == 1 then
row:addClass("navbox-odd")
applyStyle(row, oddStyle)
else
row:addClass("navbox-even")
applyStyle(row, evenStyle)
end
if header then
row:node(makeCell("div", "navbox-group navbox-header", header, getArg(args, "header" .. i .. "style", groupStyle)))
elseif group then
if groupIcon or groupLink then
local groupCell = mw.html.create("div"):addClass("navbox-group")
applyStyle(groupCell, groupStyle)
if groupIcon then
groupCell:wikitext(frame:expandTemplate{title = "Icon", args = {groupIcon}} .. " " )
end
if groupLink then
groupCell:wikitext("[[:Category:" .. groupLink .. "|" .. group .. "]]" )
else
groupCell:wikitext(group)
end
row:node(groupCell)
else
row:node(makeCell("div", "navbox-group", group, groupStyle))
end
end
local listCell = mw.html.create("div"):addClass(rowClass)
applyStyle(listCell, getArg(args, "list" .. i .. "style", listStyle))
addWikitext(listCell, list or "")
row:node(listCell)
inner:node(row)
end
end
if image or imageleft then
local imageRow = mw.html.create("div"):addClass("navbox-image-row")
if imageleft then
imageRow:node(makeCell("div", "navbox-image navbox-image-left", imageleft, getArg(args, "imageleftstyle")))
end
if image then
imageRow:node(makeCell("div", "navbox-image", image, getArg(args, "imagestyle")))
end
inner:node(imageRow)
end
root:node(inner)
if below then
root:node(makeCell("div", "navbox-below", below, getArg(args, "belowstyle")))
end
return tostring(root)
end
return p