Module:Side box/sandbox: Difference between revisions

Content deleted Content added
redundant
nothing could go possibly wrong with this design
Line 5:
local p = {}
 
local function p.mainmakeData(frameargs)
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 = {}
 
Line 31 ⟶ 14:
end
if args.position and args.position:lower() == 'left' then
table.insert(data.classes, 'mboxside-smallbar-left')
else
table.insert(data.classes, 'mboxside-smallbar-right')
end
table.insert(data.classes, args.class)
Line 69 ⟶ 52:
end
 
local function p.renderSidebox(data)
-- Renders the sidebox HTML.
 
-- Table root
local root = mw.html.create('tablediv')
root:attr('role', 'presentation')
:addClass('side-box')
for i, class in ipairs(data.classes or {}) do
root:addClass(class)
end
root:css{border = '1px solid #aaa', ['background-color'] = '#f9f9f9', color = '#000'}
if data.style then
root:cssText(data.style)
Line 85 ⟶ 68:
-- The "above" row
if data.above then
local aboveCellabove = root:newline():tag('tr'):tag('tddiv')
above:addClass('side-box-abovebelow')
aboveCell
:newline()
:attr('colspan', data.imageright and 3 or 2)
:addClasswikitext('mbox-text'data.above)
if data.textstyle then
aboveCellabove:cssText(data.textstyle)
end
if data.abovestyle then
aboveCellabove:cssText(data.abovestyle)
end
aboveCell
:newline()
:wikitext(data.above)
end
 
-- The body row
local bodyRowbody = root:newline():tag('trdiv'):addClass('side-box-flex'):newline()
if data.image then
bodyRowbody:tag('tddiv')
:addClass('mboxside-box-image')
:wikitext(data.image)
else
bodyRow:tag('td'):css('width', '1px')
end
local textCelltext = bodyRowbody:newline():tag('tddiv')
textCelltext:addClass('mboxside-box-text')
textCell :addClass(data.textclass or 'plainlist')
if data.textstyle then
textCelltext:cssText(data.textstyle)
end
textCelltext:wikitext(data.text)
if data.imageright then
bodyRowbody:newline():tag('tddiv')
:addClass('mboxside-box-imageright')
:wikitext(data.imageright)
end
Line 124 ⟶ 102:
-- The below row
if data.below then
local belowCellbelow = root:newline():tag('tr'):tag('tddiv')
below
belowCell
:addClass('side-box-abovebelow')
:attr('colspan', data.imageright and 3 or 2)
:addClasswikitext('mbox-text'data.below)
if data.textstyle then
belowCellbelow:cssText(data.textstyle)
end
belowCell:wikitext(data.below)
end
 
root:newline()
return tostringmw.getCurrentFrame(root):extensionTag{
'templatestyles', args = { src = 'Module:Side box/styles.css' }
} .. tostring(root)
end
 
function p._main(args)
local data = p.makeData(args)
return p.renderSidebox(data)
end
 
function p.makeDatamain(argsframe)
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