Modulo:Immagine multipla: differenze tra le versioni

Contenuto cancellato Contenuto aggiunto
Moroboshi (discussione | contributi)
fix conversione totalwidth
Moroboshi (discussione | contributi)
semplifico il codice
Riga 1:
-- implements [[template:multiple image]]
local p = {}
 
local function isnotempty(s)
return s and s:match( '^%s*(.-)%s*$' ) ~= ''
end
 
local function renderImageCell(image, width, height, link, alt, caption, textalign, istyle)
Line 21 ⟶ 17:
end
imagediv:wikitext('[[file:' .. image .. widthstr .. linkstr .. altstr .. ']]')
if isnotempty(caption) then
local captiondiv = root:tag('div')
captiondiv:addClass('thumbcaption')
captiondiv:css('clear', 'left')
if isnotempty(textalign) then
captiondiv:css('text-align', textalign)
end
Line 35 ⟶ 31:
local function getWidth(w1, w2)
local w
if isnotempty(w1) then
w =return tonumber(w1) or 200
elseif isnotempty(w2) then
w = tonumber(w2)
end
return w(w2 and tonumber(w2)) or 200
end
 
Line 69 ⟶ 63:
-- passed to the template. Index could be not consecutive but the gap between
-- different index must be five or less
local function getImageNumbers(pargsargs)
local imagenumbers = {}
local istart = 1
Line 77 ⟶ 71:
local found = false
for i=istart, iend do
if pargsargs['immagine' .. tostring(i)] then
imagenumbers[#imagenumbers+1] = i
found = true
Line 93 ⟶ 87:
end
 
local function renderMultipleImagesp._render(args, pargs)
 
local width = pargsargs['larghezza']
local dir = pargsargs['direzione']
local align = pargs['allinea'] or args['allinea']
local capalign = pargs['allinea didascalia'] or args['allinea didascalia'] --NEW
local totalwidth = pargs(args['larghezza totale'] orand tonumber(args['larghezza totale'])) or --NEW0
local imgstyle = args['stile immagine']
totalwidth = (totalwidth and tonumber(totalwidth)) or 0
local imgstyleheader = pargs['stile immagine'] or args['stile immaginetitolo']
local headerfooter = pargsargs['titolo'] or pargs['titolosotto']
local footer = pargs['sotto']
local perrow = nil
local thumbclass = {
Line 118 ⟶ 111:
 
-- find all the nonempty images
local imagenumbers = getImageNumbers(pargsargs)
local imagecount = #imagenumbers
if imagecount == 0 then
Line 128 ⟶ 121:
perrow = getPerRow('1', imagecount)
else
perrow = getPerRow(pargsargs['per riga'], imagecount)
end
Line 145 ⟶ 138:
if( k <= imagecount ) then
local i = imagenumbers[k]
widths[k] = getWidth(width, pargsargs['larghezza' .. i])
widthsum[r] = widthsum[r] + widths[k]
end
Line 166 ⟶ 159:
if( k<= imagecount ) then
local i = imagenumbers[k]
local h = tonumber( pargsargs['altezza' .. i] or '' ) or 0
if (h > 0) then
ar[j] = widths[k]/h
Line 207 ⟶ 200:
bodywidth = math.max( 100, bodywidth - 8);
 
local bg = pargsargs['sfondo'] or ''
-- create the array of images
local root = mw.html.create('div')
Line 216 ⟶ 209:
if( align == 'center' or align == 'centre' or align == 'centro') then
root:addClass('center')
end
if( pargs['bordo sopra'] or args['bordo sopra']) then
root:css('margin-top', pargs['bordo sopra'] or args['bordo sopra'])
end
if( pargs['bordo sotto'] or args['bordo sotto']) then
root:css('margin-bottom', pargs['bordo sotto'] or args['bordo sotto'])
end
if( bg ~= '' ) then
Line 235 ⟶ 222:
end
-- add the header
if( isnotempty(header) ) then
div:tag('div')
:css('clear', 'both')
:css('text-align', pargsargs['allinea titolo'] or 'center')
:css('background-color', pargsargs['sfondo titolo'] or 'transparent')
:wikitext(header)
end
Line 258 ⟶ 245:
imagediv:css('margin', '1px')
local i = imagenumbers[k]
local img = pargsargs['immagine' .. i]
local w = widths[k]
imagediv:css('width', tostring(2 + w) .. 'px')
:css('max-width', tostring(2 + w) .. 'px')
imagediv:wikitext(renderImageCell(img, w, heights[k],
pargsargs['collegamento' .. i], pargsargs['alt' .. i],
pargsargs['didascalia' .. i], capalign, imgstyle))
end
end
Line 274 ⟶ 261:
end
-- add the footer
if( isnotempty(footer) ) then
div:tag('div')
:addClass('thumbcaption')
:css('clear', 'left')
:css('text-align', pargs['allinea sotto'] or args['allinea sotto'] or 'left')
:css('background-color', pargsargs['sfondo sotto'] or 'transparent')
:wikitext(footer)
end
Line 289 ⟶ 276:
function p.render( frame )
local getArgs = require('Module:Arguments').getArgs
--local pargs = getArgs(frame, {parentOnly=true})
local args = getArgs(frame, {frameOnly=true})
return renderMultipleImagesp._render( args, pargs )
end