Открыть меню
Переключить меню настроек
Открыть персональное меню
Вы не представились системе
Ваш 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:
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 root = mw.html.create('div')
Строка 11: Строка 11:
         :addClass('yastre-carousel')
         :addClass('yastre-carousel')


     local i = 1
     local files = {}
     local total = 0
    for k, v in ipairs(args) do
     while args do total = total + 1; i = i + 1 end
        local file = mw.text.trim(v)
        if file ~= '' then
            table.insert(files, file)
        end
    end
 
     local total = #files
 
     if total == 0 then
        return "<!-- Карусель пуста -->"
    end


     i = 1
     for i, file in ipairs(files) do
    while args do
        local file = mw.text.trim(args)
         local item = inner:tag('div'):addClass('carousel-item')
         local item = inner:tag('div'):addClass('carousel-item')
          
          
Строка 24: Строка 32:
         elseif i == 2 then
         elseif i == 2 then
             item:addClass('next')
             item:addClass('next')
         elseif i == total then
         elseif i == total and total > 2 then
             item:addClass('prev')
             item:addClass('prev')
         else
         else
Строка 30: Строка 38:
         end
         end


         item:wikitext('[]')
         item:tag('div')
       
            :addClass('carousel-image')
        i = i + 1
            :wikitext('[]')
     end
     end



Версия от 16:45, 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 = {}
    for k, v in ipairs(args) do
        local file = mw.text.trim(v)
        if file ~= '' then
            table.insert(files, file)
        end
    end

    local total = #files

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

    for i, file in ipairs(files) do
        local item = inner:tag('div'):addClass('carousel-item')
        
        if i == 1 then
            item:addClass('active')
        elseif i == 2 then
            item:addClass('next')
        elseif i == 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