Editing Module:Navbox with collapsible groups

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. Read the Privacy Policy to learn what information we collect about you and how we use it.

If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.

Latest revision Your text
Line 1: Line 1:
-- This module implements {{Navbox with collapsible groups}}
-- This module implements {{Navbox with collapsible groups}}
local q = {}
local p = {}
 
local Navbox = require('Module:Navbox')
local Navbox = require('Module:Navbox')
local getArgs -- lazily initialized


-- helper functions
-- helper functions
local function concatstrings(s)
local function concatstrings(t)
local r = table.concat(s, '')
local res = table.concat(t, '')
if r:match('^%s*$') then r = nil end
if res:match('^%s*$') then res = nil end
return r
return res
end
end


local function concatstyles(s)
local function concatstyles(t)
local r = table.concat(s, ';')
local res = table.concat(t, ';')
while r:match(';%s*;') do
while res:match(';%s*;') do
r = mw.ustring.gsub(r, ';%s*;', ';')
res = mw.ustring.gsub(res, ';%s*;', ';')
end
end
if r:match('^%s*;%s*$') then r = nil end
if res:match('^%s*;%s*$') then res = nil end
return r
return res
end
end


function q._navbox(pargs)
function p._navbox(args)
-- table for args passed to navbox
-- table for args passed to navbox
local targs = {}
local targs = {}
Line 25: Line 27:
-- process args
-- process args
local passthrough = {
local passthrough = {
['name']=true,['navbar']=true,['state']=true,['border']=true,
['name']=1,['navbar']=1,['state']=1,['border']=1,
['bodyclass']=true,['groupclass']=true,['listclass']=true,
['bodyclass']=1,['groupclass']=1,['listclass']=1,
['style']=true,['bodystyle']=true,['basestyle']=true,
['style']=1,['bodystyle']=1,['basestyle']=1,
['title']=true,['titleclass']=true,['titlestyle']=true,
['title']=1,['titleclass']=1,['titlestyle']=1,
['above']=true,['aboveclass']=true,['abovestyle']=true,
['above']=1,['aboveclass']=1,['abovestyle']=1,
['below']=true,['belowclass']=true,['belowstyle']=true,
['below']=1,['belowclass']=1,['belowstyle']=1,
['image']=true,['imageclass']=true,['imagestyle']=true,
['image']=1,['imageclass']=1,['imagestyle']=1,
['imageleft']=true,['imageleftstyle']=true
['imageleft']=1,['imageleftstyle']=1
}
}
for k,v in pairs(pargs) do
for k,v in pairs(args) do
if k and type(k) == 'string' then
if k and type(k) == 'string' then
if passthrough[k] then
if passthrough[k] then
Line 41: Line 43:
or k:match('^content[0-9][0-9]*$') ) then
or k:match('^content[0-9][0-9]*$') ) then
local n = mw.ustring.gsub(k, '^[a-z]*([0-9]*)$', '%1')
local n = mw.ustring.gsub(k, '^[a-z]*([0-9]*)$', '%1')
if (targs['list' .. n] == nil and pargs['group' .. n] == nil
if (targs['list' .. n] == nil and args['group' .. n] == nil
and pargs['sect' .. n] == nil and pargs['section' .. n] == nil) then
and args['sect' .. n] == nil and args['section' .. n] == nil) then
targs['list' .. n] = concatstrings(
targs['list' .. n] = (args['list' .. n] or '') .. (args['content' .. n] or '')
{pargs['list' .. n] or '', pargs['content' .. n] or ''})
end
end
elseif (k:match('^group[0-9][0-9]*$')  
elseif (k:match('^group[0-9][0-9]*$')  
Line 52: Line 53:
if targs['list' .. n] == nil then
if targs['list' .. n] == nil then
local titlestyle = concatstyles(
local titlestyle = concatstyles(
{pargs['groupstyle'] or '',pargs['secttitlestyle'] or '',  
{args['groupstyle'] or '',args['secttitlestyle'] or '',  
pargs['group' .. n .. 'style'] or '',  
args['group' .. n .. 'style'] or '',  
pargs['section' .. n ..'titlestyle'] or ''})
args['section' .. n ..'titlestyle'] or ''})
local liststyle = concatstyles(
local liststyle = concatstyles(
{pargs['liststyle'] or '', pargs['contentstyle'] or '',  
{args['liststyle'] or '', args['contentstyle'] or '',  
pargs['list' .. n .. 'style'] or '',  
args['list' .. n .. 'style'] or '',  
pargs['content' .. n .. 'style'] or ''})
args['content' .. n .. 'style'] or ''})
local title = concatstrings(
local title = concatstrings(
{pargs['group' .. n] or '',  
{args['group' .. n] or '',  
pargs['sect' .. n] or '',
args['sect' .. n] or '',
pargs['section' .. n] or ''})
args['section' .. n] or ''})
local list = concatstrings(
local list = concatstrings(
{pargs['list' .. n] or '',  
{args['list' .. n] or '',  
pargs['content' .. n] or ''})
args['content' .. n] or ''})
local state = (pargs['abbr' .. n] and pargs['abbr' .. n] == pargs['selected'])  
local state = (args['abbr' .. n] and args['abbr' .. n] == args['selected'])  
and 'uncollapsed' or pargs['state' .. n] or 'collapsed'
and 'uncollapsed' or args['state' .. n] or 'collapsed'
 
targs['list' .. n] = Navbox._navbox(
targs['list' .. n] = Navbox._navbox(
{'child', navbar = 'plain', state = state,
{navbar = 'plain', state = state,
basestyle = pargs['basestyle'],
basestyle = args['basestyle'],
title = title, titlestyle = titlestyle,
title = title, titlestyle = titlestyle,
list1 = list, liststyle = liststyle,
list = list, liststyle = liststyle,
listclass = pargs['list' .. n .. 'class'],
listclass = args['list' .. n .. 'class'],
image = pargs['image' .. n],
image = args['image' .. n],
imageleft = pargs['imageleft' .. n],
imageleft = args['imageleft' .. n],
listpadding = pargs['listpadding']})
listpadding = args['listpadding']})
end
end
end
end
end
end
end
end
-- ordering of style and bodystyle
targs['style'] = concatstyles({targs['style'] or '', targs['bodystyle'] or ''})
targs['bodystyle'] = nil
-- child or subgroup
-- child or subgroup
if targs['border'] == nil then targs['border'] = pargs[1] end
if targs['border'] == nil then targs['border'] = args[1] end


return Navbox._navbox(targs)
return Navbox._navbox(targs)
end
end


function q.navbox(frame)
function p.navbox(frame)
local pargs = require('Module:Arguments').getArgs(frame, {wrappers = {'Template:Navbox with collapsible groups'}})
if not getArgs then
getArgs = require('Module:Arguments').getArgs
end
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.
-- Read the arguments in the order they'll be output in, to make references number in the right order.
local _
local _
_ = pargs.title
_ = args.title
_ = pargs.above
_ = args.above
for i = 1, 20 do
for i = 1, 20 do
_ = pargs["group" .. tostring(i)]
_ = args["group" .. tostring(i)]
_ = pargs["list" .. tostring(i)]
_ = args["list" .. tostring(i)]
end
end
_ = pargs.below
_ = args.below


return q._navbox(pargs)
return p._navbox(args)
end
end


return q
return p
Please note that all contributions to Nonbinary Wiki are considered to be released under the Creative Commons Attribution-ShareAlike (see Nonbinary Wiki:Copyrights for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource. Do not submit copyrighted work without permission!
Cancel Editing help (opens in new window)

Template used on this page: