Modulo:Partiti/sandbox: differenze tra le versioni

Contenuto cancellato Contenuto aggiunto
Moroboshi (discussione | contributi)
Nessun oggetto della modifica
151 cp (discussione | contributi)
Nessun oggetto della modifica
 
(14 versioni intermedie di 2 utenti non mostrate)
Riga 5:
-- corregge un valore di ritorno se questo inizia per '#'
-- vedi bug https://phabricator.wikimedia.org/T14974
-- sostiuendosostituendo l'entità html al carattere #
-- =====================================================
local function fix_return(colore)
Riga 24:
local x2 = mw.ustring.find(b,'%|')
local x3 = mw.ustring.find(b,'%]%]')
local x4 = mw.ustring.find(b,'%<s')
local x5 = mw.ustring.find(b,'%–')
if (x3) then
if (x4) then
a=mw.ustring.sub(a,x1,x3+x1)
end
if (x5) then
a=mw.ustring.sub(a,x1,x3+x1)
end
if (x2) then
a = mw.ustring.sub(a,x1+2,x2+x1)
Line 32 ⟶ 40:
end
end
a = mw.text.decode(a)
return a
end
Line 45 ⟶ 54:
-- ==========================================================
local function _colore(partito, default, ombra)
default = default or '#DABAD0'
if partito == nil then return fix_return(default) end
local partito_indice = estrai(partito)
Line 58 ⟶ 67:
end
 
-- ==========================================================
 
-- Funzione specializzata per il template elezioni
-- Calcola il colore in base al fatto che siano valorizzati i
-- seguenti parametri in ordine di precedenza:
-- - colore
-- - coalizione
-- - partito
-- ==========================================================
local function colore_elezioni(frame)
local args = getArgs(frame)
Line 65 ⟶ 81:
if args.coalizione then
local try_colore_coalizione =_colore(args.coalizione)
if try_colore_coalizione and try_colore_coalizione ~='' then return try_colore_coalizione end
end
if args.partito then
return _colore(args.partito)
end
if args.partito then return _colore(args.partito) end
if args.gruppo then return _colore(args.gruppo) end
if args.coll then return _colore(args.coll) end
return ''
end
Line 110 ⟶ 126:
cls[3] = 255 - math.floor((255-cls[3])*opac)
return string.format('&#35;%02x%02x%02x',cls[1],cls[2],cls[3])
end
 
-- ==========================================================
-- Converte codice hex in rgb percentuale
-- ==========================================================
local function codice(frame)
local args = getArgs(frame, {frameOnly = true})
local col = _colore(args[1], args[2])
local rgb = col:sub(6)
return (rgb:sub(1,6))
end
 
local function cod(frame)
local args = getArgs(frame, {frameOnly = true})
local col = _colore(args[1], args[2])
local rgb = col:sub(6)
local cls = {}
if (rgb:len() == 6) then
cls[1] = tonumber(rgb:sub(1,2),16) or 255
cls[2] = tonumber(rgb:sub(3,4),16) or 255
cls[3] = tonumber(rgb:sub(5,6),16) or 255
end
cls[1] = math.floor(cls[1]/255)
cls[2] = math.floor(cls[2]/255)
cls[3] = math.floor(cls[3]/255)
return string.format('%02x%02x%02x',cls[1],cls[2],cls[3])
end
 
Line 177 ⟶ 219:
color_table = color_table,
colore_ombra = colore_ombra,
sfondo = sfondo,
codice = codice,
cod = cod
}