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:ButtonLink » : 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 -- 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
 
Hiob (discussion | contributions)
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 style = ''
     local divStyle = ''
     if bg ~= '' then
     if bg ~= '' then
         style = ' style="background: ' .. bg .. ';"'
         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 HTML final
     -- Construction du lien
     local html = mw.html.create('div')
     local linkHtml = '<a href="' .. mw.text.encode(link) .. '" class="button-link__link" title="' .. mw.text.encode(title) .. '">'  
        :addClass(cssClass)
                    .. imageCode  
        :cssText(bg ~= '' and 'background: ' .. bg or nil)
                    .. textHtml  
        :tag('a')
                    .. '</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)
     -- 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

Dernière version du 5 novembre 2025 à 16:11

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
Les témoins (''cookies'') nous aident à fournir nos services. En utilisant nos services, vous acceptez notre utilisation de témoins.