Module:Sidebar: Difference between revisions
parser fix |
add support for {{sidebar with collapsible groups}} |
||
Line 191: | Line 191: | ||
return tostring(root) | return tostring(root) | ||
end | end | ||
function | function _collapsibleSidebar(args) | ||
local | args.abovestyle = 'border-top: 1px solid #aaa; border-bottom: 1px solid #aaa;' .. (args.abovestyle or '') | ||
for k, v in pairs(args) do | |||
local num = ('' .. k):match('^list(%d+)$') | |||
if num then | |||
local expand = args.expanded == 'all' or args.expanded == args['list' .. num .. 'name'] | |||
local row = HtmlBuilder.create('div') | |||
row | |||
.addClass('NavFrame') | |||
.addClass((not expand) and 'collapsed') | |||
.css('border', 'none') | |||
.css('padding', 0) | |||
.cssText(args.listframestyle) | |||
.cssText(args['list' .. num .. 'style']) | |||
.tag('div') | |||
.addClass('NavHead') | |||
.addClass(args.listtitleclass) | |||
.css('font-size', '105%') | |||
.css('background', 'transparent') | |||
.css('text-align', 'left') | |||
.cssText(args.basestyle) | |||
.cssText(args.listtitlestyle) | |||
.cssText(args['list' .. num .. 'titlestyle']) | |||
.wikitext(args['list' .. num .. 'title'] or 'List') | |||
.done() | |||
.tag('div') | |||
.addClass('NavContent') | |||
.addClass(args.listclass) | |||
.addClass(args['list' .. num .. 'class']) | |||
.css('font-size', '105%') | |||
.css('padding', '0.2em 0 0.4em') | |||
.css('text-align', 'center') | |||
.cssText(args.liststyle) | |||
.cssText(args['list' .. num .. 'style']) | |||
.wikitext(args['list' .. num]) | |||
args['content' .. num] = tostring(row) | |||
end | end | ||
end | end | ||
-- ParserFunctions considers the empty string to be false, so to preserve the previous | return _sidebar(args) | ||
end | |||
function makeWrapper(func) | |||
return function(frame) | |||
local origArgs | |||
if frame == mw.getCurrentFrame() then | |||
-- We're being called via #invoke. If the invoking template passed any args, use | |||
-- them. Otherwise, use the args that were passed into the template. | |||
origArgs = frame:getParent().args | |||
for k, v in pairs(frame.args) do | |||
origArgs = frame.args | |||
break | |||
end | |||
else | |||
-- We're being called from another module or from the debug console, so assume | |||
-- the args are passed in directly. | |||
origArgs = frame | |||
end | |||
-- ParserFunctions considers the empty string to be false, so to preserve the previous | |||
-- behavior of the template, change any empty arguments to nil, so Lua will consider | |||
-- them false too. | |||
local args = {} | |||
for k, v in pairs(origArgs) do | |||
if v ~= '' then | |||
args[k] = v | |||
end | |||
end | end | ||
return func(args) | |||
end | end | ||
end | end | ||
return | return { | ||
sidebar = makeWrapper(_sidebar), | |||
collapsible = makeWrapper(_collapsibleSidebar) | |||
} |