(Translated by https://www.hiragana.jp/)
「モジュール:Navbox/former/sandbox」の版間の差分 - Wikipedia

「モジュール: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