« Module:Icône » : différence entre les versions

avt-tooltip pour mobile
Annulation des modifications 169152 de Atsarb (discussion)
 
(2 versions intermédiaires par le même utilisateur non affichées)
Ligne 14 : Ligne 14 :


function p._build(args)
function p._build(args)
    local name = args[1] or DEFAULT_ICON_NAME
local name = args[1] or DEFAULT_ICON_NAME
    local link = args['lien'] or args['link'] or ''
local link = args['lien'] or args['link'] or ''
   
    local icon = icons[name:lower()] or icons[DEFAULT_ICON_NAME]
local icon = icons[name:lower()] or icons[DEFAULT_ICON_NAME]
    local filename = icon.filename
local filename = icon.filename
    local tooltip = args['infobulle'] or args['tooltip'] or icon.tooltip
local tooltip = args['infobulle'] or args['tooltip'] or icon.tooltip
   
    local userSize = args[2] or DEFAULT_SIZE
-- Calcul des dimensions
    local size = STANDARD_SIZE[userSize]
local userSize = args[2] or DEFAULT_SIZE
    if not size then
local size = STANDARD_SIZE[userSize]
        size = userSize:gsub('[px]', '')
if not size then
        size = tonumber(size)
size = userSize:gsub('[px]', '')
        if not size then
size = tonumber(size)
            size = STANDARD_SIZE[DEFAULT_SIZE]
if not size then
        end
size = STANDARD_SIZE[DEFAULT_SIZE]
    end
end
 
end
    local wrapper = mw.html.create('span')
        :addClass('avt-tooltip')
return tostring(mw.html.create('span')
        :css('position', 'relative')
:css('cursor', 'help')
        :css('display', 'inline-block')
:attr('title', tooltip)
 
:wikitext('[[Fichier:'..filename..'|'..size..'x'..size..'px|link='..link..'|alt=]]')
    local iconHtml = '[[Fichier:'..filename..'|'..size..'x'..size..'px|link='..link..'|alt=]]'
:allDone())
    local popup = mw.html.create('span')
        :addClass('avt-tooltip-popup')
        :css('position', 'absolute')
        :css('bottom', '100%')
        :css('left', '50%')
        :css('transform', 'translateX(-50%)')
        :css('background', '#333')
        :css('color', '#fff')
        :css('padding', '5px 8px')
        :css('border-radius', '4px')
        :css('white-space', 'nowrap')
        :css('display', 'none') -- à afficher via hover ou JS
        :wikitext(tooltip)
 
    wrapper:wikitext(iconHtml)
    wrapper:node(popup)
 
    return tostring(wrapper)
end
end


--[[
--[[
Fonction utilisée dans la doc du modèle pour présenter
Fonction utilisée dans la doc du modèle pour présenter
les cônes disponibles aux contributeurs
les icônes disponibles aux contributeurs
]]
]]
function p.doc()
function p.doc()

Dernière version du 24 août 2025 à 17:11

Documentation du module

Ce module contient le paramétrage du modèle {{Icône}}.

Documentation transclues de Module:Icône/doc.
local p = {}

local icons = require('Module:Icône/Données')

local DEFAULT_ICON_NAME = '_DEFAULT'
local DEFAULT_SIZE = 'normal'
local STANDARD_SIZE = {
	petit = '20',
	normal  = '30',
	grand    = '50',
	big = '50',
	geant = '80'
}

function p._build(args)
	local name = args[1] or DEFAULT_ICON_NAME
	local link = args['lien'] or args['link'] or ''
	
	local icon = icons[name:lower()] or icons[DEFAULT_ICON_NAME]
	local filename = icon.filename
	local tooltip = args['infobulle'] or args['tooltip'] or icon.tooltip
	
	-- Calcul des dimensions
	local userSize = args[2] or DEFAULT_SIZE
	local size = STANDARD_SIZE[userSize]
	if not size then
		size = userSize:gsub('[px]', '')
		size = tonumber(size)
		if not size then
			size = STANDARD_SIZE[DEFAULT_SIZE]
		end
	end
	
	return tostring(mw.html.create('span')
		:css('cursor', 'help')
		:attr('title', tooltip)
		:wikitext('[[Fichier:'..filename..'|'..size..'x'..size..'px|link='..link..'|alt=]]')
		:allDone())
end

--[[
	Fonction utilisée dans la doc du modèle pour présenter
	les icônes disponibles aux contributeurs
]]
function p.doc()
	local tabDefinition = '{| class="va-table va-table-center-col2" style="float:left;margin-right:4px;width:250px;"\n!style="width:70%;"|mot-clé!!style="width:30%;"|icône\n'
	local doc = tabDefinition

	keywords = {}
    for k in pairs(icons) do
        table.insert(keywords, k)
    end
    table.sort(keywords)
    
    local split = math.ceil(#keywords / 3)
    local n = 0
    
    for k, v in ipairs(keywords) do
    	if n > split then
    		doc = doc..'\n|}'
    		doc = doc..'\n'..tabDefinition
    		n = 0
    	end
    	
    	n = n + 1
    	local icon = icons[v]
    	
    	doc = doc..'|-\n|<code>'..v..'</code>||[[Fichier:'..icon.filename..'|20x20px|link=]]\n'
    end
    
    doc = doc..'|}'

	return doc
end

function p.build(frame)
	local args = {}
	
	local argsParent = frame:getParent().args
	for cle, val in pairs(argsParent) do
		if val then
			args[cle] = mw.text.trim(val)
		end
	end
	
	return p._build(args)
end

return p