Mudanças entre as edições de "Módulo:WeeklyBosses"

De Wiki Gla
Ir para navegação Ir para pesquisar
m
m
Linha 1: Linha 1:
--[[
--[[
Module:WeeklyBosses – Botões de redirecionamento para bosses semanais.
Module:WeeklyBosses – Botões de redirecionamento para bosses semanais.
Args vêm do #invoke (frame.args). data-href com URL completa para o redirect funcionar.
Params: imgbtn, txtbtn, linkbtn, bg, imgsize (tamanho em px), imgx/imgy (posição da img: % ou left/center/right e top/center/bottom).
]]
]]


Linha 7: Linha 7:


function p.main(frame)
function p.main(frame)
    -- Parâmetros: do #invoke (frame.args) ou da predefinição que chama o invoke (getParent().args)
     local parentFrame = frame:getParent()
     local parentFrame = frame:getParent()
     local args = frame.args or (parentFrame and parentFrame.args) or {}
     local args = frame.args or (parentFrame and parentFrame.args) or {}
Linha 21: Linha 20:
         local bg = mw.text.trim(args['bg' .. i] or args['background'] or '#2a3544')
         local bg = mw.text.trim(args['bg' .. i] or args['background'] or '#2a3544')
         local nome = (txt ~= '' and txt or link)
         local nome = (txt ~= '' and txt or link)
        local imgsize = mw.text.trim(args['imgsize' .. i] or args['imgsize'] or '80')
        local imgx = mw.text.trim(args['imgx' .. i] or args['imgx'] or '50%')
        local imgy = mw.text.trim(args['imgy' .. i] or args['imgy'] or '50%')
        if imgsize == '' then imgsize = '80' end
        if imgx == '' then imgx = '50%' end
        if imgy == '' then imgy = '50%' end


        -- Imagem: só wikitext com |link= vazio; preprocess para renderizar
         local conteudo
         local conteudo
         if img ~= '' then
         if img ~= '' then
             local imgWikitext = '[[Arquivo:' .. img .. '|48px|link=]]'
             local imgWikitext = '[[Arquivo:' .. img .. '|' .. imgsize .. 'px|link=]]'
             local imgHtml = (parent or frame):preprocess(imgWikitext)
             local imgHtml = (parent or frame):preprocess(imgWikitext)
             conteudo = imgHtml .. '<br/>' .. mw.text.encode(nome, 'entity')
             conteudo = '<div class="weekly-bosses__btn-img">' ..
            imgHtml .. '</div><br/>' .. mw.text.encode(nome, 'entity')
         else
         else
             conteudo = mw.text.encode(nome, 'entity')
             conteudo = mw.text.encode(nome, 'entity')
         end
         end


        -- URL completa no Lua para o redirect não depender do JS da wiki
         local uri = mw.uri.fullUrl(link)
         local uri = mw.uri.fullUrl(link)
         local href = (type(uri) == 'string') and uri or tostring(uri)
         local href = (type(uri) == 'string') and uri or tostring(uri)


         table.insert(out,
         local dataAttrs = 'data-background="' .. mw.text.encode(bg, 'entity') ..
            '<div class="weekly-bosses__btn" data-background="' .. mw.text.encode(bg, 'entity') ..
             '" data-link="' .. mw.text.encode(link, 'entity') ..
             '" data-link="' .. mw.text.encode(link, 'entity') ..
             '" data-href="' .. mw.text.encode(href, 'entity') .. '">' ..
             '" data-href="' .. mw.text.encode(href, 'entity') .. '"'
            conteudo .. '</div>')
        if img ~= '' then
            dataAttrs = dataAttrs .. ' data-imgsize="' .. mw.text.encode(imgsize, 'entity') ..
                '" data-imgx="' .. mw.text.encode(imgx, 'entity') ..
                '" data-imgy="' .. mw.text.encode(imgy, 'entity') .. '"'
        end
        table.insert(out, '<div class="weekly-bosses__btn" ' .. dataAttrs .. '>' .. conteudo .. '</div>')
     end
     end



Edição das 04h33min de 22 de fevereiro de 2026

A documentação para este módulo pode ser criada em Módulo:WeeklyBosses/doc

--[[
Module:WeeklyBosses – Botões de redirecionamento para bosses semanais.
Params: imgbtn, txtbtn, linkbtn, bg, imgsize (tamanho em px), imgx/imgy (posição da img: % ou left/center/right e top/center/bottom).
]]

local p = {}

function p.main(frame)
    local parentFrame = frame:getParent()
    local args = frame.args or (parentFrame and parentFrame.args) or {}
    local parent = parentFrame
    local out = {}

    for i = 1, 10 do
        local link = mw.text.trim(args['linkbtn' .. i] or '')
        if link == '' then break end

        local txt = mw.text.trim(args['txtbtn' .. i] or '')
        local img = mw.text.trim(args['imgbtn' .. i] or '')
        local bg = mw.text.trim(args['bg' .. i] or args['background'] or '#2a3544')
        local nome = (txt ~= '' and txt or link)
        local imgsize = mw.text.trim(args['imgsize' .. i] or args['imgsize'] or '80')
        local imgx = mw.text.trim(args['imgx' .. i] or args['imgx'] or '50%')
        local imgy = mw.text.trim(args['imgy' .. i] or args['imgy'] or '50%')
        if imgsize == '' then imgsize = '80' end
        if imgx == '' then imgx = '50%' end
        if imgy == '' then imgy = '50%' end

        local conteudo
        if img ~= '' then
            local imgWikitext = '[[Arquivo:' .. img .. '|' .. imgsize .. 'px|link=]]'
            local imgHtml = (parent or frame):preprocess(imgWikitext)
            conteudo = '<div class="weekly-bosses__btn-img">' ..
            imgHtml .. '</div><br/>' .. mw.text.encode(nome, 'entity')
        else
            conteudo = mw.text.encode(nome, 'entity')
        end

        local uri = mw.uri.fullUrl(link)
        local href = (type(uri) == 'string') and uri or tostring(uri)

        local dataAttrs = 'data-background="' .. mw.text.encode(bg, 'entity') ..
            '" data-link="' .. mw.text.encode(link, 'entity') ..
            '" data-href="' .. mw.text.encode(href, 'entity') .. '"'
        if img ~= '' then
            dataAttrs = dataAttrs .. ' data-imgsize="' .. mw.text.encode(imgsize, 'entity') ..
                '" data-imgx="' .. mw.text.encode(imgx, 'entity') ..
                '" data-imgy="' .. mw.text.encode(imgy, 'entity') .. '"'
        end
        table.insert(out, '<div class="weekly-bosses__btn" ' .. dataAttrs .. '>' .. conteudo .. '</div>')
    end

    return '<div class="weekly-bosses">' .. table.concat(out) .. '</div>'
end

return p