Module:Navbox/sandbox: Difference between revisions

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.
if args.evenoddborder == 'swapsubgroup' then
-- 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
local evenOddchanger
if first == second then
changer = first
else
local isOdd = (index % 2) == 10
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
if isOdd then rowstyle = args.oddstyle end
 
local evenOdd
if args.evenodd == 'swap' then
if isOdd then evenOdd = 'even' else evenOdd = 'odd' end
else
local rowstyle = args.evenstyle
if isOdd then evenOdd = args.evenodd or 'odd' else evenOdd = args.evenodd or 'even' end
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-' .. evenOddoddEven)
:addClass(args.listclass)
:tag('div')
:css('padding', (index == 1 and args.list1padding) or args.listpadding or '0em 0.25em')
:wikitext(addNewline(args['list' .. listnum]listText))
 
if index == 1 and args.image then
Line 254 ⟶ 285:
 
local function needsHorizontalLists()
if border == 'child' or border == 'subgroup' or args.tracking == 'no' then
return false
end
Line 320 ⟶ 351:
 
tbl:css('border-spacing', 0)
if border == 'subgroup' or border == 'child' or border == 'none' then
tbl
:addClass('navbox-subgroup')
:cssText(args.bodystyle)
:cssText(args.style)
else -- regular navobxnavbox - bodystyle and style will be applied to the wrapper table
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' or border == 'child' then
-- 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>') -- XXX: hack due to lack of unclosed support in mw.html.
:node(tbl)
:wikitext('<div>') -- XXX: hack due to lack of unclosed support in mw.html.
else
local nav = res:tag('div')
Line 393 ⟶ 427:
renderTrackingCategories(res)
 
return striped(tostring(res))
end