Basculer le menu
Changer de menu des préférences
Basculer le menu personnel
Non connecté(e)
Votre adresse IP sera visible au public si vous faites des modifications.

« Module:MiniCard » : différence entre les versions

De Nefald
Hiob (discussion | contributions)
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... »
 
Hiob (discussion | contributions)
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 "")
      
      
    -- 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
     if text == "" and link ~= "" then
         text = link
         text = link
     end
     end
      
      
    -- Détection lien externe
     local isExternal = link:match("^https?://") or link:match("^//")
     local isExternal = link:match("^https?://") or link:match("^//")
      
      
     -- Construction de la card (HTML)
     -- Construction HTML avec mw.html
     local card = mw.html.create('span'):addClass('minicard')
     local button = mw.html.create('span'):addClass('minicard-button')
      
      
     -- Ajouter classe si pas d'image
     -- Icône si image fournie
     if image == "" then
     if image ~= "" then
        card:addClass('minicard--no-image')
         local icon = button:tag('span'):addClass('minicard-icon')
    else
         icon:wikitext('[[Fichier:' .. image .. '|20px|link=]]')
        -- Background avec image
         local bg = card:tag('span'):addClass('minicard-background')
         -- Image sans lien (important: link= vide)
        bg:wikitext('[[Fichier:' .. image .. '|link=|60px]]')
        -- Overlay
        bg:tag('span'):addClass('minicard-overlay')
     end
     end
      
      
     -- Texte
     -- Texte
     card:tag('span'):addClass('minicard-text'):wikitext(text)
     button:tag('span'):addClass('minicard-text'):wikitext(text)
      
      
     -- Wrapper avec lien
    -- 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')
            :addClass('minicard-wrapper')
          
          
         if isExternal then
         if isExternal then
Ligne 47 : Ligne 38 :
                   :addClass('external')
                   :addClass('external')
         else
         else
            -- Lien interne : construire l'URL
             local title = mw.title.new(link)
             local title = mw.title.new(link)
             if title then
             wrapper:attr('href', title and title:fullUrl() or mw.uri.localUrl(link))
                wrapper:attr('href', title:fullUrl())
            else
                wrapper:attr('href', '#')
            end
         end
         end
          
          
         wrapper:node(card)
         wrapper:node(button)
         return css .. tostring(wrapper)
         return styles .. tostring(wrapper)
    else
        -- Pas de lien
        return css .. tostring(card)
     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
Les témoins (''cookies'') nous aident à fournir nos services. En utilisant nos services, vous acceptez notre utilisation de témoins.