Modulo:Navbox: differenze tra le versioni

Contenuto cancellato Contenuto aggiunto
aggiornato stile documentazione a quello usato in Mediawiki per Lua, utilizzo di Modulo:Controllo parametri sconosciuti, successivo a questo modulo
navbar obbligatorio, v. Discussioni_template:Navbox#Barra_navigazione_Template. è disabilitato senza valido motivo in oltre 700 template, mentre gli usi in portali/progetti sono 7 e risolvibili in altri modi
 
(7 versioni intermedie di 2 utenti non mostrate)
Riga 3:
]]--
 
require('Modulo:No globalsstrict')
 
local getArgs = require('Modulo:Arguments').getArgs
Riga 23:
local ret, ids = {}, {}
for key, _ in pairs(args) do
if type(key) == 'string' then
local id = key:match('^list(%d+)$') or (withGroup and key:match('^group(%d+)$'))
if local id and= tonumberkey:match(id'^list(%d+)$') <=or (withGroup and MAX_LIST_NAVBOX or MAX_LIST_NAVBOX_SUBGROUPkey:match('^group(%d+)$')) then
if id and tonumber(id) <= (withGroup and MAX_LIST_NAVBOX or MAX_LIST_NAVBOX_SUBGROUP) then
ids[tonumber(id)] = true
end
end
end
Line 46 ⟶ 48:
 
-- Con il debug ridefinisce il metodo mw.html:css,
-- permettendo di eseguire i test senza controllare anche iil cssCSS.
--
-- @param {table} tableNode
Line 52 ⟶ 54:
local mt = getmetatable(tableNode)
mt.__index.css = function(t, name, val) return t end
end
 
-- Verifica se il template è elaborato nella sua pagina
local function isTemplatePage(name)
local title = mw.title.getCurrentTitle().prefixedText
name = 'Template:' .. (name or '')
return name == title and true or false
end
 
-- Carica il CSS via TemplateStyles quando opportuno
local function loadCSS(name)
local prefix = isTemplatePage(name) and 'mobile-' or ''
local styles = 'Modulo:Navbox/' .. prefix .. 'styles.css'
return mw.getCurrentFrame():extensionTag{
name = 'templatestyles',
args = {src = styles}
}
end
 
Line 67 ⟶ 86:
local self = {}
local thNode
local thStyle = {
['text-align'] = 'center',
width = '100%',
background = '#ccf',
['font-size'] = '90%'
}
 
setmetatable(self, { __index = Navbox })
Line 86 ⟶ 99:
:tag('th')
:attr('colspan', self.args.image and '3' or '2')
:css(thStyle)
:cssText(self.args.titlestyle)
self:_addTnavbar(thNode)
if self.args.navbar ~= 'plain' then
self:_addTnavbar(thNode)
end
if self.args.title then
self:_addTitle(thNode)
Line 117 ⟶ 127:
-- Configura gli stili CSS della tabella
function Navbox:_setupTableNode()
local tableStyle = {
margin = 'auto',
width = '100%',
clear = 'both',
border = '1px solid #aaa',
padding = '2px'
}
self.tableNode
:addClass(isTemplatePage(self.args.name) and 'navbox_mobile' or 'navbox')
:addClass('mw-collapsible')
:addClass(isTemplatePage(self.args.state == 'collapsed'name) and 'mw-collapsedautocollapse' or
(self.args.state == 'autocollapsecollapsed' and 'autocollapsemw-collapsed' or
(not self.args.state == 'autocollapse' and 'autocollapse' or nil)))
not self.args.state and 'autocollapse' or nil)
:addClass('nowraplinks')
:addClass('noprint metadata')
:attr('id', 'navbox-' .. (self.args.name or ''))
:addClass('metadata')
:css(tableStyle)
:cssText(self.args.style)
:cssText(self.args.bodystyle)
Line 142 ⟶ 144:
-- @param {table} node
function Navbox:_addTnavbar(node)
local divStyle = {
float = 'left',
width = '6em',
['text-align'] = 'left',
padding = '0 10px 0 0',
margin = '0px'
}
local tnavbar = mw.getCurrentFrame():expandTemplate {
title = 'Tnavbar',
Line 156 ⟶ 151:
}
}
node:tag('div'):cssaddClass(divStyle'navbox_navbar'):wikitext(tnavbar)
end
 
