« Module:MiniCard » : différence entre les versions
De Nefald
Autres actions
Page créée avec « local p = {} function p.main(frame) local args = frame:getParent().args local link = mw.text.trim(args.link or "") local text = mw.text.trim(args.text or "") local image = mw.text.trim(args.image or "") -- Charger le CSS local css = frame:extensionTag('templatestyles', '', {src='Modèle:MiniCard/styles.css'}) -- Si pas de texte, utiliser le lien comme texte if text == "" and link ~= "" then text = link end... » |
Aucun résumé des modifications |
||
| (Une version intermédiaire par le même utilisateur non affichée) | |||
| Ligne 7 : | Ligne 7 : | ||
local image = mw.text.trim(args.image or "") | local image = mw.text.trim(args.image or "") | ||
if text == "" and link ~= "" then | if text == "" and link ~= "" then | ||
text = link | text = link | ||
end | end | ||
local isExternal = link:match("^https?://") or link:match("^//") | local isExternal = link:match("^https?://") or link:match("^//") | ||
-- Construction | -- Construction HTML avec mw.html | ||
local | local button = mw.html.create('span'):addClass('minicard-button') | ||
-- | -- Icône si image fournie | ||
if image | if image ~= "" then | ||
local icon = button:tag('span'):addClass('minicard-icon') | |||
icon:wikitext('[[Fichier:' .. image .. '|20px|link=]]') | |||
local | |||
end | end | ||
-- Texte | -- Texte | ||
button:tag('span'):addClass('minicard-text'):wikitext(text) | |||
-- Wrapper | -- CSS | ||
local styles = frame:extensionTag('templatestyles', '', {src='Modèle:MiniCard/styles.css'}) | |||
-- Wrapper lien | |||
if link ~= "" then | if link ~= "" then | ||
local wrapper = mw.html.create('a') | local wrapper = mw.html.create('a'):addClass('minicard-link') | ||
if isExternal then | if isExternal then | ||
| Ligne 47 : | Ligne 38 : | ||
:addClass('external') | :addClass('external') | ||
else | else | ||
local title = mw.title.new(link) | local title = mw.title.new(link) | ||
wrapper:attr('href', title and title:fullUrl() or mw.uri.localUrl(link)) | |||
end | end | ||
wrapper:node( | wrapper:node(button) | ||
return | return styles .. tostring(wrapper) | ||
end | end | ||
return styles .. tostring(button) | |||
end | end | ||
return p | return p | ||
Dernière version du 11 novembre 2025 à 13:55
La documentation pour ce module peut être créée à Module:MiniCard/doc
local p = {}
function p.main(frame)
local args = frame:getParent().args
local link = mw.text.trim(args.link or "")
local text = mw.text.trim(args.text or "")
local image = mw.text.trim(args.image or "")
if text == "" and link ~= "" then
text = link
end
local isExternal = link:match("^https?://") or link:match("^//")
-- Construction HTML avec mw.html
local button = mw.html.create('span'):addClass('minicard-button')
-- Icône si image fournie
if image ~= "" then
local icon = button:tag('span'):addClass('minicard-icon')
icon:wikitext('[[Fichier:' .. image .. '|20px|link=]]')
end
-- Texte
button:tag('span'):addClass('minicard-text'):wikitext(text)
-- CSS
local styles = frame:extensionTag('templatestyles', '', {src='Modèle:MiniCard/styles.css'})
-- Wrapper lien
if link ~= "" then
local wrapper = mw.html.create('a'):addClass('minicard-link')
if isExternal then
wrapper:attr('href', link)
:attr('target', '_blank')
:attr('rel', 'noopener noreferrer')
:addClass('external')
else
local title = mw.title.new(link)
wrapper:attr('href', title and title:fullUrl() or mw.uri.localUrl(link))
end
wrapper:node(button)
return styles .. tostring(wrapper)
end
return styles .. tostring(button)
end
return p