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

跳到导航 跳到搜索
添加406字节 、​ 2022年9月11日 (星期日)
无编辑摘要
无编辑摘要
无编辑摘要
 
(未显示同一用户的14个中间版本)
第1行: 第1行:


--理论上能调整所有的style,并可新增class
--理论上能调整所有的style,并可新增class
--|(css)  整個storage container的css
--|stab(css)  选择栏的css。曾经为select(css)
--|stab(css)  选择栏的css。曾经为select(css)
--|sitem(css)  选择栏中每个物件的css
--|sitem(css)  选择栏中每个物件的css
第8行: 第9行:
--[[ 非css的参数设定
--[[ 非css的参数设定
splitCount      = 5:    决定每行有几个物件
splitCount      = 5:    决定每行有几个物件
initialTab      = nil:  决定页面加载出来时,收纳表预设显示的tab。
                        nil的话就是一开始都不显示东西
textDisplay    = down: 内容相对于选择栏的位置,可输入
textDisplay    = down: 内容相对于选择栏的位置,可输入
                         top(内容在选择栏上)
                         top(内容在选择栏上)
                         down(内容在选择栏下)
                         down(内容在选择栏下)
                         left(内容在选择栏左,此时若用户无指定,则selectWidth会被预设成20%、textWidth被设成60%、textHeight, selectHeight皆被设成400px)
                         left(内容在选择栏左)
                         right(内容在选择栏右,同上)
                         right(内容在选择栏右)
--]]
--]]


local p = {}
local p = {}
local notCSS = { --非CSS的参数
local notCSS = { --非CSS的参数
    splitCount  = true,
    initialTab  = true,
     textDisplay = true,
     textDisplay = true,
    splitCount  = true
}
}


第26行: 第30行:
local ordering = {
local ordering = {
     tabIndices = {},
     tabIndices = {},
     div = {},
     stgt = {},
     stab = {},
     stab = {},
     sitem = {},
     sitm = {},
     ctab = {},
     ctab = {},
     citem = {},
     citm = {},
}
}
local CSSvalue = {
local CSSvalue = {
     div = {class=''},
     stgt = {},
     stab = {
     stab = {},
        class      = '',
     sitm = {},
        splitCount = '5',
     ctab = {},
        display    = 'grid',
     citm = {},
        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=''},
}
}


 
local initialTab = nil


--处理旧参数名与别名
--处理旧参数名与别名
第62行: 第51行:
     str = str:gsub('^select', 'stab')
     str = str:gsub('^select', 'stab')
     str = str:gsub('^text', 'ctab')
     str = str:gsub('^text', 'ctab')
     str = str:gsub('^sitem', '^sitm')
     str = str:gsub('^sitem', 'sitm')
     str = str:gsub('^citem', '^citm')
     str = str:gsub('^citem', 'citm')
     --[[str = str:gsub('^selecttab', 'stab')
     --[[str = str:gsub('^selecttab', 'stab')
     str = str:gsub('^selectitem', 'sitem')
     str = str:gsub('^selectitem', 'sitem')
第69行: 第58行:
     str = str:gsub('^contentitem', 'citem')]]--
     str = str:gsub('^contentitem', 'citem')]]--
     return str:gsub("^%u", string.lower) --第一个字小写
     return str:gsub("^%u", string.lower) --第一个字小写
end
--空的数值填入预设值
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
end


第74行: 第93行:


--处理选择栏
--处理选择栏
local function renderSelect(contents, horizontal)
local function renderSelect(contents)
     local tabs_pages = mw.html.create('div')
     local tabs_pages = mw.html.create('div')
         :addClass('tabs_pages ' .. CSSvalue['stab']['class'])
         :addClass('tabs_pages stab ' .. CSSvalue['stab']['class'])
         :css('grid-template-columns',
         :css('grid-template-columns',
             string.rep('1fr ', tonumber(contents['splitCount'])))
             string.rep('1fr ', tonumber(contents['splitCount'])))
    if horizontal then
        tabs_pages
            :css('display', 'inline-grid')
            :css('height', '400px')
            :css('overflow-y', 'auto')
            :css('width', '20%')
    end
    if CSSvalue['stab']['height'] ~= nil then
        tabs_pages:css('overflow-y', 'auto')
    end
    if CSSvalue['stab']['width'] ~= nil then
        tabs_pages:css('overflow-x', 'auto')
    end


     for _, CSS in ipairs(ordering['stab']) do
     for _, CSS in ipairs(ordering['stab']) do
第98行: 第103行:
     end
     end


     for _, tabIndex in ipairs(ordering['tabIndices']) do
     for originalIndex, tabIndex in ipairs(ordering['tabIndices']) do
         tabs_pages:tag('div')
         local sitm = tabs_pages:tag('div')
             :addClass('tab ' .. CSSvalue['sitm']['class'])
             :addClass('tab sitm ' .. CSSvalue['sitm']['class'])
             :wikitext(contents['tab' .. tabIndex])
             :wikitext(contents['tab' .. tabIndex])
        if originalIndex == initialTab then sitm:addClass('active') end
         for _, CSS in ipairs(ordering['sitm']) do
         for _, CSS in ipairs(ordering['sitm']) do
             tabs_pages:css(CSS, CSSvalue['sitm'][CSS])
             sitm:css(CSS, CSSvalue['sitm'][CSS])
         end
         end
     end
     end
