463
个编辑
无编辑摘要 |
无编辑摘要 |
||
第16行: | 第16行: | ||
local p = {} | local p = {} | ||
local | local notCSS = { --非CSS的参数 | ||
textDisplay = true, | textDisplay = true, | ||
splitCount = true | splitCount = true | ||
} | } | ||
--用于处理编号非连续的情况与css优先度的问题 | |||
local | --优先度问题如:直接塞:css(table),margin-left被margin盖掉 | ||
--前者范围较小,因此(应该是)希望前者优先 | |||
local ordering = { | |||
tabIndices = {}, | |||
div = {}, | |||
stab = {}, | |||
} | sitem = {}, | ||
ctab = {}, | |||
citem = {}, | |||
} | } | ||
local | local CSSvalue = { | ||
class | div = {class=''}, | ||
display = ' | stab = { | ||
class = '', | |||
[' | splitCount = '5', | ||
display = 'grid', | |||
margin = '2.5%', | |||
gap = '6px', | |||
}, | |||
sitem = { | |||
class = '', | |||
margin = '0', | |||
padding = '0', | |||
['font-weight'] = '700', | |||
}, | |||
ctab = { | |||
class = '', | |||
display = 'inline', | |||
margin = '2.5%', | |||
['margin-left'] = '0', | |||
}, | |||
citem = {class=''}, | |||
} | } | ||
--处理旧参数名与别名 | --处理旧参数名与别名 | ||
第56行: | 第62行: | ||
str = str:gsub('^select', 'stab') | str = str:gsub('^select', 'stab') | ||
str = str:gsub('^text', 'ctab') | str = str:gsub('^text', 'ctab') | ||
--[[str = str:gsub('^selecttab', ' | str = str:gsub('^sitem', '^sitm') | ||
str = str:gsub('^selectitem', ' | str = str:gsub('^citem', '^citm') | ||
str = str:gsub('^contenttab', ' | --[[str = str:gsub('^selecttab', 'stab') | ||
str = str:gsub('^contentitem', ' | str = str:gsub('^selectitem', 'sitem') | ||
return str | str = str:gsub('^contenttab', 'ctab') | ||
str = str:gsub('^contentitem', 'citem')]]-- | |||
return str:gsub("^%u", string.lower) --第一个字小写 | |||
end | end | ||
--处理选择栏 | --处理选择栏 | ||
local function renderSelect(contents, | local function renderSelect(contents, horizontal) | ||
local tabs_pages = mw.html.create('div') | local tabs_pages = mw.html.create('div') | ||
:addClass('tabs_pages ' .. | :addClass('tabs_pages ' .. CSSvalue['stab']['class']) | ||
:css('grid-template-columns', | :css('grid-template-columns', | ||
string.rep('1fr ', tonumber( | string.rep('1fr ', tonumber(contents['splitCount']))) | ||
if | if horizontal then | ||
tabs_pages | tabs_pages | ||
:css('display', 'inline-grid') | :css('display', 'inline-grid') | ||
第77行: | 第87行: | ||
:css('width', '20%') | :css('width', '20%') | ||
end | end | ||
if | if CSSvalue['stab']['height'] ~= nil then | ||
tabs_pages:css('overflow-y', 'auto') | tabs_pages:css('overflow-y', 'auto') | ||
end | end | ||
if | if CSSvalue['stab']['width'] ~= nil then | ||
tabs_pages:css('overflow-x', 'auto') | tabs_pages:css('overflow-x', 'auto') | ||
end | end | ||
for _, CSS in ipairs(ordering['stab']) do | |||
tabs_pages:css(CSS, CSSvalue['stab'][CSS]) | |||
end | |||
for _, tabIndex in ipairs(ordering['tabIndices']) do | |||
for _, tabIndex in ipairs(tabIndices) do | |||
tabs_pages:tag('div') | tabs_pages:tag('div') | ||
:addClass('tab ' .. | :addClass('tab ' .. CSSvalue['sitm']['class']) | ||
:wikitext(contents['tab' .. tabIndex]) | :wikitext(contents['tab' .. tabIndex]) | ||
for _, CSS in ipairs(ordering['sitm']) do | |||
tabs_pages:css(CSS, CSSvalue['sitm'][CSS]) | |||
end | |||
end | end | ||
第103行: | 第113行: | ||
--处理内容栏 | --处理内容栏 | ||
local function renderContent(contents, | local function renderContent(contents, horizontal) | ||
local tabs_contents = mw.html.create('div') | local tabs_contents = mw.html.create('div') | ||
:addClass('tabs-contents ' .. | :addClass('tabs-contents ' .. CSSvalue['ctab']['class']) | ||
if | if horizontal then | ||
tabs_contents | tabs_contents | ||
:css('height', '400px') | :css('height', '400px') | ||
:css('overflow-y', 'auto') | :css('overflow-y', 'auto') | ||
:css('width', '60%') | :css('width', '60%') | ||
end | end | ||
if | if CSSvalue['ctab']['height'] ~= nil then | ||
tabs_contents:css('overflow-y', 'auto') | tabs_contents:css('overflow-y', 'auto') | ||
end | end | ||
if | if CSSvalue['ctab']['width'] ~= nil then | ||
tabs_contents:css('overflow-x', 'auto') | tabs_contents:css('overflow-x', 'auto') | ||
end | |||
for _, CSS in ipairs(ordering['ctab']) do | |||
tabs_contents:css(CSS, CSSvalue['ctab'][CSS]) | |||
end | end | ||
for _, tabIndex in ipairs(ordering['tabIndices']) do | |||
for _, tabIndex in ipairs(tabIndices) do | |||
tabs_contents:tag('div') | tabs_contents:tag('div') | ||
:addClass('tab-c ' .. | :addClass('tab-c ' .. CSSvalue['citm']['class']) | ||
:wikitext(contents['content' .. tabIndex]) | :wikitext(contents['content' .. tabIndex]) | ||
for _, CSS in ipairs(ordering['citm']) do | |||
tabs_contents:css(CSS, CSSvalue['citm'][CSS]) | |||
end | |||
end | end | ||
第141行: | 第148行: | ||
function p.selectTable(frame) | function p.selectTable(frame) | ||
local args = {} | local args = {splitCount=5} | ||
--获取页面传来的参数,而非模板#invoke時的参数 | --获取页面传来的参数,而非模板#invoke時的参数 | ||
第148行: | 第155行: | ||
--将获取的参数传给args | --将获取的参数传给args | ||
for k, v in pairs(page_args) do | for k, v in pairs(page_args) do | ||
if v ~= 'nil' then args[replaceArgsName(k)] = v end | if v ~= 'nil' then args[replaceArgsName(k)] = v end | ||
end | end | ||
table.sort(args) | |||
local validArgs = {stab=true, sitm=true, ctab=true, citm=true} | |||
for k, v in pairs(args) do | for k, v in pairs(args) do | ||
k = '' .. k | k = '' .. k; v = '' .. v | ||
if not ( | if not (notCSS[k] or k:match('^content%d+')) then | ||
if k:match('^tab%d+$') then | if k:match('^tab%d+$') then | ||
table.insert(tabIndices, tonumber(k:sub(4))) | table.insert(ordering['tabIndices'], tonumber(k:sub(4))) | ||
elseif | elseif validArgs[k:sub(1, 4)] then | ||
local prefix = k:sub(1, 4) | |||
local CSS = k:sub(5) | |||
CSSvalue[prefix][CSS] = v | |||
if not (CSS == 'class') then table.insert(ordering[prefix], CSS) end | |||
else | else | ||
table.insert(ordering['div'], k) | |||
CSSvalue['div'][k] = v | |||
end | end | ||
end | end | ||
end | end --由于args被排序过了,因此ordering内的阵列也是排序好的 | ||
local mainDiv = mw.html.create('div') | local mainDiv = mw.html.create('div') | ||
local | local horizontal = args['textDisplay'] == 'left' or args['textDisplay'] == 'right' | ||
if | if horizontal then | ||
mainDiv:css('display', 'flex') | |||
args['splitCount'] = args['splitCount'] or 1 | |||
end | |||
mainDiv:addClass('tabs-container ' .. CSSvalue['div']['class']) | |||
for _, divCSS in ipairs(ordering['div']) do | |||
mainDiv:css(divCSS, CSSvalue['div'][divCSS]) | |||
end | |||
:css(divCSS) | |||
if args['textDisplay'] == 'top' or args['textDisplay'] == 'left' then | if args['textDisplay'] == 'top' or args['textDisplay'] == 'left' then | ||
mainDiv:node(renderContent(args, | mainDiv:node(renderContent(args, horizontal)) | ||
mainDiv:node(renderSelect(args, | mainDiv:node(renderSelect(args, horizontal)) | ||
else | else | ||
mainDiv:node(renderSelect(args, | mainDiv:node(renderSelect(args, horizontal)) | ||
mainDiv:node(renderContent(args, | mainDiv:node(renderContent(args, horizontal)) | ||
end | end | ||