Line 163 ⟶ 158:
-- @param {table} node
function Navbox:_addTitle(node)
node:tag('span'):cssaddClass('font-size', '110%navbox_title'):wikitext(self.args.title)
end
 
Line 171 ⟶ 166:
-- @param {string} argStyle
function Navbox:_addAboveOrBelow(arg, argStyle)
local tdStyle = {
background = '#ddf',
['text-align'] = 'center',
['font-size'] = '90%'
}
self.tableNode
:tag('tr')
:tag('tdth')
:attr('colspan', self.args.image and '3' or '2')
:cssaddClass(tdStyle'navbox_abovebelow')
:cssText(argStyle)
:wikitext(arg)
Line 190 ⟶ 180:
-- @param {number} rowspan
function Navbox:_addImage(trNode, rowspan)
local tdStyle = {
['vertical-align'] = 'middle',
['padding-left'] = '7px',
width = '0%'
}
trNode
:tag('td')
:attr('rowspan', rowspan)
:cssaddClass(tdStyle'navbox_image')
:cssText(self.args.imagestyle)
:wikitext(self.args.image)
Line 206 ⟶ 191:
function Navbox:_addLists()
local rowIds, altStyle, altBackground
local thStyle = {
background = '#ddf',
['white-space'] = 'nowrap',
padding = '0 10px',
['font-size'] = '90%'
}
-- crea una riga per ogni groupN/listN
rowIds = getIds(self.args, true)
for _i, id in ipairs(rowIds) do
local trNode = self.tableNode:tag('tr')
-- groupN
Line 220 ⟶ 199:
trNode:tag('th')
:attr('colspan', self.args['list' .. id] and '1' or '2')
:cssaddClass(thStyle'navbox_group')
:cssText(self.args.groupstyle)
:cssText(self.args['group' .. id .. 'style'])
Line 228 ⟶ 207:
if self.args['list' .. id] then
local list = trimSep(self.args['list' .. id])
if (idi % 2) == 0 then
altStyle = self.args.evenstyle
altBackground = '#f7f7f7navbox_even'
else
altStyle = self.args.oddstyle
altBackground = nil'navbox_odd'
end
trNode:tag('td')
:attr('colspan', self.args['group' .. id] and '1' or '2')
:cssaddClass('width', '100%navbox_list')
:cssaddClass('text-align',not self.args['group' .. id] and 'leftnavbox_center' or 'center'nil)
:css('font-size', '90%')
:addClass('nowraplinks'altBackground)
:css('text-align', self.args['group' .. id] and 'left' or 'center')
:css('background', altBackground)
:cssText(self.args.liststyle)
:cssText(altStyle)
Line 287 ⟶ 265:
-- Configura gli stili CSS della tabella.
function NavboxSubgroup:_setupTableNode()
local tableStyle = {
background = 'transparent',
['font-size'] = '100%',
padding = '0',
border = '0',
margin = '-3px',
width = '100%'
}
self.tableNode
:addClass('navboxsubnavbox')
:addClass('nowraplinks')
:css(tableStyle)
:cssText(self.args.bodystyle)
end
Line 305 ⟶ 273:
function NavboxSubgroup:_addLists()
local listIds, altStyle
local thStyle = {
background = '#ddf',
padding = '0 10px',
}
-- crea una row per ogni listN
listIds = getIds(self.args)
Line 317 ⟶ 281:
if self.args['group' .. id] then
trNode:tag('th')
:cssaddClass(thStyle'subnavbox_group')
:cssText(self.args.groupstyle)
:wikitext(self.args['group' .. id])
Line 328 ⟶ 292:
trNode:tag('td')
:attr('colspan', self.args['group' .. id] and '1' or '2')
:cssaddClass('text-align',not self.args['group' .. id] and 'leftnavbox_center' or 'center'nil)
:cssText(self.args.liststyle)
:cssText(altStyle)
Line 343 ⟶ 307:
-- Funzione per l'utilizzo da un altro modulo.
function p._navbox(args)
return loadCSS(args.name) .. Navbox:new(args):getHTML()
end