Bureaucrats, Moderators (CommentStreams), Interface administrators, Push subscription managers, Suppressors, Administrators
11,987
edits
(we cookin with plainlist templatestyles now) |
m (1 revision imported) |
||
| Line 1: | Line 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 = {} | ||
| Line 11: | Line 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) | ||
| Line 29: | Line 40: | ||
if args.image and args.image ~= 'none' then | if args.image and args.image ~= 'none' then | ||
data.image = args.image | data.image = args.image | ||
end | end | ||
-- Copy over data that | -- Copy over data that doesn't need adjusting | ||
local argsToCopy = { | local argsToCopy = { | ||
-- Styles | -- Styles | ||
'style', | 'style', | ||
'textstyle', | 'textstyle', | ||
-- Above row | -- Above row | ||
| Line 69: | Line 66: | ||
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) | ||
end | end | ||
-- 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 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 | ||
| Line 130: | Line 120: | ||
-- 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 | ||
return tostring(root) | |||
return | |||
end | end | ||
return p | return p | ||