Module:Message box: Difference between revisions
Content added Content deleted
(start work on a module for displaying Template:Mbox-family message boxes) |
(more abstraction for box structure and better small=yes support) |
||
Line 4: | Line 4: | ||
local p = {} |
local p = {} |
||
local function generateBoxStructure() |
|||
⚫ | |||
⚫ | |||
local row = box.tag('tr') |
|||
return root, box, row |
|||
end |
|||
function p.build(data, args) |
function p.build(data, args) |
||
-- Process config data |
-- Process config data. |
||
local isSmall = args.small == 'yes' or args.small == true |
local isSmall = args.small == 'yes' or args.small == true |
||
local typeData = data.types[args.type] |
local typeData = data.types[args.type] |
||
local invalidType = args.type and not typeData and true or false |
local invalidType = args.type and not typeData and true or false |
||
typeData = typeData or data.types[data.default] |
typeData = typeData or data.types[data.default] |
||
local image, imageRight, text, imageSize |
|||
if isSmall then |
|||
image = args.smallimage or args.image |
|||
imageRight = args.smallimageright or args.imageright |
|||
text = args.smalltext or args.text |
|||
imageSize = data.imageSizeSmall or data.imageSize |
|||
else |
|||
⚫ | |||
imageRight = args.imageright |
|||
⚫ | |||
imageSize = data.imageSizeLarge or data.imageSize |
|||
end |
|||
-- Get the box structure. |
|||
local root, box, row = generateBoxStructure() |
|||
-- Build the box. |
-- Build the box. |
||
⚫ | |||
⚫ | |||
box |
box |
||
.attr('id', args.id) |
.attr('id', args.id) |
||
Line 28: | Line 49: | ||
-- Add the left-hand image. |
-- Add the left-hand image. |
||
if image ~= 'none' then |
|||
if args.image ~= 'none' then |
|||
row.tag('td') |
row.tag('td') |
||
.addClass('mbox-image') |
.addClass('mbox-image') |
||
.wikitext( |
.wikitext(image or mw.ustring.format('[[File:%s|%s|link=|alt=]]', typeData.image, imageSize)) |
||
'[[File:%s|%s|link=|alt=]]', |
|||
⚫ | |||
(args.small == 'yes' or args.small == true) and data.imageSizeSmall or data.imageSizeLarge or data.imageSize |
|||
⚫ | |||
elseif data.imageEmptyCell then |
elseif data.imageEmptyCell then |
||
row.tag('td') |
row.tag('td') |
||
Line 46: | Line 62: | ||
.addClass('mbox-text') |
.addClass('mbox-text') |
||
.cssText(args.textstyle) |
.cssText(args.textstyle) |
||
.wikitext( |
.wikitext(text) |
||
-- Add the right-hand image. |
-- Add the right-hand image. |
||
if |
if imageRight then |
||
row.tag('td') |
row.tag('td') |
||
.addClass('mbox-imageright') |
.addClass('mbox-imageright') |
||
.wikitext( |
.wikitext(imageRight) |
||
end |
end |
||