463
个编辑
小无编辑摘要 |
小无编辑摘要 |
||
第1行: | 第1行: | ||
local p = {} | local p = {} | ||
-- | --处理可选择人名 | ||
function renderSelect(tabIndices, args) | |||
local splitCount = tonumber(args['splitCount']) | |||
local tabs_pages = mw.html.create('div') | |||
:addClass('tabs_pages') | |||
:css('display: grid') | |||
:css('grid-template-columns', string.rep('1fr ', splitCount)) | |||
for i, tabIndex in ipairs(tabIndices) do | |||
tabs_pages:node('strong') | |||
:addClass('tab') | |||
:wikitext(args['tab' .. tabIndex]) | |||
if (i-1)%splitCount==0 then tabs_pages:tag('br') end | |||
end | |||
return tabs_pages | |||
end | |||
--处理感言内容 | |||
local | function renderContent(tabIndices, args) | ||
local tabs_contents = mw.html.create('div') | |||
:addClass('tabs-contents') | |||
: | |||
for i, tabIndex in ipairs(tabIndices) do | |||
for i, | tabs_contents:node('div') | ||
:addClass('tab-c') | |||
:wikitext(args['content' .. tabIndex]) | |||
:wikitext(args[' | |||
end | end | ||
return tabs_contents | |||
return | |||
end | end | ||
function p.testimonials(frame) | |||
local args, tabIndices = {}, {} | |||
--获取页面传来的参数,而非模板本身的参数 | |||
-- | |||
local parent_args = frame:getParent().args; | local parent_args = frame:getParent().args; | ||
--可自定义每行几人,预设5 | |||
if args['splitCount'] == nil then args['splitCount'] = 5 end | |||
--将获取的参数传给args | --将获取的参数传给args | ||
for k, v in pairs(parent_args) do | for k, v in pairs(parent_args) do | ||
if v ~= 'nil' then | if v ~= 'nil' then args[k] = v end --避免空的参数 | ||
end | end | ||
--|tab(x) 的数字可能非123...,可能是012...、037...等 | |||
--用于处理上述情况 | |||
for k, v in pairs(args) do | for k, v in pairs(args) do | ||
local tabIndex = ('' .. k):match('^tab(%d+)$') | |||
local | if tabIndex then table.insert(tabIndices, tonumber(tabIndex)) end | ||
if | |||
end | end | ||
table.sort( | table.sort(tabIndices) | ||
--处理勋章 | --处理勋章 | ||
local mainDiv = | local mainDiv = mw.html.create('div') | ||
:addClass('tabs-container') | |||
mainDiv:node(renderSelect(tabIndices, args)) | |||
mainDiv:node(renderContent(tabIndices, args)) | |||
return tostring(mainDiv) | return tostring(mainDiv) |