Dokumentacja dla tego modułu może zostać utworzona pod nazwą Moduł:Galeria skórek/opis

local Skins = {}

-- Parameter names
local param = {
    champ       = 'Bohater',
    skin        = 'Skórka',
    date        = 'Data',
    image       = 'Obraz',
    cid         = 'CID',
    sid         = 'SID',
    price       = 'Cena',
    description = 'Opis',
    unavailable = 'Niedostępna',
    display     = 'Wyświetl',
    width       = 'Szerokość',
    color       = 'Kolor',
}

-- Strings
local strings = {
    price = '[[Riot Points| %d ]]',
    date = '{{#time:j xg Y|%s}}',
    classic_skin = 'Klasyczna',
}
-- Settings
Skins.padding = 6 -- Combined padding (left and right) of the slideshow frame - used to calculate max width of the image with 700px being max width of the whole thing

-- Funciton to customize
function Skins.description(text)
    local v = text:lower()
    if v == 'legacy' then return "wycofana ze sprzedaży ([[Skórki Legacy|Legacy]])"
    elseif v == 'legendarna' then return "'''[[Skórki legendarne|Legendarna]]'''"
    elseif v == 'mityczna' then return "'''[[Skórki mityczne|Mityczna]]'''"
    elseif v == 'cesarska' then return "'''[[Skórki cesarskie|Cesarska]]'''"
    else return text end
end

-- Rest of the module - modify at your own risk ;)

-- Dependencies
local HF = require("Module:HF")
local FN = require("Module:Filename")


Skins.vars = {}
function ternary(cond, T, F)
    if cond then return T else return F end
end

