Модуль:Carousel: различия между версиями
Материал из YastreWiki
Дополнительные действия
Нет описания правки |
Нет описания правки |
||
| Строка 4: | Строка 4: | ||
local parent = frame:getParent() | local parent = frame:getParent() | ||
local args = parent and parent.args or frame.args | local args = parent and parent.args or frame.args | ||
local root = mw.html.create('div') | local root = mw.html.create('div') | ||
:addClass('yastre-carousel-container') | :addClass('yastre-carousel-container') | ||
local inner = root:tag('div') | local inner = root:tag('div') | ||
:addClass('yastre-carousel') | :addClass('yastre-carousel') | ||
| Строка 13: | Строка 11: | ||
local files = {} | local files = {} | ||
local i = 1 | local i = 1 | ||
while args ~= nil do | while args[i] ~= nil do | ||
local file = mw.text.trim(args) | local file = mw.text.trim(args[i]) | ||
if file ~= '' then | if file ~= '' then | ||
table.insert(files, file) | table.insert(files, file) | ||
| Строка 23: | Строка 21: | ||
local total = #files | local total = #files | ||
if total == 0 then | if total == 0 then | ||
return "<!-- Карусель пуста -->" | return "<!-- Карусель пуста -->" | ||
| Строка 30: | Строка 27: | ||
for index, file in ipairs(files) do | for index, file in ipairs(files) do | ||
local item = inner:tag('div'):addClass('carousel-item') | local item = inner:tag('div'):addClass('carousel-item') | ||
if index == 1 then | if index == 1 then | ||
item:addClass('active') | item:addClass('active') | ||
| Строка 43: | Строка 40: | ||
item:tag('div') | item:tag('div') | ||
:addClass('carousel-image') | :addClass('carousel-image') | ||
:wikitext(']') | :wikitext('[[File:' .. file .. '|800px]]') | ||
end | end | ||
Версия от 17:05, 20 февраля 2026
Для документации этого модуля может быть создана страница Модуль:Carousel/doc
local p = {}
function p.render(frame)
local parent = frame:getParent()
local args = parent and parent.args or frame.args
local root = mw.html.create('div')
:addClass('yastre-carousel-container')
local inner = root:tag('div')
:addClass('yastre-carousel')
local files = {}
local i = 1
while args[i] ~= nil do
local file = mw.text.trim(args[i])
if file ~= '' then
table.insert(files, file)
end
i = i + 1
end
local total = #files
if total == 0 then
return "<!-- Карусель пуста -->"
end
for index, file in ipairs(files) do
local item = inner:tag('div'):addClass('carousel-item')
if index == 1 then
item:addClass('active')
elseif index == 2 then
item:addClass('next')
elseif index == total and total > 2 then
item:addClass('prev')
else
item:addClass('hidden')
end
item:tag('div')
:addClass('carousel-image')
:wikitext('[[File:' .. file .. '|800px]]')
end
return tostring(root)
end
return p