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

削除された内容 追加された内容
Waiesu (会話 | 投稿記録)
m編集の要約なし
Waiesu (会話 | 投稿記録)
Navbox with collapsible groupsを修正, 変数をローカル化
1行目:
local p = {}
 
--[[
61行目:
Define Arguments
]]
local args = {}
local border
local child, none = false, false
local collapsible = ''
local colspan, rowspan = 0, 0
local basestyle = ''
local bdcolor, trborder = '', ''
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 ⟶ 90行目:
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,local liststyleswitch = {}, {}
--common
group, groupstyle = {}, {}
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
 
263 ⟶ 291行目:
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
336 ⟶ 346行目:
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 ⟶ 364行目:
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 ⟶ 376行目:
--i = 1
i = 1
result = result .. trborder
if args.imageleft then
406 ⟶ 389行目:
result = result .. trborder
i = j
list[1], list[i] = list[i], nil
funcList()
end