Content deleted Content added
change requested at Template talk:Navbox#Row colour: fix coloring of alternate rows so it always starts with 'odd' (and shows image if given) even if some list items are omitted |
experiment with automatic-striping for nested navboxes providing they do not use "|evenodd = swap"; not successful for "Container test" where original module starts each subgroup as odd |
||
Line 12:
local border
local listnums = {}
local ODD_EVEN_MARKER = '\127_ODDEVEN_\127'
local function striped(wikitext)
-- Return wikitext with markers replaced for odd/even striping.
-- No change; striping occurs in outermost navbox.
return wikitext
end
local first, second = 'odd', 'even'
if args.evenodd then
if args.evenodd == 'swap' then
first, second = second, first
else
first = args.evenodd
second = first
end
end
if first == second then
changer = first
else
changer = function (s)
index = index + 1
return index % 2 == 1 and first or second
end
end
return (wikitext:gsub(ODD_EVEN_MARKER, changer)) -- () omits gsub count
end
local function addNewline(s)
Line 211 ⟶ 240:
end
local rowstyle -- usually nil so cssText(rowstyle) usually adds nothing
▲ local isOdd = (index % 2) == 1
if index % 2 == 1 then
local rowstyle = args.evenstyle▼
▲ local evenOdd
▲ if args.evenodd == 'swap' then
else
end
local listText = args['list' .. listnum]
local oddEven = ODD_EVEN_MARKER
if listText:sub(1, 12) == '</div><table' then
-- Assume list text is for a subgroup navbox so no automatic striping for this row.
oddEven = 'odd'
end
listCell
:css('padding', '0px')
Line 228 ⟶ 259:
:cssText(args['list' .. listnum .. 'style'])
:addClass('navbox-list')
:addClass('navbox-' ..
:addClass(args.listclass)
:tag('div')
:css('padding', (index == 1 and args.list1padding) or args.listpadding or '0em 0.25em')
:wikitext(addNewline(
if index == 1 and args.image then
Line 254 ⟶ 285:
local function needsHorizontalLists()
if
return false
end
Line 320 ⟶ 351:
tbl:css('border-spacing', 0)
if border == 'subgroup
tbl
:addClass('navbox-subgroup')
:cssText(args.bodystyle)
:cssText(args.style)
else -- regular
tbl
:addClass('navbox-inner')
Line 353 ⟶ 384:
border = mw.text.trim(args.border or args[1] or '')
if border == 'child' then
border = 'subgroup'
end
-- render the main body of the navbox
Line 368 ⟶ 402:
nav:attr('aria-label', 'Navbox')
end
elseif border == 'subgroup
-- We assume that this navbox is being rendered in a list cell of a parent navbox, and is
-- therefore inside a div with padding:0em 0.25em. We start with a </div> to avoid the
-- padding being applied, and at the end add a <div> to balance out the parent's </div>
res
:wikitext('</div>')
:node(tbl)
:wikitext('<div>')
else
local nav = res:tag('div')
Line 393 ⟶ 427:
renderTrackingCategories(res)
return striped(tostring(res))
end
|