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

削除された内容 追加された内容
Waiesu (会話 | 投稿記録)
1行目:
local p = {}
 
--[[
6行目:
function p.tnavbar(frame)
local args = frame.args
if not args[1] then return ' ' end
local function tf(x)
61行目:
Define Arguments
]]
local args = {}
local border
local child, none = false, false
local collapsible = ''
local colspan, rowspan = 0, 0
local basestyle = ''
local odd, even = 'odd', 'even'
 
local list, liststyle = {}, {}
local group, groupstyle = {}, {}
local colheader, colheadercolspan, colheaderstyle = {}, {}, {}
local col, colstyle, colwidth = {}, {}, {}
local colfooter, colfootercolspan, colfooterstyle = {}, {}, {}
local abbr, state = {}, {}
local sect, section = {}, {}
local secttitlestyle = {}
local content, contentstyle = {}
local image, imageleft = {}, {}
 
local result = '' --出力用
 
local function defArgs(frame)
--グローバル変数として定義
args = require('Module:Arguments').getArgs(frame, {parentOnly = true})
border = args.border or args[1]
69 ⟶ 89行目:
colspan = 2 + (args.imageleft and 1 or 0) + (args.image and 1 or 0)
if args.basestyle then basestyle = args.basestyle .. ';' end
basestyle = args.basestyle .. ';'
else
basestyle = ''
end
bdcolor = args.style and string.match(args.style, 'background.-:(.-);') or '#fff' --ボーダー色
trborder = '<tr style="border-width:2px;border-style:solid none;border-color:' .. bdcolor .. '">' --ボーダーつきtr
list, liststyle = {}, {}
group, groupstyle = {}, {}
local switch = {
--common
list = function(num, v) list[num] = '\n' .. v end,
liststyle = function(num, v) liststyle[num] = v end,
group = function(num, v) group[num] = v end,
groupstyle = function(num, v) groupstyle[num] = v end,
--for with_columns
colheader = function(num,v) colheader[num] = v end,
colheadercolspan = function(num,v) colheadercolspan[num] = v end,
colheaderstyle = function(num,v) colheaderstyle[num] = v end,
col = function(num,v) col[num] = v end,
colstyle = function(num,v) colstyle[num] = v end,
colwidth = function(num,v) colwidth[num] = v end,
colfooter = function(num,v) colfooter[num] = v end,
colfootercolspan = function(num,v) colfootercolspan[num] = v end,
colfooterstyle = function(num,v) colfooterstyle[num] = v end,
--for with_collapsible_groups
abbr = function(num, v) abbr[num] = v end,
state = function(num, v) state[num] = v end,
sect = function(num, v) group[num] = v end,
section = function(num, v) group[num] = v end,
secttitlestyle = function(num, v) groupstyle[num] = v end,
content = function(num, v) list[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
iflocal str1, num, str2 = string.match(k, 'list(%D+)(%d+$)(%D*)') then
str1, num, str2 = str1 or '', tonumber(num), str2 or ''
list[tonumber(string.match(k, 'list(%d+)$'))] = '\n' .. v
if switch[str1 .. str2] and num then switch[str1 .. str2](num, v) end
v = nil
elseif string.match(k, 'list%d+style') then
liststyle[tonumber(string.match(k, 'list(%d+)style'))] = v
v = nil
elseif string.match(k, 'group%d+$') then
group[tonumber(string.match(k, 'group(%d+)$'))] = v
v = nil
elseif string.match(k, 'group%d+style') then
groupstyle[tonumber(string.match(k, 'group(%d+)style'))] = v
v = nil
end
end
rowspan = (#list - 1) * 2 - 1
odd, even = 'odd', 'even'
result = '' --出力用
end
 
112 ⟶ 137行目:
end
result = result .. '<table class="' .. (args.nowraplinks or '') .. (args.bodyclass or '')
if args.title then
result = result .. ' ' .. collapsible .. (args.state or ' autocollapse')
end
if child or none then
result = result .. ' navbox-subgroup" style="margin:-2px;width:calc(100% 0+ 4px);' .. (args.bodystyle or '') .. (args.style or '')
else
result = result .. '" style="background:transparent;color:inherit;border:1px solid ' .. bdcolor
end
result = result .. ';min-width:100%;border-spacing:02px;border-collapse:collapseseparate;' .. (args.innerstyle or '') .. '">'
end
 
129 ⟶ 154行目:
]]
local function title()
result = result .. trborder
if args.titlegroup then
result = result .. '<tr><td class="navbox-group ' .. (args.titlegroupclass or '') .. '" style="' .. basestyle .. (args.groupstyle or '') .. ';' .. (args.titlegroupstyle or '') .. '">' .. args.titlegroup .. '</td><th style="border-left:2px solid #fdfdfd;width:100%;'
else
result = result .. '<tr><th style="'
end
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>'
if args.navbar == 'off' then
if args.state == 'plain' then
result = result .. '<div style="float:right;width:6em;">&nbsp;</div>'
end
else
if args.state ~= 'plain' then
result = result .. '<div style="float:left;width:6em;text-align:left;">&nbsp;</div>'
end
end
else
local tbl = {args = {args.name, mini = '1', fontstyle = basestyle .. (args.titlestyle or '') .. ';border:none;', fontcolor = ''}}
result = result .. '<div style="float:left;width6emwidth:6em;text-align:left;">' .. p.tnavbar(tbl) .. '</div>'
if args.state == 'plain' then
result = result .. '<div style="float:right;width:6em;">&nbsp;</div>'
end
end
160 ⟶ 173行目:
args.titleclass = ''
end
result = result .. '<span ' .. args.titleclass .. ' style="font-size:' .. ((child or none) and '100' or '110') .. '%;">' .. args.title .. '</span></th></tr>'
if args.state == 'plain' or args.state == 'off' then
result = result .. '<div style="float:right;width:6em;">&nbsp;</div>'
end
result = result .. '</th></tr>'
end
167 ⟶ 185行目:
]]
local function above()
result = result .. trborder .. '<tr><td class="navbox-abovebelow ' .. (args.aboveclass or '') .. '" style="' .. basestyle .. (args.abovestyle or '') .. '" colspan=' .. colspan .. '>\n' .. args.above .. '</td></tr>'
end
175 ⟶ 193行目:
--first group/list and images
local function body1()
result = result .. trborder'<tr>'
if args.imageleft then
result = result .. '<td style="width:0;padding:0 2px 0 0;' .. (args.imageleftstyle or '') .. '" rowspan=' .. rowspan .. '>' .. args.imageleft .. '</td>'
end
if group[1] then
result = result .. '<td class="navbox-group ' .. (args.groupclass or '') .. '" style="border-right:2px solid ' .. bdcolor .. ';' .. basestyle .. (args.groupwidth and ('width:' .. args.groupwidth .. ';') or '') .. (args.groupstyle or '') .. ';' .. (groupstyle[1] or '') .. '">' .. group[1] .. '</td><td style="text-align:left;'
else
result = result .. '<td colspan=2 style="'
186 ⟶ 204行目:
result = result .. (args.groupwidth and '' or 'width:100%;') .. 'padding:0;' .. (args.liststyle or '') .. ';' .. (odd == 'odd' and (args.oddstyle or '') or (args.evenstyle or '')) .. ';' .. (liststyle[1] 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%;padding:0 0 0 2px;' .. (args.imagestyle or '') .. '" rowspan=' .. rowspan .. '>' .. args.image .. '</td>'
end
result = result .. '</tr>'
196 ⟶ 214行目:
for i in pairs(list) do
odd, even = even, odd
result = result .. trborder
if group[i] then
result = result .. '<tr><td class="navbox-group ' .. (args.groupclass or '') .. '" style="border-right:2px solid ' .. bdcolor .. ';' .. basestyle .. (args.groupwidth and ('width:' .. args.groupwidth .. ';') or '') .. (args.groupstyle or '') .. ';' .. (groupstyle[i] or '') .. '">' .. group[i] .. '</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[i] 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>'
210 ⟶ 227行目:
]]
local function below()
result = result .. trborder .. '<tr><td class="navbox-abovebelow ' .. (args.belowclass or '') .. '" style="' .. basestyle .. (args.belowstyle or '') .. '" colspan=' .. colspan .. '>\n' .. args.below .. '</td></tr>'
end
263 ⟶ 280行目:
function p.with_columns(frame)
defArgs(frame)
local colheader, colheadercolspan, colheaderstyle = {}, {}, {}
local col, colstyle, colwidth = {}, {}, {}
local colfooter, colfootercolspan, colfooterstyle = {}, {}, {}
for k, v in pairs(args) do
if string.match(k, 'col%d+header$') then
colheader[tonumber(string.match(k, 'col(%d+)header$'))] = v
elseif string.match(k, 'col%d+headercolspan') then
colheadercolspan[tonumber(string.match(k, 'col(%d+)headercolspan'))] = v
elseif string.match(k, 'col%d+headerstyle') then
colheaderstyle[tonumber(string.match(k, 'col(%d+)headerstyle'))] = v
elseif string.match(k, 'col%d+$') then
col[tonumber(string.match(k, 'col(%d+)$'))] = v
elseif string.match(k, 'col%d+style') then
colstyle[tonumber(string.match(k, 'col(%d+)style'))] = v
elseif string.match(k, 'col%d+width') then
colwidth[tonumber(string.match(k, 'col(%d+)width'))] = v
end
end
top()
if args.title then title() end
if args.above then above() end
local cols = '</div><table class="navbox-columns-table" style="border-spacing:02px;border-collapse:collapseseparate;text-align:left;' .. ((colheader[1] or args.fullwidth) and 'width:100%;' or 'margin:0 auto;') .. (args.coltablestyle or '') .. '">'
--Header row
if colheader[1] then
cols = cols .. '<tr class="navbox-abovebelow" style="border-bottom:2px solid #fdfdfd;font-weight:bold;' .. (args.colheaderstyle or '') .. '"><td colspan=' .. (colheadercolspan[1] or '1') .. ' style="border-right:2px solid #fdfdfd;' .. (colheaderstyle[1] or '') .. '">' .. colheader[1] .. '</td>'
colheader[1] = nil
for i in pairs(colheader) do
cols = cols .. '<td colspan=' .. (colheadercolspan[i] or '1') .. ' style="border-left:2px solid #fdfdfd;' .. (colheaderstyle[i] or '') .. '">' .. colheader[i] .. '</td>'
end
cols = cols .. '</tr>'
304 ⟶ 303行目:
end
end
cols = cols .. '<td style="border-right:2px solid #fdfdfd;padding:0;' .. (args.oddcolstyle or '') .. ';' .. (colstyle[1] or '') .. ';width:' .. (colwidth[1] or args.colwidth or '10em;') .. '"><div>' .. col[1] .. '</div></td>'
col[1] = nil
for i in pairs(col) do
cols = cols .. '<td style="border-left:2px solid #fdfdfd;padding:0;' .. (args.oddcolstyle or '') .. ';' .. (colstyle[i] or '') .. ';width:' .. (colwidth[i] or args.colwidth or '10em;') .. '"><div>' .. col[i] .. '</div></td>'
args.oddcolstyle, args.evencolstyle = args.evencolstyle, args.oddcolstyle
end
314 ⟶ 313行目:
--Footer row
if colfooter[1] then
cols = cols .. '<tr class="navbox-abovebelow" style="font-weight:bold;' .. (args.colfooterstyle or '') .. '"><td colspan=' .. (colfootercolspan[1] or '1') .. ' style="border-right:2px solid #fdfdfd;' .. (colfooterstyle[1] or '') .. '">' .. colfooter[1] .. '</td>'
colfooter[1] = nil
for i in pairs(colfooter) do
cols = cols .. '<td colspan=' .. (colfootercolspan[i] or '1') .. ' style="border-left:2px solid #fdfdfd;' .. colfooterstyle[i] .. '">' .. colfooter[i] .. '</td>'
end
cols = cols .. '</tr>'
336 ⟶ 335行目:
function p.with_collapsible_groups(frame)
defArgs(frame)
local abbr, state = {}, {}
local sect, section = {}, {}
local secttitlestyle = {}
local content, contentstyle = {}
local image, imageleft = {}, {}
for k, v in pairs(args) do
if string.match(k, 'abbr%d+$') then
abbr[tonumber(string.match(k, 'abbr(%d+)$'))] = v
elseif string.match(k, 'state%d+$') then
state[tonumber(string.match(k, 'state(%d+)$'))] = v
elseif string.match(k, 'sect%d+$') then
group[tonumber(string.match(k, 'sect(%d+)$'))] = v
elseif string.match(k, 'section%d+') then
group[tonumber(string.match(k, 'section(%d+)'))] = v
elseif string.match(k, 'sect%dtitlestyle') then
groupstyle[tonumber(string.match(k, 'sect(%d+)titlestyle'))] = v
elseif string.match(k, 'content%d+$') then
list[tonumber(string.match(k, 'content(%d+)$'))] = v
elseif string.match(k, 'content%d+style') then
liststyle[tonumber(string.match(k, 'content(%d+)style'))] = v
elseif string.match(k, 'image%d+') then
image[tonumber(string.match(k, 'image(%d+)'))] = v
elseif string.match(k, 'imageleft%d+') then
imageleft[tonumber(string.match(k, 'imageleft(%d+)'))] = v
end
end
top()
if args.title then title() end
if args.above then above() end
local i = 1
local function funcList()
local collapsible = (args.selected == abbr[i] or args.selected == group[i]) and '' or 'collapsible '
args.name = nil
args.state = collapsible .. (state[i] or 'collapsed')
379 ⟶ 353行目:
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[i] or '') .. '" class="navbox-list navbox-' .. (args.evenodd == 'swap' and even or args.evenodd or odd) .. ' ' .. (args.listclass or '') .. '"><div>'
if args.title then
if i ~= 1 then list[1], list[i] = list[i], nil end
none = true
top()
392 ⟶ 365行目:
--i = 1
result = result .. '<tr>'
i = 1
result = result .. trborder
if args.imageleft then
result = result .. '<td style="width:0;padding:0 2px 0 0;' .. (args.imageleftstyle or '') .. '" rowspan=' .. rowspan .. '>' .. args.imageleft .. '</td>'
404 ⟶ 376行目:
--i > 2
for j in pairs(list) do
result = result .. trborder'<tr>'
i = j
list[1], list[i] = list[i], nil
funcList()
end
435 ⟶ 408行目:
end
end
local result = '<table style="width:100%;border-spacing:02px;border-collapse:collapseseparate;text-align:center;">'
local h = 1
repeat