function Skins.create(args, loading)
    loading = loading or nil
    Skins.id = 'skins-' .. tostring(math.random(1000000,9999999))
    local slideshow = mw.html.create('div'):attr('id', Skins.id)
    
    slideshow:addClass('skins-slideshow plainlinks')
    if loading then slideshow:addClass('loadings') end
    if args.position == 'left' then
        slideshow:addClass('floatleft')
    elseif args.position == 'right' then
        slideshow:addClass('floatright')
    end
    if args.class then
        slideshow:addClass(args.class)
    end
    if not loading and not args['disable-resize'] then slideshow:addClass('resizable') end
    
    Skins.size = {}
    if loading then
        Skins.size.width = math.min(308, math.max(50, tonumber(args[param.width] or 180)))
        Skins.size.height = math.floor(Skins.size.width * 1.818 + 0.5)
    else
        Skins.size.width = 700 - Skins.padding
        Skins.size.height = math.floor(Skins.size.width * 0.59 + 0.5)
    end
    slideshow:css('width', tostring(Skins.size.width)..'px'):css('height', tostring(Skins.size.height)..'px'):css('line-height', tostring(Skins.size.height)..'px')
    
    local wrapper = slideshow:tag('div'):addClass('skins-slideshow-wrapper')
                      
    local list = wrapper:tag('ul'):addClass('skins-slideshow-list'):css('width', tostring(Skins.size.width)..'px'):css('height', tostring(Skins.size.height)..'px'):css('line-height', tostring(Skins.size.height)..'px')
    
    Skins.images = 0 -- Image count
    local images = {} -- Image parameters
    local indexes = {} -- List of indexes for sorting
    
    for k, v in pairs(args) do
        local keySplit = HF.explode(":", tostring(k))
        local index  = tonumber(HF.trim(keySplit[1]))
        local key    = tostring(HF.trim(keySplit[2]))
        local value  = tostring(HF.trim(v))
        
        if keySplit[2] ~= nil then
            if type(index) == 'number' then
                if images[index] == nil then
                    table.insert(indexes, index)
                    images[index] = {}
                    Skins.images = Skins.images + 1
                end
                images[index][key] = value
            end
        else
            if not HF.isempty(value) then
                Skins.vars[HF.trim(tostring(k))] = value
            end
        end
    end
    
    if #indexes == 0 then return '' end
    
    table.sort(indexes)
    
    if not loading then
        local counter = mw.html.create('div'):addClass('skins-slideshow-counter'):css('z-index', tostring(#indexes)):wikitext(mw.getCurrentFrame():preprocess(mw.ustring.format("{{int:wikiaPhotoGallery-slideshow-view-number|<span id=\"%s\">%d</span>|%d}}", Skins.id .. '-counter', 1, #indexes)))
        slideshow:node(counter)
    end
    
    local p = mw.html.create('div'):addClass('skins-slideshow-prev'):css('z-index', tostring(#indexes)):attr('title', mw.getCurrentFrame():preprocess('{{int:wikiaPhotoGallery-slideshow-view-prev-tooltip}}')):done()
    local n = mw.html.create('div'):tag('div'):addClass('skins-slideshow-next'):css('z-index', tostring(#indexes)):attr('title', mw.getCurrentFrame():preprocess('{{int:wikiaPhotoGallery-slideshow-view-next-tooltip}}')):done()
    
    local controls = mw.html.create('div'):addClass('skins-slideshow-controls')
    
    for i, index in ipairs(indexes) do
        local elem = Skins.image(i, images[index], loading)
        if elem ~= nil then
            local id = Skins.id .. '-skin-' .. i
            elem:attr('id', id)
            local title = images[index][param.skin] or images[index][param.display] or ''
            if title == 'Klasyczna' then title = images[index][param.champ] .. ' – ' .. title end
            local ctrl = controls:tag('span'):attr('id', id .. '-ctrl'):attr('data-id', i):attr('title', title):addClass('basic-tooltip')
            local color = images[index][param.color] or ''
            if color ~= '' then
                ctrl:css('background-color', color)
            end
            if i == 1 then
                ctrl:addClass('active')
            else
                elem:css('display', 'none')
            end
            list:node(elem)
        end
    end
    
    if #indexes > 1 then
        slideshow:node(p)
        slideshow:node(n)
    end
    slideshow:node(controls)
    
    slideshow:attr('data-current-skin', '1'):attr('data-skin-count', tostring(#indexes)):attr('data-disable-leanback', ternary(args['disable-leanback'], 'true', ''))
    
    return tostring(slideshow)
end

function Skins.image(i, args, loading)
    loading = loading or nil
    args[param.champ] = args[param.champ] or Skins.vars[param.champ] or '' -- Use template default if nil
    args[param.cid]   = args[param.cid]   or Skins.vars[param.cid] or nil -- Use template default if nil
    
    args[param.skin]  = args[param.skin]  or ''
    
    local entry = mw.html.create('li'):addClass('skin-slide'):attr('data-id', i):attr('data-champion', args[param.champ] or ''):attr('data-skin', args[param.skin])
    
    entry:css('z-index', tostring(Skins.images-i))
    
    if args[param.unavailable] then
        entry:addClass('skin-unavailable')
    end
    if args['style'] then
        entry:cssText(args['style'])
    end
    if args['class'] then
        entry:addClass(args['class'])
    end
    
    args[param.price] = tonumber(args[param.price]) or 0
    
    entry:tag('div'):addClass('skin-image'):wikitext(mw.ustring.format('[[File'..':%s|%dpx|alt=|%s]]', args[param.image] or Skins.imageName(args[param.champ], args[param.skin], loading), Skins.size.width, args[param.skin])):attr('id', mw.getCurrentFrame():preprocess('{{anchorencode:'.. args[param.skin] ..'}}'))
    
    if not loading then
        if args[param.price] > 0 then
            entry:tag('div'):addClass('skin-price'):wikitext(mw.getCurrentFrame():preprocess(mw.ustring.format(strings.price, args[param.price])))
        else
            entry:addClass('skin-noprice')
        end
    
        local delim = '&thinsp;/&thinsp;'
        local caption_right = ''
        local caption_left = ''
        
        --local info = HF.explode('|', args[param.description] or '')
        local info = {args[param.description]}
        
        for i, text in ipairs(info) do
            caption_right = caption_right .. ternary(i>1, delim, '') .. Skins.description(HF.trim(text))
        end
        
        if args[param.date] then
            caption_right = caption_right .. ternary(caption_right ~= '', delim, '') .. mw.getCurrentFrame():preprocess('{{#iferror:' .. mw.ustring.format(strings.date, args[param.date]) .. '|' .. args[param.date] .. '}}')
        end
        
        if args[param.cid] ~= nil and args[param.sid] ~= nil then
            caption_left = mw.ustring.format('[http://www.lolking.net/models/?champion=%d&skin=%d %s]', tonumber(args[param.cid]), tonumber(args[param.sid]), args[param.display] or args[param.skin])
        else
            caption_left = args[param.display] or args[param.skin]
        end
        
        entry:tag('div'):addClass('skin-caption'):wikitext(mw.ustring.format('<div class="skin-caption-right">%s</div>%s', caption_right, caption_left))
    end
    if args[param.skin] == '' then args[param.skin] = nil end
    return entry
end

function Skins.imageName(champion, skin, loading)
    if skin == '' or champion == '' then return '' end
    loading = loading or nil
    if loading then
        return FN.loading{champion, skin}
    else
        return FN.skin{champion, skin}
    end
end

function Skins.slideshow(frame)
    return Skins.create(arguments(mergeFrames(frame, frame:getParent())))
end
function Skins.loadings(frame)
    return Skins.create(arguments(mergeFrames(frame, frame:getParent())), true)
end
function mergeFrames(frame, parent) -- Allows to overwrite with parameters from the template that invoked the module
    local args = {}
    if frame then
        for k,v in pairs(frame.args) do
            args[k] = v
        end
    end
    if parent then
        for k,v in pairs(parent.args) do
            args[k] = v
        end
    end
    return args
end
function arguments(origArgs)
    local args = {}
    for k, v in pairs(origArgs) do
        if type(v) == 'string' then v = HF.trim(v) end
        if v ~= '' then args[k] = v end
    end
    return args
end
return Skins
Treści społeczności są dostępne na podstawie licencji CC-BY-SA, o ile nie zaznaczono inaczej.