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 divStyle = ''
if bg ~= '' then
divStyle = 'background: ' .. bg .. ';'
end
-- Construction de l'image via le parser MediaWiki
local imageCode = frame:preprocess('[[Fichier:' .. image .. '|' .. size .. '|center|link=|alt=' .. alt .. ']]')
-- Construction du span texte
local textHtml = ''
if text ~= '' then
textHtml = '<span class="button-link__text">' .. mw.text.encode(text) .. '</span>'
end
-- Construction du lien
local linkHtml = '<a href="' .. mw.text.encode(link) .. '" class="button-link__link" title="' .. mw.text.encode(title) .. '">'
.. imageCode
.. textHtml
.. '</a>'
-- Construction de la div conteneur
local divHtml = '<div class="' .. cssClass .. '"'
if divStyle ~= '' then
divHtml = divHtml .. ' style="' .. divStyle .. '"'
end
divHtml = divHtml .. '>' .. linkHtml .. '</div>'
-- Ajout des styles
local styles = frame:extensionTag('templatestyles', '', {src='ButtonLink/styles.css'})
return styles .. divHtml
end
return p