Modulo:Immagine multipla: differenze tra le versioni
Contenuto cancellato Contenuto aggiunto
fix per div centrato |
Evita background-color: transparent, non funziona bene con la night mode. Impostando il valore a nil la proprietà viene omessa del tutto. |
||
(10 versioni intermedie di 3 utenti non mostrate) | |||
Riga 1:
--=====================================================
-- Implementazione del [[template:Immagine multipla]]
-- Importato e modificato da
-- https://en.wikipedia.org/w/index.php?title=Module:Multiple_image&oldid=706647916
--=====================================================
local p = {}
--=====================================================
-- Generazione del codice una singola cella contenente
-- un'immagine
--=====================================================
local function renderImageCell(image, width, height, link, alt, caption, textalign, istyle)
local root = mw.html.create('')
Line 12 ⟶ 21:
imagediv:addClass('thumbimage')
imagediv:cssText(istyle)
if
imagediv:css('height', tostring(height) .. 'px')
imagediv:css('overflow', 'hidden')
Line 29 ⟶ 38:
end
--=====================================================
local function getWidth(w1, w2)▼
-- Ritorna una tabella che contiene il numero di immagini
-- per ogni riga.
if w1 then▼
-- pstr deve essere una stringa di numeri separati da qualunque
--
end▼
--=====================================================
return (w2 and tonumber(w2)) or 200▼
end▼
local function getPerRow(pstr, ic)
-- split string into array using any non-digit as a dilimiter
Line 58 ⟶ 65:
end
return prownum
▲end
--=====================================================
-- Ritorna le dimensioni dell'immagine (larghezza x altezza)
-- Se queste non sono passate dai parametri tenta di recuperarle
-- dalle informazioni del file immagine, altrimenti ricade su
-- una larghezza pari a 200 e un'altezza pari alla larghezza
--=====================================================
local wr = w and tonumber(w)
local hr = h and tonumber(h)
local page = mw.title.new(name, 'Media')
if not wr then
wr = page.file and page.file.width
end▼
hr = page.file and page.file.height
end▼
▲ end
wr = wr or 200
hr = hr or wr
return wr, hr
end
Line 77 ⟶ 108:
end
if found then
istart =
iend = iend + istep
else
Line 87 ⟶ 118:
end
-- La funzione effettiva di creazione della galleria
function p._render(args)
local width = (args['larghezza'] and tonumber(args['larghezza'])) or 200
local dir = args['direzione']
local align = args['allinea']
Line 131 ⟶ 163:
local widthmax = 0
local widthsum = {}
local heights = {}▼
local k = 0
for r=1,rowcount do
Line 137 ⟶ 170:
k = k + 1
if k <= imagecount then
widths[k], heights[k] = get_dimensions(w, h, args['immagine' .. imagenumbers[k]])
end▼
widthsum[r] = widthsum[r] + widths[k]
end
Line 145 ⟶ 184:
-- if total_width has been specified, rescale the image widths
▲ local heights = {}
if totalwidth > 0 then
widthmax = 0
Line 156 ⟶ 194:
for j=1,perrow[r] do
k = k + 1
if
▲ local h = tonumber( args['altezza' .. i] or '' ) or 0
▲ if (h > 0) then
▲ ar[j] = widths[k]/h
else
ar[j] = widths[k]/100
Line 173 ⟶ 208:
for j=1,perrow[r] do
k = k + 1
if
local i = imagenumbers[k]
widths[k] = math.floor(ar[j]*ht + 0.5)
Line 192 ⟶ 227:
local bodywidth = 0
for r=1,rowcount do
local bw = widthsum[r] + 4 * (perrow[r] - 1) +
bodywidth = math.max(bodywidth, bw)
end
-- The body has a min-width of 100, which needs to be taken into account on specific widths
bodywidth = math.max( 100, bodywidth
-- crea il div esterno per la galleria di immagini
local root = mw.html.create('div')
root:addClass('thumb')
root:addClass(thumbclass[align] or 'tright')
-- crea il div interno
root:css('clear', 'both')▼
root:css('text-align', 'center')▼
▲ end
▲ end
local div = root:tag('div')
div:addClass('thumbinner')
div:css('width', tostring(bodywidth+2) .. 'px')
:css('
if
div:css('
end
--
if header then
div:tag('div')
:css('clear', 'both')
:css('text-align', args['allinea titolo'] or 'center')
:css('background-color', args['sfondo titolo']
:wikitext(header)
end
Line 236 ⟶ 258:
for j=1,perrow[r] do
k = k + 1
if
local imagediv = div:tag('div')
imagediv:addClass('tsingle')
if dir ~= 'vertical' then
imagediv:css('float', 'left')
▲ end
▲ if bg ~= '' then
end
imagediv:css('margin', '1px')
Line 250 ⟶ 269:
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],
args['collegamento' .. i], args['alt' .. i],
Line 256 ⟶ 277:
end
end
--
▲ :css('clear', 'left')
▲ end
end
-- add the footer
Line 268 ⟶ 286:
:css('clear', 'left')
:css('text-align', args['allinea sotto'] or 'left')
:css('background-color', args['sfondo sotto']
end
return tostring(root)
Line 276 ⟶ 294:
end
--interfaccia verso il template immagine multipla
function p.render( frame )
local getArgs = require('Module:Arguments').getArgs
Line 283 ⟶ 302:
end
--interfaccia verso template più specifici ({{Doppia immagine}}, {{tripla immagine}}...)
function p.render_frame( frame )
local getArgs = require('Module:Arguments').getArgs
local args = getArgs(frame, {frameOnly=true})
return p._render( args )
end
return p
|