Modifica di Modulo:Side box
Vai alla navigazione
Vai alla ricerca
Questa modifica può essere annullata. Controlla le differenze mostrate sotto fra le due versioni per essere certo che il contenuto corrisponda a quanto desiderato, e quindi pubblicare le modifiche per completare la procedura di annullamento.
Versione attuale | Il tuo testo | ||
Riga 1: | Riga 1: | ||
-- This module implements {{side box}}. | |||
local yesno = require('Module:Yesno') | local yesno = require('Module:Yesno') | ||
local p = {} | local p = {} | ||
local function makeData(args) | function p.main(frame) | ||
local origArgs = frame:getParent().args | |||
local args = {} | |||
for k, v in pairs(origArgs) do | |||
v = v:match('%s*(.-)%s*$') | |||
if v ~= '' then | |||
args[k] = v | |||
end | |||
end | |||
return p._main(args) | |||
end | |||
function p._main(args) | |||
local data = p.makeData(args) | |||
return p.renderSidebox(data) | |||
end | |||
function p.makeData(args) | |||
local data = {} | local data = {} | ||
Riga 11: | Riga 31: | ||
end | end | ||
if args.position and args.position:lower() == 'left' then | if args.position and args.position:lower() == 'left' then | ||
table.insert(data.classes, ' | table.insert(data.classes, 'mbox-small-left') | ||
else | else | ||
table.insert(data.classes, ' | table.insert(data.classes, 'mbox-small') | ||
end | end | ||
table.insert(data.classes, args.class) | table.insert(data.classes, args.class) | ||
Riga 33: | Riga 44: | ||
-- Copy over data that does not need adjusting | -- Copy over data that does not need adjusting | ||
local argsToCopy = { | local argsToCopy = { | ||
-- Classes | -- Classes | ||
'textclass', | 'textclass', | ||
-- Styles | -- Styles | ||
'style', | 'style', | ||
'textstyle', | 'textstyle', | ||
-- Above row | -- Above row | ||
Riga 64: | Riga 69: | ||
end | end | ||
function p.renderSidebox(data) | |||
-- Renders the sidebox HTML. | -- Renders the sidebox HTML. | ||
-- Table root | -- Table root | ||
local root = mw.html.create(' | local root = mw.html.create('table') | ||
root:attr('role', | root:attr('role', 'presentation') | ||
for i, class in ipairs(data.classes or {}) do | for i, class in ipairs(data.classes or {}) do | ||
root:addClass(class) | root:addClass(class) | ||
end | end | ||
root:css{border = '1px solid #aaa', ['background-color'] = '#f9f9f9', color = '#000'} | |||
if data.style then | if data.style then | ||
root:cssText(data.style) | root:cssText(data.style) | ||
Riga 81: | Riga 85: | ||
-- The "above" row | -- The "above" row | ||
if data.above then | if data.above then | ||
local | local aboveCell = root:newline():tag('tr'):tag('td') | ||
aboveCell | |||
: | :attr('colspan', data.imageright and 3 or 2) | ||
: | :addClass('mbox-text') | ||
if data.textstyle then | if data.textstyle then | ||
aboveCell:cssText(data.textstyle) | |||
end | end | ||
if data.abovestyle then | if data.abovestyle then | ||
aboveCell:cssText(data.abovestyle) | |||
end | end | ||
aboveCell | |||
:newline() | |||
:wikitext(data.above) | |||
end | end | ||
-- The body row | -- The body row | ||
local | local bodyRow = root:newline():tag('tr'):newline() | ||
if data.image then | if data.image then | ||
bodyRow:tag('td') | |||
:addClass(' | :addClass('mbox-image') | ||
:wikitext(data.image) | :wikitext(data.image) | ||
else | |||
bodyRow:tag('td'):css('width', '1px') | |||
end | end | ||
local | local textCell = bodyRow:newline():tag('td') | ||
textCell:addClass('mbox-text') | |||
textCell:addClass(data.textclass or 'plainlist') | |||
if data.textstyle then | if data.textstyle then | ||
textCell:cssText(data.textstyle) | |||
end | end | ||
textCell:wikitext(data.text) | |||
if data.imageright then | if data.imageright then | ||
bodyRow:newline():tag('td') | |||
:addClass(' | :addClass('mbox-imageright') | ||
:wikitext(data.imageright) | :wikitext(data.imageright) | ||
end | end | ||
Riga 118: | Riga 124: | ||
-- The below row | -- The below row | ||
if data.below then | if data.below then | ||
local | local belowCell = root:newline():tag('tr'):tag('td') | ||
belowCell | |||
: | :attr('colspan', data.imageright and 3 or 2) | ||
: | :addClass('mbox-text') | ||
if data.textstyle then | if data.textstyle then | ||
belowCell:cssText(data.textstyle) | |||
end | end | ||
belowCell:wikitext(data.below) | |||
end | end | ||
root:newline() | root:newline() | ||
return tostring(root) | |||
return | |||
end | end | ||
return p | return p |