模块:收纳表:修订间差异

跳到导航 跳到搜索
添加4,711字节 、​ 2022年9月11日 (星期日)
无编辑摘要
无编辑摘要
无编辑摘要
 
(未显示同一用户的37个中间版本)
第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 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


--处理可选择人名
 
function renderSelect(tabIndices, args)
 
     local splitCount = tonumber(args['splitCount'])
--空的数值填入预设值
local function fillWithDefaultCSS(contents, horizontal)
     local defaults = {
        stgt = {class = '',},
        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')
     local tabs_pages = mw.html.create('div')
         :addClass('tabs_pages')
         :addClass('tabs_pages stab ' .. CSSvalue['stab']['class'])
        :css('display: grid')
         :css('grid-template-columns',
         :css('grid-template-columns', string.rep('1fr ', splitCount))
            string.rep('1fr ', tonumber(contents['splitCount'])))
 
    for _, CSS in ipairs(ordering['stab']) do
        tabs_pages:css(CSS, CSSvalue['stab'][CSS])
    end


     for i, tabIndex in ipairs(tabIndices) do
     for originalIndex, tabIndex in ipairs(ordering['tabIndices']) do
         tabs_pages:node('strong')
         local sitm = tabs_pages:tag('div')
             :addClass('tab')
             :addClass('tab sitm ' .. CSSvalue['sitm']['class'])
             :wikitext(args['tab' .. tabIndex])
             :wikitext(contents['tab' .. tabIndex])
         if (i-1)%splitCount==0 then tabs_pages:tag('br') end
         if originalIndex == initialTab then sitm:addClass('active') end
        for _, CSS in ipairs(ordering['sitm']) do
            sitm:css(CSS, CSSvalue['sitm'][CSS])
        end
     end
     end


     return tabs_pages
     return tostring(tabs_pages)
end
end




--处理感言内容
 
function renderContent(tabIndices, args)
--处理内容栏
local function renderContent(contents)
     local tabs_contents = mw.html.create('div')
     local tabs_contents = mw.html.create('div')
         :addClass('tabs-contents')
         :addClass('tabs-contents ctab ' .. CSSvalue['ctab']['class'])


     for i, tabIndex in ipairs(tabIndices) do
     for _, CSS in ipairs(ordering['ctab']) do
         tabs_contents:node('div')
         tabs_contents:css(CSS, CSSvalue['ctab'][CSS])
            :addClass('tab-c')
            :wikitext(args['content' .. tabIndex])
     end
     end


     return tabs_contents
    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
end




function p.testimonials(frame)
    local args, tabIndices = {}, {}


    --获取页面传来的参数,而非模板本身的参数
function p.selectTable(frame)
     local parent_args = frame:getParent().args;
     local args = {}


     --可自定义每行几人,预设5
     --获取页面传来的参数,而非模板#invoke時的参数
     if args['splitCount'] == nil then args['splitCount'] = 5 end
     local page_args = frame:getParent().args;


     --将获取的参数传给args
     --将获取的参数传给args
     for k, v in pairs(parent_args) do
     for k, v in pairs(page_args) do
         if v ~= 'nil' then args[k] = v end --避免空的参数
    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
     end


     --|tab(x) 的数字可能非123...,可能是012...、037...等
 
     --用于处理上述情况
     --处理ordering
     for k, v in pairs(args) do
     local elements = {'stgt', 'stab', 'sitm', 'ctab', 'citm'}
        local tabIndex = ('' .. k):match('^tab(%d+)$')
     for _, s in ipairs(elements) do
         if tabIndex then table.insert(tabIndices, tonumber(tabIndex)) end
        for k, _ in pairs(CSSvalue[s]) do
            if k ~= 'class' then table.insert(ordering[s], k) end
        end
         table.sort(ordering[s])
     end
     end
     table.sort(tabIndices)
     table.sort(ordering['tabIndices'])


    --处理勋章
     local mainDiv = mw.html.create('div')
     local mainDiv = mw.html.create('div')
        :addClass('tabs-container')
    mainDiv:addClass('tabs-container stgt ' .. CSSvalue['stgt']['class'])
     mainDiv:node(renderSelect(tabIndices, args))
     for _, divCSS in ipairs(ordering['stgt']) do
     mainDiv:node(renderContent(tabIndices, args))
        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)
     return tostring(mainDiv)

导航菜单