Module:Mbox

-- local Mbox = {} local getArgs = require('Dev:Arguments').getArgs

function Mbox.main(frame) local args = getArgs(frame)

-- styles local styles = {} styles['border-left-color'] = args.bordercolor styles['background-color'] = args.bgcolor

-- images local image = args.image or '' local imageadjust = '' if args.imageadjust then imageadjust = '|' .. args.imageadjust end local imagewidth = args.imagewidth or '80px' local imagelink = '|link=' local imagelinkarg = args.imagelink if imagelinkarg then imagelink = imagelink .. imagelinkarg end

local imagewikitext = ''

-- id for closure local id = args.id or 'mbox' local typeclass = args.type

local container = mw.html.create('div') :addClass('mbox') :addClass(typeclass and ('mbox-type-' .. typeclass)) :addClass(args.class) :css(styles) :cssText(args.style)

local content = container:tag('div') :addClass('mbox__content') local collapsed = args.collapsed

if image ~= '' then local image = content:tag('div') :addClass('mbox__content__image') :addClass('mw-collapsible') :attr('id', 'mw-customcollapsible-' .. id) :wikitext(imagewikitext) if collapsed then image:addClass('mw-collapsed') end end -- dev:FandomIcons support local icon = args.icon or '' if icon ~= '' then local icon = content:tag('div') :addClass('mbox__content__image') :addClass('fandom-icons') :addClass('mw-collapsible') :attr('id', 'mw-customcollapsible-' .. id) :wikitext(icon) if collapsed then icon:addClass('mw-collapsed') end end

local contentwrapper = content:tag('div') :addClass('mbox__content__wrapper') local header = args.header

if header then contentwrapper:tag('div') :addClass('mbox__content__header') :wikitext(header) end

local textarg = args.text if textarg then local text = contentwrapper:tag('div') :addClass('mbox__content__text') :addClass('mw-collapsible') :attr('id', 'mw-customcollapsible-' .. id) :wikitext(textarg) if collapsed then text:addClass('mw-collapsed') end

local comment = args.comment if comment then text:tag('div') :addClass('mbox__content__text__comment') :wikitext(comment) end end

contentwrapper:tag('span') :addClass('mbox__close') :addClass('mw-customtoggle-' .. id) :attr('title', 'Dismiss')

local asidearg = args.aside if asidearg then local aside = content:tag('div') :addClass('mbox__content__aside') :addClass('mw-collapsible') :attr('id', 'mw-customcollapsible-' .. id) :wikitext(asidearg) if collapsed then aside:addClass('mw-collapsed') end end

return container end

return Mbox