445
edits
m (ce / test?) |
m (38 revisions imported from wikipedia:Module:Navbox_with_collapsible_groups: see Topic:Vtixlm0q28eo6jtf) |
||
(23 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
-- This module implements {{Navbox with collapsible groups}} | -- This module implements {{Navbox with collapsible groups}} | ||
local | local q = {} | ||
local Navbox = require('Module:Navbox') | local Navbox = require('Module:Navbox') | ||
-- helper functions | -- helper functions | ||
Line 21: | Line 19: | ||
end | end | ||
function | function q._navbox(pargs) | ||
-- table for args passed to navbox | -- table for args passed to navbox | ||
local targs = {} | local targs = {} | ||
Line 38: | Line 34: | ||
['imageleft']=true,['imageleftstyle']=true | ['imageleft']=true,['imageleftstyle']=true | ||
} | } | ||
for k,v in pairs( | for k,v in pairs(pargs) do | ||
if k and type(k) == 'string' then | if k and type(k) == 'string' then | ||
if passthrough[k] then | if passthrough[k] then | ||
Line 45: | Line 41: | ||
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 | if (targs['list' .. n] == nil and pargs['group' .. n] == nil | ||
and | and pargs['sect' .. n] == nil and pargs['section' .. n] == nil) then | ||
targs['list' .. n] = concatstrings( | targs['list' .. n] = concatstrings( | ||
{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]*$') | ||
or k:match('^sect[0-9][0-9]*$') | or k:match('^sect[0-9][0-9]*$') | ||
or k:match('^section[0-9][0-9]*$') ) then | or k:match('^section[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 then | if targs['list' .. n] == nil then | ||
local titlestyle = concatstyles( | local titlestyle = concatstyles( | ||
{ | {pargs['groupstyle'] or '',pargs['secttitlestyle'] or '', | ||
pargs['group' .. n .. 'style'] or '', | |||
pargs['section' .. n ..'titlestyle'] or ''}) | |||
local liststyle = concatstyles( | local liststyle = concatstyles( | ||
{ | {pargs['liststyle'] or '', pargs['contentstyle'] or '', | ||
pargs['list' .. n .. 'style'] or '', | |||
pargs['content' .. n .. 'style'] or ''}) | |||
local title = concatstrings( | local title = concatstrings( | ||
{ | {pargs['group' .. n] or '', | ||
pargs['sect' .. n] or '', | |||
pargs['section' .. n] or ''}) | |||
local list = concatstrings( | local list = concatstrings( | ||
{ | {pargs['list' .. n] or '', | ||
pargs['content' .. n] or ''}) | |||
local state = ( | local state = (pargs['abbr' .. n] and pargs['abbr' .. n] == pargs['selected']) | ||
and 'uncollapsed' or | and 'uncollapsed' or pargs['state' .. n] or 'collapsed' | ||
basestyle = | targs['list' .. n] = Navbox._navbox( | ||
{'child', navbar = 'plain', state = state, | |||
basestyle = pargs['basestyle'], | |||
title = title, titlestyle = titlestyle, | title = title, titlestyle = titlestyle, | ||
list1 = list, liststyle = liststyle, | list1 = list, liststyle = liststyle, | ||
listclass = | listclass = pargs['list' .. n .. 'class'], | ||
image = | image = pargs['image' .. n], | ||
imageleft = | imageleft = pargs['imageleft' .. n], | ||
listpadding = | listpadding = pargs['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'] = | if targs['border'] == nil then targs['border'] = pargs[1] end | ||
return Navbox._navbox(targs) | return Navbox._navbox(targs) | ||
end | end | ||
function | function q.navbox(frame) | ||
local pargs = require('Module:Arguments').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 | ||
_ = | _ = pargs.above | ||
for i = 1, 20 do | for i = 1, 20 do | ||
_ = | _ = pargs["group" .. tostring(i)] | ||
_ = | _ = pargs["list" .. tostring(i)] | ||
end | end | ||
_ = | _ = pargs.below | ||
return | return q._navbox(pargs) | ||
end | end | ||
return | return q |