模块:收纳表:修订间差异
跳到导航
跳到搜索
小无编辑摘要 |
无编辑摘要 |
||
第1行: | 第1行: | ||
--各个可在模版中使用的的参数的用途,如 | |||
--(参数名)(=某值,代表预设值,nil代表空的值): (用途) | |||
--大小写有区别! | |||
--[[ | |||
selectHeight = nil: 选择栏的高度,如100px。若有设置而内容太长挤不进去,则右方会多一个滚动条 | |||
textHeight = nil: 内容框的高度,如10em。同上。 | |||
selectWidth = nil: 选择栏的宽度,如50%。若有设置而内容太长挤不进去,则下方会多一个滚动条 | |||
textWidth = nil: 内容框的宽度,如75ch。同上。 | |||
splitCount = 5: 决定每行有几个物件 | |||
textDisplay = top: 内容相对于选择栏的位置,可输入 | |||
top(内容在选择栏上) | |||
down(内容在选择栏下) | |||
left(内容在选择栏左,此时selectWidth会被设置成20%、textWidth被设成60%、textHeight, selectHeight皆被设成400px) | |||
right(内容在选择栏右,同上) | |||
--]] | |||
local p = {} | local p = {} | ||
--处理可选择人名 | --处理可选择人名 | ||
function renderSelect(tabIndices, args) | local function renderSelect(tabIndices, args) | ||
local splitCount = tonumber(args['splitCount']) | local splitCount = tonumber(args['splitCount']) | ||
local tabs_pages = mw.html.create('div') | local tabs_pages = mw.html.create('div') | ||
第9行: | 第26行: | ||
:css('display', 'grid') | :css('display', 'grid') | ||
:css('margin', '2.5%') | :css('margin', '2.5%') | ||
:css('gap', ' | :css('gap', '6px') | ||
:css('grid-template-columns', string.rep('1fr ', splitCount)) | :css('grid-template-columns', string.rep('1fr ', splitCount)) | ||
if args['textDisplay'] == 'left' or args['textDisplay'] == 'right' then | |||
tabs_pages | |||
:css('display', 'inline-grid') | |||
:css('height', '400px') | |||
:css('width', '20%') | |||
end | |||
if args['selectHeight'] ~= nil then | |||
tabs_pages | |||
:css('height', args['selectHeight']) | |||
:css('overflow-y', 'auto') | |||
end | |||
if args['selectWidth'] ~= nil then | |||
tabs_pages | |||
:css('width', args['selectWidth']) | |||
:css('overflow-x', 'auto') | |||
end | |||
for | for _, tabIndex in ipairs(tabIndices) do | ||
tabs_pages:tag('div') | tabs_pages:tag('div') | ||
:addClass('tab') | :addClass('tab') | ||
:css('margin', '0') | :css('margin', '0') | ||
:css('font-weight', '700') | :css('font-weight', '700') | ||
:wikitext(args['tab' .. tabIndex]) | :wikitext(args['tab' .. tabIndex]) | ||
第23行: | 第56行: | ||
return tostring(tabs_pages) | return tostring(tabs_pages) | ||
end | end | ||
--处理感言内容 | --处理感言内容 | ||
function renderContent(tabIndices, args) | local function renderContent(tabIndices, args) | ||
local tabs_contents = mw.html.create('div') | local tabs_contents = mw.html.create('div') | ||
:addClass('tabs-contents') | :addClass('tabs-contents') | ||
for | if args['textDisplay'] == 'left' or args['textDisplay'] == 'right' then | ||
tabs_contents | |||
:css('display', 'inline-grid') | |||
:css('height', '400px') | |||
:css('width', '60%') | |||
end | |||
if args['textHeight'] ~= nil then | |||
tabs_contents | |||
:css('height', args['textHeight']) | |||
:css('overflow-y', 'auto') | |||
end | |||
if args['textWidth'] ~= nil then | |||
tabs_contents | |||
:css('width', args['textWidth']) | |||
:css('overflow-x', 'auto') | |||
end | |||
for _, tabIndex in ipairs(tabIndices) do | |||
tabs_contents:tag('div') | tabs_contents:tag('div') | ||
:addClass('tab-c') | :addClass('tab-c') | ||
第40行: | 第91行: | ||
function p. | |||
local args | function p.selectTable(frame) | ||
local args = {splitCount=5} | |||
local tabIndices = {} | |||
--获取页面传来的参数,而非模板本身的参数 | --获取页面传来的参数,而非模板本身的参数 | ||
local parent_args = frame:getParent().args; | local parent_args = frame:getParent().args; | ||
--将获取的参数传给args | --将获取的参数传给args | ||
第56行: | 第106行: | ||
--|tab(x) 的数字可能非123...,可能是012...、037...等 | --|tab(x) 的数字可能非123...,可能是012...、037...等 | ||
--用于处理上述情况 | --用于处理上述情况 | ||
for k, | for k, _ in pairs(args) do | ||
local tabIndex = ('' .. k):match('^tab(%d+)$') | local tabIndex = ('' .. k):match('^tab(%d+)$') | ||
if tabIndex then table.insert(tabIndices, tonumber(tabIndex)) end | if tabIndex then table.insert(tabIndices, tonumber(tabIndex)) end | ||
第65行: | 第115行: | ||
local mainDiv = mw.html.create('div') | local mainDiv = mw.html.create('div') | ||
:addClass('tabs-container') | :addClass('tabs-container') | ||
mainDiv:node(renderSelect(tabIndices, args)) | |||
mainDiv:node(renderContent(tabIndices, args)) | if args['textDisplay'] == 'down' or args['textDisplay'] == 'left' then | ||
mainDiv:node(renderContent(tabIndices, args)) | |||
mainDiv:node(renderSelect(tabIndices, args)) | |||
else | |||
mainDiv:node(renderSelect(tabIndices, args)) | |||
mainDiv:node(renderContent(tabIndices, args)) | |||
end | |||
return tostring(mainDiv) | return tostring(mainDiv) |
2022年6月7日 (二) 15:35的版本
此模块的文档可以在模块:收纳表/doc创建
--各个可在模版中使用的的参数的用途,如 --(参数名)(=某值,代表预设值,nil代表空的值): (用途) --大小写有区别! --[[ selectHeight = nil: 选择栏的高度,如100px。若有设置而内容太长挤不进去,则右方会多一个滚动条 textHeight = nil: 内容框的高度,如10em。同上。 selectWidth = nil: 选择栏的宽度,如50%。若有设置而内容太长挤不进去,则下方会多一个滚动条 textWidth = nil: 内容框的宽度,如75ch。同上。 splitCount = 5: 决定每行有几个物件 textDisplay = top: 内容相对于选择栏的位置,可输入 top(内容在选择栏上) down(内容在选择栏下) left(内容在选择栏左,此时selectWidth会被设置成20%、textWidth被设成60%、textHeight, selectHeight皆被设成400px) right(内容在选择栏右,同上) --]] local p = {} --处理可选择人名 local function renderSelect(tabIndices, args) local splitCount = tonumber(args['splitCount']) local tabs_pages = mw.html.create('div') :addClass('tabs_pages') :css('display', 'grid') :css('margin', '2.5%') :css('gap', '6px') :css('grid-template-columns', string.rep('1fr ', splitCount)) if args['textDisplay'] == 'left' or args['textDisplay'] == 'right' then tabs_pages :css('display', 'inline-grid') :css('height', '400px') :css('width', '20%') end if args['selectHeight'] ~= nil then tabs_pages :css('height', args['selectHeight']) :css('overflow-y', 'auto') end if args['selectWidth'] ~= nil then tabs_pages :css('width', args['selectWidth']) :css('overflow-x', 'auto') end for _, tabIndex in ipairs(tabIndices) do tabs_pages:tag('div') :addClass('tab') :css('margin', '0') :css('font-weight', '700') :wikitext(args['tab' .. tabIndex]) end return tostring(tabs_pages) end --处理感言内容 local function renderContent(tabIndices, args) local tabs_contents = mw.html.create('div') :addClass('tabs-contents') if args['textDisplay'] == 'left' or args['textDisplay'] == 'right' then tabs_contents :css('display', 'inline-grid') :css('height', '400px') :css('width', '60%') end if args['textHeight'] ~= nil then tabs_contents :css('height', args['textHeight']) :css('overflow-y', 'auto') end if args['textWidth'] ~= nil then tabs_contents :css('width', args['textWidth']) :css('overflow-x', 'auto') end for _, tabIndex in ipairs(tabIndices) do tabs_contents:tag('div') :addClass('tab-c') :wikitext(args['content' .. tabIndex]) end return tostring(tabs_contents) end function p.selectTable(frame) local args = {splitCount=5} local tabIndices = {} --获取页面传来的参数,而非模板本身的参数 local parent_args = frame:getParent().args; --将获取的参数传给args for k, v in pairs(parent_args) do if v ~= 'nil' then args[k] = v end --避免空的参数 end --|tab(x) 的数字可能非123...,可能是012...、037...等 --用于处理上述情况 for k, _ in pairs(args) do local tabIndex = ('' .. k):match('^tab(%d+)$') if tabIndex then table.insert(tabIndices, tonumber(tabIndex)) end end table.sort(tabIndices) --处理勋章 local mainDiv = mw.html.create('div') :addClass('tabs-container') if args['textDisplay'] == 'down' or args['textDisplay'] == 'left' then mainDiv:node(renderContent(tabIndices, args)) mainDiv:node(renderSelect(tabIndices, args)) else mainDiv:node(renderSelect(tabIndices, args)) mainDiv:node(renderContent(tabIndices, args)) end return tostring(mainDiv) end return p