打开/关闭菜单
打开/关闭个人菜单
未登录
未登录用户的IP地址会在进行任意编辑后公开展示。

模块:Infobox/item/multidata:修订间差异

来自Cookie☆Wiki
(test)
(fix)
第36行: 第36行:
if i % itemsPerRow == 1 then result = result .. '<div style="display: flex">' end
if i % itemsPerRow == 1 then result = result .. '<div style="display: flex">' end
result = result .. frame:expandTemplate{ title = 'Infobox/item/data', args = {
result = result .. frame:expandTemplate{ title = 'Infobox/item/data', args = {
width = widthPercent, data = unnamed[i], bgcolor = p.getBackgroundColor(i, itemsPerRow)
width = widthPercent, data = unnamed[i],
label = parent.args['label' .. i],
bgcolor = p.getBackgroundColor(i, itemsPerRow)
} }
} }
if i % itemsPerRow == 0 then result = result .. '</div>' end
if i % itemsPerRow == 0 then result = result .. '</div>' end

2019年1月15日 (二) 06:20的版本

此模块的文档可以在模块:Infobox/item/multidata/doc创建

local p = {}

function p.getBackgroundColor(i, perRow)
    local isEvenColumn = ((math.floor((i-1)/perRow)%2)==0)
    local delta = 0
    if not isEvenColumn then delta = 1 end
    if (((i-1)%perRow)+delta) % 2 == 1 then return nil end
    return '#e5ded6'
end

function p.make()
    local frame = mw.getCurrentFrame()
    local parent = frame:getParent()
    local itemsPerRow = tonumber(parent.args['row-items'])
    if itemsPerRow == nil then
        error('"row-items" is not a number')
    end
    
    local count = 0
    local unnamed = {}
    for k, v in pairs(parent.args) do
        if tonumber(k) ~= nil and v ~= nil and v ~= '' then
            table.insert(unnamed, v)
            count = count + 1

        end
    end

    local result = ''

    local widthPercent = string.format('%.2f', 100/itemsPerRow) .. '%'
    local majorPart = math.floor(count / itemsPerRow) * itemsPerRow
    local i = 1
    while (true) do
        if i > majorPart then break end
        if i % itemsPerRow == 1 then result = result .. '<div style="display: flex">' end
        result = result .. frame:expandTemplate{ title = 'Infobox/item/data', args = {
            width = widthPercent, data = unnamed[i],
            label = parent.args['label' .. i],
            bgcolor = p.getBackgroundColor(i, itemsPerRow)
        } }
        if i % itemsPerRow == 0 then result = result .. '</div>' end
        i = i + 1
    end

    local remain = count - majorPart
    if remain ~= 0 then
        widthPercent = string.format('%.2f', 100/(remain)) .. '%'
        result = result .. '<div style="display: flex">'
        while (true) do
            if i > count then break end
            result = result .. frame:expandTemplate{ title = 'Infobox/item/data', args = {
                width = widthPercent, data = unnamed[i],
                label = parent.args['label' .. i],
                bgcolor = p.getBackgroundColor(i, itemsPerRow)
            } }
            i = i + 1
        end
        result = result .. '</div>'
    end

    return result
end

return p