Module:Navbox/sandbox: Difference between revisions

Content deleted Content added
oy oy oy take a minute for things
Tag: Reverted
more localize
Tag: Reverted
Line 4:
local getArgs -- lazily initialized
local args
local format = string.format
 
local function striped(wikitext, border)
Line 11 ⟶ 12:
-- where a child navbox is not contained in a parent navbox.
if border == cfg.keyword.border_subgroup and
args[cfg.arg.orphan] ~= cfg.keyword.orphan_yes then
-- No change; striping occurs in outermost navbox.
return wikitext .. cfg.category.orphan
end
local first, second = 'odd', 'even'
if args[cfg.arg.evenodd] then
if args[cfg.arg.evenodd] == 'swap' then
first, second = second, first
else
first = args[cfg.arg.evenodd]
second = first
end
Line 71 ⟶ 72:
 
local function renderNavBar(titleCell)
if args[cfg.arg.navbar] ~= cfg.keyword.navbar_off and
args[cfg.arg.navbar] ~= cfg.keyword.navbar_plain and
(args[cfg.arg.name] or not mw.getCurrentFrame():getParent():getTitle():gsub('/sandbox$', '') == 'Template:Navbox') then
titleCell:wikitext(navbar{
args[cfg.arg.name],
[cfg.navbar.mini] = 1,
[cfg.navbar.fontstyle] = (args[cfg.arg.basestyle] or '') .. ';' ..
(args[cfg.arg.titlestyle] or '') ..
';background:none transparent;border:none;box-shadow:none;padding:0;'
})
Line 85 ⟶ 87:
 
local function renderTitleRow(tbl)
if not args[cfg.arg.title] then return end
 
local titleRow = tbl:tag('tr')
 
if args[cfg.arg.titlegroup] then
titleRow
:tag('th')
:attr('scope', 'row')
:addClass('navbox-group')
:addClass(args[cfg.arg.titlegroupclass])
:cssText(args[cfg.arg.basestyle])
:cssText(args[cfg.arg.groupstyle])
:cssText(args[cfg.arg.titlegroupstyle])
:wikitext(args[cfg.arg.titlegroup])
end
 
local titleCell = titleRow:tag('th'):attr('scope', 'col')
 
if args[cfg.arg.titlegroup] then
titleCell
:css('border-left', '2px solid #fdfdfd')
Line 110 ⟶ 112:
 
local titleColspan = 2
if args[cfg.arg.imageleft] then titleColspan = titleColspan + 1 end
if args[cfg.arg.image] then titleColspan = titleColspan + 1 end
if args[cfg.arg.titlegroup] then titleColspan = titleColspan - 1 end
 
titleCell
:cssText(args[cfg.arg.basestyle])
:cssText(args[cfg.arg.titlestyle])
:addClass('navbox-title')
:attr('colspan', titleColspan)
Line 125 ⟶ 127:
:tag('div')
-- id for aria-labelledby attribute
:attr('id', mw.uri.anchorEncode(args[cfg.arg.title]))
:addClass(args[cfg.arg.titleclass])
:css('font-size', '114%')
:css('margin', '0 4em')
:wikitext(processItem(args[cfg.arg.title]))
end
 
local function getAboveBelowColspan()
local ret = 2
if args[cfg.arg.imageleft] then ret = ret + 1 end
if args[cfg.arg.image] then ret = ret + 1 end
return ret
end
 
local function renderAboveRow(tbl)
if not args[cfg.arg.above] then return end
 
tbl:tag('tr')
:tag('td')
:addClass('navbox-abovebelow')
:addClass(args[cfg.arg.aboveclass])
:cssText(args[cfg.arg.basestyle])
:cssText(args[cfg.arg.abovestyle])
:attr('colspan', getAboveBelowColspan())
:tag('div')
-- id for aria-labelledby attribute, if no title
:attr('id', args[cfg.arg.title] and nil or mw.uri.anchorEncode(args[cfg.arg.above]))
:wikitext(processItem(args[cfg.arg.above], args[cfg.arg.nowrapitems]))
end
 
local function renderBelowRow(tbl)
if not args[cfg.arg.below] then return end
 
tbl:tag('tr')
:tag('td')
:addClass('navbox-abovebelow')
:addClass(args[cfg.arg.belowclass])
:cssText(args[cfg.arg.basestyle])
:cssText(args[cfg.arg.belowstyle])
:attr('colspan', getAboveBelowColspan())
:tag('div')
:wikitext(processItem(args[cfg.arg.below], args[cfg.arg.nowrapitems]))
end
 
local function renderListRow(tbl, index, listnum, listnumslistnums_size)
local row = tbl:tag('tr')
 
