Открыть меню
Переключить меню настроек
Открыть персональное меню
Вы не представились системе
Ваш IP-адрес будет виден всем, если вы внесёте какие-либо изменения.

Модуль:Carousel

Материал из YastreWiki

Для документации этого модуля может быть создана страница Модуль:Carousel/doc

local p = {}

function p.render(frame)
    local parent = frame:getParent()
    local args = parent and parent.args or frame.args

    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

    local parts = {}
    table.insert(parts, '<div class="yastre-carousel-container"><div class="yastre-carousel">')

    for index, file in ipairs(files) do
        local cls = 'carousel-item'
        if index == 1 then
            cls = cls .. ' active'
        elseif index == 2 then
            cls = cls .. ' next'
        elseif index == total and total > 2 then
            cls = cls .. ' prev'
        else
            cls = cls .. ' hidden'
        end

        local img = frame:preprocess('[[File:' .. file .. '|800px]]')
        table.insert(parts, '<div class="' .. cls .. '"><div class="carousel-image">' .. img .. '</div></div>')
    end

    table.insert(parts, '</div></div>')
    return table.concat(parts)
end

return p