« Module:Collapse list » : différence entre les versions

De Wikimedica
(Classe pour les ...)
(Espace)
 
Ligne 19 : Ligne 19 :


     if i == count + 1 then
     if i == count + 1 then
     output = output .. ' <span class="collapsible-list-dots">... </span><span class="collapsible-list" style="display:none;">'
     output = output .. ' <span class="collapsible-list-dots">...</span><span class="collapsible-list" style="display:none;">'
     end  
     end  
    
    
Ligne 30 : Ligne 30 :
     -- If the list was concatenated, close the span
     -- If the list was concatenated, close the span
     if # list > count then  
     if # list > count then  
     output = output .. '</span><span class="collapsible-list-toggle" style="cursor: pointer">[+]</span>'  
     output = output .. '</span>&nbsp;<span class="collapsible-list-toggle" style="cursor: pointer">[+]</span>'  
     end
     end
      
      

Dernière version du 13 mars 2024 à 17:41


Utilisation

Affiche une version réduite d'une liste d'items et permet de la ventiler.

Exemples

Paramètres

Affiche une version réduite d'une liste d'items et permet de la ventiler.

Paramètres du modèle

ParamètreDescriptionTypeÉtat
Liste1

aucune description

Chaîneobligatoire
Compte2

Après combien d'items est-ce qu'il faut stopper la liste.

Par défaut
10
Nombrefacultatif
séparateur3

La chaîne qui sépare les éléments de la liste.

Par défaut
,
Chaînefacultatif

-- For debugging: =p.collapse(mw.getCurrentFrame():newChild{title="Module:Collapse",args={"a, b, c, d, e, f", 3}})

local p = {}

function p.collapse( frame )
    list = frame.args[1]
    
    count = 10
    if frame.args[2] then count = tonumber(frame.args[2]) end
    
    separator = ','
    if frame.args[3] then separator = frame.args[3] end
    	
    list = mw.text.split(list, separator);
    
    output = ''
    
    for i = 1, #list do

    	if i == count + 1 then
    		output = output .. ' <span class="collapsible-list-dots">...</span><span class="collapsible-list" style="display:none;">'
    	end 
    	
    	output = output .. list[i]
    	
    	-- if this is not the last element, add a separator
    	if i ~= #list then output = output .. separator end
    end
    
    -- If the list was concatenated, close the span
    if # list > count then 
    	output = output .. '</span>&nbsp;<span class="collapsible-list-toggle" style="cursor: pointer">[+]</span>' 
    end
    
    -- The JS code to make the list collapsible is in MediaWiki:Common.js and MediaWiki:Mobile.css.
    
    return output
end

return p