FANDOM


local LuaInfobox = {}
 
function LuaInfobox.Slideshow(field, vars)
    field.Controls =  mw.ustring.lower(field.Controls or 'prevnext')
 
    local default = tonumber(field.Value or '') or nil
    local slides = {}
    local indexes = {}
    for k,v in pairs(field) do
        if v ~= '' then
            local match = mw.ustring.match(k, 'Slide (%-?%d+)')
            if match ~= nil then
                match = tonumber(match)
                slides[match] = v
                table.insert(indexes, match)
            end
        end
    end
    table.sort(indexes)
 
    if slides[default] == nil then default = indexes[1] end
    field.Value = default
 
    local wrapper = mw.html.create('div'):addClass('infobox-slideshow-wrapper')
    local div = mw.html.create('div'):addClass('infobox-slideshow')
 
    local controls = mw.html.create('div'):addClass('infobox-slideshow-controls')
 
    local container = div:tag('div'):addClass('infobox-slideshow-slides')
    for i,v in ipairs(indexes) do
        local slide = mw.html.create('div'):addClass('infobox-slideshow-slide')
        if v == default then slide:addClass('active') end
 
        slide:attr('data-id', v):wikitext(slides[v])
 
        if controls then
            local switch = controls:tag('span'):addClass('infobox-slideshow-switch'):attr('data-id', v)
            if field['Label ' .. v] then switch:wikitext(field['Label ' .. v]) end
            if v == default then switch:addClass('active') end
        end
 
        container:node(slide)
    end
 
    if mw.ustring.find(field.Controls, 'prevnext') ~= nil then
        div:tag('div'):addClass('infobox-slideshow-prev')
        div:tag('div'):addClass('infobox-slideshow-next')
    end
 
    if mw.ustring.find(field.Controls, 'above') ~= nil then wrapper:node(controls) end
    wrapper:node(div)
    if mw.ustring.find(field.Controls, 'below') ~= nil then wrapper:node(controls) end
 
    return tostring(wrapper)
end
function ternary(cond, T, F)
    if cond then return T else return F end
end
return LuaInfobox

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.