Модуль:Football box collapsible (Bk;rl,&Football box collapsible)
Перейти к навигации
Перейти к поиску
![]() | Этот шаблон реализован на основе Lua |
Реализация {{Footballbox collapsible}}.
-- Реализация [[Шаблон:Football box collapsible]]
local fbxb = require("Модуль:Football box/base")
local p = {}
local colors = {
["W"] = "bbf3bb",
["L"] = "ffbbbb",
["T"] = "D", ["D"] = "ffffbb",
["SW"] = "PW", ["PW"] = "bbf3ff",
["V"] = "P", ["P"] = "bbbbbb"}
local tracking, preview
local function checkarg(k, v, tracking, preview)
fbxb.checkarg(k, v, 'Страницы, использующие шаблон footballbox collapsible с неизвестными параметрами', tracking, preview)
end
local function background(frame, c, r, bg)
local data = colors
local res = data[r:upper()]
if res then
res = '#' .. (data[res] or res)
elseif fbxb.isnotempty(bg) then
res = '#' .. bg
else
res = 'transparent'
end
return res
end
local function teamname(team)
local prefix, suffix, b = "", "", "'''";
if mw.ustring.sub(team, 1, 3) ~= b and mw.ustring.sub(team, -3) ~= b then
prefix = '<span class="fn org">' .. b .. ' ';
suffix = ' ' .. b .. "</span>";
else
if mw.ustring.sub(team, 1, 3) == b then
prefix = '<span class="fn org">';
team = mw.ustring.sub(team, 4);
else
prefix = '<span class="fn org">' .. b;
end
if mw.ustring.sub(team, -3) == b then
suffix = "</span>";
team = mw.ustring.sub(team, 1, mw.ustring.len(team) - 3);
else
suffix = b .. "</span>";
end
end
return prefix .. team .. suffix;
end
local function score(s, a, ag, p, so)
s = fbxb.nowrap(fbxb.bold(s ~= '' and s or '–:–'))
if a ~= '' then
s = s .. fbxb.small(' (' .. fbxb.labels['aet'] .. ')')
end
if ag ~= '' then
s = s .. '<br>' .. fbxb.small(' (' .. fbxb.bold(ag) .. ' ' .. fbxb.labels['agg'] .. ')')
end
if p ~= '' then
s = s .. '<br>' .. fbxb.small(' (' .. fbxb.bold(p) .. ' ' .. fbxb.labels['pen'] .. ')')
elseif so ~= '' then
s = s .. '<br>' .. fbxb.small(' (' .. fbxb.bold(so) .. ' ' .. fbxb.labels['so'] .. ')')
end
return s
end
function p.main(frame)
-- Exit early if we are using section transclusion for a different section
local tsection = frame:getParent().args['transcludesection'] or frame:getParent().args['section'] or ''
local bsection = frame.args['section'] or ''
if ( tsection ~= '' and bsection ~= '') then
if ( tsection ~= bsection) then
return ''
end
end
local args = (frame.args['team1'] or frame.args['team2']) and frame.args or frame:getParent().args
local id = fbxb.trim(args['id'])
local bars = (args['nobars'] == nil) or (args['bars'] == '')
local class = fbxb.trim(args['class'] or 'mw-collapsible mw-collapsed') or ''
local width1 = {['1'] = '28%', ['1.1'] = '22%', ['1.2'] = '28%', ['default'] = '19%'}
local width2 = {['1'] = '19%', ['1.1'] = '25%', ['1.2'] = '19%', ['default'] = '23%'}
local width3 = {['1'] = '8%', ['1.1'] = '8%', ['1.2'] = '8%', ['default'] = '12%'}
local width4 = {['1'] = '19%', ['1.1'] = '19%', ['1.2'] = '26%', ['default'] = '23%'}
local width5 = {['1'] = '26%', ['1.1'] = '26%', ['1.2'] = '19%', ['default'] = '23%'}
local location = nil
local extra = {}
local notes = {}
tracking, preview = {}, {}
fbxb.process_rus_params(args)
for k, v in pairs(args) do
if v ~= '' then
checkarg(k, v, tracking, preview)
end
end
if fbxb.isnotempty(args['class']) then
if fbxb.isnotempty(args['class']) == 'collapsible' or fbxb.isnotempty(args['class']) == 'mw-collapsible' or fbxb.isnotempty(args['class']) == 'uncollapsed' then
--valid
elseif fbxb.isnotempty(args['class']) == '' then
table.insert(tracking, '[[Категория:Страницы, использующие шаблон footballbox collapsible с пустым параметром class]]')
else
table.insert(tracking, '[[Категория:Страницы, использующие шаблон footballbox collapsible с параметром class]]')
end
end
-- требуемые параметры
for i, k in ipairs({'team1', 'team2'}) do
if args[k] == nil then
args[k] = '{{{' .. k .. '}}}'
end
end
-- карточка стадиона
if fbxb.isnotempty(args['stadium']) then
args['stadium'] = tostring(mw.html.create('span'):addClass('location'):wikitext(args['stadium']))
end
-- информация о месте проведения матча и стадионе
if fbxb.isnotempty(args['location']) then
location = args['location']
if fbxb.isnotempty(args['stadium']) then
table.insert(extra, fbxb.labels['stadium'] .. ' ' .. args['stadium'])
end
elseif fbxb.isnotempty(args['stadium']) then
location = args['stadium']
end
-- дополнительная информация
for i, k in ipairs({'attendance', 'referee', 'assistantreferees', 'assistantreferee2', 'VAR', 'assistantVAR', 'assistantsVAR',
'fourthofficial', 'fifthofficial', 'goallineassistants', 'goallineassistant2', 'potm', 'motm', 'mvp'}) do
if fbxb.isnotempty(args[k]) then
table.insert(extra, fbxb.labels[k] .. ' ' .. args[k])
end
end
-- счёт
local scorestr = ''
if args['score1'] or args['score2'] then
scorestr = (args['score1'] or '0') .. '–' .. (args['score2'] or '0')
elseif args['score'] then
scorestr = args['score']
end
if args['scorenote'] then
scorestr = scorestr .. '<br>' .. args['scorenote']
end
-- комментарии
if fbxb.isnotempty(args['note']) then
table.insert(notes, "''" .. fbxb.labels['note'] .. " " .. args['note'] .. "''")
end
if fbxb.isnotempty(args['seealso']) then
table.insert(notes, "''" .. fbxb.labels['seealso'] .. " " .. args['seealso'] .. "''")
end
-- составы команд (только в рувики)
if fbxb.isnotempty(args['squad1']) then
table.insert(notes, "" .. fbxb.bold(fbxb.check_team_pattern(args['team1'])) .. ": " .. args['squad1'] .. "")
end
if fbxb.isnotempty(args['squad2']) then
table.insert(notes, "" .. fbxb.bold(fbxb.check_team_pattern(args['team2'])) .. ": " .. args['squad2'] .. "")
end
-- проверка на таблицу
if class == '' or class == 'uncollapsed' then
class = ''
elseif #extra > 0 or #notes > 0 or
fbxb.isnotempty(args['time']) or fbxb.isnotempty(args['report']) or
fbxb.isnotempty(args['goals1']) or fbxb.isnotempty(args['goals2']) or
fbxb.isnotempty(args['penalties1']) or fbxb.isnotempty(args['penalties2']) or
fbxb.isnotempty(args['shootout1']) or fbxb.isnotempty(args['shootout2']) then
elseif class == 'collapsible collapsed' or class == 'mw-collapsible mw-collapsed' then
class = ''
end
-- Start box
local root = mw.html.create('div')
:addClass('vevent')
:attr('id', id)
root:tag('span')
:addClass('summary')
:css('display', 'none')
:wikitext(args['team1'] .. ' v ' .. args['team2'])
root:newline()
-- Start table
local rClassName = 'vevent tmpl-football-box-collapsible'
local rbg = background(frame, 'default', args['result'] or '', args['bg'] or '')
if rbg == 'transparent' then
rClassName = rClassName .. ' tmpl-football-box-collapsible-transparent'
end
local rtable = root:tag('table')
:attr('cellspacing', 0)
:addClass(class ~= '' and class or nil)
:addClass(rClassName)
:css('border-top', bars and '1px solid #999' or nil)
:css('border-bottom', bars and '1px solid #999' or nil)
:css('margin-bottom', bars and '-1px' or nil)
:css('width', args['size'] or '100%')
:css('background', rbg)
local row = rtable:tag('tr'):css('vertical-align', 'top')
-- дата и раунд
local cell = row:tag('td')
:css('width', width1[args['format'] or 'default'] or width1['default'])
if fbxb.isnotempty(args['date']) then
cell:tag('span')
:css('white-space', 'nowrap')
:css('float', 'right')
:css('margin-left', '0.5em')
:wikitext(args['date'])
cell:wikitext(' ')
end
if fbxb.isnotempty(args['round']) then
cell:wikitext(fbxb.small(args['round']))
end
-- команда1
row:tag('td')
:css('width', width2[args['format'] or 'default'] or width2['default'])
:css('text-align', 'right')
:addClass('vcard attendee')
:wikitext(teamname(args['team1']))
-- счёт
row:tag('td')
:css('width', width3[args['format'] or 'default'] or width3['default'])
:css('text-align', 'center')
:wikitext(score(scorestr, args['aet'] or '', args['aggregatescore'] or '', args['penaltyscore'] or '', args['shootoutscore'] or ''))
-- команда2
row:tag('td')
:css('width', width4[args['format'] or 'default'] or width4['default'])
:addClass('vcard attendee')
:wikitext(teamname(args['team2']))
-- место проведения матча и стадион
row:tag('td')
:css('width', width5[args['format'] or 'default'] or nil)
:css('font-size', location and '85%' or nil)
:wikitext(location)
if #extra > 0 or
fbxb.isnotempty(args['time']) or fbxb.isnotempty(args['report']) or
fbxb.isnotempty(args['goals1']) or fbxb.isnotempty(args['goals2']) then
local row = rtable:tag('tr'):css('vertical-align', 'top'):css('font-size', '85%')
-- время
row:tag('td')
:css('text-align', fbxb.isnotempty(args['time']) and 'right' or nil)
:wikitext(args['time'])
row:newline()
-- голы1
row:tag('td')
:css('text-align', fbxb.isnotempty(args['goals1']) and 'right' or nil)
:wikitext(fbxb.fmtlist(args['goals1']))
row:newline()
-- отчёт
row:tag('td')
:css('text-align', fbxb.isnotempty(args['report']) and 'center' or nil)
:wikitext(fbxb.makelink(args['report'] or '', '(отчёт)'))
row:newline()
-- голы2
row:tag('td')
:wikitext(fbxb.fmtlist(args['goals2']))
row:newline()
-- место проведения, стадион
row:tag('td')
:wikitext(table.concat(extra, '<br>'))
end
if fbxb.isnotempty(args['penalties1']) or fbxb.isnotempty(args['penalties2']) then
row = rtable:tag('tr')
row:tag('td'):attr('rowspan', 2)
row:tag('td'):attr('colspan', 3):css('text-align', 'center'):wikitext(fbxb.bold(fbxb.labels['penalties']))
row:tag('td'):attr('rowspan', 2)
row = rtable:tag('tr'):css('vertical-align', 'top'):css('font-size', '85%')
row:newline()
row:tag('td')
:css('text-align', fbxb.isnotempty(args['penalties1']) and 'right' or nil)
:wikitext(fbxb.fmtlist(args['penalties1']))
row:newline()
row:tag('td')
row:newline()
row:tag('td')
:wikitext(fbxb.fmtlist(args['penalties2']))
row:newline()
elseif fbxb.isnotempty(args['shootout1']) or fbxb.isnotempty(args['shootout2']) then
row = rtable:tag('tr')
row:tag('td'):attr('rowspan', 2)
row:tag('td'):attr('colspan', 3):css('text-align', 'center'):wikitext(fbxb.bold(fbxb.labels['shootout']))
row:tag('td'):attr('rowspan', 2)
row = rtable:tag('tr'):css('vertical-align', 'top'):css('font-size', '85%')
row:newline()
row:tag('td')
:css('text-align', fbxb.isnotempty(args['shootout1']) and 'right' or nil)
:wikitext(fbxb.fmtlist(args['shootout1']))
row:newline()
row:tag('td')
row:newline()
row:tag('td')
:wikitext(fbxb.fmtlist(args['shootout2']))
row:newline()
end
if #notes > 0 then
row = rtable:tag('tr'):css('font-size', '85%')
row:tag('td')
:attr('colspan', 5)
:wikitext(table.concat(notes, '<br>'))
row:newline()
end
local trackstr = (#tracking > 0) and table.concat(tracking, '') or ''
if #preview > 0 and frame:preprocess("{{REVISIONID}}") == "" then
trackstr = tostring(mw.html.create('div')
:addClass('hatnote')
:css('color', 'red')
:tag('strong'):wikitext('Внимание:'):done()
:wikitext('Неизвестные параметры: ' .. table.concat(preview, '; ')))
end
return tostring(root) .. trackstr
end
return p