Module:ButtonLink
De Nefald
Autres actions
La documentation pour ce module peut être créée à Module:ButtonLink/doc
local p = {}
function p.main(frame)
local args = frame:getParent().args
-- Récupération des paramètres
local link = args.link or ''
local image = args.image or ''
local text = args.text or ''
local color = args.color or ''
local bg = args.bg or ''
local size = args.size or 'x40px'
local title = args.title or text
local alt = args.alt or text
-- Construction des classes CSS
local cssClass = 'button-link'
if color ~= '' then
cssClass = cssClass .. ' button-link--' .. color
end
-- Style inline si bg personnalisé
local style = ''
if bg ~= '' then
style = ' style="background: ' .. bg .. ';"'
end
-- Construction de l'image
local imageCode = '[[Fichier:' .. image .. '|' .. size .. '|center|link=|alt=' .. alt .. ']]'
-- Construction du texte
local textHtml = ''
if text ~= '' then
textHtml = '<span class="button-link__text">' .. text .. '</span>'
end
-- Construction du HTML final
local html = mw.html.create('div')
:addClass(cssClass)
:cssText(bg ~= '' and 'background: ' .. bg or nil)
:tag('a')
:addClass('button-link__link')
:attr('href', link)
:attr('title', title)
:wikitext(imageCode)
:wikitext(textHtml)
:done()
return frame:extensionTag('templatestyles', '', {src='ButtonLink/styles.css'}) .. tostring(html)
end
return p