« Module:ButtonLink » : différence entre les versions
De Nefald
Autres actions
Page créée avec « 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... » Balises : Modification par mobile Modification par le web mobile |
m Raw Balises : Modification par mobile Modification par le web mobile |
||
| Ligne 21 : | Ligne 21 : | ||
-- Style inline si bg personnalisé | -- Style inline si bg personnalisé | ||
local | local divStyle = '' | ||
if bg ~= '' then | if bg ~= '' then | ||
divStyle = 'background: ' .. bg .. ';' | |||
end | end | ||
-- Construction de l'image | -- Construction de l'image via le parser MediaWiki | ||
local imageCode = '[[Fichier:' .. image .. '|' .. size .. '|center|link=|alt=' .. alt .. ']]' | local imageCode = frame:preprocess('[[Fichier:' .. image .. '|' .. size .. '|center|link=|alt=' .. alt .. ']]') | ||
-- Construction du texte | -- Construction du span texte | ||
local textHtml = '' | local textHtml = '' | ||
if text ~= '' then | if text ~= '' then | ||
textHtml = '<span class="button-link__text">' .. text .. '</span>' | textHtml = '<span class="button-link__text">' .. mw.text.encode(text) .. '</span>' | ||
end | end | ||
-- Construction du | -- Construction du lien | ||
local | 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 | end | ||
return p | return p | ||