第113行: 第119行:


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


    if horizontal then
        tabs_contents
            :css('height', '400px')
            :css('overflow-y', 'auto')
            :css('width', '60%')
    end
    if CSSvalue['ctab']['height'] ~= nil then
        tabs_contents:css('overflow-y', 'auto')
    end
    if CSSvalue['ctab']['width'] ~= nil then
        tabs_contents:css('overflow-x', 'auto')
    end
     for _, CSS in ipairs(ordering['ctab']) do
     for _, CSS in ipairs(ordering['ctab']) do
         tabs_contents:css(CSS, CSSvalue['ctab'][CSS])
         tabs_contents:css(CSS, CSSvalue['ctab'][CSS])
     end
     end


     for _, tabIndex in ipairs(ordering['tabIndices']) do
     for originalIndex, tabIndex in ipairs(ordering['tabIndices']) do
         tabs_contents:tag('div')
         local citm = tabs_contents:tag('div')
             :addClass('tab-c ' .. CSSvalue['citm']['class'])
             :addClass('tab-c citm ' .. CSSvalue['citm']['class'])
             :wikitext(contents['content' .. tabIndex])
             :wikitext(contents['content' .. tabIndex])
        if originalIndex == initialTab then citm:addClass('active') end
         for _, CSS in ipairs(ordering['citm']) do
         for _, CSS in ipairs(ordering['citm']) do
             tabs_contents:css(CSS, CSSvalue['citm'][CSS])
             citm:css(CSS, CSSvalue['citm'][CSS])
         end
         end
     end
     end
第148行: 第143行:


function p.selectTable(frame)
function p.selectTable(frame)
     local args = {splitCount=5}
     local args = {}


     --获取页面传来的参数,而非模板#invoke時的参数
     --获取页面传来的参数,而非模板#invoke時的参数
第155行: 第150行:
     --将获取的参数传给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
    k = '' .. k
         if v ~= 'nil' then
            if notCSS[k] then args[k] = v
            else args[replaceArgsName(k)] = v end
        end
     end
     end
     table.sort(args)
     initialTab = tonumber(args['initialTab'])


     local validArgs = {stab=true, sitm=true, ctab=true, citm=true}
 
     for k, v in pairs(args) do
    --处理CSSvalue
     local validArgs = {stgt=true, stab=true, sitm=true, ctab=true, citm=true}
     for k, v in pairs(args) do  
         k = '' .. k; v = '' .. v
         k = '' .. k; v = '' .. v
         if not (notCSS[k] or k:match('^content%d+')) then
         if not (notCSS[k] or k:match('^content%d+')) then
第169行: 第170行:
                 local CSS = k:sub(5)
                 local CSS = k:sub(5)
                 CSSvalue[prefix][CSS] = v
                 CSSvalue[prefix][CSS] = v
                if not (CSS == 'class') then table.insert(ordering[prefix], CSS) end
             else
             else
                table.insert(ordering['div'], k)
                 CSSvalue['stgt'][k] = v
                 CSSvalue['div'][k] = v
             end
             end
         end
         end
     end --由于args被排序过了,因此ordering内的阵列也是排序好的
     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
 


     local mainDiv = mw.html.create('div')
    --处理ordering
    local horizontal = args['textDisplay'] == 'left' or args['textDisplay'] == 'right'
     local elements = {'stgt', 'stab', 'sitm', 'ctab', 'citm'}
     if horizontal then
     for _, s in ipairs(elements) do
         mainDiv:css('display', 'flex')
         for k, _ in pairs(CSSvalue[s]) do
         args['splitCount'] = args['splitCount'] or 1
            if k ~= 'class' then table.insert(ordering[s], k) end
        end
         table.sort(ordering[s])
     end
     end
    table.sort(ordering['tabIndices'])


     mainDiv:addClass('tabs-container ' .. CSSvalue['div']['class'])
    local mainDiv = mw.html.create('div')
     for _, divCSS in ipairs(ordering['div']) do
     mainDiv:addClass('tabs-container stgt ' .. CSSvalue['stgt']['class'])
         mainDiv:css(divCSS, CSSvalue['div'][divCSS])
     for _, divCSS in ipairs(ordering['stgt']) do
         mainDiv:css(divCSS, CSSvalue['stgt'][divCSS])
     end
     end


     if args['textDisplay'] == 'top' or args['textDisplay'] == 'left' then
     if args['textDisplay'] == 'top' or args['textDisplay'] == 'left' then
         mainDiv:node(renderContent(args, horizontal))
         mainDiv:node(renderContent(args))
         mainDiv:node(renderSelect(args, horizontal))
         mainDiv:node(renderSelect(args))
     else
     else
         mainDiv:node(renderSelect(args, horizontal))
         mainDiv:node(renderSelect(args))
         mainDiv:node(renderContent(args, horizontal))
         mainDiv:node(renderContent(args))
     end
     end


导航菜单