Module:Message box: Difference between revisions

Content added Content deleted
(more abstraction for box structure and better small=yes support)
(add imbox)
Line 2: Line 2:


local htmlBuilder = require('Module:HtmlBuilder')
local htmlBuilder = require('Module:HtmlBuilder')
local yesno = require('Module:Yesno')


local p = {}
local p = {}
Line 14: Line 15:
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 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 isSmall = (args.small == 'yes' or args.small == true) and true or false
local image, imageRight, text, imageSize
local image, imageRight, text, imageSize
if isSmall then
if isSmall then
Line 24: Line 25:
imageRight = args.smallimageright or args.imageright
imageRight = args.smallimageright or args.imageright
text = args.smalltext or args.text
text = args.smalltext or args.text
imageSize = data.imageSizeSmall or data.imageSize
imageSize = data.imageSizeSmall or data.imageSize or '40x40px'
else
else
image = args.image
image = args.image
imageRight = args.imageright
imageRight = args.imageright
text = args.text
text = args.text
imageSize = data.imageSizeLarge or data.imageSize
imageSize = data.imageSizeLarge or data.imageSize or '40x40px'
end
end


Line 43: Line 44:
end
end
box
box
.addClass(isSmall and 'mbox-small')
.addClass(data.classPlainlinksYesno and yesno(args.plainlinks or true) and 'plainlinks')
.addClass(typeData.class)
.addClass(typeData.class)
.addClass(args.class)
.addClass(args.class)
Line 55: Line 58:
elseif data.imageEmptyCell then
elseif data.imageEmptyCell then
row.tag('td')
row.tag('td')
.addClass('mbox-empty-cell')
.addClass('mbox-empty-cell') -- No image. Cell with some width or padding necessary for text cell to have 100% width.
end
end


Line 65: Line 68:


-- Add the right-hand image.
-- Add the right-hand image.
if imageRight then
if imageRight and not (data.imageRightNone and imageRight == 'none') then
row.tag('td')
row.tag('td')
.addClass('mbox-imageright')
.addClass('mbox-imageright')
.wikitext(imageRight)
.wikitext(imageRight)
end

-- Add the below row.
if data.below and args.below then
box.tag('tr')
.tag('td')
.attr('colspan', args.imageright and '3' or '2')
.addClass('mbox-text')
.cssText(args.textstyle)
.wikitext(args.below)
end
end


Line 102: Line 115:
data.default = 'system'
data.default = 'system'
data.classes = { 'plainlinks', 'fmbox' }
data.classes = { 'plainlinks', 'fmbox' }
data.imageSize = '40x40px'
data.imageEmptyCell = false
data.imageEmptyCell = false
data.imageRightNone = false
return p.build(data, args)
return p.build(data, args)
end
end
Line 144: Line 157:
data.imageSizeSmall = '30x30px'
data.imageSizeSmall = '30x30px'
data.imageEmptyCell = true
data.imageEmptyCell = true
data.imageRightNone = true
return p.build(data, args)
end

function p._imbox(args)
local data = {}
data.types = {
speedy = {
class = 'imbox-speedy',
image = 'Imbox speedy deletion.png'
},
delete = {
class = 'imbox-delete',
image = 'Imbox deletion.png'
},
content = {
class = 'imbox-content',
image = 'Imbox content.png'
},
style = {
class = 'imbox-style',
image = 'Edit-clear.svg'
},
move = {
class = 'imbox-move',
image = 'Imbox move.png'
},
protection = {
class = 'imbox-protection',
image = 'Imbox protection.png'
},
license = {
class = 'imbox-license',
image = 'Imbox license.png'
},
featured = {
class = 'imbox-featured',
image = 'Imbox featured.png'
},
notice = {
class = 'imbox-notice',
image = 'Imbox notice.png'
}
}
data.default = 'notice'
data.classes = {'imbox'}
data.classPlainlinksYesno = true
data.imageEmptyCell = true
data.below = true
return p.build(data, args)
return p.build(data, args)
end
end
Line 178: Line 240:


p.fmbox = makeWrapper(p._fmbox)
p.fmbox = makeWrapper(p._fmbox)
p.imbox = makeWrapper(p._imbox)
p.ombox = makeWrapper(p._ombox)
p.ombox = makeWrapper(p._ombox)