Module:Navbox with collapsible groups
Appearance
![]() | This module is rated as ready for general use. It has reached a mature form and is thought to be relatively bug-free and ready for use wherever appropriate. It is ready to mention on help pages and other Wikipedia resources as an option for new users to learn. To reduce server load and bad output, it should be improved by sandbox testing rather than repeated trial-and-error editing. |
![]() | This module is subject to page protection. It is a highly visible module in use by a very large number of pages, or is substituted very frequently. Because vandalism or mistakes would affect many pages, and even trivial editing might cause substantial load on the servers, it is protected from editing. |
![]() | This Lua module is used on approximately 16,000 pages and changes may be widely noticed. Test changes in the module's /sandbox or /testcases subpages, or in your own module sandbox. Consider discussing changes on the talk page before implementing them. |
![]() | This module depends on the following other modules: |
Implements {{Navbox with collapsible groups}}
Usage
{{#invoke:Navbox with collapsible groups|navbox}}
See Template:Navbox with collapsible groups for more detailed usage.
See also
-- This module implements {{Navbox with collapsible groups}}
require('Module:No globals')
local p = {}
local Navbox = require('Module:Navbox')
local getArgs -- lazily initialized
-- helper functions
local function concatstrings(s)
local r = table.concat(s, '')
if r:match('^%s*$') then r = nil end
return r
end
local function concatstyles(s)
local r = table.concat(s, ';')
while r:match(';%s*;') do
r = mw.ustring.gsub(r, ';%s*;', ';')
end
if r:match('^%s*;%s*$') then r = nil end
return r
end
function p._navbox(frame, args)
local tracking = ''
-- table for args passed to navbox
local targs = {}
-- process args
local passthrough = {
['name']=true,['navbar']=true,['state']=true,['border']=true,
['bodyclass']=true,['groupclass']=true,['listclass']=true,
['style']=true,['bodystyle']=true,['basestyle']=true,
['title']=true,['titleclass']=true,['titlestyle']=true,
['above']=true,['aboveclass']=true,['abovestyle']=true,
['below']=true,['belowclass']=true,['belowstyle']=true,
['image']=true,['imageclass']=true,['imagestyle']=true,
['imageleft']=true,['imageleftstyle']=true
}
for k,v in pairs(args) do
if k and type(k) == 'string' then
if passthrough[k] then
targs[k] = v
elseif (k:match('^list[0-9][0-9]*$')
or k:match('^content[0-9][0-9]*$') ) then
local n = mw.ustring.gsub(k, '^[a-z]*([0-9]*)$', '%1')
if (targs['list' .. n] == nil and args['group' .. n] == nil
and args['sect' .. n] == nil and args['section' .. n] == nil) then
targs['list' .. n] = concatstrings(args['list' .. n] or '', args['content' .. n] or '')
end
elseif (k:match('^group[0-9][0-9]*$')
or k:match('^sect[0-9][0-9]*$')
or k:match('^section[0-9][0-9]*$') ) then
local n = mw.ustring.gsub(k, '^[a-z]*([0-9]*)$', '%1')
if targs['list' .. n] == nil then
local titlestyle = concatstyles(
{args['groupstyle'] or '',args['secttitlestyle'] or '',
args['group' .. n .. 'style'] or '',
args['section' .. n ..'titlestyle'] or ''})
local liststyle = concatstyles(
{args['liststyle'] or '', args['contentstyle'] or '',
args['list' .. n .. 'style'] or '',
args['content' .. n .. 'style'] or ''})
local title = concatstrings(
{args['group' .. n] or '',
args['sect' .. n] or '',
args['section' .. n] or ''})
local list = concatstrings(
{args['list' .. n] or '',
args['content' .. n] or ''})
local state = (args['abbr' .. n] and args['abbr' .. n] == args['selected'])
and 'uncollapsed' or args['state' .. n] or 'collapsed'
local sargs = {'child', navbar = 'plain', state = state,
basestyle = args['basestyle'],
title = title, titlestyle = titlestyle,
list1 = list, liststyle = liststyle,
listclass = args['list' .. n .. 'class'],
image = args['image' .. n],
imageleft = args['imageleft' .. n],
listpadding = args['listpadding']}
targs['list' .. n] = frame:expandTemplate{title='Navbox', args = sargs}
tracking = tracking .. '<hr /><center><b>k = ' .. k .. ', n = ' .. n .. '</b></center><hr />\n'
for ks,vs in pairs(sargs) do
tracking = tracking .. ks .. ' = ' .. vs .. '<br>\n'
end
tracking = tracking .. '\n<hr />\n'
end
end
end
end
-- child or subgroup
if targs['border'] == nil then targs['border'] = args[1] end
-- debug
tracking = tracking .. '<hr /><center><b>targs</b></center><hr />\n'
for k,v in pairs(targs) do
tracking = tracking .. k .. ' = ' .. v .. '<br>\n'
end
tracking = tracking .. '\n<hr />\n'
return Navbox._navbox(targs) .. tracking
end
function p.navbox(frame)
if not getArgs then
getArgs = require('Module:Arguments').getArgs
end
local args = getArgs(frame, {wrappers = {'Template:Navbox with collapsible groups'}})
-- Read the arguments in the order they'll be output in, to make references number in the right order.
local _
_ = args.title
_ = args.above
for i = 1, 20 do
_ = args["group" .. tostring(i)]
_ = args["list" .. tostring(i)]
end
_ = args.below
return p._navbox(frame, args)
end
return p