Mòdul:Side box

A continuació es mostra la documentació transclosa de la subpàgina /ús. [salta a la caixa de codi]
Implementa {{Caixa lateral}}. Per a proves podeu utilitzar Mòdul:Side box/proves.
-- This module implements {{side box}}.
local p = {}
function p.main(frame)
-- local args = frame.args
local args = (frame.args[3] ~= nil) and frame.args or frame:getParent().args
local root = mw.html.create('table')
-- root:attr('role', 'presentation')
root:css('border-spacing', '0px 0px')
root:css('width', '238px')
root:css('font-size', '88%')
root:css('line-height', '1.25em')
root:css('border', '1px solid #aaa')
root:css('background-color', '#f9f9f9')
sposition = args['posició'] or args['position'] or ''
if (sposition == 'esquerra') or (sposition == 'left') then
root:css('margin', '4px 1em 4px 0')
root:css('border-collapse', 'collapse')
elseif (sposition == 'centre') or (sposition == 'center') then
root:css('clear', 'both')
root:css('margin', 'auto')
else
root:css('clear', 'right')
root:css('float', 'right')
root:css('margin', '4px 0 4px 1em')
end
local sstyle = args['estil'] or args['style'] or ''
if sstyle then
root:cssText(sstyle)
end
-- general --
local stextstyle = args['estil_de_text'] or args['textstyle'] or ''
local simageright = args['imatge_dreta'] or args['imageright'] or ''
-- The "above" row
local sabove = args['dalt'] or args['above'] or ''
if sabove ~= '' then
local aboveCell = root:newline():tag('tr'):tag('td')
aboveCell
:attr('colspan', simageright and 3 or 2)
:addClass('mbox-text')
if stextstyle ~= '' then
aboveCell:cssText(stextstyle)
end
local sabovestyle = args['estil_de_dalt'] or args['abovestyle'] or ''
if sabovestyle ~= '' then
aboveCell:cssText(sabovestyle)
end
aboveCell
:newline()
:wikitext(sabove)
end
-- The body row
local bodyRow = root:newline():tag('tr'):newline()
local simage = args['imatge'] or args['image'] or ''
local stext = args['text'] or ''
if simage ~= '' then
bodyRow:tag('td')
:addClass('mbox-image')
:wikitext(simage)
else
bodyRow:tag('td'):css('width', '1px')
end
if (stext ~= '') or ((simage == '') and (stext == '')) then
local textCell = bodyRow:newline():tag('td')
textCell:addClass('mbox-text plainlist')
if stextstyle ~= '' then
textCell:cssText(stextstyle)
end
if (simage == '') and (stext == '') then
textCell:wikitext('Cal assignar un text i/o una imatge, així: |text= i/o |imatge')
else
textCell:wikitext(stext)
end
end
if simageright ~= '' then
bodyRow:newline():tag('td')
:addClass('mbox-imageright')
:wikitext(simageright)
end
-- The below row
local sbelow = args['sota'] or args['below'] or ''
if sbelow ~= '' then
local belowCell = root:newline():tag('tr'):tag('td')
belowCell
:attr('colspan', simageright and 3 or 2)
:addClass('mbox-text')
if stextstyle ~= '' then
belowCell:cssText(stextstyle)
end
belowCell:wikitext(sbelow)
end
root:newline()
return tostring(root)
end
return p