Module:Boîte d'informations (Galerie)

De Encyclopédie francophone de la Roue du Temps
Aller à la navigation Aller à la recherche
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

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('htmltag')
                :attr('tagname', 'button')
                :attr('type','button')
                :attr('id', 'tab-' .. uid .. '-' .. i)
                :attr('role', 'tab')
                :attr('aria-controls', 'pane-' .. uid .. '-' .. i)
                :attr('aria-selected', 1 == i and 'true' or 'false')
                :attr('data-target', '#pane-' .. uid .. '-' .. i)
                :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(tostring(tabs)) .. tostring(panes) .. '</div>'
end

return p