Module:Mbox
Jump to navigation
Jump to search
-- <nowiki>
local Mbox = {}
local getArgs = require('Dev:Arguments').getArgs
function Mbox.main(frame)
local args = getArgs(frame)
-- left border color
if args.bordercolor then
bordercolor = args.bordercolor
elseif args.type then
if args.type == 'important' then
bordercolor = 'rgba(200, 0, 0, 0.8)'
elseif args.type == 'moderate' then
bordercolor = 'rgba(233, 124, 47, 0.8)'
elseif args.type == 'minor' then
bordercolor = 'rgba(241, 197, 37, 0.8)'
end
end
-- image
local image = args.image or ''
local imagewidth = args.imagewidth or '40px'
local imagelink = '|link='
if args.imagelink then
imagelink = imagelink .. args.imagelink
end
local imagewikitext = '[[File:' .. image .. '|' .. imagewidth .. imagelink .. ']]'
-- construct mbox
local container = mw.html.create('div')
:addClass('mbox')
:addClass(args.class)
:css('border-left-color', bordercolor)
:cssText(args.style)
local content = container:tag('div')
:addClass('mbox__content')
if args.image then
local image = content:tag('div')
:addClass('mbox__content__image')
:wikitext(imagewikitext)
end
local contentwrapper = content:tag('div')
:addClass('mbox__content__wrapper')
if args.header then
contentwrapper:tag('div')
:addClass('mbox__content__header')
:wikitext(args.header)
end
if args.text then
local text = contentwrapper:tag('div')
:addClass('mbox__content__text')
:wikitext(args.text)
if args.comment then
text:tag('div')
:addClass('mbox__content__text__comment')
:wikitext(args.comment)
end
end
if args.aside then
local aside = content:tag('div')
:addClass('mbox__content__aside')
:wikitext(args.aside)
end
return container
end
return Mbox