if index == 1 and args[cfg.arg.imageleft] then
row
:tag('td')
:addClass('noviewer')
:addClass('navbox-image')
:addClass(args[cfg.arg.imageclass])
:css('width', '1px') -- Minimize width
:css('padding', '0 2px 0 0')
:cssText(args[cfg.arg.imageleftstyle])
:attr('rowspan', #listnumslistnums_size)
:tag('div')
:wikitext(processItem(args[cfg.arg.imageleft]))
end
 
local group_and_num = format(cfg.arg.group_and_num, listnum)
if args['group' .. listnum] then
local groupstyle_and_num = format(cfg.arg.groupstyle_and_num, listnum)
if args['group' .. listnumgroup_and_num] then
local groupCell = row:tag('th')
 
-- id for aria-labelledby attribute, if lone 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
 
Line 198 ⟶ 202:
:attr('scope', 'row')
:addClass('navbox-group')
:addClass(args[cfg.arg.groupclass])
:cssText(args[cfg.arg.basestyle])
-- If groupwidth not specified, minimize width
:css('width', args[cfg.arg.groupwidth] or '1%')
 
groupCell
:cssText(args[cfg.arg.groupstyle])
:cssText(args['group' .. listnum .. 'style'groupstyle_and_num])
:wikitext(args['group' .. listnumgroup_and_num])
end
 
local listCell = row:tag('td')
 
if args['group' .. listnumgroup_and_num] then
listCell
:css('text-align', 'left')
Line 220 ⟶ 224:
end
 
if not args[cfg.arg.groupwidth] then
listCell:css('width', '100%')
end
Line 226 ⟶ 230:
local rowstyle -- usually nil so cssText(rowstyle) usually adds nothing
if index % 2 == 1 then
rowstyle = args[cfg.arg.oddstyle]
else
rowstyle = args[cfg.arg.evenstyle]
end
 
local listTextlist_and_num = args['list' format(cfg.arg.list_and_num, listnum])
local liststyle_and_num = format(cfg.arg.liststyle_and_num, listnum)
local listclass_and_num = format(cfg.arg.listclass_and_num, listnum)
local listText = args[list_and_num]
local oddEven = cfg.marker.oddeven
if listText:sub(1, 12) == '</div><table' then
Line 239 ⟶ 246:
listCell
:css('padding', '0')
:cssText(args[cfg.arg.liststyle])
:cssText(rowstyle)
:cssText(args['list' .. listnum .. 'style'liststyle_and_num])
:addClass('navbox-list')
:addClass('navbox-' .. oddEven)
:addClass(args[cfg.arg.listclass])
:addClass(args['list' .. listnum .. 'class'listclass_and_num])
:tag('div')
:css('padding', (index == 1 and args[cfg.arg.list1padding]) or args[cfg.arg.listpadding] or '0 0.25em')
:wikitext(processItem(listText, args[cfg.arg.nowrapitems]))
 
if index == 1 and args[cfg.arg.image] then
row
:tag('td')
:addClass('noviewer')
:addClass('navbox-image')
:addClass(args[cfg.arg.imageclass])
:css('width', '1px') -- Minimize width
:css('padding', '0 0 0 2px')
:cssText(args[cfg.arg.imagestyle])
:attr('rowspan', #listnumslistnums_size)
:tag('div')
:wikitext(processItem(args[cfg.arg.image]))
end
end
Line 267 ⟶ 274:
local function needsHorizontalLists(border)
if border == cfg.keyword.border_subgroup or
args[cfg.arg.tracking] == cfg.keyword.tracking_no then
return false
end
return not (cfg.list_classes[args[cfg.arg.listclass]] or cfg.list_classes[args[cfg.arg.bodyclass]])
end
 
Line 325 ⟶ 332:
local tbl = mw.html.create('table')
:addClass('nowraplinks')
:addClass(args[cfg.arg.bodyclass])
 
if args[cfg.arg.title] and (args[cfg.arg.state] ~= 'plain' and args[cfg.arg.state] ~= 'off') then
if args[cfg.arg.state] == 'collapsed' then args[cfg.arg.state] = 'mw-collapsed' end
tbl
:addClass('mw-collapsible')
:addClass(args[cfg.arg.state] or 'autocollapse')
end
 
Line 338 ⟶ 345:
tbl
:addClass('navbox-subgroup')
:cssText(args[cfg.arg.bodystyle])
:cssText(args[cfg.arg.style])
else -- regular navbox - bodystyle and style will be applied to the wrapper table
tbl
Line 346 ⟶ 353:
:css('color', 'inherit')
end
tbl:cssText(args[cfg.arg.innerstyle])
 
renderTitleRow(tbl)
renderAboveRow(tbl)
local listnums_size = #listnums
for i, listnum in ipairs(listnums) do
renderListRow(tbl, i, listnum, listnumslistnums_size)
end
renderBelowRow(tbl)
Line 370 ⟶ 378:
table.sort(listnums)
 
local border = mw.text.trim(args[cfg.arg.border] or args[1] or '')
if border == 'child' then
border = 'subgroup'
Line 385 ⟶ 393:
:node(tbl)
-- aria-labelledby title, otherwise above, otherwise lone group
if args[cfg.arg.title] or args[cfg.arg.above] or (args[cfg.arg.group1] and not args[cfg.arg.group2]) then
nav:attr('aria-labelledby', mw.uri.anchorEncode(args[cfg.arg.title] or args[cfg.arg.above] or args[cfg.arg.group1]))
else
nav:attr('aria-label', 'Navbox')
Line 402 ⟶ 410:
:attr('role', 'navigation')
:addClass('navbox')
:addClass(args[cfg.arg.navboxclass])
:cssText(args[cfg.arg.bodystyle])
:cssText(args[cfg.arg.style])
:css('padding', '3px')
:node(tbl)
-- aria-labelledby title, otherwise above, otherwise lone group
if args[cfg.arg.title] or args[cfg.arg.above] or (args[cfg.arg.group1] and not args[cfg.arg.group2]) then
nav:attr('aria-labelledby', mw.uri.anchorEncode(args[cfg.arg.title] or args[cfg.arg.above] or args[cfg.arg.group1]))
else
nav:attr('aria-label', 'Navbox')
Line 415 ⟶ 423:
end
 
if (args[cfg.arg.nocat] or 'false'):lower() == 'false' then
renderTrackingCategories(res, border)
end
Line 429 ⟶ 437:
-- Read the arguments in the order they'll be output in, to make references number in the right order.
local _
_ = args[cfg.arg.title]
_ = args[cfg.arg.above]
for i = 1, 20 do
_ = args["group"format(group_and_num, .. tostring(i)]
_ = args["list"format(list_and_num, .. tostring(i)]
end
_ = args[cfg.arg.below]
 
return p._navbox(args)