Перейти к содержанию

Модуль:Football: различия между версиями

Нет описания правки
Реализована работа хайлайтов
Строка 492: Строка 492:
end
end


 
-- =====================================================
-- Выделение победителей и проигравших
-- =====================================================
local highlights = {}
-- Есть ли текст хотя бы у одного хайлайта
local hasHightlightText = false
for i = 1, 10 do
local hl = trim(args["highlight" .. i])
if hl == nil or trim(hl)=="" then
break
end
local parts = split(hl, ";")
if parts.text ~="" then
hasHightlightText = true
end
local highlight = {
place = parts[1],
count = parts[2],
color = parts[3],
text = parts[4]
}
table.insert(highlights, highlight)
end
-- -----------------------------------------------------
-- -----------------------------------------------------
-- Сравнение команд
-- Сравнение команд
Строка 637: Строка 665:
table.sort(standings, compareTeams)
table.sort(standings, compareTeams)


-- =====================================================
-- Подсветка
-- =====================================================
for _, hl in ipairs(highlights) do
local team = standings[hl.place]
team.highlightColor = hl.color
team.highlightCount = hl.count
team.highlightText = hl.text
if team.highlightCount~=1 then
local c = hl.place
for i = 1, team.highlightCount do
c = c + 1
standings[c].highlightColor = hl.color
end
end
-- Если у нас есть текст с пометками, то нужно объединить пустые ячейки без текста
if hasHightlightText and hl.place + team.highlightCount <= #standings then
local nextStanding = standings[hl.place + team.highlightCount]
local nextHighlight = #standings
if _ ~= #highlights then
nextHighlight = highlights[_+1].place
end
nextStanding.highlightCount = hl.count
nextStanding.highlightText = ""
end
end
-- =====================================================
-- =====================================================
-- ТАБЛИЦА ЧЕМПИОНАТА
-- ТАБЛИЦА ЧЕМПИОНАТА
Строка 674: Строка 732:
"О"
"О"
}
}
if hasHightlightText then
table.insert(headings, "Повышение или выбывание")
end


for _, heading in ipairs(headings) do
for _, heading in ipairs(headings) do
Строка 692: Строка 754:
local row =
local row =
mw.html.create("tr")
mw.html.create("tr")
 
if team.color ~= "" then
row:addClass("highlight"):addClass(team.highlightColor)
end


row:node(
row:node(
Строка 751: Строка 816:
cell("td", team.points)
cell("td", team.points)
)
)
if hasHightlightText then
row:node(
cell("td")
:wikitext(team.highlightText)
:attr("rowspan", team.highlightCount)
)
end