|
|
(未显示同一用户的3个中间版本) |
第1行: |
第1行: |
|
| |
|
| --理论上能调整所有的style,并可新增class
| |
| --|(css) 整個storage container的css
| |
| --|stab(css) 选择栏的css。曾经为select(css)
| |
| --|sitem(css) 选择栏中每个物件的css
| |
| --|ctab(css) 内容栏的css。曾经为text(css)
| |
| --|citem(css) 内容栏中每个物件的css
| |
|
| |
| --[[ 非css的参数设定
| |
| splitCount = 5: 决定每行有几个物件
| |
| initialTab = nil: 决定页面加载出来时,收纳表预设显示的tab。
| |
| nil的话就是一开始都不显示东西
| |
| textDisplay = down: 内容相对于选择栏的位置,可输入
| |
| top(内容在选择栏上)
| |
| down(内容在选择栏下)
| |
| left(内容在选择栏左)
| |
| right(内容在选择栏右)
| |
| --]]
| |
|
| |
| local p = {}
| |
| local notCSS = { --非CSS的参数
| |
| splitCount = true,
| |
| initialTab = true,
| |
| textDisplay = true,
| |
| }
| |
|
| |
| --用于处理编号非连续的情况与css优先度的问题
| |
| --优先度问题如:直接塞:css(table),margin-left被margin盖掉
| |
| --前者范围较小,因此(应该是)希望前者优先
| |
| local ordering = {
| |
| tabIndices = {},
| |
| stgt = {},
| |
| stab = {},
| |
| sitm = {},
| |
| ctab = {},
| |
| citm = {},
| |
| }
| |
|
| |
| local CSSvalue = {
| |
| stgt = {},
| |
| stab = {},
| |
| sitm = {},
| |
| ctab = {},
| |
| citm = {},
| |
| }
| |
|
| |
| local initialTab = nil
| |
|
| |
| --处理旧参数名与别名
| |
| local function replaceArgsName(str)
| |
| str = str:gsub('^select', 'stab')
| |
| str = str:gsub('^text', 'ctab')
| |
| str = str:gsub('^sitem', 'sitm')
| |
| str = str:gsub('^citem', 'citm')
| |
| --[[str = str:gsub('^selecttab', 'stab')
| |
| str = str:gsub('^selectitem', 'sitem')
| |
| str = str:gsub('^contenttab', 'ctab')
| |
| str = str:gsub('^contentitem', 'citem')]]--
| |
| return str:gsub("^%u", string.lower) --第一个字小写
| |
| end
| |
|
| |
|
| |
|
| |
| --空的数值填入预设值
| |
| local function fillWithDefaultCSS(contents, horizontal)
| |
| local defaults = {
| |
| stgt = {class = 'min-width:800px',},
| |
| stab = {class = '',},
| |
| sitm = {class = '',},
| |
| ctab = {class = '',},
| |
| citm = {class = '',},
| |
| }
| |
| if horizontal then
| |
| contents['splitCount'] = contents['splitCount'] or '1'
| |
| end
| |
| contents['splitCount'] = contents['splitCount'] or '5'
| |
|
| |
| local elements = {'stgt', 'stab', 'sitm', 'ctab', 'citm'}
| |
| for _, elem in ipairs(elements) do
| |
| local resizeFlowDir = {height='y', width='x'}
| |
| for size, dir in pairs(resizeFlowDir) do
| |
| if CSSvalue[elem][size] then
| |
| defaults[elem]['overflow-'..dir] = 'auto'
| |
| end
| |
| end
| |
| for CSS, defaultValue in pairs(defaults[elem]) do
| |
| CSSvalue[elem][CSS] = CSSvalue[elem][CSS] or defaultValue
| |
| end
| |
| end
| |
| end
| |
|
| |
|
| |
|
| |
| --处理选择栏
| |
| local function renderSelect(contents)
| |
| local tabs_pages = mw.html.create('div')
| |
| :addClass('tabs_pages stab ' .. CSSvalue['stab']['class'])
| |
| :css('grid-template-columns',
| |
| string.rep('1fr ', tonumber(contents['splitCount'])))
| |
|
| |
| for _, CSS in ipairs(ordering['stab']) do
| |
| tabs_pages:css(CSS, CSSvalue['stab'][CSS])
| |
| end
| |
|
| |
| for originalIndex, tabIndex in ipairs(ordering['tabIndices']) do
| |
| local sitm = tabs_pages:tag('div')
| |
| :addClass('tab sitm ' .. CSSvalue['sitm']['class'])
| |
| :wikitext(contents['tab' .. tabIndex])
| |
| if originalIndex == initialTab then sitm:addClass('active') end
| |
| for _, CSS in ipairs(ordering['sitm']) do
| |
| sitm:css(CSS, CSSvalue['sitm'][CSS])
| |
| end
| |
| end
| |
|
| |
| return tostring(tabs_pages)
| |
| end
| |
|
| |
|
| |
|
| |
| --处理内容栏
| |
| local function renderContent(contents)
| |
| local tabs_contents = mw.html.create('div')
| |
| :addClass('tabs-contents ctab ' .. CSSvalue['ctab']['class'])
| |
|
| |
| for _, CSS in ipairs(ordering['ctab']) do
| |
| tabs_contents:css(CSS, CSSvalue['ctab'][CSS])
| |
| end
| |
|
| |
| for originalIndex, tabIndex in ipairs(ordering['tabIndices']) do
| |
| local citm = tabs_contents:tag('div')
| |
| :addClass('tab-c citm ' .. CSSvalue['citm']['class'])
| |
| :wikitext(contents['content' .. tabIndex])
| |
| if originalIndex == initialTab then citm:addClass('active') end
| |
| for _, CSS in ipairs(ordering['citm']) do
| |
| citm:css(CSS, CSSvalue['citm'][CSS])
| |
| end
| |
| end
| |
|
| |
| return tostring(tabs_contents)
| |
| end
| |
|
| |
|
| |
|
| |
| function p.selectTable(frame)
| |
| local args = {}
| |
|
| |
| --获取页面传来的参数,而非模板#invoke時的参数
| |
| local page_args = frame:getParent().args;
| |
|
| |
| --将获取的参数传给args
| |
| for k, v in pairs(page_args) do
| |
| k = '' .. k
| |
| if v ~= 'nil' then
| |
| if notCSS[k] then args[k] = v
| |
| else args[replaceArgsName(k)] = v end
| |
| end
| |
| end
| |
| initialTab = tonumber(args['initialTab'])
| |
|
| |
|
| |
| --处理CSSvalue
| |
| local validArgs = {stgt=true, stab=true, sitm=true, ctab=true, citm=true}
| |
| for k, v in pairs(args) do
| |
| k = '' .. k; v = '' .. v
| |
| if not (notCSS[k] or k:match('^content%d+')) then
| |
| if k:match('^tab%d+$') then
| |
| table.insert(ordering['tabIndices'], tonumber(k:sub(4)))
| |
| elseif validArgs[k:sub(1, 4)] then
| |
| local prefix = k:sub(1, 4)
| |
| local CSS = k:sub(5)
| |
| CSSvalue[prefix][CSS] = v
| |
| else
| |
| CSSvalue['stgt'][k] = v
| |
| end
| |
| end
| |
| end
| |
| local horizontal = args['textDisplay']=='left' or args['textDisplay']=='right'
| |
| fillWithDefaultCSS(args, horizontal)
| |
| if horizontal then
| |
| CSSvalue['stgt']['class'] = CSSvalue['stgt']['class'] .. ' hori'
| |
| CSSvalue['stab']['class'] = CSSvalue['stab']['class'] .. ' hori'
| |
| CSSvalue['ctab']['class'] = CSSvalue['stab']['class'] .. ' hori'
| |
| end
| |
|
| |
|
| |
| --处理ordering
| |
| local elements = {'stgt', 'stab', 'sitm', 'ctab', 'citm'}
| |
| for _, s in ipairs(elements) do
| |
| for k, _ in pairs(CSSvalue[s]) do
| |
| if k ~= 'class' then table.insert(ordering[s], k) end
| |
| end
| |
| table.sort(ordering[s])
| |
| end
| |
| table.sort(ordering['tabIndices'])
| |
|
| |
| local mainDiv = mw.html.create('div')
| |
| mainDiv:addClass('tabs-container stgt ' .. CSSvalue['stgt']['class'])
| |
| for _, divCSS in ipairs(ordering['stgt']) do
| |
| mainDiv:css(divCSS, CSSvalue['stgt'][divCSS])
| |
| end
| |
|
| |
| if args['textDisplay'] == 'top' or args['textDisplay'] == 'left' then
| |
| mainDiv:node(renderContent(args))
| |
| mainDiv:node(renderSelect(args))
| |
| else
| |
| mainDiv:node(renderSelect(args))
| |
| mainDiv:node(renderContent(args))
| |
| end
| |
|
| |
| return tostring(mainDiv)
| |
| end
| |
|
| |
| return p
| |