Modulo:Navbox: differenze tra le versioni

Contenuto cancellato Contenuto aggiunto
aggiunto modulo No globals
aggiornato all'uso degli apici singoli, virgolette e singolo underscore
Riga 4:
]]
 
require("Module'Modulo:No globals"')
 
local getArgs = require("'Modulo:Arguments"').getArgs
 
-- Configurazione
local cfg = mw.loadData("'Modulo:Navbox/Configurazione"')
 
-------------------------------------------------------------------------------
Riga 20:
 
if not ret then
local id = name:match("'^list(%d+)$"') or name:match("'^group(%d+)$"') or
name:match("'^list(%d+)style$"') or name:match("'^group(%d+)style$"')
if id then
ret = tonumber(id) <= maxList
Riga 38:
 
for k, v in pairs(args) do
if type(k) == "'string"' and v ~= ""'' and isValidArg(k, validArgs, maxList) then
ret[k] = v
end
Riga 51:
 
for k, v in pairs(args) do
local id = k:match("'^list(%d+)$"')
if id then
table.insert(ret, tonumber(id))
Riga 78:
local thNode
local thStyle = {
["'text-align"'] = "'center"',
width = "'100%"',
background = "'#ccf"',
["'font-size"'] = "'90%"'
}
 
setmetatable(self, { __index = Navbox, })
__tostring = function(t) return self:__tostring() end })
self.args = args
-- costruzione table
self.tableNode = mw.html.create("'table"')
if self.args.debug then
disableCSS(self.tableNode)
end
self:__setupTableNode_setupTableNode()
-- prima row: contiene la navbar e il titolo
thNode = self.tableNode:tag("'tr"')
:tag("'th"')
:attr("'colspan"', self.args.image and "'3"' or "'2"')
:css(thStyle)
:cssText(self.args.titlestyle)
if self.args.navbar ~= "'plain"' then
self:__addTnavbar_addTnavbar(thNode)
end
if self.args.title then
self:__addTitle_addTitle(thNode)
end
-- eventuale row per l'above
if self.args.above then
self:__addAboveOrBelow_addAboveOrBelow(self.args.above, self.args.abovestyle)
end
-- altre row
self:__addLists_addLists()
-- eventuale row finale per il below
if self.args.below then
self:__addAboveOrBelow_addAboveOrBelow(self.args.below, self.args.belowstyle)
end
 
Line 119 ⟶ 118:
end
 
function Navbox:__tostringgetHTML()
return tostring(self.tableNode)
end
 
function Navbox:__setupTableNode_setupTableNode()
local tableStyle = {
margin = "'auto"',
width = "'100%"',
clear = "'both"',
border = "'1px solid #aaa"',
padding = "'2px"'
}
self.tableNode
:addClass("'navbox"')
:addClass("'mw-collapsible"')
:addClass(self.args.state == "'collapsed"' and "'mw-collapsed"' or
(self.args.state == "'autocollapse"' and "'autocollapse"' or
(not self.args.state and "'autocollapse"' or nil)))
:addClass("'nowraplinks"')
:addClass("'noprint"')
:addClass("'metadata"')
:css(tableStyle)
:cssText(self.args.style)
Line 145 ⟶ 144:
end
 
function Navbox:__addTnavbar_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"',
args = {
[1] = self.args.name,
["'mini"'] = 1
}
}
node:tag("'div"'):css(divStyle):wikitext(tnavbar)
end
 
function Navbox:__addTitle_addTitle(node)
node:tag("'span"'):css("'font-size"', "'110%"'):wikitext(self.args.title)
end
 
function Navbox:__addAboveOrBelow_addAboveOrBelow(arg, argStyle)
local tdStyle = {
background = "'#ddf"',
["'text-align"'] = "'center"',
["'font-size"'] = "'90%"'
}
self.tableNode
:tag("'tr"')
:tag("'td"')
:attr("'colspan"', self.args.image and "'3"' or "'2"')
:css(tdStyle)
:cssText(argStyle)
Line 182 ⟶ 181:
end
 
function Navbox:__addImage_addImage(trNode, rowspan)
local tdStyle = {
["'vertical-align"'] = "'middle"',
["'padding-left"'] = "'7px"',
width = "'0%"'
}
trNode
:tag("'td"')
:attr("'rowspan"', rowspan)
:css(tdStyle)
:cssText(self.args.imagestyle)
Line 196 ⟶ 195:
end
 
function Navbox:__addLists_addLists()
local listIds, altStyle, altBackground
local thStyle = {
background = "'#ddf"',
["'white-space"'] = "'nowrap"',
padding = "'0 10px"',
["'font-size"'] = "'90%"'
}
-- crea una row per ogni listN
listIds = getListIds(self.args)
for _, id in ipairs(listIds) do
local trNode = self.tableNode:tag("'tr"')
-- i groupN sono visibili solo se c'è la corrispettiva listN
if self.args["'group"' .. id] then
trNode:tag("'th"')
:css(thStyle)
:cssText(self.args.groupstyle)
:cssText(self.args["'group"' .. id .. "'style"'])
:wikitext(self.args["'group"' .. id])
end
if (id % 2) == 0 then
altStyle = self.args.evenstyle
altBackground = "'#f7f7f7"'
else
altStyle = self.args.oddstyle
altBackground = nil
end
trNode:tag("'td"')
:attr("'colspan"', self.args["'group"' .. id] and "'1"' or "'2"')
:css("'width"', "'100%"')
:css("'font-size"', "'90%"')
:css("'text-align"', self.args["'group"' .. id] and "'left"' or "'center"')
:css("'background"', altBackground)
:cssText(self.args.liststyle)
:cssText(altStyle)
:cssText(self.args["'list"' .. id .. "'style"'])
:wikitext(self.args["'list"' .. id])
if id == 1 and self.args.image then
self:__addImage_addImage(trNode, #listIds)
end
end
Line 248 ⟶ 247:
local self = {}
 
setmetatable(self, { __index = NavboxSubgroup, })
__tostring = function(t) return self:__tostring() end })
self.args = args
-- costruzione table
self.tableNode = mw.html.create("'table"')
if self.args.debug then
disableCSS(self.tableNode)
end
self:__setupTableNode_setupTableNode()
self:__addLists_addLists()
 
return self
end
 
function NavboxSubgroup:__tostringgetHTML()
return tostring(self.tableNode)
end
 
function NavboxSubgroup:__setupTableNode_setupTableNode()
local tableStyle = {
background = "'transparent"',
["'font-size"'] = "'100%"',
padding = "'0"',
border = "'0"',
margin = "'-3px"',
width = "'100%"'
}
self.tableNode
:addClass("'navbox"')
:addClass("'nowraplinks"')
:css(tableStyle)
:cssText(self.args.bodystyle)
end
 
function NavboxSubgroup:__addLists_addLists()
local listIds, altStyle
local thStyle = {
background = "'#ddf"',
padding = "'0 10px"',
}
-- crea una row per ogni listN
listIds = getListIds(self.args)
for _, id in ipairs(listIds) do
local trNode = self.tableNode:tag("'tr"')
-- i groupN sono visibili solo se c'è la corrispettiva listN
if self.args["'group"' .. id] then
trNode:tag("'th"')
:css(thStyle)
:cssText(self.args.groupstyle)
:wikitext(self.args["'group"' .. id])
end
if (id % 2) == 0 then
Line 304 ⟶ 302:
altStyle = self.args.oddstyle
end
trNode:tag("'td"')
:attr("'colspan"', self.args["'group"' .. id] and "'1"' or "'2"')
:css("'text-align"', self.args["'group"' .. id] and "'left"' or "'center"')
:cssText(self.args.liststyle)
:cssText(altStyle)
:wikitext(self.args["'list"' .. id])
end
end
Line 320 ⟶ 318:
 
function p._navbox(args)
return Navbox:new(parseArgs(args)):getHTML()
end
 
function p._navbox_subgroup(args)
return NavboxSubgroup:new(parseArgs(args, true)):getHTML()
end