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

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

Материал из YastreWiki
Новая страница: «local p = {} function p.render(frame) local parent = frame:getParent() local args = parent.args local root = mw.html.create('div') :addClass('yastre-carousel-container') local inner = root:tag('div') :addClass('yastre-carousel') local i = 1 local total = 0 while args do total = total + 1; i = i + 1 end i = 1 while args do local file = mw.text.trim(args) local item = inner:tag('div'):add...»
 
Нет описания правки
 
(не показаны 3 промежуточные версии этого же участника)
Строка 3: Строка 3:
function p.render(frame)
function p.render(frame)
     local parent = frame:getParent()
     local parent = frame:getParent()
     local args = parent.args
     local args = parent and parent.args or frame.args


     local root = mw.html.create('div')
     local files = {}
         :addClass('yastre-carousel-container')
    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 inner = root:tag('div')
     local total = #files
         :addClass('yastre-carousel')
    if total == 0 then
         return '<!-- Карусель пуста -->'
    end


     local i = 1
     local parts = {}
     local total = 0
     table.insert(parts, '<div class="yastre-carousel-container"><div class="yastre-carousel">')
    while args do total = total + 1; i = i + 1 end


     i = 1
     for index, file in ipairs(files) do
    while args do
         local cls = 'carousel-item'
        local file = mw.text.trim(args)
         if index == 1 then
         local item = inner:tag('div'):addClass('carousel-item')
             cls = cls .. ' active'
       
         elseif index == 2 then
         if i == 1 then
             cls = cls .. ' next'
             item:addClass('active')
         elseif index == total and total > 2 then
         elseif i == 2 then
             cls = cls .. ' prev'
             item:addClass('next')
         elseif i == total then
             item:addClass('prev')
         else
         else
             item:addClass('hidden')
             cls = cls .. ' hidden'
         end
         end


         item:wikitext('[]')
         local img = frame:preprocess('[[File:' .. file .. '|800px]]')
          
         table.insert(parts, '<div class="' .. cls .. '"><div class="carousel-image">' .. img .. '</div></div>')
        i = i + 1
     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