Différences entre les versions de « Module:Boîte d'informations (Galerie) »
Aller à la navigation
Aller à la recherche
(Page créée avec « local p = {} local random = math.random math.randomseed(os.time()) local function uuid() local template ='xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx' return (strin... ») |
|||
| Ligne 35 : | Ligne 35 : | ||
:tag('button') | :tag('button') | ||
:attr('type', 'button') | :attr('type', 'button') | ||
:attr('id', 'tab-' .. uid) | :attr('id', 'tab-' .. uid .. '-' .. i) | ||
:attr('data-target', '#pane-' .. uid) | :attr('data-target', '#pane-' .. uid .. '-' .. i) | ||
:attr('role', 'tab') | :attr('role', 'tab') | ||
:attr('aria-controls', 'pane-' .. uid) | :attr('aria-controls', 'pane-' .. uid .. '-' .. i) | ||
:attr('aria-selected', 1 == i and 'true' or 'false') | :attr('aria-selected', 1 == i and 'true' or 'false') | ||
:wikitext(tabName) | :wikitext(tabName) | ||
| Ligne 50 : | Ligne 50 : | ||
:tag('div') | :tag('div') | ||
:addClass('mw-gallery-pane') | :addClass('mw-gallery-pane') | ||
:attr('id', 'pane-' .. uid) | :attr('id', 'pane-' .. uid .. '-' .. i) | ||
:attr('role', 'tabpanel') | :attr('role', 'tabpanel') | ||
:attr('aria-labelledby', 'tab-' .. uid) | :attr('aria-labelledby', 'tab-' .. uid .. '-' .. i) | ||
:attr('tabindex', '0') | :attr('tabindex', '0') | ||
:wikitext('' ~= tabPicture and '[[Image:' .. tabPicture .. '|290px]]' or '') | :wikitext('' ~= tabPicture and '[[Image:' .. tabPicture .. '|290px]]' or '') | ||
| Ligne 59 : | Ligne 59 : | ||
pane:wikitext('<p class="mw-caption">' .. value .. '</p>') | pane:wikitext('<p class="mw-caption">' .. value .. '</p>') | ||
end | end | ||
if 1 == i then | if 1 == i then | ||
pane:addClass('active') | pane:addClass('active') | ||
| Ligne 68 : | Ligne 68 : | ||
end | end | ||
end | end | ||
return '<div class="mw-gallery">' .. frame:preprocess('<html>' .. tostring(tabs) .. '</html>') .. tostring(panes) .. '</div>' | return '<div class="mw-gallery">' .. frame:preprocess('<html>' .. tostring(tabs) .. '</html>') .. tostring(panes) .. '</div>' | ||
end | end | ||
return p | return p | ||
Version du 23 novembre 2023 à 19:25
Le module Module:Boîte d'informations (Galerie) est utilisé en association avec les différentes boîtes d'information afin de mettre en place une galerie de photos plutôt qu'une seule photo via le paramètre
galerie.
Syntaxe
{{Galerie (Boîte d'informations)
| Onglet #1
| Image #1
| Légende #1
| ...
| ...
| ...
| Onglet #n
| Image #n
| Légende #n
}}
Paramètres
Les paramètres s'utilisent par groupe de trois et sont répétables à l'infini.
| Clé | Titre | Description |
|---|---|---|
| Onglet #? | Titre de l'onglet #? | |
| Image #? | Nom de l'image #? | |
| Légende #? | Légende de l'image #? |
Exemple
{{Boîte d'informations Personnage
| classes =
| titre = Trollocs
| sous titre =
| image =
| légende =
| galerie = {{Boîte d'informations Galerie
| Apparence #1
| Trollocs 2.gif
|
| Apparence #2
| Trollocs 3.gif
| Autre apparence
}}
}}
Trollocs
<html>
- <button type="button" id="tab-d8e42484-5345-4a02-8f1e-9bede5733c29-1" data-target="#pane-d8e42484-5345-4a02-8f1e-9bede5733c29-1" role="tab" aria-controls="pane-d8e42484-5345-4a02-8f1e-9bede5733c29-1" aria-selected="true" class="active">Apparence #1</button>
- <button type="button" id="tab-d8e42484-5345-4a02-8f1e-9bede5733c29-2" data-target="#pane-d8e42484-5345-4a02-8f1e-9bede5733c29-2" role="tab" aria-controls="pane-d8e42484-5345-4a02-8f1e-9bede5733c29-2" aria-selected="false">Apparence #2</button>
Références
local p = {}
local random = math.random
math.randomseed(os.time())
local function uuid()
local template ='xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'
return (string.gsub(template, '[xy]', function (c)
local v = (c == 'x') and random(0, 0xf) or random(8, 0xb)
return string.format('%x', v)
end))
end
function p.build(frame)
local args = frame:getParent().args
local uid = uuid()
local tabs = mw.html.create('ul'):addClass('mw-gallery-tabs'):attr('role', 'tablist')
local panes = mw.html.create('div'):addClass('mw-gallery-panes')
local tabName, tabPicture = nil, nil
local tab, pane = nil, nil
local i = 1
for index, value in ipairs(args) do
if 1 == index % 3 then
-- Memorize tab name
tabName = mw.text.trim(value)
elseif 2 == index % 3 then
-- Memory picture's name
tabPicture = mw.text.trim(value)
else
-- Build tab
tab = tabs
:tag('li')
:attr('role', 'presentation')
:tag('button')
:attr('type', 'button')
:attr('id', 'tab-' .. uid .. '-' .. i)
:attr('data-target', '#pane-' .. uid .. '-' .. i)
:attr('role', 'tab')
:attr('aria-controls', 'pane-' .. uid .. '-' .. i)
:attr('aria-selected', 1 == i and 'true' or 'false')
:wikitext(tabName)
if 1 == i then
tab:addClass('active')
end
-- Build pane
pane = panes
:tag('div')
:addClass('mw-gallery-pane')
:attr('id', 'pane-' .. uid .. '-' .. i)
:attr('role', 'tabpanel')
:attr('aria-labelledby', 'tab-' .. uid .. '-' .. i)
:attr('tabindex', '0')
:wikitext('' ~= tabPicture and '[[Image:' .. tabPicture .. '|290px]]' or '')
if value ~= nill and value ~= '' then
pane:wikitext('<p class="mw-caption">' .. value .. '</p>')
end
if 1 == i then
pane:addClass('active')
end
i = i + 1
tabName, tabPicture, tab, pane = nil, nil, nil, nil
end
end
return '<div class="mw-gallery">' .. frame:preprocess('<html>' .. tostring(tabs) .. '</html>') .. tostring(panes) .. '</div>'
end
return p
