Module:NavboxMobile: Difference between revisions
EnWikiAdmin (talk | contribs) No edit summary |
EnWikiAdmin (talk | contribs) No edit summary |
||
Line 305: | Line 305: | ||
-- List rows | -- List rows | ||
-- | -- | ||
local function renderListRow(tbl, listnum) | local function renderListRow(tbl, index, listnum, listnums_size) | ||
local row = addTableRow(tbl) | local row = addTableRow(tbl) | ||
-- Process group | -- Process group (e.g., `group1`, `group2`) | ||
if args[ | local group_and_num = format(cfg.arg.group_and_num, listnum) | ||
local groupstyle_and_num = format(cfg.arg.groupstyle_and_num, listnum) | |||
if args[group_and_num] then | |||
local groupCell = row:tag('th') | local groupCell = row:tag('th') | ||
-- ID for aria-labelledby attribute if it's the first group with no title or above | |||
if listnum == 1 and not (args[cfg.arg.title] or args[cfg.arg.above] or args[cfg.arg.group2]) then | |||
groupCell:attr('id', mw.uri.anchorEncode(args[cfg.arg.group1])) | |||
end | |||
groupCell | groupCell | ||
:attr('scope', 'row') | :attr('scope', 'row') | ||
Line 316: | Line 324: | ||
:cssText(args.basestyle) | :cssText(args.basestyle) | ||
:cssText(args.groupstyle) | :cssText(args.groupstyle) | ||
:cssText(args[ | :cssText(args[groupstyle_and_num]) | ||
:wikitext(processItem(args[ | :wikitext(processItem(args[group_and_num])) | ||
end | end | ||
-- Add | -- Add list cell | ||
local listCell = row:tag('td') | local listCell = row:tag('td') | ||
-- | -- If there's a group, add a class; otherwise, make the cell span both columns | ||
if args[group_and_num] then | |||
listCell:addClass(cfg.class.navbox_list_with_group) | |||
else | |||
listCell:attr('colspan', 2) | |||
end | |||
-- Set cell width if group width is not specified | |||
if not args[cfg.arg.groupwidth] then | |||
listCell:css('width', '100%') | |||
end | end | ||
-- Apply styles for odd/even rows | |||
local rowstyle = nil | |||
if index % 2 == 1 then | |||
rowstyle = args[cfg.arg.oddstyle] | |||
else | |||
rowstyle = args[cfg.arg.evenstyle] | |||
end | |||
-- Handle the list itself | |||
local list_and_num = format(cfg.arg.list_and_num, listnum) | |||
local listText = args[list_and_num] | |||
-- Check for nested subgroups | -- Check for nested subgroups | ||
if inArray(cfg.keyword.subgroups, | if inArray(cfg.keyword.subgroups, listText) then | ||
local childArgs = { | local childArgs = { | ||
border = | [cfg.arg.border] = cfg.keyword.border_subgroup, | ||
navbar = | [cfg.arg.navbar] = cfg.keyword.navbar_plain | ||
} | } | ||
local hasChildArgs = false | |||
for k, v in pairs(args) do | for k, v in pairs(args) do | ||
k = tostring(k) | |||
for _, w in ipairs(cfg.keyword.subgroups) do | |||
w = w .. listnum .. "_" | |||
if (#k > #w) and (k:sub(1, #w) == w) then | |||
childArgs[k:sub(#w + 1)] = v | |||
hasChildArgs = true | |||
end | |||
end | end | ||
end | end | ||
listText = hasChildArgs and p._navboxMobile(childArgs) or listText | |||
end | end | ||
-- | -- Odd/even class and striping | ||
local | local oddEven = cfg.marker.oddeven | ||
if listText:sub(1, 12) == '</div><table' then | |||
-- If listText is for a subgroup navbox, no automatic striping for this row | |||
oddEven = listText:find(cfg.pattern.navbox_title) and cfg.marker.restart or cfg.class.navbox_odd_part | |||
end | |||
-- Apply list-specific styles | |||
local liststyle_and_num = format(cfg.arg.liststyle_and_num, listnum) | |||
local listclass_and_num = format(cfg.arg.listclass_and_num, listnum) | |||
:css(' | listCell | ||
:css('padding', '0') | |||
:cssText(args[cfg.arg.liststyle]) | |||
:cssText(rowstyle) | |||
:cssText(args[liststyle_and_num]) | |||
:addClass(cfg.class.navbox_list) | |||
:addClass(cfg.class.navbox_part .. oddEven) | |||
:addClass(args[cfg.arg.listclass]) | |||
:addClass(args[listclass_and_num]) | |||
:tag('div') | |||
:css('padding', args[cfg.arg.list1padding] or args[cfg.arg.listpadding] or '0 0.25em') | |||
:wikitext(processItem(listText, args[cfg.arg.nowrapitems])) | |||
end | |||