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

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

Материал из YastreWiki
Нет описания правки
Нет описания правки
 
(не показаны 2 промежуточные версии этого же участника)
Строка 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')
        :addClass('yastre-carousel-container')
    local inner = root:tag('div')
        :addClass('yastre-carousel')


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


     local total = #files
     local total = #files
     if total == 0 then
     if total == 0 then
         return "<!-- Карусель пуста -->"
         return '<!-- Карусель пуста -->'
     end
     end


     for i, file in ipairs(files) do
    local parts = {}
         local item = inner:tag('div'):addClass('carousel-item')
    table.insert(parts, '<div class="yastre-carousel-container"><div class="yastre-carousel">')
       
 
         if i == 1 then
     for index, file in ipairs(files) do
             item:addClass('active')
         local cls = 'carousel-item'
         elseif i == 2 then
         if index == 1 then
             item:addClass('next')
             cls = cls .. ' active'
         elseif i == total and total > 2 then
         elseif index == 2 then
             item:addClass('prev')
             cls = cls .. ' next'
         elseif index == total and total > 2 then
             cls = cls .. ' prev'
         else
         else
             item:addClass('hidden')
             cls = cls .. ' hidden'
         end
         end


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


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


return p
return p

Текущая версия от 17:06, 20 февраля 2026

Для документации этого модуля может быть создана страница Модуль: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