Module:Navbox: Difference between revisions
Created page with "-- -- This module implements {{Navbox}} -- local p = {} local navbar = require('Module:Navbar')._navbar local getArgs -- lazily initialized local args local border local listnums local ODD_EVEN_MARKER = '\127_ODDEVEN_\127' local RESTART_MARKER = '\127_ODDEVEN0_\127' local REGEX_MARKER = '\127_ODDEVEN(%d?)_\127' local function striped(wikitext) -- Return wikitext with markers replaced for odd/even striping. -- Child (subgroup) navboxes are flagged with a category th..." |
No edit summary |
||
| (9 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
require('strict') | |||
local p = {} | |||
-- | local cfg = mw.loadData('Module:Navbox/configuration') | ||
local inArray = require("Module:TableTools").inArray | |||
local getArgs -- lazily initialized | |||
local hiding_templatestyles = {} | |||
local | -- global passthrough variables | ||
local passthrough = { | |||
[cfg.arg.above]=true,[cfg.arg.aboveclass]=true,[cfg.arg.abovestyle]=true, | |||
[cfg.arg.basestyle]=true, | |||
[cfg.arg.below]=true,[cfg.arg.belowclass]=true,[cfg.arg.belowstyle]=true, | |||
[cfg.arg.bodyclass]=true, | |||
[cfg.arg.groupclass]=true, | |||
[cfg.arg.image]=true,[cfg.arg.imageclass]=true,[cfg.arg.imagestyle]=true, | |||
[cfg.arg.imageleft]=true,[cfg.arg.imageleftstyle]=true, | |||
[cfg.arg.listclass]=true, | |||
[cfg.arg.name]=true, | |||
[cfg.arg.navbar]=true, | |||
[cfg.arg.state]=true, | |||
[cfg.arg.title]=true,[cfg.arg.titleclass]=true,[cfg.arg.titlestyle]=true, | |||
argHash=true | |||
} | |||
local | -- helper functions | ||
local | local andnum = function(s, n) return string.format(cfg.arg[s .. '_and_num'], n) end | ||
local isblank = function(v) return (v or '') == '' end | |||
local | local function concatstrings(s) | ||
local r = table.concat(s, '') | |||
local | if r:match('^%s*$') then return nil end | ||
return r | |||
end | |||
local function | local function concatstyles(s) | ||
local r = '' | |||
for _, v in ipairs(s) do | |||
v = mw.text.trim(v, "%s;") | |||
if not isblank(v) then r = r .. v .. ';' end | |||
end | end | ||
local | if isblank(r) then return nil end | ||
return r | |||
end | |||
local function getSubgroup(args, listnum, listText, prefix) | |||
local subArgs = { | |||
[cfg.arg.border] = cfg.keyword.border_subgroup, | |||
[cfg.arg.navbar] = cfg.keyword.navbar_plain, | |||
argHash = 0 | |||
local | } | ||
local hasSubArgs = false | |||
local subgroups_and_num = prefix and {prefix} or cfg.arg.subgroups_and_num | |||
for k, v in pairs(args) do | |||
k = tostring(k) | |||
for _, w in ipairs(subgroups_and_num) do | |||
if | w = string.format(w, listnum) .. "_" | ||
if (#k > #w) and (k:sub(1, #w) == w) then | |||
subArgs[k:sub(#w + 1)] = v | |||
hasSubArgs = true | |||
subArgs.argHash = subArgs.argHash + (v and #v or 0) | |||
end | end | ||
end | end | ||
end | end | ||
return hasSubArgs and p._navbox(subArgs) or listText | |||
return ( | |||
end | end | ||
-- Main functions | |||
if | function p._navbox(args) | ||
if args.type == cfg.keyword.with_collapsible_groups then | |||
return p._withCollapsibleGroups(args) | |||
return | elseif args.type == cfg.keyword.with_columns then | ||
return p._withColumns(args) | |||
end | end | ||
if | |||
local | local function striped(wikitext, border) | ||
-- Return wikitext with markers replaced for odd/even striping. | |||
-- Child (subgroup) navboxes are flagged with a category that is removed | |||
if | -- by parent navboxes. The result is that the category shows all pages | ||
-- where a child navbox is not contained in a parent navbox. | |||
local orphanCat = cfg.category.orphan | |||
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 .. orphanCat | |||
end | |||
local first, second = cfg.class.navbox_odd_part, cfg.class.navbox_even_part | |||
if args[cfg.arg.evenodd] then | |||
if args[cfg.arg.evenodd] == cfg.keyword.evenodd_swap then | |||
first, second = second, first | |||
else | |||
first = args[cfg.arg.evenodd] | |||
second = first | |||
end | |||
end | |||
local changer | |||
if first == second then | |||
changer = first | |||
else | |||
local index = 0 | |||
changer = function (code) | |||
if code == '0' then | |||
-- Current occurrence is for a group before a nested table. | |||
-- Set it to first as a valid although pointless class. | |||
-- The next occurrence will be the first row after a title | |||
-- in a subgroup and will also be first. | |||
index = 0 | |||
return first | |||
end | |||
index = index + 1 | |||
return index % 2 == 1 and first or second | |||
end | end | ||
end | end | ||
local regex = orphanCat:gsub('([%[%]])', '%%%1') | |||
return (wikitext:gsub(regex, ''):gsub(cfg.marker.regex, changer)) -- () omits gsub count | |||
end | end | ||
if item:match('^[*:;#]') then | |||
return '\n' .. item ..'\n' | local function processItem(item, nowrapitems) | ||
if item:sub(1, 2) == '{|' then | |||
-- Applying nowrap to lines in a table does not make sense. | |||
-- Add newlines to compensate for trim of x in |parm=x in a template. | |||
return '\n' .. item .. '\n' | |||
end | |||
if nowrapitems == cfg.keyword.nowrapitems_yes then | |||
local lines = {} | |||
for line in (item .. '\n'):gmatch('([^\n]*)\n') do | |||
local prefix, content = line:match('^([*:;#]+)%s*(.*)') | |||
if prefix and not content:match(cfg.pattern.nowrap) then | |||
line = string.format(cfg.nowrap_item, prefix, content) | |||
end | |||
table.insert(lines, line) | |||
end | |||
item = table.concat(lines, '\n') | |||
end | |||
if item:match('^[*:;#]') then | |||
return '\n' .. item .. '\n' | |||
end | |||
return item | |||
end | end | ||
local function | local function has_navbar() | ||
return args[cfg.arg.navbar] ~= cfg.keyword.navbar_off | |||
and args[cfg.arg.navbar] ~= cfg.keyword.navbar_plain | |||
and ( | |||
args. | args[cfg.arg.name] | ||
or mw.getCurrentFrame():getParent():getTitle():gsub(cfg.pattern.sandbox, '') | |||
~= cfg.pattern.navbox | |||
) | |||
end | end | ||
-- extract text color from css, which is the only permitted inline CSS for the navbar | |||
local function extract_color(css_str) | |||
-- return nil because navbar takes its argument into mw.html which handles | |||
-- nil gracefully, removing the associated style attribute | |||
-- | return mw.ustring.match(';' .. css_str .. ';', '.*;%s*([Cc][Oo][Ll][Oo][Rr]%s*:%s*.-)%s*;') or nil | ||
local function | |||
end | end | ||
local titleCell = | local function renderNavBar(titleCell) | ||
if has_navbar() then | |||
local navbar = require('Module:Navbar')._navbar | |||
titleCell:wikitext(navbar{ | |||
[cfg.navbar.name] = args[cfg.arg.name], | |||
[cfg.navbar.mini] = 1, | |||
[cfg.navbar.fontstyle] = extract_color( | |||
(args[cfg.arg.basestyle] or '') .. ';' .. (args[cfg.arg.titlestyle] or '') | |||
) | |||
}) | |||
end | |||
end | end | ||
local | local function renderTitleRow(tbl) | ||
if not args[cfg.arg.title] then return end | |||
local titleRow = tbl:tag('tr') | |||
: | |||
local titleCell = titleRow:tag('th'):attr('scope', 'col') | |||
local titleColspan = 2 | |||
if args[cfg.arg.imageleft] then titleColspan = titleColspan + 1 end | |||
if args[cfg.arg.image] then titleColspan = titleColspan + 1 end | |||
end | |||
titleCell | |||
:cssText(args[cfg.arg.basestyle]) | |||
:cssText(args[cfg.arg.titlestyle]) | |||
:addClass(cfg.class.navbox_title) | |||
:attr('colspan', titleColspan) | |||
renderNavBar(titleCell) | |||
titleCell | |||
:tag('div') | |||
-- id for aria-labelledby attribute | |||
:attr('id', mw.uri.anchorEncode(args[cfg.arg.title]) .. args.argHash) | |||
: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 | |||
end | |||
local function | local function renderAboveRow(tbl) | ||
if not args[cfg.arg.above] then return end | |||
tbl:tag('tr') | |||
:tag('td') | |||
:addClass(cfg.class.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 | |||
end | :attr('id', (not args[cfg.arg.title]) and | ||
(mw.uri.anchorEncode(args[cfg.arg.above]) .. args.argHash) | |||
or nil) | |||
:wikitext(processItem(args[cfg.arg.above], args[cfg.arg.nowrapitems])) | |||
end | |||
local function renderBelowRow(tbl) | |||
if not args[cfg.arg.below] then return end | |||
local function | |||
tbl:tag('tr') | |||
:tag('td') | :tag('td') | ||
:addClass( | :addClass(cfg.class.navbox_abovebelow) | ||
:addClass(args. | :addClass(args[cfg.arg.belowclass]) | ||
: | :cssText(args[cfg.arg.basestyle]) | ||
:cssText(args[cfg.arg.belowstyle]) | |||
:cssText(args. | :attr('colspan', getAboveBelowColspan()) | ||
:attr(' | |||
:tag('div') | :tag('div') | ||
:wikitext(processItem(args. | :wikitext(processItem(args[cfg.arg.below], args[cfg.arg.nowrapitems])) | ||
end | end | ||
local function renderListRow(tbl, index, listnum, listnums_size) | |||
local | local row = tbl:tag('tr') | ||
if index == 1 and args[cfg.arg.imageleft] then | |||
if | row | ||
:tag('td') | |||
:addClass(cfg.class.noviewer) | |||
:addClass(cfg.class.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', listnums_size) | |||
:tag('div') | |||
:wikitext(processItem(args[cfg.arg.imageleft])) | |||
end | end | ||
groupCell | local group_and_num = andnum('group', listnum) | ||
:attr('scope', 'row') | local groupstyle_and_num = andnum('groupstyle', listnum) | ||
if args[group_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]) .. args.argHash) | |||
end | |||
groupCell | |||
:attr('scope', 'row') | |||
:addClass(cfg.class.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[groupstyle_and_num]) | |||
:wikitext(args[group_and_num]) | |||
end | |||
local listCell = row:tag('td') | |||
if args[group_and_num] then | |||
listCell | |||
:addClass(cfg.class.navbox_list_with_group) | |||
else | |||
listCell:attr('colspan', 2) | |||
end | |||
if not args[cfg.arg.groupwidth] then | |||
listCell:css('width', '100%') | |||
end | |||
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 list_and_num = andnum('list', listnum) | |||
local listText = inArray(cfg.keyword.subgroups, args[list_and_num]) | |||
and getSubgroup(args, listnum, args[list_and_num]) or args[list_and_num] | |||
local oddEven = cfg.marker.oddeven | |||
if listText:sub(1, 12) == '</div><table' then | |||
-- Assume list text is for a subgroup navbox so no automatic striping for this row. | |||
oddEven = listText:find(cfg.pattern.navbox_title) and cfg.marker.restart or cfg.class.navbox_odd_part | |||
end | |||
end | |||
-- | local liststyle_and_num = andnum('liststyle', listnum) | ||
local listclass_and_num = andnum('listclass', listnum) | |||
listCell | |||
:css('padding', '0') | |||
:cssText(args[cfg.arg.liststyle]) | |||
:cssText(rowstyle) | |||
:cssText(args[liststyle_and_num]) | |||
:addClass(cfg.arg.itemclass) -- pizza | |||
: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', | |||
(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(cfg.class.noviewer) | |||
:addClass(cfg.class.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', listnums_size) | |||
:tag('div') | |||
:wikitext(processItem(args[cfg.arg.image])) | |||
end | |||
end | end | ||
local function has_list_class(htmlclass) | |||
local function | |||
local patterns = { | local patterns = { | ||
'^' .. htmlclass .. '$', | '^' .. htmlclass .. '$', | ||
| Line 322: | Line 349: | ||
'%s' .. htmlclass .. '%s' | '%s' .. htmlclass .. '%s' | ||
} | } | ||
for arg, _ in pairs(args) do | |||
for _ | if type(arg) == 'string' and mw.ustring.find(arg, cfg.pattern.class) then | ||
for _, pattern in ipairs(patterns) do | for _, pattern in ipairs(patterns) do | ||
if mw.ustring.find(args[arg] or '', pattern) then | |||
return true | |||
end | |||
end | end | ||
end | end | ||
end | end | ||
if | return false | ||
return frame:extensionTag{ | end | ||
name = 'templatestyles', args = { src = | |||
-- there are a lot of list classes in the wild, so we add their TemplateStyles | |||
local function add_list_styles() | |||
local frame = mw.getCurrentFrame() | |||
local function add_list_templatestyles(htmlclass, templatestyles) | |||
if has_list_class(htmlclass) then | |||
return frame:extensionTag{ | |||
name = 'templatestyles', args = { src = templatestyles } | |||
} | |||
else | |||
return '' | |||
end | |||
end | |||
local hlist_styles = add_list_templatestyles('hlist', cfg.hlist_templatestyles) | |||
local plainlist_styles = add_list_templatestyles('plainlist', cfg.plainlist_templatestyles) | |||
-- a second workaround for [[phab:T303378]] | |||
-- when that issue is fixed, we can actually use has_navbar not to emit the | |||
-- tag here if we want | |||
if has_navbar() and hlist_styles == '' then | |||
hlist_styles = frame:extensionTag{ | |||
name = 'templatestyles', args = { src = cfg.hlist_templatestyles } | |||
} | } | ||
end | end | ||
-- hlist -> plainlist is best-effort to preserve old Common.css ordering. | |||
-- this ordering is not a guarantee because most navboxes will emit only | |||
-- one of these classes [hlist_note] | |||
return hlist_styles .. plainlist_styles | |||
end | end | ||
local | 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 has_list_class(cfg.pattern.hlist) and not has_list_class(cfg.pattern.plainlist) | |||
end | end | ||
local function hasBackgroundColors() | local function hasBackgroundColors() | ||
for _, key in ipairs({cfg.arg.titlestyle, cfg.arg.groupstyle, | |||
cfg.arg.basestyle, cfg.arg.abovestyle, cfg.arg.belowstyle}) do | |||
if tostring(args[key]):find('background', 1, true) then | |||
return true | |||
end | |||
end | end | ||
return false | |||
end | end | ||
local function hasBorders() | local function hasBorders() | ||
for _, key in ipairs({cfg.arg.groupstyle, cfg.arg.basestyle, | |||
cfg.arg.abovestyle, cfg.arg.belowstyle}) do | |||
if tostring(args[key]):find('border', 1, true) then | |||
return true | |||
end | |||
end | end | ||
return false | |||
end | end | ||
local function isIllegible() | local function isIllegible() | ||
local styleratio = require('Module:Color contrast')._styleratio | |||
for key, style in pairs(args) do | |||
end | if tostring(key):match(cfg.pattern.style) then | ||
if styleratio{mw.text.unstripNoWiki(style)} < 4.5 then | |||
return true | |||
end | |||
end | |||
end | |||
return false | |||
end | |||
local function getTrackingCategories() | local function getTrackingCategories(border) | ||
local cats = {} | |||
if needsHorizontalLists(border) then table.insert(cats, cfg.category.horizontal_lists) end | |||
if hasBackgroundColors() then table.insert(cats, cfg.category.background_colors) end | |||
if isIllegible() then table.insert(cats, cfg.category.illegible) end | |||
if hasBorders() then table.insert(cats, cfg.category.borders) end | |||
return cats | |||
end | end | ||
local function renderTrackingCategories(builder) | local function renderTrackingCategories(builder, border) | ||
local title = mw.title.getCurrentTitle() | |||
if title.namespace ~= 10 then return end -- not in template space | |||
local subpage = title.subpageText | |||
if subpage == cfg.keyword.subpage_doc or subpage == cfg.keyword.subpage_sandbox | |||
or subpage == cfg.keyword.subpage_testcases then return end | |||
for _, cat in ipairs(getTrackingCategories(border)) do | |||
builder:wikitext('[[Category:' .. cat .. ']]') | |||
end | |||
end | end | ||
local function renderMainTable(border, listnums) | |||
local tbl = mw.html.create('table') | |||
:addClass(cfg.class.nowraplinks) | |||
local function renderMainTable() | :addClass(args[cfg.arg.bodyclass]) | ||
:addClass(' | local state = args[cfg.arg.state] | ||
:addClass(args. | if args[cfg.arg.title] and state ~= cfg.keyword.state_plain and state ~= cfg.keyword.state_off then | ||
if state == cfg.keyword.state_collapsed then | |||
state = cfg.class.collapsed | |||
end | |||
tbl | |||
:addClass(cfg.class.collapsible) | |||
:addClass(state or cfg.class.autocollapse) | |||
end | |||
tbl:css('border-spacing', 0) | |||
if border == cfg.keyword.border_subgroup or border == cfg.keyword.border_none then | |||
tbl | |||
:addClass(cfg.class.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 | |||
:addClass(cfg.class.navbox_inner) | |||
:css('background', 'transparent') | |||
: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, listnums_size) | |||
end | |||
renderBelowRow(tbl) | |||
return tbl | |||
tbl | |||
end | end | ||
local function add_navbox_styles(hiding_templatestyles) | |||
local frame = mw.getCurrentFrame() | |||
-- This is a lambda so that it doesn't need the frame as a parameter | |||
local function add_user_styles(templatestyles) | |||
if not isblank(templatestyles) then | |||
return frame:extensionTag{ | |||
name = 'templatestyles', args = { src = templatestyles } | |||
} | |||
:addClass( | end | ||
: | return '' | ||
: | end | ||
-- get templatestyles. load base from config so that Lua only needs to do | |||
-- the work once of parser tag expansion | |||
local base_templatestyles = cfg.templatestyles | |||
local templatestyles = add_user_styles(args[cfg.arg.templatestyles]) | |||
local child_templatestyles = add_user_styles(args[cfg.arg.child_templatestyles]) | |||
-- The 'navbox-styles' div exists to wrap the styles to work around T200206 | |||
-- more elegantly. Instead of combinatorial rules, this ends up being linear | |||
-- number of CSS rules. | |||
return mw.html.create('div') | |||
:addClass(cfg.class.navbox_styles) | |||
:wikitext( | |||
add_list_styles() .. -- see [hlist_note] applied to 'before base_templatestyles' | |||
base_templatestyles .. | |||
templatestyles .. | |||
child_templatestyles .. | |||
table.concat(hiding_templatestyles) | |||
) | |||
:done() | |||
end | end | ||
-- work around [[phab:T303378]] | |||
-- for each arg: find all the templatestyles strip markers, insert them into a | |||
for | -- table. then remove all templatestyles markers from the arg | ||
local strip_marker_pattern = '(\127[^\127]*UNIQ%-%-templatestyles%-%x+%-QINU[^\127]*\127)' | |||
local argHash = 0 | |||
for k, arg in pairs(args) do | |||
if type(arg) == 'string' then | |||
for marker in string.gfind(arg, strip_marker_pattern) do | |||
table.insert(hiding_templatestyles, marker) | |||
end | |||
argHash = argHash + #arg | |||
args[k] = string.gsub(arg, strip_marker_pattern, '') | |||
end | |||
end | end | ||
if not args.argHash then args.argHash = argHash end | |||
end | |||
local listnums = {} | |||
listnums = {} | |||
for k, _ in pairs(args) do | for k, _ in pairs(args) do | ||
if type(k) == 'string' then | if type(k) == 'string' then | ||
local listnum = k:match(' | local listnum = k:match(cfg.pattern.listnum) | ||
if listnum and args[andnum('list', tonumber(listnum))] then | |||
table.insert(listnums, tonumber(listnum)) | |||
end | |||
end | end | ||
end | end | ||
table.sort(listnums) | table.sort(listnums) | ||
border = mw.text.trim(args.border or args[1] or '') | local border = mw.text.trim(args[cfg.arg.border] or args[1] or '') | ||
if border == | if border == cfg.keyword.border_child then | ||
border = | border = cfg.keyword.border_subgroup | ||
end | end | ||
-- render the main body of the navbox | -- render the main body of the navbox | ||
local tbl = renderMainTable() | local tbl = renderMainTable(border, listnums) | ||
local res = mw.html.create() | local res = mw.html.create() | ||
-- render the appropriate wrapper for the navbox, based on the border param | |||
if border == cfg.keyword.border_none then | |||
res:node(add_navbox_styles(hiding_templatestyles)) | |||
-- render the appropriate wrapper | |||
if border == | |||
local nav = res:tag('div') | local nav = res:tag('div') | ||
:attr('role', 'navigation') | :attr('role', 'navigation') | ||
:node(tbl) | :node(tbl) | ||
-- aria-labelledby title, otherwise above, otherwise lone group | -- aria-labelledby title, otherwise above, otherwise lone group | ||
if args.title or args.above or (args.group1 and not args.group2) then | if args[cfg.arg.title] or args[cfg.arg.above] or (args[cfg.arg.group1] | ||
nav:attr('aria-labelledby', mw.uri.anchorEncode(args.title or args.above or args.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] | |||
) .. args.argHash | |||
) | |||
else | else | ||
nav:attr('aria-label', | nav:attr('aria-label', cfg.aria_label) | ||
end | end | ||
elseif border == | elseif border == cfg.keyword.border_subgroup then | ||
-- We assume that this navbox is being rendered in a list cell of a | -- 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. | -- parent navbox, and is therefore inside a div with padding:0em 0.25em. | ||
| Line 496: | Line 590: | ||
res | res | ||
:wikitext('</div>') | :wikitext('</div>') | ||
:node(tbl) | :node(tbl) | ||
:wikitext('<div>') | :wikitext('<div>') | ||
else | else | ||
res:node(add_navbox_styles(hiding_templatestyles)) | |||
local nav = res:tag('div') | local nav = res:tag('div') | ||
:attr('role', 'navigation') | :attr('role', 'navigation') | ||
:addClass( | :addClass(cfg.class.navbox) | ||
:addClass(args.navboxclass) | :addClass(args[cfg.arg.navboxclass]) | ||
:cssText(args.bodystyle) | :addClass('foo') | ||
:cssText(args.style) | :cssText(args[cfg.arg.bodystyle]) | ||
:cssText(args[cfg.arg.style]) | |||
:css('padding', '3px') | :css('padding', '3px') | ||
:node(tbl) | :node(tbl) | ||
-- aria-labelledby title, otherwise above, otherwise lone group | -- aria-labelledby title, otherwise above, otherwise lone group | ||
if args.title or args.above or (args.group1 and not args.group2) then | if args[cfg.arg.title] or args[cfg.arg.above] | ||
nav:attr('aria-labelledby', mw.uri.anchorEncode(args.title or args.above or args.group1)) | 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] | |||
) .. args.argHash | |||
) | |||
else | else | ||
nav:attr('aria-label', ' | nav:attr('aria-label', cfg.aria_label .. args.argHash) | ||
end | |||
end | |||
if (args[cfg.arg.nocat] or cfg.keyword.nocat_false):lower() == cfg.keyword.nocat_false then | |||
renderTrackingCategories(res, border) | |||
end | |||
return striped(tostring(res), border) | |||
end --p._navbox | |||
function p._withCollapsibleGroups(pargs) | |||
-- table for args passed to navbox | |||
local targs = {} | |||
-- process args | |||
local passthroughLocal = { | |||
[cfg.arg.bodystyle] = true, | |||
[cfg.arg.border] = true, | |||
[cfg.arg.style] = true, | |||
} | |||
for k,v in pairs(pargs) do | |||
if k and type(k) == 'string' then | |||
if passthrough[k] or passthroughLocal[k] then | |||
targs[k] = v | |||
elseif (k:match(cfg.pattern.num)) then | |||
local n = k:match(cfg.pattern.num) | |||
local list_and_num = andnum('list', n) | |||
if ((k:match(cfg.pattern.listnum) or k:match(cfg.pattern.contentnum)) | |||
and targs[list_and_num] == nil | |||
and pargs[andnum('group', n)] == nil | |||
and pargs[andnum('sect', n)] == nil | |||
and pargs[andnum('section', n)] == nil) then | |||
targs[list_and_num] = concatstrings({ | |||
pargs[list_and_num] or '', | |||
pargs[andnum('content', n)] or '' | |||
}) | |||
if (targs[list_and_num] and inArray(cfg.keyword.subgroups, targs[list_and_num])) then | |||
targs[list_and_num] = getSubgroup(pargs, n, targs[list_and_num]) | |||
end | |||
elseif ((k:match(cfg.pattern.groupnum) or k:match(cfg.pattern.sectnum) or k:match(cfg.pattern.sectionnum)) | |||
and targs[list_and_num] == nil) then | |||
local titlestyle = concatstyles({ | |||
pargs[cfg.arg.groupstyle] or '', | |||
pargs[cfg.arg.secttitlestyle] or '', | |||
pargs[andnum('groupstyle', n)] or '', | |||
pargs[andnum('sectiontitlestyle', n)] or '' | |||
}) | |||
local liststyle = concatstyles({ | |||
pargs[cfg.arg.liststyle] or '', | |||
pargs[cfg.arg.contentstyle] or '', | |||
pargs[andnum('liststyle', n)] or '', | |||
pargs[andnum('contentstyle', n)] or '' | |||
}) | |||
local title = concatstrings({ | |||
pargs[andnum('group', n)] or '', | |||
pargs[andnum('sect', n)] or '', | |||
pargs[andnum('section', n)] or '' | |||
}) | |||
local list = concatstrings({ | |||
pargs[list_and_num] or '', | |||
pargs[andnum('content', n)] or '' | |||
}) | |||
if list and inArray(cfg.keyword.subgroups, list) then | |||
list = getSubgroup(pargs, n, list) | |||
end | |||
local abbr_and_num = andnum('abbr', n) | |||
local state = (pargs[abbr_and_num] and pargs[abbr_and_num] == pargs[cfg.arg.selected]) | |||
and cfg.keyword.state_uncollapsed | |||
or (pargs[andnum('state', n)] or cfg.keyword.state_collapsed) | |||
targs[list_and_num] =p._navbox({ | |||
cfg.keyword.border_child, | |||
[cfg.arg.navbar] = cfg.keyword.navbar_plain, | |||
[cfg.arg.state] = state, | |||
[cfg.arg.basestyle] = pargs[cfg.arg.basestyle], | |||
[cfg.arg.title] = title, | |||
[cfg.arg.titlestyle] = titlestyle, | |||
[andnum('list', 1)] = list, | |||
[cfg.arg.liststyle] = liststyle, | |||
[cfg.arg.listclass] = pargs[andnum('listclass', n)], | |||
[cfg.arg.image] = pargs[andnum('image', n)], | |||
[cfg.arg.imageleft] = pargs[andnum('imageleft', n)], | |||
[cfg.arg.listpadding] = pargs[cfg.arg.listpadding], | |||
argHash = pargs.argHash | |||
}) | |||
end | |||
end | |||
end | |||
end | |||
-- ordering of style and bodystyle | |||
targs[cfg.arg.style] = concatstyles({targs[cfg.arg.style] or '', targs[cfg.arg.bodystyle] or ''}) | |||
targs[cfg.arg.bodystyle] = nil | |||
-- child or subgroup | |||
if targs[cfg.arg.border] == nil then targs[cfg.arg.border] = pargs[1] end | |||
return p._navbox(targs) | |||
end --p._withCollapsibleGroups | |||
function p._withColumns(pargs) | |||
-- table for args passed to navbox | |||
local targs = {} | |||
-- tables of column numbers | |||
local colheadernums = {} | |||
local colnums = {} | |||
local colfooternums = {} | |||
-- process args | |||
local passthroughLocal = { | |||
[cfg.arg.evenstyle]=true, | |||
[cfg.arg.groupstyle]=true, | |||
[cfg.arg.liststyle]=true, | |||
[cfg.arg.oddstyle]=true, | |||
[cfg.arg.state]=true, | |||
} | |||
for k,v in pairs(pargs) do | |||
if passthrough[k] or passthroughLocal[k] then | |||
targs[k] = v | |||
elseif type(k) == 'string' then | |||
if k:match(cfg.pattern.listnum) then | |||
local n = k:match(cfg.pattern.listnum) | |||
targs[andnum('liststyle', n + 2)] = pargs[andnum('liststyle', n)] | |||
targs[andnum('group', n + 2)] = pargs[andnum('group', n)] | |||
targs[andnum('groupstyle', n + 2)] = pargs[andnum('groupstyle', n)] | |||
if v and inArray(cfg.keyword.subgroups, v) then | |||
targs[andnum('list', n + 2)] = getSubgroup(pargs, n, v) | |||
else | |||
targs[andnum('list', n + 2)] = v | |||
end | |||
elseif (k:match(cfg.pattern.colheadernum) and v ~= '') then | |||
table.insert(colheadernums, tonumber(k:match(cfg.pattern.colheadernum))) | |||
elseif (k:match(cfg.pattern.colnum) and v ~= '') then | |||
table.insert(colnums, tonumber(k:match(cfg.pattern.colnum))) | |||
elseif (k:match(cfg.pattern.colfooternum) and v ~= '') then | |||
table.insert(colfooternums, tonumber(k:match(cfg.pattern.colfooternum))) | |||
end | |||
end | |||
end | |||
table.sort(colheadernums) | |||
table.sort(colnums) | |||
table.sort(colfooternums) | |||
-- HTML table for list1 | |||
local coltable = mw.html.create( 'table' ):addClass('navbox-columns-table') | |||
local row, col | |||
local tablestyle = ( (#colheadernums > 0) or (not isblank(pargs[cfg.arg.fullwidth])) ) | |||
and 'width:100%' | |||
or 'width:auto; margin-left:auto; margin-right:auto' | |||
coltable:cssText(concatstyles({ | |||
'border-spacing: 0px; text-align:left', | |||
tablestyle, | |||
pargs[cfg.arg.coltablestyle] or '' | |||
})) | |||
--- Header row --- | |||
if (#colheadernums > 0) then | |||
row = coltable:tag('tr') | |||
for k, n in ipairs(colheadernums) do | |||
col = row:tag('td'):addClass('navbox-abovebelow') | |||
col:cssText(concatstyles({ | |||
(k > 1) and 'border-left:2px solid #fdfdfd' or '', | |||
'font-weight:bold', | |||
pargs[cfg.arg.colheaderstyle] or '', | |||
pargs[andnum('colheaderstyle', n)] or '' | |||
})) | |||
col:attr('colspan', tonumber(pargs[andnum('colheadercolspan', n)])) | |||
col:wikitext(pargs[andnum('colheader', n)]) | |||
end | |||
end | |||
--- Main columns --- | |||
row = coltable:tag('tr'):css('vertical-align', 'top') | |||
for k, n in ipairs(colnums) do | |||
if k == 1 and isblank(pargs[andnum('colheader', 1)]) | |||
and isblank(pargs[andnum('colfooter', 1)]) | |||
and isblank(pargs[cfg.arg.fullwidth]) then | |||
local nopad = inArray( | |||
{'off', '0', '0em', '0px'}, | |||
mw.ustring.gsub(pargs[cfg.arg.padding] or '', '[;%%]', '')) | |||
if not nopad then | |||
row:tag('td'):wikitext(' ') | |||
:css('width', (pargs[cfg.arg.padding] or '5em')) | |||
end | |||
end | |||
col = row:tag('td'):addClass('navbox-list') | |||
col:cssText(concatstyles({ | |||
(k > 1) and 'border-left:2px solid #fdfdfd' or '', | |||
'padding:0px', | |||
pargs[cfg.arg.colstyle] or '', | |||
((n%2 == 0) and pargs[cfg.arg.evencolstyle] or pargs[cfg.arg.oddcolstyle]) or '', | |||
pargs[andnum('colstyle', n)] or '', | |||
'width:' .. (pargs[andnum('colwidth', n)] or pargs[cfg.arg.colwidth] or '10em') | |||
})) | |||
local wt = pargs[andnum('col', n)] | |||
if wt and inArray(cfg.keyword.subgroups, wt) then | |||
wt = getSubgroup(pargs, n, wt, cfg.arg.col_and_num) | |||
end | end | ||
col:tag('div'):newline():wikitext(wt):newline() | |||
end | end | ||
if ( | --- Footer row --- | ||
if (#colfooternums > 0) then | |||
row = coltable:tag('tr') | |||
for k, n in ipairs(colfooternums) do | |||
col = row:tag('td'):addClass('navbox-abovebelow') | |||
col:cssText(concatstyles({ | |||
(k > 1) and 'border-left:2px solid #fdfdfd' or '', | |||
'font-weight:bold', | |||
pargs[cfg.arg.colfooterstyle] or '', | |||
pargs[andnum('colfooterstyle', n)] or '' | |||
})) | |||
col:attr('colspan', tonumber(pargs[andnum('colfootercolspan', n)])) | |||
col:wikitext(pargs[andnum('colfooter', n)]) | |||
end | |||
end | end | ||
return | -- assign table to list1 | ||
end | targs[andnum('list', 1)] = tostring(coltable) | ||
if isblank(pargs[andnum('colheader', 1)]) | |||
and isblank(pargs[andnum('col', 1)]) | |||
and isblank(pargs[andnum('colfooter', 1)]) then | |||
targs[andnum('list', 1)] = targs[andnum('list', 1)] .. | |||
cfg.category.without_first_col | |||
end | |||
-- Other parameters | |||
targs[cfg.arg.border] = pargs[cfg.arg.border] or pargs[1] | |||
targs[cfg.arg.evenodd] = (not isblank(pargs[cfg.arg.evenodd])) and pargs[cfg.arg.evenodd] or nil | |||
targs[cfg.arg.list1padding] = '0px' | |||
targs[andnum('liststyle', 1)] = 'background:transparent;color:inherit;' | |||
targs[cfg.arg.style] = concatstyles({pargs[cfg.arg.style], pargs[cfg.arg.bodystyle]}) | |||
targs[cfg.arg.tracking] = 'no' | |||
return p._navbox(targs) | |||
end --p._withColumns | |||
-- Template entry points | |||
function p.navbox (frame, boxtype) | |||
local function readArgs(args, prefix) | |||
-- Read the arguments in the order they'll be output in, to make references | |||
-- number in the right order. | |||
local _ = 0 | |||
_ = _ + (args[prefix .. cfg.arg.title] and #args[prefix .. cfg.arg.title] or 0) | |||
_ = _ + (args[prefix .. cfg.arg.above] and #args[prefix .. cfg.arg.above] or 0) | |||
-- 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[prefix .. andnum('group', i)] and #args[prefix .. andnum('group', i)] or 0) | |||
if inArray(cfg.keyword.subgroups, args[prefix .. andnum('list', i)]) then | |||
for _, v in ipairs(cfg.arg.subgroups_and_num) do | |||
readArgs(args, prefix .. string.format(v, i) .. "_") | |||
end | |||
readArgs(args, prefix .. andnum('col', i) .. "_") | |||
end | |||
end | |||
_ = _ + (args[prefix .. cfg.arg.below] and #args[prefix .. cfg.arg.below] or 0) | |||
return _ | |||
end | |||
if not getArgs then | if not getArgs then | ||
getArgs = require('Module:Arguments').getArgs | getArgs = require('Module:Arguments').getArgs | ||
end | end | ||
args = getArgs(frame, {wrappers = {' | local args = getArgs(frame, {wrappers = {cfg.pattern[boxtype or 'navbox']}}) | ||
args.argHash = readArgs(args, "") | |||
args.type = args.type or cfg.keyword[boxtype] | |||
return p['_navbox'](args) | |||
end | end | ||
p[cfg.keyword.with_collapsible_groups] = function (frame) | |||
return p.navbox(frame, 'with_collapsible_groups') | |||
end | |||
return p. | p[cfg.keyword.with_columns] = function (frame) | ||
return p.navbox(frame, 'with_columns') | |||
end | end | ||
return p | return p | ||
Latest revision as of 18:26, 6 August 2025
Template:For Template:Documentation subpage Template:High use Template:Template display Template:Lua Template:Navbox suite Template:Lua sidebar
This template allows a navigational template to be set up relatively quickly by supplying it with one or more lists of links. It comes equipped with default styles that should work for most navigational templates. Changing the default styles is possible, but not recommended. Using this template, or one of its "Navbox suite" sister templates, is highly recommended for standardization of navigational templates, and for ease of use.
Usage
[edit source]Please remove the parameters that are left blank.
{{Navbox
| name = {{subst:PAGENAME}}{{subst:void|Don't change anything on this line. It will change itself when you save.}}
| title =
| listclass = hlist
| state = {{{state|}}}
| above =
| image =
| group1 =
| list1 =
| group2 =
| list2 =
| group3 =
| list3 =
<!-- ... -->
| below =
}}<noinclude>
{{navbox documentation}}
<!-- add a navbox category here -->
</noinclude>
Parameter list
[edit source]{{Template:PAGENAMETDOC
| name = Navbox/doc
| state = uncollapsed
| title = {{{title}}}
| above = {{{above}}}
| image = {{{image}}}
| group1 = {{{group1}}}
| list1 = {{{list1}}}
| group2 = {{{group2}}}
| list2 = {{{list2}}}
| group3 = {{{group3}}}
| list3 = {{{list3}}}
| group4 = {{{group4}}}
| list4 = {{{list4}}}
| below = {{{below}}}
See alternate navbox formats under: Layout of table
}}
The navbox uses lowercase parameter names, as shown in the box (above). The required name and title will create a one-line box if other parameters are omitted.
Notice "group1" (etc.) is optional, as are sections named "above/below". Template:Clear The basic and most common parameters are as follows (see below for the full list):
name– the name (Wikipedia location) of the template.title– text in the title bar, such as: [[Widget stuff]].listclass– a CSS class for the list cells, usuallyhlistfor horizontal lists. Alternatively, use bodyclass for the whole box.state– controls when a navbox is expanded or collapsed.titlestyle– a CSS style for the title-bar, such as:background: gray;groupstyle– a CSS style for the group-cells, such as:background: #eee;above– text to appear above the group/list section (could be a list of overall wikilinks).image– an optional right-side image, coded as the whole image, such as:[[File:XX.jpg|80px|alt=Alternate text]]- Note that most of such images don't comply with MOS:DECOR and should be removed at sight.
imageleft– an optional left-side image (code the same as the "image" parameter).groupn– the left-side text before list-n (if group-n omitted, list-n extends to the left edge of the box, and defaults totext-align:centerstyling).listn– text listing wikilinks using a wikilist format.below– optional text to appear below the group/list section.
Parameter descriptions
[edit source]The following is a complete list of parameters for using Template:Tl. In most cases, the only required parameters are name, title, and list1, though child navboxes do not even require those to be set.
Template:Tl shares numerous common parameter names with its sister templates, Template:Tl and Template:Tl, for consistency and ease of use. Parameters marked with an asterisk (*) are common to all three master templates.
Setup parameters
[edit source]- name*
- The name of the template, which is needed for the "V • T • E" ("View • Talk • Edit") links to work properly on all pages where the template is used. You can enter Template:Tlc for this value as a shortcut. The name parameter is only mandatory if a
titleis specified, and theborderparameter is not set, and thenavbarparameter is not used to disable the navbar. - state* [
autocollapse, collapsed, expanded, plain, off]Template:Anchor -
- Defaults to
autocollapse. A navbox withautocollapsewill start out collapsed if there are two or more collapsible elements on the same page. Otherwise, the navbox will be expanded. For the technically minded, see MediaWiki:Common.js (search for "autocollapse"). - If set to
collapsed, the navbox will always start out in a collapsed state. - If set to
expanded, the navbox will always start out in an expanded state. - If set to
plain, the navbox will always be expanded with no [hide] link on the right, and the title will remain centered (by using padding to offset the V • T • E links). - If set to
off, the navbox will always be expanded with no [hide] link on the right, but no padding will be used to keep the title centered. This is for advanced use only; the "plain" option should suffice for most applications where the [show]/[hide] button needs to be hidden.
- Defaults to
- To show the box when standalone (non-included) but then auto-hide contents when in an article, put "expanded" inside Template:Xtag tags. This setting will force the box to be visible when standalone (even when followed by other boxes), displaying "[hide]", but then it will auto-collapse the box when stacked inside an article:
- Often times, editors will want a default initial state for a navbox, which may be overridden in an article. Here is the trick to do this:
- In your intermediate template, create a parameter also named "state" as a pass-through like this:
- The Template:Tag
|will make the template expanded when viewing the template page by itself.- Example 1: Template:Tl with autocollapse as the default initial state. Catalan peseta transcludes it and has only one navbox; thus, the peso navbox shows. Chilean peso has more than two navboxes; thus, the peso navbox collapses.
- Example 2: Template:Tl with expanded as the default initial state, as such:
- Template:Para All transcluding articles show the content by default, unless there is a hypothetical article that specifies Template:Tlc when transcluding.
- Example 3: Template:Tl with collapsed as the default initial state, as such:
- Template:Para All transcluding articles will show the template as collapsed by default, but the template will still be uncollapsed when displayed on its own page.
- The template Template:Tl explains how to use the
stateparameter. It can be added to a Template:Xtag section after the template definition or to the instructions on the Template:Tl.
- navbar*
- If set to
plain, the V • T • E links on the left side of the titlebar will not be displayed, and padding will be automatically used to keep the title centered. Useoffto remove the V • T • E links, but not apply padding (this is for advanced use only; the "plain" option should suffice for most applications where a navbar is not desired). It is highly recommended that one not hide the navbar, in order to make it easier for users to edit the template, and to keep a standard style across pages. - border*
- See later section on using navboxes within one another for examples and a more complete description. If set to
childorsubgroup, then the navbox can be used as a borderless child that fits snugly in another navbox. The border is hidden and there is no padding on the sides of the table, so it fits into the list area of its parent navbox. If set tonone, then the border is hidden and padding is removed, and the navbox may be used as a child of another container (do not use thenoneoption inside of another navbox; similarly, only use thechild/subgroupoption inside of another navbox). If set to anything else (default), then a regular navbox is displayed with a 1px border. An alternate way to specify the border to be a subgroup style is like this (i.e. use the first unnamed parameter instead of the named border parameter): - Template:Tlx
Cells
[edit source]- title*
- Text that appears centered in the top row of the table. It is usually the template's topic, i.e. a succinct description of the body contents. This should be a single line, but if a second line is needed, use
{{-}}to ensure proper centering. This parameter is technically not mandatory, but using Template:Tl is rather pointless without a title. - above*
- A full-width cell displayed between the titlebar and first group/list, i.e. above the template's body (groups, lists and image). In a template without an image, above behaves in the same way as the list1 parameter without the group1 parameter.
- groupn*
- (i.e. group1, group2, etc.) If specified, text appears in a header cell displayed to the left of listn. If omitted, listn uses the full width of the table.
- listn*
- (i.e. list1, list2, etc.) The body of the template, usually a list of links. Format is inline, although the text can be entered on separate lines if the entire list is enclosed within Template:Tag. At least one list parameter is required; each additional list is displayed in a separate row of the table. Each listn may be preceded by a corresponding groupn parameter, if provided (see below).
- Entries should be separated using a newline and an asterisk (*). If instead two asterisks are used, it provides nesting within the previous entry by enclosing the entry with brackets. Increasing the number of asterisks used increases the number of brackets around entries.
- Set to the keyword
childorsubgroupto denote that the list is using the inline #Child navboxes (does not work with Template:Tl or Template:Tl). - image*
- An image to be displayed in a cell below the title and to the right of the body (the groups/lists). For the image to display properly, the list1 parameter must be specified. The image parameter accepts standard wikicode for displaying an image, e.g.: Template:Elc nb: including Template:Para will produce the usual left margin to provide separation from the list items and zebra striping.
- Note that most of such images don't comply with MOS:DECOR and should be removed at sight. A rare example of a correct usage would be this one: a map shows (in green) the location of a region within the state of Kazakhstan, and this is consistently implemented for all state's regions.
- imageleft*
- An image to be displayed in a cell below the title and to the left of the body (lists). For the image to display properly, the list1 parameter must be specified and no groups can be specified. It accepts the same sort of parameter that image accepts.
- below*
- A full-width cell displayed below the template's body (groups, lists and image). In a template without an image, below behaves in the same way as the template's final listn parameter without a groupn parameter. For an example of the below parameter in use, see Template:Oldid version of Template:Tl. Template:Tl is often used for non-article links, for example
Template:Tlf Template:Elc.
Style parameters
[edit source]Styles are generally advised against, to maintain consistency among templates and pages in Wikipedia; but the option to modify styles is given.
- bodystyle*
- Specifies CSS styles to apply to the template body. This option should be used sparingly as it can lead to visual inconsistencies. Examples:
bodystyle = background: #nnnnnn;bodystyle = width: N [em/%/px or width: auto];bodystyle = float: [left/right/none];bodystyle = clear: [right/left/both/none];
- basestyle*
- CSS styles to apply to the title, above, below, and group cells all at once. The styles are not applied to list cells. This is convenient for easily changing the basic color of the navbox without having to repeat the style specifications for the different parts of the navbox. Example:
basestyle = background: lightskyblue; - titlestyle*
- CSS styles to apply to title, most often the titlebar's background color:
titlestyle = background: #nnnnnn;titlestyle = background: name;titlestyle = background: none;— for no background color
- groupstyle*
- CSS styles to apply to the groupN cells. This option overrides any styles that are applied to the entire table. Examples:
groupstyle = background: #nnnnnn;groupstyle = text-align: [left/center/right];groupstyle = vertical-align: [top/middle/bottom];
- groupnstyle*
- CSS styles to apply to a specific group, in addition to any styles specified by the groupstyle parameter. This parameter should only be used when absolutely necessary in order to maintain standardization and simplicity. Example:
group3style = background: red; color: white; - groupwidth
- A number and unit specifying a uniform width for the group cells, in cases where little content in the list cells may cause group cells to be too wide. No default. However, may be overridden by the group(n)style parameter. Example:
groupwidth = 9em - liststyle*
- CSS styles to apply to all lists. Overruled by the oddstyle and evenstyle parameters (if specified) hereafter. When using backgound colors in the navbox, see the note hereafter.
- listnstyle*
- CSS styles to apply to a specific list, in addition to any styles specified by the liststyle parameter. This parameter should only be used when absolutely necessary in order to maintain standardization and simplicity. Example:
list5style = background: #ddddff; - listpadding*
- A number and unit specifying the padding in each list cell. The list cells come equipped with a default padding of 0.25em on the left and right, and 0 on the top and bottom. Due to complex technical reasons, simply setting "liststyle = padding: 0.5em;" (or any other padding setting) will not work. Examples:
listpadding = 0.5em 0;(sets 0.5em padding for the top/bottom, and 0 padding for the left/right.)listpadding = 0;(removes all list padding.)
- oddstyle
- evenstyle
- Applies to odd/even list numbers. Overrules styles defined by liststyle. The default behavior is to add striped colors (white and gray) to odd/even rows, respectively, in order to improve readability. These should not be changed except in extraordinary circumstances.
- evenodd
[swap, even, odd, off] - If set to
swap, then the automatic striping of even and odd rows is reversed. Normally, even rows get a light gray background for striping; when this parameter is used, the odd rows receive the gray striping instead of the even rows. Setting toevenoroddsets all rows to have that striping color. Setting tooffdisables automatic row striping. - abovestyle*
- belowstyle*
- CSS styles to apply to the top cell (specified via the above parameter) and bottom cell (specified via the below parameter). Typically used to set background color or text alignment:
abovestyle = background: #nnnnnn;abovestyle = text-align: [left/center/right];belowstyle = background: #nnnnnn;belowstyle = text-align: [left/center/right];
- imagestyle*
- imageleftstyle*
- CSS styles to apply to the cells where the image/imageleft sits. These styles should only be used in exceptional circumstances, usually to fix width problems if the width of groups is set and the width of the image cell grows too large. Example:
imagestyle = width:5em;
Default styles
[edit source]The style settings listed here are those that editors using the navbox change most often. The other more complex style settings were left out of this list to keep it simple. Most styles are set in Module:Navbox/styles.css.
bodystyle = background: #fdfdfd; width: 100%; vertical-align: middle;
titlestyle = background: #ccccff; padding-left: 1em; padding-right: 1em; text-align: center;
abovestyle = background: #ddddff; padding-left: 1em; padding-right: 1em; text-align: center;
belowstyle = background: #ddddff; padding-left: 1em; padding-right: 1em; text-align: center;
groupstyle = background: #ddddff; padding-left: 1em; padding-right: 1em; text-align: right;
liststyle = background: transparent; text-align: left/center;
oddstyle = background: transparent;
evenstyle = background: #f7f7f7;
Since liststyle and oddstyle are transparent, odd lists have the color of the bodystyle, which defaults to #fdfdfd (white with a hint of gray). A list defaults to text-align: left; if it has a group, if not it defaults to text-align: center;. Since only bodystyle has a vertical-align all the others inherit its vertical-align: middle;.
Advanced parameters
[edit source]- bodyclass
- aboveclass
- groupclass
- listclass
- belowclass
- This enables attaching a CSS class to group or list cells. The most common use for listclass is to give it the
hlistclass that will cause lists to render horizontally. All these parameters accept thehlistclass, but if more than one parameter is used forhlist, use Template:Para instead. - Template:Tl automatically adds the class
nowraplinkswhich can be overridden, for example withTemplate:Para. - innerstyle
- A very advanced parameter to be used only for advanced meta-templates employing the navbox. Internally, the navbox uses an outer table to draw the border, and then an inner table for everything else (title/above/groups/lists/below/images, etc.). The style/bodystyle parameter sets the style for the outer table, which the inner table inherits, but in advanced cases (meta-templates) it may be necessary to directly set the style for the inner table. This parameter provides access to that inner table so styles can be applied. Use at your own risk.
- nowrapitems
- Setting
|nowrapitems=yesapplies nowrap to each line in a list item, and to anyaboveorbelowitem. - orphan
- Setting
|orphan=yesin a child navbox fixes odd/even striping and removes Category:Navbox orphans.
Microformats
[edit source]- bodyclass
- This parameter is inserted into the "class" attribute for the navbox as a whole.
- titleclass
- This parameter is inserted into the "class" attribute for the navbox's title caption.
This template supports the addition of microformat information. This is done by adding "class" attributes to various data cells, indicating what kind of information is contained within. To flag a navbox as containing hCard information about a person, for example, add the following parameter:
| bodyclass = vcard
and
| titleclass = fn
or (for example):
| title = The books of <span class="fn">[[Iain Banks]]</span>
...and so forth.
See Wikipedia:WikiProject Microformats for more information on adding microformat information to Wikipedia, and microformat for more information on microformats in general.
Layout of table
[edit source]Without image, above and below
[edit source]Table generated by Template:Tl without image, above and below parameters (gray list background color added for illustration only):
{{Template:PAGENAMETDOC | name = Navbox/doc | state = uncollapsed | liststyle = background: silver; | title = {{{title}}} | group1 = {{{group1}}} | list1 = {{{list1}}} | group2 = {{{group2}}} | list2 = {{{list2}}} | list3 = {{{list3}}} without {{{group3}}} | group4 = {{{group4}}} | list4 = {{{list4}}} }}
With image, above and below
[edit source]Table generated by Template:Tl with image, above and below parameters (gray list background color added for illustration only):
{{Template:PAGENAMETDOC | name = Navbox/doc | state = uncollapsed | liststyle = background: silver; | image = {{{image}}} | title = {{{title}}} | above = {{{above}}} | group1 = {{{group1}}} | list1 = {{{list1}}} | group2 = {{{group2}}} | list2 = {{{list2}}} | list3 = {{{list3}}} without {{{group3}}} | group4 = {{{group4}}} | list4 = {{{list4}}} | below = {{{below}}} }}
With image and without groups
[edit source]Table generated by Template:Tl with image, imageleft, lists, and without groups, above, below (gray list background color added for illustration only):
{{Template:PAGENAMETDOC | name = Navbox/doc | state = uncollapsed | liststyle = background: silver; | image = {{{image}}} | imageleft = {{{imageleft}}} | title = {{{title}}} | list1 = {{{list1}}} | list2 = {{{list2}}} | list3 = {{{list3}}} | list4 = {{{list4}}} }}
Examples
[edit source]No image
[edit source]{{Navbox
| name = Navbox/doc
| title = [[MSC Malaysia]]
| listclass = hlist
| group1 = Centre
| list1 =
* [[Cyberjaya]]
| group2 = Area
| list2 =
* [[Klang Valley]]
| group3 = Major landmarks
| list3 =
* [[Petronas Twin Towers]]
* [[Kuala Lumpur Tower]]
* [[Kuala Lumpur Sentral]]
* [[Technology Park Malaysia]]
* [[Putrajaya]]
* [[Cyberjaya]]
* [[Kuala Lumpur International Airport]]
| group4 = Infrastructure
| list4 =
* [[Express Rail Link]]
* [[KL-KLIA Dedicated Expressway]]
| group5 = Prime applications
| list5 =
* [[E-Government]]
* [[MyKad]]
}}
{{Template:PAGENAMETDOC | name = Navbox/doc | state = uncollapsed | title = MSC Malaysia | listclass = hlist | group1 = Centre | list1 =
| group2 = Area | list2 =
| group3 = Major landmarks | list3 =
- Petronas Twin Towers
- Kuala Lumpur Tower
- Kuala Lumpur Sentral
- Technology Park Malaysia
- Putrajaya
- Cyberjaya
- Kuala Lumpur International Airport
| group4 = Infrastructure | list4 =
| group5 = Prime applications | list5 =
}}
Child navboxes
[edit source]It is possible to place multiple navboxes within a single border. These can either be specified inline or by using a nested navbox template, although the latter method can result in a significantly large post-expand include size.
To specify child navboxes inline, set the listn parameter to child or subgroup. Elements of the child navbox can be specified by prepending childn_, subgroupn_, or just n_ to the parameter names (e.g. 1_list1). Child navboxes can be nested by adding an additional prefix (e.g. 1_1_list1). The basic code for doing this is as follows (which adds a subgroup for the first group/list area):
{{Navbox
| name = {{subst:PAGENAME}}
| title = Title
| group1 = [optional]
| list1 = child
| 1_title = [optional]
| 1_group1 = [optional]
| 1_list1 = child
| 1_1_title = [optional]
| 1_1_group1 = [optional]
| 1_1_list1 =
...list contents...
...
...
}}
To specify child navboxes using a nested template, use "child" as the first parameter or set the border parameter. The basic code for doing this is as follows (which adds a subgroup for the first group/list area):
{{Navbox
| name = {{subst:PAGENAME}}
| title = Title
| group1 = [optional]
| list1 = {{Navbox|child
...child navbox parameters...
}}
...
}}
Subgroups example
[edit source]This example shows two subgroups and a sub-subgroup created using child and subgroup keywords (both are interchangible). The striping is alternated automatically. To remove the striping altogether, you can set childn_liststyle = background:transparent; in each.
{{Template:PAGENAMETDOC | name = Navbox/doc | state = uncollapsed | title = Multiple subgroup example | above = Above | below = Below | group1 = Group1 | list1 = List1 | group2 = Group2 | list2 = child
| child2_group1 = Group2.1 | child2_list1 = List1 | child2_group2 = Group2.2 | child2_list2 = List2 | child2_group3 = Group2.3 | child2_list3 = List3
| group3 = Group3 | list3 = List3 | group4 = Group4 | list4 = subgroup
| subgroup4_group1 = Group4.1 | subgroup4_list1 = List1 | subgroup4_group2 = Group4.2 | subgroup4_list2 = List2 | subgroup4_group3 = Group4.3 | subgroup4_list3 = child |subgroup4_child3_group1 = Group 4.3.1 |subgroup4_child3_list1 = List1 |subgroup4_child3_group2 = Group 4.3.2 |subgroup4_child3_list2 = List2
}}
Relationship with other Navbox templates
[edit source]This navbox template works in conjunction with two other templates: Template:Tl and Template:Tl. All three of these templates share common parameters for consistency and ease of use (such parameters are marked with an asterisk (*) in the parameter descriptions list hereinbefore). Most importantly, each template can be used as a child of one another. Using the inline notation, the n_type= parameter can be set to with columns or with collapsible groups to set the type of that child navbox, as shown in the example below. Press the edit button for the section to view the code.
You can also nest these or other navbox templates by using the Template:Para parameter, or by specifying the first unnamed parameter to be child. For example: {{Navbox|child ...}}, {{Navbox with columns|child ...}} or {{Navbox with collapsible groups|child ...}}. Note that this style of nesting can lead to a large increase in the template's post-expand include size.
Multiple show/hides in a single container
[edit source]The example below is generated using a regular navbox for the main container, then its list1, list2, and list3 parameters each contain the child keyword. The view (v), talk (t), edit (e) navbar links are hidden automatically because the "child" or "subgroup" keyword is used, so using navbar = plain for each of them is not necessary. The code N_state = {{#ifeq:{{{selected|}}|ABBREVIATION|uncollapsed|{{{stateN|collapsed}}}}} is used to replicate the abbrN = ABBREVIATION functionality of Template:Tl.
{{Template:PAGENAMETDOC | name = Navbox/doc | title = Former French overseas empire | state = uncollapsed | list1 = child
| 1_state = collapsed | 1_title = Former French colonies in Africa and the Indian Ocean | 1_listclass = hlist | 1_group1 = Mahgreb | 1_list1 =
| 1_group2 = French West Africa | 1_list2 =
- Côte d'Ivoire
- Dahomey
- French Sudan
- Guinea
- Mauritania
- Niger
- Senegal
- Upper Volta
- French Togoland
- James Island
| 1_group3 = French Equatorial Africa | 1_list3 =
| 1_group4 = Comoros | 1_list4 =
| list2 = child
| 2_state = collapsed | 2_title = Former French colonies in the Americas | 2_listclass = hlist | 2_list1 =
- New FranceTemplate:Spaces(Acadia, Louisiana, Canada, Terre Neuve) 1655–1763
| 2_list2 =
| 2_below = French West India Company
| list3 = child
| 3_state = collapsed | 3_title = Former French colonies in Asia and Oceania | 3_listclass = hlist | 3_group1 = Asia | 3_list1 = child | 3_1_group1 = French India | 3_1_list1 =
| 3_1_group2 = French Indochina | 3_1_list2 =
| 3_1_group3 = Other Asian | 3_1_list3 =
| 3_group4 = Oceania | 3_list4 =
| 3_below = French East India Company
}}
Technical details
[edit source]- The Template:Navbar links are produced by Template:Navbar. If you have a question about them, it is probably best to ask at Template talk:Navbar.
- The 2px wide border between groups and lists is drawn using the border-left property of the list cell. Thus, if you wish to change the background color of the template (for example
bodystyle = background:purple;), then you'll need to make the border-left-color match the background color (i.e.liststyle = border-left-color: purple;). If you wish to have a border around each list cell, then the 2px border between the list cells and group cells will disappear; you'll have to come up with your own solution. - Adjacent navboxes have only a 1 pixel border between them. If you set the top or bottom margin of
style/bodystyle, then this will not work. - The default margin-left and margin-right of the outer navbox table are set to "auto;". If you wish to use navbox as a float, you need to manually set the margin-left and margin-right values, because the auto margins interfere with the float option. For example, add the following code to use the navbox as a float:
bodystyle = width: 22em; float: right; margin-left: 1em; margin-right: 0;
- Navbox templates, including this one, are a major contributor to the post-expand include size of pages, and can cause pages to exceed the limit and not render correctly. There are a few ways to mitigate this.
- Template:Tlx can be replaced with Template:Mlx, which approximately halves the include size.
- Nesting other templates inside of a navbox can cause the include size increase by a factor of two or more. Using the in-line child syntax documented at #Child navboxes mitigates this, but only for plain Navboxes, Navboxes with columns, and Navboxes with collapsible groups (not other types of navboxes).
Copying to other projects or wikis
[edit source]If you are trying to copy Template:Tlf to your local wiki, there are several other things that must be installed or copied over as well:
- The Scribunto and TemplateStyles extensions must be installed.
- Module:Navbox and its module and TemplateStyles dependencies, listed at Module:Navbox/doc
- Optionally, the
Add support to mw-collapsible for autocollapse, innercollapse and outercollapsescript from MediaWiki:Common.js may be copied, if autocollapsing is desired.
TemplateData
[edit source]Creates a navigational box for links to other pages. Does not display in mobile.
| Parameter | Description | Type | Status | |
|---|---|---|---|---|
| Name | name | The name of the template. Needed for "View • Talk • Edit" links to work properly.
| String | suggested |
| Title | title | Text in the title bar; centered in the top row of the table. Usually the template's topic.
| Unknown | suggested |
| Group 1 | group1 | If specified, text appears in a header cell displayed to the left of list 1. If omitted, list 1 uses the full width of the table. | Unknown | suggested |
| List 1 | list1 | Body of the template; usually a list of links. Format is inline. At least one list parameter is required; each additional list is displayed in a separate row of the table. Each listn may be preceded by a corresponding groupn parameter. Entries should be separated using a newline and an asterisk. If two asterisks are used, it provides nesting within the previous entry with brackets. | Unknown | required |
| List class | listclass | CSS class for the list cells, usually hlist for horizontal lists. Alternatively, use bodyclass for the whole box.
| String | optional |
| State | state | Controls when a navbox is expanded or collapsed
| Unknown | suggested |
| Above | above | Full-width cell displayed between the titlebar and first group/list, i.e. above the template's body (groups, lists and image) | String | suggested |
| Below | below | Full-width cell displayed below the template's body. | Unknown | suggested |
| Image | image | Image to be displayed in a cell below the title and to the right of the body
| File | suggested |
| group2 | group2 | no description | Unknown | suggested |
| list2 | list2 | no description | Unknown | suggested |
| group3 | group3 | no description | Unknown | suggested |
| list3 | list3 | no description | Unknown | suggested |
| group4 | group4 | no description | Unknown | optional |
| list4 | list4 | no description | Unknown | optional |
| Image left | imageleft | Image to be displayed in a cell below the title and to the left of the body. For the image to display properly, list1 parameter must be specified and no groups can be specified.
| File | optional |
| Navbar status | navbar | no description
| String | optional |
| Border status | border | no description
| String | optional |
| bodystyle | bodystyle | no description | Unknown | optional |
| basestyle | basestyle | no description | Unknown | optional |
| titlestyle | titlestyle | no description | Unknown | optional |
| groupstyle | groupstyle | no description | Unknown | optional |
| liststyle | liststyle | no description | Unknown | optional |
| group1style | group1style | no description | Unknown | optional |
| list1style | list1style | no description | Unknown | optional |
| groupwidth | groupwidth | no description | Unknown | optional |
| listpadding | listpadding | no description | Unknown | optional |
| oddstyle | oddstyle | no description | Unknown | optional |
| evenstyle | evenstyle | no description | Unknown | optional |
| evenodd | evenodd | no description
| Unknown | optional |
| abovestyle | abovestyle | no description | Unknown | optional |
| belowstyle | belowstyle | no description | Unknown | optional |
| imagestyle | imagestyle | no description | Unknown | optional |
| imageleftstyle | imageleftstyle | no description | Unknown | optional |
See also
[edit source]- Template:Tl — To create a row of ten evenly spaced year links.
- Template:Tl — groups several navigation boxes together.
- Template:Tl — To display text at normal font-weight within a context where the default font-weight is bold, e.g. header cells in tables.
- Template:Tl — Vertically-aligned navigation templates.
- Template:Tl — Shows the standard documentation using Template:Tl.
- Template:Navbox/testcases — For additional examples of template code.
- Wikipedia:Line-break handling — The how-to guide about how to handle word wraps (line breaks) on Wikipedia, such as the wrapping of the link lists used in navboxes.
- Wikipedia:Template documentation — Guideline to creating the accompanying documentation
- Template:Tl, Template:Tl and Template:Tl are deprecated in favor of the
hlistclass for formatting lists. See Flatlist for a technical explanation of howhlistworks.
Tracking categories
[edit source]require('strict')
local p = {}
local cfg = mw.loadData('Module:Navbox/configuration')
local inArray = require("Module:TableTools").inArray
local getArgs -- lazily initialized
local hiding_templatestyles = {}
-- global passthrough variables
local passthrough = {
[cfg.arg.above]=true,[cfg.arg.aboveclass]=true,[cfg.arg.abovestyle]=true,
[cfg.arg.basestyle]=true,
[cfg.arg.below]=true,[cfg.arg.belowclass]=true,[cfg.arg.belowstyle]=true,
[cfg.arg.bodyclass]=true,
[cfg.arg.groupclass]=true,
[cfg.arg.image]=true,[cfg.arg.imageclass]=true,[cfg.arg.imagestyle]=true,
[cfg.arg.imageleft]=true,[cfg.arg.imageleftstyle]=true,
[cfg.arg.listclass]=true,
[cfg.arg.name]=true,
[cfg.arg.navbar]=true,
[cfg.arg.state]=true,
[cfg.arg.title]=true,[cfg.arg.titleclass]=true,[cfg.arg.titlestyle]=true,
argHash=true
}
-- helper functions
local andnum = function(s, n) return string.format(cfg.arg[s .. '_and_num'], n) end
local isblank = function(v) return (v or '') == '' end
local function concatstrings(s)
local r = table.concat(s, '')
if r:match('^%s*$') then return nil end
return r
end
local function concatstyles(s)
local r = ''
for _, v in ipairs(s) do
v = mw.text.trim(v, "%s;")
if not isblank(v) then r = r .. v .. ';' end
end
if isblank(r) then return nil end
return r
end
local function getSubgroup(args, listnum, listText, prefix)
local subArgs = {
[cfg.arg.border] = cfg.keyword.border_subgroup,
[cfg.arg.navbar] = cfg.keyword.navbar_plain,
argHash = 0
}
local hasSubArgs = false
local subgroups_and_num = prefix and {prefix} or cfg.arg.subgroups_and_num
for k, v in pairs(args) do
k = tostring(k)
for _, w in ipairs(subgroups_and_num) do
w = string.format(w, listnum) .. "_"
if (#k > #w) and (k:sub(1, #w) == w) then
subArgs[k:sub(#w + 1)] = v
hasSubArgs = true
subArgs.argHash = subArgs.argHash + (v and #v or 0)
end
end
end
return hasSubArgs and p._navbox(subArgs) or listText
end
-- Main functions
function p._navbox(args)
if args.type == cfg.keyword.with_collapsible_groups then
return p._withCollapsibleGroups(args)
elseif args.type == cfg.keyword.with_columns then
return p._withColumns(args)
end
local function striped(wikitext, border)
-- Return wikitext with markers replaced for odd/even striping.
-- Child (subgroup) navboxes are flagged with a category that is removed
-- by parent navboxes. The result is that the category shows all pages
-- where a child navbox is not contained in a parent navbox.
local orphanCat = cfg.category.orphan
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 .. orphanCat
end
local first, second = cfg.class.navbox_odd_part, cfg.class.navbox_even_part
if args[cfg.arg.evenodd] then
if args[cfg.arg.evenodd] == cfg.keyword.evenodd_swap then
first, second = second, first
else
first = args[cfg.arg.evenodd]
second = first
end
end
local changer
if first == second then
changer = first
else
local index = 0
changer = function (code)
if code == '0' then
-- Current occurrence is for a group before a nested table.
-- Set it to first as a valid although pointless class.
-- The next occurrence will be the first row after a title
-- in a subgroup and will also be first.
index = 0
return first
end
index = index + 1
return index % 2 == 1 and first or second
end
end
local regex = orphanCat:gsub('([%[%]])', '%%%1')
return (wikitext:gsub(regex, ''):gsub(cfg.marker.regex, changer)) -- () omits gsub count
end
local function processItem(item, nowrapitems)
if item:sub(1, 2) == '{|' then
-- Applying nowrap to lines in a table does not make sense.
-- Add newlines to compensate for trim of x in |parm=x in a template.
return '\n' .. item .. '\n'
end
if nowrapitems == cfg.keyword.nowrapitems_yes then
local lines = {}
for line in (item .. '\n'):gmatch('([^\n]*)\n') do
local prefix, content = line:match('^([*:;#]+)%s*(.*)')
if prefix and not content:match(cfg.pattern.nowrap) then
line = string.format(cfg.nowrap_item, prefix, content)
end
table.insert(lines, line)
end
item = table.concat(lines, '\n')
end
if item:match('^[*:;#]') then
return '\n' .. item .. '\n'
end
return item
end
local function has_navbar()
return args[cfg.arg.navbar] ~= cfg.keyword.navbar_off
and args[cfg.arg.navbar] ~= cfg.keyword.navbar_plain
and (
args[cfg.arg.name]
or mw.getCurrentFrame():getParent():getTitle():gsub(cfg.pattern.sandbox, '')
~= cfg.pattern.navbox
)
end
-- extract text color from css, which is the only permitted inline CSS for the navbar
local function extract_color(css_str)
-- return nil because navbar takes its argument into mw.html which handles
-- nil gracefully, removing the associated style attribute
return mw.ustring.match(';' .. css_str .. ';', '.*;%s*([Cc][Oo][Ll][Oo][Rr]%s*:%s*.-)%s*;') or nil
end
local function renderNavBar(titleCell)
if has_navbar() then
local navbar = require('Module:Navbar')._navbar
titleCell:wikitext(navbar{
[cfg.navbar.name] = args[cfg.arg.name],
[cfg.navbar.mini] = 1,
[cfg.navbar.fontstyle] = extract_color(
(args[cfg.arg.basestyle] or '') .. ';' .. (args[cfg.arg.titlestyle] or '')
)
})
end
end
local function renderTitleRow(tbl)
if not args[cfg.arg.title] then return end
local titleRow = tbl:tag('tr')
local titleCell = titleRow:tag('th'):attr('scope', 'col')
local titleColspan = 2
if args[cfg.arg.imageleft] then titleColspan = titleColspan + 1 end
if args[cfg.arg.image] then titleColspan = titleColspan + 1 end
titleCell
:cssText(args[cfg.arg.basestyle])
:cssText(args[cfg.arg.titlestyle])
:addClass(cfg.class.navbox_title)
:attr('colspan', titleColspan)
renderNavBar(titleCell)
titleCell
:tag('div')
-- id for aria-labelledby attribute
:attr('id', mw.uri.anchorEncode(args[cfg.arg.title]) .. args.argHash)
: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(cfg.class.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', (not args[cfg.arg.title]) and
(mw.uri.anchorEncode(args[cfg.arg.above]) .. args.argHash)
or nil)
: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(cfg.class.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, listnums_size)
local row = tbl:tag('tr')
if index == 1 and args[cfg.arg.imageleft] then
row
:tag('td')
:addClass(cfg.class.noviewer)
:addClass(cfg.class.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', listnums_size)
:tag('div')
:wikitext(processItem(args[cfg.arg.imageleft]))
end
local group_and_num = andnum('group', listnum)
local groupstyle_and_num = andnum('groupstyle', listnum)
if args[group_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]) .. args.argHash)
end
groupCell
:attr('scope', 'row')
:addClass(cfg.class.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[groupstyle_and_num])
:wikitext(args[group_and_num])
end
local listCell = row:tag('td')
if args[group_and_num] then
listCell
:addClass(cfg.class.navbox_list_with_group)
else
listCell:attr('colspan', 2)
end
if not args[cfg.arg.groupwidth] then
listCell:css('width', '100%')
end
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 list_and_num = andnum('list', listnum)
local listText = inArray(cfg.keyword.subgroups, args[list_and_num])
and getSubgroup(args, listnum, args[list_and_num]) or args[list_and_num]
local oddEven = cfg.marker.oddeven
if listText:sub(1, 12) == '</div><table' then
-- Assume list text is for a subgroup navbox so no automatic striping for this row.
oddEven = listText:find(cfg.pattern.navbox_title) and cfg.marker.restart or cfg.class.navbox_odd_part
end
local liststyle_and_num = andnum('liststyle', listnum)
local listclass_and_num = andnum('listclass', listnum)
listCell
:css('padding', '0')
:cssText(args[cfg.arg.liststyle])
:cssText(rowstyle)
:cssText(args[liststyle_and_num])
:addClass(cfg.arg.itemclass) -- pizza
: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',
(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(cfg.class.noviewer)
:addClass(cfg.class.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', listnums_size)
:tag('div')
:wikitext(processItem(args[cfg.arg.image]))
end
end
local function has_list_class(htmlclass)
local patterns = {
'^' .. htmlclass .. '$',
'%s' .. htmlclass .. '$',
'^' .. htmlclass .. '%s',
'%s' .. htmlclass .. '%s'
}
for arg, _ in pairs(args) do
if type(arg) == 'string' and mw.ustring.find(arg, cfg.pattern.class) then
for _, pattern in ipairs(patterns) do
if mw.ustring.find(args[arg] or '', pattern) then
return true
end
end
end
end
return false
end
-- there are a lot of list classes in the wild, so we add their TemplateStyles
local function add_list_styles()
local frame = mw.getCurrentFrame()
local function add_list_templatestyles(htmlclass, templatestyles)
if has_list_class(htmlclass) then
return frame:extensionTag{
name = 'templatestyles', args = { src = templatestyles }
}
else
return ''
end
end
local hlist_styles = add_list_templatestyles('hlist', cfg.hlist_templatestyles)
local plainlist_styles = add_list_templatestyles('plainlist', cfg.plainlist_templatestyles)
-- a second workaround for [[phab:T303378]]
-- when that issue is fixed, we can actually use has_navbar not to emit the
-- tag here if we want
if has_navbar() and hlist_styles == '' then
hlist_styles = frame:extensionTag{
name = 'templatestyles', args = { src = cfg.hlist_templatestyles }
}
end
-- hlist -> plainlist is best-effort to preserve old Common.css ordering.
-- this ordering is not a guarantee because most navboxes will emit only
-- one of these classes [hlist_note]
return hlist_styles .. plainlist_styles
end
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 has_list_class(cfg.pattern.hlist) and not has_list_class(cfg.pattern.plainlist)
end
local function hasBackgroundColors()
for _, key in ipairs({cfg.arg.titlestyle, cfg.arg.groupstyle,
cfg.arg.basestyle, cfg.arg.abovestyle, cfg.arg.belowstyle}) do
if tostring(args[key]):find('background', 1, true) then
return true
end
end
return false
end
local function hasBorders()
for _, key in ipairs({cfg.arg.groupstyle, cfg.arg.basestyle,
cfg.arg.abovestyle, cfg.arg.belowstyle}) do
if tostring(args[key]):find('border', 1, true) then
return true
end
end
return false
end
local function isIllegible()
local styleratio = require('Module:Color contrast')._styleratio
for key, style in pairs(args) do
if tostring(key):match(cfg.pattern.style) then
if styleratio{mw.text.unstripNoWiki(style)} < 4.5 then
return true
end
end
end
return false
end
local function getTrackingCategories(border)
local cats = {}
if needsHorizontalLists(border) then table.insert(cats, cfg.category.horizontal_lists) end
if hasBackgroundColors() then table.insert(cats, cfg.category.background_colors) end
if isIllegible() then table.insert(cats, cfg.category.illegible) end
if hasBorders() then table.insert(cats, cfg.category.borders) end
return cats
end
local function renderTrackingCategories(builder, border)
local title = mw.title.getCurrentTitle()
if title.namespace ~= 10 then return end -- not in template space
local subpage = title.subpageText
if subpage == cfg.keyword.subpage_doc or subpage == cfg.keyword.subpage_sandbox
or subpage == cfg.keyword.subpage_testcases then return end
for _, cat in ipairs(getTrackingCategories(border)) do
builder:wikitext('[[Category:' .. cat .. ']]')
end
end
local function renderMainTable(border, listnums)
local tbl = mw.html.create('table')
:addClass(cfg.class.nowraplinks)
:addClass(args[cfg.arg.bodyclass])
local state = args[cfg.arg.state]
if args[cfg.arg.title] and state ~= cfg.keyword.state_plain and state ~= cfg.keyword.state_off then
if state == cfg.keyword.state_collapsed then
state = cfg.class.collapsed
end
tbl
:addClass(cfg.class.collapsible)
:addClass(state or cfg.class.autocollapse)
end
tbl:css('border-spacing', 0)
if border == cfg.keyword.border_subgroup or border == cfg.keyword.border_none then
tbl
:addClass(cfg.class.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
:addClass(cfg.class.navbox_inner)
:css('background', 'transparent')
: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, listnums_size)
end
renderBelowRow(tbl)
return tbl
end
local function add_navbox_styles(hiding_templatestyles)
local frame = mw.getCurrentFrame()
-- This is a lambda so that it doesn't need the frame as a parameter
local function add_user_styles(templatestyles)
if not isblank(templatestyles) then
return frame:extensionTag{
name = 'templatestyles', args = { src = templatestyles }
}
end
return ''
end
-- get templatestyles. load base from config so that Lua only needs to do
-- the work once of parser tag expansion
local base_templatestyles = cfg.templatestyles
local templatestyles = add_user_styles(args[cfg.arg.templatestyles])
local child_templatestyles = add_user_styles(args[cfg.arg.child_templatestyles])
-- The 'navbox-styles' div exists to wrap the styles to work around T200206
-- more elegantly. Instead of combinatorial rules, this ends up being linear
-- number of CSS rules.
return mw.html.create('div')
:addClass(cfg.class.navbox_styles)
:wikitext(
add_list_styles() .. -- see [hlist_note] applied to 'before base_templatestyles'
base_templatestyles ..
templatestyles ..
child_templatestyles ..
table.concat(hiding_templatestyles)
)
:done()
end
-- work around [[phab:T303378]]
-- for each arg: find all the templatestyles strip markers, insert them into a
-- table. then remove all templatestyles markers from the arg
local strip_marker_pattern = '(\127[^\127]*UNIQ%-%-templatestyles%-%x+%-QINU[^\127]*\127)'
local argHash = 0
for k, arg in pairs(args) do
if type(arg) == 'string' then
for marker in string.gfind(arg, strip_marker_pattern) do
table.insert(hiding_templatestyles, marker)
end
argHash = argHash + #arg
args[k] = string.gsub(arg, strip_marker_pattern, '')
end
end
if not args.argHash then args.argHash = argHash end
local listnums = {}
for k, _ in pairs(args) do
if type(k) == 'string' then
local listnum = k:match(cfg.pattern.listnum)
if listnum and args[andnum('list', tonumber(listnum))] then
table.insert(listnums, tonumber(listnum))
end
end
end
table.sort(listnums)
local border = mw.text.trim(args[cfg.arg.border] or args[1] or '')
if border == cfg.keyword.border_child then
border = cfg.keyword.border_subgroup
end
-- render the main body of the navbox
local tbl = renderMainTable(border, listnums)
local res = mw.html.create()
-- render the appropriate wrapper for the navbox, based on the border param
if border == cfg.keyword.border_none then
res:node(add_navbox_styles(hiding_templatestyles))
local nav = res:tag('div')
:attr('role', 'navigation')
: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]
) .. args.argHash
)
else
nav:attr('aria-label', cfg.aria_label)
end
elseif border == cfg.keyword.border_subgroup 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>')
:node(tbl)
:wikitext('<div>')
else
res:node(add_navbox_styles(hiding_templatestyles))
local nav = res:tag('div')
:attr('role', 'navigation')
:addClass(cfg.class.navbox)
:addClass(args[cfg.arg.navboxclass])
:addClass('foo')
: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]
) .. args.argHash
)
else
nav:attr('aria-label', cfg.aria_label .. args.argHash)
end
end
if (args[cfg.arg.nocat] or cfg.keyword.nocat_false):lower() == cfg.keyword.nocat_false then
renderTrackingCategories(res, border)
end
return striped(tostring(res), border)
end --p._navbox
function p._withCollapsibleGroups(pargs)
-- table for args passed to navbox
local targs = {}
-- process args
local passthroughLocal = {
[cfg.arg.bodystyle] = true,
[cfg.arg.border] = true,
[cfg.arg.style] = true,
}
for k,v in pairs(pargs) do
if k and type(k) == 'string' then
if passthrough[k] or passthroughLocal[k] then
targs[k] = v
elseif (k:match(cfg.pattern.num)) then
local n = k:match(cfg.pattern.num)
local list_and_num = andnum('list', n)
if ((k:match(cfg.pattern.listnum) or k:match(cfg.pattern.contentnum))
and targs[list_and_num] == nil
and pargs[andnum('group', n)] == nil
and pargs[andnum('sect', n)] == nil
and pargs[andnum('section', n)] == nil) then
targs[list_and_num] = concatstrings({
pargs[list_and_num] or '',
pargs[andnum('content', n)] or ''
})
if (targs[list_and_num] and inArray(cfg.keyword.subgroups, targs[list_and_num])) then
targs[list_and_num] = getSubgroup(pargs, n, targs[list_and_num])
end
elseif ((k:match(cfg.pattern.groupnum) or k:match(cfg.pattern.sectnum) or k:match(cfg.pattern.sectionnum))
and targs[list_and_num] == nil) then
local titlestyle = concatstyles({
pargs[cfg.arg.groupstyle] or '',
pargs[cfg.arg.secttitlestyle] or '',
pargs[andnum('groupstyle', n)] or '',
pargs[andnum('sectiontitlestyle', n)] or ''
})
local liststyle = concatstyles({
pargs[cfg.arg.liststyle] or '',
pargs[cfg.arg.contentstyle] or '',
pargs[andnum('liststyle', n)] or '',
pargs[andnum('contentstyle', n)] or ''
})
local title = concatstrings({
pargs[andnum('group', n)] or '',
pargs[andnum('sect', n)] or '',
pargs[andnum('section', n)] or ''
})
local list = concatstrings({
pargs[list_and_num] or '',
pargs[andnum('content', n)] or ''
})
if list and inArray(cfg.keyword.subgroups, list) then
list = getSubgroup(pargs, n, list)
end
local abbr_and_num = andnum('abbr', n)
local state = (pargs[abbr_and_num] and pargs[abbr_and_num] == pargs[cfg.arg.selected])
and cfg.keyword.state_uncollapsed
or (pargs[andnum('state', n)] or cfg.keyword.state_collapsed)
targs[list_and_num] =p._navbox({
cfg.keyword.border_child,
[cfg.arg.navbar] = cfg.keyword.navbar_plain,
[cfg.arg.state] = state,
[cfg.arg.basestyle] = pargs[cfg.arg.basestyle],
[cfg.arg.title] = title,
[cfg.arg.titlestyle] = titlestyle,
[andnum('list', 1)] = list,
[cfg.arg.liststyle] = liststyle,
[cfg.arg.listclass] = pargs[andnum('listclass', n)],
[cfg.arg.image] = pargs[andnum('image', n)],
[cfg.arg.imageleft] = pargs[andnum('imageleft', n)],
[cfg.arg.listpadding] = pargs[cfg.arg.listpadding],
argHash = pargs.argHash
})
end
end
end
end
-- ordering of style and bodystyle
targs[cfg.arg.style] = concatstyles({targs[cfg.arg.style] or '', targs[cfg.arg.bodystyle] or ''})
targs[cfg.arg.bodystyle] = nil
-- child or subgroup
if targs[cfg.arg.border] == nil then targs[cfg.arg.border] = pargs[1] end
return p._navbox(targs)
end --p._withCollapsibleGroups
function p._withColumns(pargs)
-- table for args passed to navbox
local targs = {}
-- tables of column numbers
local colheadernums = {}
local colnums = {}
local colfooternums = {}
-- process args
local passthroughLocal = {
[cfg.arg.evenstyle]=true,
[cfg.arg.groupstyle]=true,
[cfg.arg.liststyle]=true,
[cfg.arg.oddstyle]=true,
[cfg.arg.state]=true,
}
for k,v in pairs(pargs) do
if passthrough[k] or passthroughLocal[k] then
targs[k] = v
elseif type(k) == 'string' then
if k:match(cfg.pattern.listnum) then
local n = k:match(cfg.pattern.listnum)
targs[andnum('liststyle', n + 2)] = pargs[andnum('liststyle', n)]
targs[andnum('group', n + 2)] = pargs[andnum('group', n)]
targs[andnum('groupstyle', n + 2)] = pargs[andnum('groupstyle', n)]
if v and inArray(cfg.keyword.subgroups, v) then
targs[andnum('list', n + 2)] = getSubgroup(pargs, n, v)
else
targs[andnum('list', n + 2)] = v
end
elseif (k:match(cfg.pattern.colheadernum) and v ~= '') then
table.insert(colheadernums, tonumber(k:match(cfg.pattern.colheadernum)))
elseif (k:match(cfg.pattern.colnum) and v ~= '') then
table.insert(colnums, tonumber(k:match(cfg.pattern.colnum)))
elseif (k:match(cfg.pattern.colfooternum) and v ~= '') then
table.insert(colfooternums, tonumber(k:match(cfg.pattern.colfooternum)))
end
end
end
table.sort(colheadernums)
table.sort(colnums)
table.sort(colfooternums)
-- HTML table for list1
local coltable = mw.html.create( 'table' ):addClass('navbox-columns-table')
local row, col
local tablestyle = ( (#colheadernums > 0) or (not isblank(pargs[cfg.arg.fullwidth])) )
and 'width:100%'
or 'width:auto; margin-left:auto; margin-right:auto'
coltable:cssText(concatstyles({
'border-spacing: 0px; text-align:left',
tablestyle,
pargs[cfg.arg.coltablestyle] or ''
}))
--- Header row ---
if (#colheadernums > 0) then
row = coltable:tag('tr')
for k, n in ipairs(colheadernums) do
col = row:tag('td'):addClass('navbox-abovebelow')
col:cssText(concatstyles({
(k > 1) and 'border-left:2px solid #fdfdfd' or '',
'font-weight:bold',
pargs[cfg.arg.colheaderstyle] or '',
pargs[andnum('colheaderstyle', n)] or ''
}))
col:attr('colspan', tonumber(pargs[andnum('colheadercolspan', n)]))
col:wikitext(pargs[andnum('colheader', n)])
end
end
--- Main columns ---
row = coltable:tag('tr'):css('vertical-align', 'top')
for k, n in ipairs(colnums) do
if k == 1 and isblank(pargs[andnum('colheader', 1)])
and isblank(pargs[andnum('colfooter', 1)])
and isblank(pargs[cfg.arg.fullwidth]) then
local nopad = inArray(
{'off', '0', '0em', '0px'},
mw.ustring.gsub(pargs[cfg.arg.padding] or '', '[;%%]', ''))
if not nopad then
row:tag('td'):wikitext(' ')
:css('width', (pargs[cfg.arg.padding] or '5em'))
end
end
col = row:tag('td'):addClass('navbox-list')
col:cssText(concatstyles({
(k > 1) and 'border-left:2px solid #fdfdfd' or '',
'padding:0px',
pargs[cfg.arg.colstyle] or '',
((n%2 == 0) and pargs[cfg.arg.evencolstyle] or pargs[cfg.arg.oddcolstyle]) or '',
pargs[andnum('colstyle', n)] or '',
'width:' .. (pargs[andnum('colwidth', n)] or pargs[cfg.arg.colwidth] or '10em')
}))
local wt = pargs[andnum('col', n)]
if wt and inArray(cfg.keyword.subgroups, wt) then
wt = getSubgroup(pargs, n, wt, cfg.arg.col_and_num)
end
col:tag('div'):newline():wikitext(wt):newline()
end
--- Footer row ---
if (#colfooternums > 0) then
row = coltable:tag('tr')
for k, n in ipairs(colfooternums) do
col = row:tag('td'):addClass('navbox-abovebelow')
col:cssText(concatstyles({
(k > 1) and 'border-left:2px solid #fdfdfd' or '',
'font-weight:bold',
pargs[cfg.arg.colfooterstyle] or '',
pargs[andnum('colfooterstyle', n)] or ''
}))
col:attr('colspan', tonumber(pargs[andnum('colfootercolspan', n)]))
col:wikitext(pargs[andnum('colfooter', n)])
end
end
-- assign table to list1
targs[andnum('list', 1)] = tostring(coltable)
if isblank(pargs[andnum('colheader', 1)])
and isblank(pargs[andnum('col', 1)])
and isblank(pargs[andnum('colfooter', 1)]) then
targs[andnum('list', 1)] = targs[andnum('list', 1)] ..
cfg.category.without_first_col
end
-- Other parameters
targs[cfg.arg.border] = pargs[cfg.arg.border] or pargs[1]
targs[cfg.arg.evenodd] = (not isblank(pargs[cfg.arg.evenodd])) and pargs[cfg.arg.evenodd] or nil
targs[cfg.arg.list1padding] = '0px'
targs[andnum('liststyle', 1)] = 'background:transparent;color:inherit;'
targs[cfg.arg.style] = concatstyles({pargs[cfg.arg.style], pargs[cfg.arg.bodystyle]})
targs[cfg.arg.tracking] = 'no'
return p._navbox(targs)
end --p._withColumns
-- Template entry points
function p.navbox (frame, boxtype)
local function readArgs(args, prefix)
-- Read the arguments in the order they'll be output in, to make references
-- number in the right order.
local _ = 0
_ = _ + (args[prefix .. cfg.arg.title] and #args[prefix .. cfg.arg.title] or 0)
_ = _ + (args[prefix .. cfg.arg.above] and #args[prefix .. cfg.arg.above] or 0)
-- 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[prefix .. andnum('group', i)] and #args[prefix .. andnum('group', i)] or 0)
if inArray(cfg.keyword.subgroups, args[prefix .. andnum('list', i)]) then
for _, v in ipairs(cfg.arg.subgroups_and_num) do
readArgs(args, prefix .. string.format(v, i) .. "_")
end
readArgs(args, prefix .. andnum('col', i) .. "_")
end
end
_ = _ + (args[prefix .. cfg.arg.below] and #args[prefix .. cfg.arg.below] or 0)
return _
end
if not getArgs then
getArgs = require('Module:Arguments').getArgs
end
local args = getArgs(frame, {wrappers = {cfg.pattern[boxtype or 'navbox']}})
args.argHash = readArgs(args, "")
args.type = args.type or cfg.keyword[boxtype]
return p['_navbox'](args)
end
p[cfg.keyword.with_collapsible_groups] = function (frame)
return p.navbox(frame, 'with_collapsible_groups')
end
p[cfg.keyword.with_columns] = function (frame)
return p.navbox(frame, 'with_columns')
end
return p