Content deleted Content added
test a child navbox feature |
debug |
||
Line 3:
local cfg = mw.loadData('Module:Navbox/configuration/sandbox')
local getArgs -- lazily initialized
local args▼
local format = string.format
local function
-- Read the arguments in the order they'll be output in, to make references▼
-- number in the right order.▼
_ = args[cfg.arg.title]▼
_ = args[cfg.arg.above]▼
-- Limit this to 20 as covering 'most' cases (that's a SWAG) and because▼
-- iterator approach won't work here▼
for i = 1, 20 do▼
_ = args[format(cfg.arg.group_and_num, i)]▼
_ = args[format(cfg.arg.list_and_num, i)]▼
end▼
_ = args[cfg.arg.below]▼
end▼
-- Return wikitext with markers replaced for odd/even striping.
-- Child (subgroup) navboxes are flagged with a category that is removed
Line 70 ⟶ 84:
end
local function has_navbar(args)
return args[cfg.arg.navbar] ~= cfg.keyword.navbar_off
and args[cfg.arg.navbar] ~= cfg.keyword.navbar_plain
Line 87 ⟶ 101:
end
local function renderNavBar(args, titleCell)
if has_navbar(args) then
local navbar = require('Module:Navbar')._navbar
titleCell:wikitext(navbar{
Line 101 ⟶ 115:
end
local function renderTitleRow(args, tbl)
if not args[cfg.arg.title] then return end
Line 118 ⟶ 132:
:attr('colspan', titleColspan)
renderNavBar(args, titleCell)
titleCell
Line 130 ⟶ 144:
end
local function getAboveBelowColspan(args)
local ret = 2
if args[cfg.arg.imageleft] then ret = ret + 1 end
Line 137 ⟶ 151:
end
local function renderAboveRow(args, tbl)
if not args[cfg.arg.above] then return end
Line 146 ⟶ 160:
:cssText(args[cfg.arg.basestyle])
:cssText(args[cfg.arg.abovestyle])
:attr('colspan', getAboveBelowColspan(args))
:tag('div')
-- id for aria-labelledby attribute, if no title
Line 153 ⟶ 167:
end
local function renderBelowRow(args, tbl)
if not args[cfg.arg.below] then return end
Line 162 ⟶ 176:
:cssText(args[cfg.arg.basestyle])
:cssText(args[cfg.arg.belowstyle])
:attr('colspan', getAboveBelowColspan(args))
:tag('div')
:wikitext(processItem(args[cfg.arg.below], args[cfg.arg.nowrapitems]))
end
local function renderListRow(args, tbl, index, listnum, listnums_size)
local row = tbl:tag('tr')
Line 238 ⟶ 252:
if listText == cfg.keyword.border_child then
local
local numChildArgs = 0
for k, v in pairs(args) do
if (#k > #list_and_num + 1) and (k:sub(1,#list_and_num+1) == (list_and_num .. '_')) then
numChildArgs = numChildArgs + 1
end
end
if
listText = p._navbox(
end
end
Line 282 ⟶ 298:
end
local function has_list_class(args, htmlclass)
local patterns = {
'^' .. htmlclass .. '$',
Line 303 ⟶ 319:
-- there are a lot of list classes in the wild, so we add their TemplateStyles
local function add_list_styles(args)
local frame = mw.getCurrentFrame()
local function add_list_templatestyles(htmlclass, templatestyles)
if has_list_class(args, htmlclass) then
return frame:extensionTag{
name = 'templatestyles', args = { src = templatestyles }
Line 321 ⟶ 337:
-- when that issue is fixed, we can actually use has_navbar not to emit the
-- tag here if we want
if has_navbar(args) and hlist_styles == '' then
hlist_styles = frame:extensionTag{
name = 'templatestyles', args = { src = cfg.hlist_templatestyles }
Line 337 ⟶ 353:
return false
end
return not has_list_class(args, cfg.pattern.hlist) and not has_list_class(args, cfg.pattern.plainlist)
end
Line 393 ⟶ 409:
end
local function renderMainTable(args, border, listnums)
local tbl = mw.html.create('table')
:addClass(cfg.class.nowraplinks)
Line 422 ⟶ 438:
tbl:cssText(args[cfg.arg.innerstyle])
renderTitleRow(args, tbl)
renderAboveRow(args, tbl)
local listnums_size = #listnums
for i, listnum in ipairs(listnums) do
renderListRow(args, tbl, i, listnum, listnums_size)
end
renderBelowRow(args, tbl)
return tbl
end
local function add_navbox_styles(args, hiding_templatestyles)
local frame = mw.getCurrentFrame()
-- This is a lambda so that it doesn't need the frame as a parameter
Line 457 ⟶ 473:
:addClass(cfg.class.navbox_styles)
:wikitext(
add_list_styles(args) .. -- see [hlist_note] applied to 'before base_templatestyles'
base_templatestyles ..
templatestyles ..
Line 482 ⟶ 498:
return templatestyles_markers
end
▲local function read_args(args)
▲ -- Read the arguments in the order they'll be output in, to make references
▲ -- number in the right order.
▲ _ = args[cfg.arg.title]
▲ _ = args[cfg.arg.above]
▲ -- Limit this to 20 as covering 'most' cases (that's a SWAG) and because
▲ -- iterator approach won't work here
▲ for i = 1, 20 do
▲ _ = args[format(cfg.arg.group_and_num, i)]
▲ _ = args[format(cfg.arg.list_and_num, i)]
▲ end
▲ _ = args[cfg.arg.below]
▲end
function p._navbox(navboxArgs)
local args = navboxArgs
local hiding_templatestyles = move_hiding_templatestyles(args)
local listnums = {}
Line 518:
-- render the main body of the navbox
local tbl = renderMainTable(args, border, listnums)
local res = mw.html.create()
Line 524:
if border == cfg.keyword.border_none then
res:node(add_navbox_styles(args, hiding_templatestyles))
local nav = res:tag('div')
:attr('role', 'navigation')
Line 550:
:wikitext('<div>')
else
res:node(add_navbox_styles(args, hiding_templatestyles))
local nav = res:tag('div')
:attr('role', 'navigation')
Line 574:
renderTrackingCategories(res, border)
end
return striped(args, tostring(res), border)
end
Line 581:
getArgs = require('Module:Arguments').getArgs
end
local args = getArgs(frame, {wrappers = {cfg.pattern.navbox}})
return p._navbox(args)
|