「モジュール:Navbox/former」の版間の差分

削除された内容 追加された内容
Waiesu (会話 | 投稿記録)
Template:Navbox with columnsにおいてcol指定が不連続な場合にエラーが表示される不具合を修正; 不具合の報告による
Waiesu (会話 | 投稿記録)
91行目:
if args.basestyle then basestyle = args.basestyle .. ';' end
local sortable_mt = {
__lt = function(a, b) return a.index < b.index end,
__concat = function(a, b)
local strA = (type(a) == 'table') and a.content or a or ''
local strB = (type(b) == 'table') and b.content or b or ''
return strA .. strB
end
}
local function sortable_args(tbl, index, content)
table.insert(tbl, {index = index, content = content})
setmetatable(tbl[#tbl], sortable_mt)
end
local switch = {
--common
list = function(num, v) sortable_args(list[num], =num, '\n' .. v) end,
liststyle = function(num, v) liststyle[num] = v end,
group = function(num, v) group[num] = v end,
101 ⟶ 113行目:
colheadercolspan = function(num,v) colheadercolspan[num] = v end,
colheaderstyle = function(num,v) colheaderstyle[num] = v end,
col = function(num, v) sortable_args(col[, num] =, '\n' .. v) end,
colstyle = function(num,v) colstyle[num] = v end,
colwidth = function(num,v) colwidth[num] = v end,
113 ⟶ 125行目:
section = function(num, v) group[num] = v end,
secttitlestyle = function(num, v) groupstyle[num] = v end,
content = function(num, v) list[num]sortable_args(content, =num, '\n' .. v) end,
contentstyle = function(num, v) liststyle[num] = v end,
image = function(num, v) image[num] = v end,
imageleft = function(num, v) imageleft[num] = v end,
}
for k, v in pairs(args) do
local str1, num, str2 = string.match(k, '(%D+)(%d+)(%D*)')
124 ⟶ 137行目:
end
table.sort(list)
local num = 0
forrowspan i= in pairs(#list) do
num = num + 1
end
rowspan = num
end
 
165 ⟶ 175行目:
result = result .. basestyle .. (args.titlestyle or '') .. '" colspan=' .. (colspan - (args.titlegroup and 1 or 0)) .. ' class="navbox-title">'
if (args.navbar == 'plain' or args.navbar == 'off') or (not args.name and (child or none)) then
result = result .. '<div style="float:left;width:6em;">&nbsp;</div>'
elseif args.navbar ~= 'off' then
else
local tbl = {args = {args.name, mini = '1', fontstyle = basestyle .. (args.titlestyle or '') .. ';border:none;', fontcolor = ''}}
result = result .. '<div style="float:left;width:6em;text-align:left;">' .. p.tnavbar(tbl) .. '</div>'
179 ⟶ 189行目:
result = result .. '<span ' .. args.titleclass .. ' style="font-size:' .. ((child or none) and '100' or '110') .. '%;">' .. args.title .. '</span>'
if args.state == 'plain' or args.state == 'off' then
result = result .. '<div style="float:right;width:6em;">&nbsp;</div>'
end
201 ⟶ 211行目:
result = result .. '<td style="width:0;' .. (args.imageleftstyle or '') .. '" rowspan=' .. rowspan .. '>' .. args.imageleft .. '</td>'
end
iflocal groupj = list[1] then.index
if group[j] then
result = result .. '<td class="navbox-group ' .. (args.groupclass or '') .. '" style="' .. basestyle .. (args.groupwidth and ('width:' .. args.groupwidth .. ';') or '') .. (args.groupstyle or '') .. ';' .. (groupstyle[1] or '') .. '">' .. group[1] .. '</td><td style="text-align:left;'
result = result .. '<td class="navbox-group ' .. (args.groupclass or '') .. '" style="' .. basestyle .. (args.groupwidth and ('width:' .. args.groupwidth .. ';') or '') .. (args.groupstyle or '') .. ';' .. (groupstyle[j] or '') .. '">' .. group[j] .. '</td><td style="text-align:left;'
else
result = result .. '<td colspan=2 style="'
end
result = result .. (args.groupwidth and '' or 'width:100%;') .. 'padding:0;' .. (args.liststyle or '') .. ';' .. (odd == 'odd' and (args.oddstyle or '') or (args.evenstyle or '')) .. ';' .. (liststyle[1j] or '') .. '" class="navbox-list navbox-' .. (args.evenodd == 'swap' and even or args.evenodd or odd) .. ' ' .. (args.listclass or '') .. '"><div style="padding:' .. (args.list1padding or args.listpadding or '0 0.25em') .. '">' .. list[1] .. '</div></td>'
if args.image then
result = result .. '<td style="width:0;' .. (args.imagestyle or '') .. '" rowspan=' .. rowspan .. '>' .. args.image .. '</td>'
215 ⟶ 226行目:
--remaining groups/lists
local function body2()
for i = 2, #list do
list[1] = nil
for i in pairs(list) do
odd, even = even, odd
iflocal groupj = list[i] then.index
if group[j] then
result = result .. '<tr><td class="navbox-group ' .. (args.groupclass or '') .. '" style="' .. basestyle .. (args.groupwidth and ('width:' .. args.groupwidth .. ';') or '') .. (args.groupstyle or '') .. ';' .. (groupstyle[i] or '') .. '">' .. group[i] .. '</td><td style="text-align:left;'
result = result .. '<tr><td class="navbox-group ' .. (args.groupclass or '') .. '" style="' .. basestyle .. (args.groupwidth and ('width:' .. args.groupwidth .. ';') or '') .. (args.groupstyle or '') .. ';' .. (groupstyle[j] or '') .. '">' .. group[j] .. '</td><td style="text-align:left;'
else
result = result .. '<tr><td colspan=2 style="'
end
result = result .. (args.groupwidth and '' or 'width:100%;') .. 'padding:0;' .. (args.liststyle or '') .. ';' .. (odd == 'odd' and (args.oddstyle or '') or (args.evenstyle or '')) .. ';' .. (liststyle[ij] or '') .. '" class="navbox-list navbox-' .. (args.evenodd == 'swap' and even or args.evenodd or odd) .. ' ' .. (args.listclass or '') .. '"><div style="padding:' .. (args.listpadding or '0 0.25em') .. '">' .. list[i] .. '</div></td></tr>'
end
end
284 ⟶ 295行目:
function p.with_columns(frame)
defArgs(frame)
table.sort(col)
mw.log(#col)
top()
if args.title then title() end
if args.above then above() end
if col[1] then
local coltbl = {}
local j = col[1].index
for i in pairs(col) do
local cols = '</div><table class="navbox-columns-table" style="border-spacing:2px;border-collapse:separate;text-align:left;margin:-2px;' .. ((colheader[j] or args.fullwidth) and 'width:100%;width:calc(100% + 4px);' or 'margin:0 auto;') .. (args.coltablestyle or '') .. '">'
coltbl[i] = {index = i, content = col[i], style = colstyle[i], width = colwidth[i]}
--Header row
if colheader[i] then
coltbl[i].header =if colheader[ij] then
cols = cols .. '<tr class="navbox-abovebelow" style="font-weight:bold;' .. (args.colheaderstyle or '') .. '">'
coltbl[i].headercolspan = colheadercolspan[i]
for i = 1, #col do
coltbl[i].headerstyle = colheaderstyle[i]
local j = col[i].index
end
if colfootercolheader[ij] then
cols = cols .. '<td colspan=' .. (colheadercolspan[j] or '1') .. ' style="' .. (colheaderstyle[j] or '') .. '">' .. colheader[j] .. '</td>'
coltbl[i].footer = colfooter[i]
end
coltbl[i].footercolspan = colfootercolspan[i]
coltbl[i].footerstyle = colfooterstyle[i]
end
end
table.sort(coltbl, function(a, b)
if a and b then
return a.index < b.index
else
return a
end
end)
local cols = '</div><table class="navbox-columns-table" style="border-spacing:2px;border-collapse:separate;text-align:left;margin:-2px;' .. ((colheader[1] or args.fullwidth) and 'width:100%;width:calc(100% + 4px);' or 'margin:0 auto;') .. (args.coltablestyle or '') .. '">'
--Header row
if colheader[1] then
cols = cols .. '<tr class="navbox-abovebelow" style="font-weight:bold;' .. (args.colheaderstyle or '') .. '">'
for i, v in ipairs(coltbl) do
if v.header then
cols = cols .. '<td colspan=' .. (v.headercolspan or '1') .. ' style="' .. (v.headerstyle or '') .. '">' .. v.header .. '</td>'
end
cols = cols .. '</tr>'
end
--Main columns
cols = cols .. '</tr>'
end
--Main columns
if col[1] then
cols = cols .. '<tr style="vertical-align:top;' .. (args.colstyle or '') .. '">'
if not (colheader[1j] or colfooter[1j] or args.fullwidth) then
iflocal args.paddingpaddingoff then= args.padding =and string.gsubfind(args.padding, '^0[ep]?[mx]?%?;?', 'off') end
if args.paddingnot == 'off'paddingoff then
cols = cols .. '<td style="width:' .. (args.padding or '5em;') .. '">&nbsp;&nbsp;&nbsp;</td>'
end
end
for i, v= in1, ipairs(coltbl)#col do
local j = col[i].index
cols = cols .. '<td style="padding:0;' .. (args.oddcolstyle or '') .. ';' .. (v.style or '') .. ';width:' .. (v.width or args.colwidth or '10em;') .. '"><div>' .. v.content .. '</div></td>'
cols = cols .. '<td style="padding:0;' .. (args.oddcolstyle or '') .. ';' .. (colstyle[j] or '') .. ';width:' .. (colwidth[j] or args.colwidth or '10em;') .. '">' .. col[i] .. '</td>'
args.oddcolstyle, args.evencolstyle = args.evencolstyle, args.oddcolstyle
end
cols = cols .. '</tr>'
--Footer row
end
if colfooter[j] then
--Footer row
cols = cols .. '<tr class="navbox-abovebelow" style="font-weight:bold;' .. (args.colfooterstyle or '') .. '">'
if colfooter[1] then
for i = 1, #col do
cols = cols .. '<tr class="navbox-abovebelow" style="font-weight:bold;' .. (args.colfooterstyle or '') .. '">'
local j = col[i].index
for i, v in ipairs(coltbl) do
if v.footercolfooter[j] then
cols = cols .. '<td colspan=' .. (v.footercolspancolfootercolspan[j] or '1') .. ' style="' .. (v.footerstylecolfooterstyle[j] or '') .. '">' .. v.footercolfooter[j] .. '</td>'
end
end
cols = cols .. '</tr>'
end
cols = cols .. '</trtable><div>'
table.insert(list, 1, cols)
table.insert(liststyle, 1, nil)
table.insert(group, 1, nil)
table.insert(groupstyle, 1, nil)
rowspan = rowspan + 1
end
cols = cols .. '</table><div>'
table.insert(list, 1, cols)
table.insert(liststyle, 1, nil)
table.insert(group, 1, nil)
table.insert(groupstyle, 1, nil)
rowspan = rowspan + 1
body1()
365 ⟶ 360行目:
function p.with_collapsible_groups(frame)
defArgs(frame)
table.sort(content)
top()
if args.title then title() end
371 ⟶ 367行目:
local i = 1
local function funcList()
list[i] = list[i] or content[i]
local j = list[i].index
collapsible = (args.selected and (args.selected == abbr[ij] or args.selected == group[ij]) or state[ij] == 'plain' or state[ij] == 'off') and '' or 'collapsible '
args.state = state[ij] or 'collapsed'
args.name = nil
args.titlestyle = basestyle .. (args.groupstyle or '') .. ';' .. (args.secttitlestyle or '') .. ';' .. (groupstyle[ij] or '')
args.liststyle = (args.liststyle or '') .. ';' .. (args.contentstyle or '') .. ';' .. (liststyle[ij] or '')
args.title, group[ij] = group[ij], nil
args.image = image[ij]
args.imageleft = imageleft[ij]
colspan = 2 + (args.imageleft and 1 or 0) + (args.image and 1 or 0)
rowspan = 1
result = result .. '<td style="' .. (args.groupwidth and '' or 'width:100%;') .. 'padding:0;' .. (args.liststyle or '') .. ';' .. (odd == 'odd' and (args.oddstyle or '') or (args.evenstyle or '')) .. ';' .. (liststyle[ij] or '') .. '" class="navbox-list navbox-' .. (args.evenodd == 'swap' and even or args.evenodd or odd) .. ' ' .. (args.listclass or '') .. '"><div>'
if args.title then
none = true
403 ⟶ 401行目:
result = result .. '<td style="width:0%;padding:0 0 0 2px;' .. (args.imagestyle or '') .. '" rowspan=' .. rowspan .. '>' .. args.image .. '</td>'
end
list[1] = nil
--i > 2
for ji in= pairs(2, #list) do
result = result .. '<tr>'
list[1] = list[ji]
i = j
funcList()
list[1], list[j] = nil, nil
end