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

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

Материал из YastreWiki
Нет описания правки
Нет описания правки
Строка 12: Строка 12:


     local files = {}
     local files = {}
     for k, v in ipairs(args) do
     local i = 1
         local file = mw.text.trim(v)
   
    while args ~= nil do
         local file = mw.text.trim(args)
         if file ~= '' then
         if file ~= '' then
             table.insert(files, file)
             table.insert(files, file)
         end
         end
        i = i + 1
     end
     end


Строка 25: Строка 28:
     end
     end


     for i, 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 i == 1 then
         if index == 1 then
             item:addClass('active')
             item:addClass('active')
         elseif i == 2 then
         elseif index == 2 then
             item:addClass('next')
             item:addClass('next')
         elseif i == total and total > 2 then
         elseif index == total and total > 2 then
             item:addClass('prev')
             item:addClass('prev')
         else
         else
Строка 40: Строка 43:
         item:tag('div')
         item:tag('div')
             :addClass('carousel-image')
             :addClass('carousel-image')
             :wikitext('[]')
             :wikitext(']')
     end
     end



Версия от 17:00, 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 ~= nil do
        local file = mw.text.trim(args)
        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(']')
    end

    return tostring(root)
end

return p